Skip to content

File-based disk-only VM snapshot with KVM as hypervisor - #10632

Merged
DaanHoogland merged 15 commits into
apache:mainfrom
scclouds:kvm-disk-only-vm-snapshot
Jul 16, 2025
Merged

File-based disk-only VM snapshot with KVM as hypervisor#10632
DaanHoogland merged 15 commits into
apache:mainfrom
scclouds:kvm-disk-only-vm-snapshot

Conversation

@JoaoJandre

Copy link
Copy Markdown
Contributor

Description

This PR implements the spec available at #9524. For more information regarding it, please read the spec.

Furthermore, the following changes that are not contemplated in the spec were added:

  1. The snapshot.merge.timeout agent property was added. It is only considered if libvirt.events.enabled is true;
  2. A new snapshot merge process (which affects normal volume snapshots and this feature) was created. When libvirt.events.enabled is true, ACS will register to gather events from Libvirt and will collect information on the process, providing a progress report in the logs. If the configuration is false, the old process is used;
  3. Volumes attached to VMs with file-based disk-only VM snapshots in KVM are able to be resized.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Basic Tests

I created a test VM to carry out the tests below. Additionally, after performing the relevant operations, the VM's XML and the storage were checked to observe if the snapshots existed.

Snapshot Creation

The tests below were also repeated with the VM stopped.

NTestResult
1Take a snapshot of VM 1 without specifying quiesceVMSnapshot created
2Take a snapshot of VM 2 specifying quiesceVMSnapshot created

Snapshot Reversion

NTestResult
1Revert VM in Running state to any snapshotError thrown
2Revert VM in Stopped state to snapshot 1 and start itVM reverted and started successfully

Snapshot Removal

NTestResult
1Create a new snapshot 3 after the second reversion test and delete snapshot 1I verified that the snapshot was no longer listed and had the correct database metadata, the file still existed because more than one delta depended on it
2Delete snapshot 2Snapshot deleted; snapshot 1 was merged with snapshot 3 since it only had the latter as a dependency
3Delete snapshot 3 (current)Snapshot removed, merged with the VM's volume
4Create 3 snapshots and remove the first oneSnapshot removed, merged with the second snapshot
5Create two snapshots, revert to the first, and delete the secondSnapshot deleted

Advanced Tests

Deletion Test

All tests were carried out with the VM stopped.

  1. I created 3 snapshots: s1, s2, and s3.
  2. I reverted the VM to snapshot s2.
  3. I created snapshot s4.
  4. I removed snapshot s2.

The snapshot was marked as hidden and was not removed from storage.

  1. I removed snapshot s3.

Snapshot s3 was removed normally. Snapshot s2 was merged with snapshot s4.

  1. I created snapshot s5.
  2. I reverted to snapshot s4.
  3. I removed snapshot s4.

Snapshot s4 was marked as hidden and was not removed from storage.

  1. I removed snapshot s5.
    Snapshot s5 was removed normally. Snapshot s4 was merged with the delta of the VM's volume.
  2. I removed the last remaining snapshot (s1). It was removed normally.

Reversion Test

  1. I created two snapshots: s1 and s2.
  2. I reverted to snapshot s1.
  3. I removed snapshot s1.

Snapshot s1 was marked as hidden and was not removed from storage.

  1. I reverted to snapshot s2. Snapshot s1 was merged with the base volume.

Concurrent Test

I created 4 VMs and took a VM snapshot of each. Then, I instructed to remove them all at the same time. All snapshots were removed simultaneously and successfully.

Test with Multiple Volumes

I created a VM with one datadisk and attached 8 more datadisks (10 volumes in total), took two VM snapshots, and then instructed to remove one at a time. The snapshots were removed successfully.

Tests Changing the snapshot.merge.timeout Config

  1. I changed the config to 1 and restarted the host;
  2. I created a VM, took a VM snapshot, accessed it, and wrote 4GB of data to it;
  3. I tried to remove the snapshot, an error occurred, and looking at the logs, it was possible to observe that it timed out;
  4. I manually aborted the blockcommit process;
  5. I changed the config to 0 and restarted the host;
  6. I tried to remove the snapshot, and it was performed correctly;

Tests Related to Volume Resize with Disk-Only VM Snapshots on KVM

TestResultExpected?
Create a VM, take a snapshot, resize the volumeResize performed successfully, both in metadata and when checked with qemu-img infoY
Stop the VM and revert the snapshotRevert performed successfully, volume size returned to original, both in metadata and qemu-img infoY
Remove the snapshot with the VM stoppedThe delta of the volume was correctly merged with the snapshot's, and the final size was that of the volumeY
Start the VM, take a new snapshot, resize the volume, and remove the snapshotDeltas were correctly merged, and the final size was that of the volumeY

The last two tests were repeated on a VM with several snapshots, so that a merge between snapshots was performed. The result was the same.

Tests Related to Events:

  1. Create VM, take disk-only VM snapshot, resize the root volume by 1GB more, stop the VM, revert the snapshot. It was observed through the cloud.usage_event table that the resize event was correctly triggered, and it was also observed via GUI that the account's resource limit was updated.
  2. Repeat the test above with a VM with two volumes, with only one resized. The test had the same result, and only one resize event was triggered, for the volume that had been resized.

@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@codecov

codecovBot commented Mar 28, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 9.41402% with 943 lines in your changes missing coverage. Please review.

Project coverage is 16.56%. Comparing base (6fdaf51) to head (44868f6).
Report is 140 commits behind head on main.

Files with missing linesPatch %Lines
...napshot/KvmFileBasedStorageVmSnapshotStrategy.java0.24%414 Missing and 1 partial ⚠️
...LibvirtCreateDiskOnlyVMSnapshotCommandWrapper.java1.04%95 Missing ⚠️
...ervisor/kvm/resource/LibvirtComputingResource.java43.93%71 Missing and 3 partials ⚠️
.../LibvirtMergeDiskOnlyVMSnapshotCommandWrapper.java1.38%71 Missing ⚠️
...LibvirtRevertDiskOnlyVMSnapshotCommandWrapper.java1.96%50 Missing ⚠️
...d/hypervisor/kvm/resource/BlockCommitListener.java28.12%22 Missing and 1 partial ⚠️
...m/cloud/agent/api/storage/SnapshotMergeTreeTO.java0.00%21 Missing ⚠️
...tack/storage/snapshot/DefaultSnapshotStrategy.java0.00%19 Missing ⚠️
...java/org/apache/cloudstack/utils/qemu/QemuImg.java0.00%19 Missing ⚠️
...nt/api/storage/MergeDiskOnlyVmSnapshotCommand.java0.00%18 Missing ⚠️
... and 19 more
Additional details and impacted files
@@ Coverage Diff @@## main #10632 +/- ##
============================================
+ Coverage 16.41% 16.56% +0.15% - Complexity 13629 14008 +379 
============================================
Files 5702 5758 +56 Lines 503405 511750 +8345 Branches 60976 62242 +1266 ============================================
+ Hits 82626 84774 +2148 - Misses 411594 417506 +5912 - Partials 9185 9470 +285 
FlagCoverage Δ
uitests3.91% <ø> (-0.09%)⬇️
unittests17.46% <9.41%> (+0.18%)⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@JoaoJandre a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13204

@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

@rohityadavcloud@sureshanaparti@weizhouapache could we run the CI?

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-13177)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 54050 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10632-t13177-kvm-ol8.zip
Smoke tests completed. 140 look OK, 1 have errors, 0 did not run
Only failed and skipped tests results shown below:

TestResultTime (s)Test File
test_02_restore_vm_strict_tags_failureFailure53.35test_vm_strict_host_tags.py
test_02_scale_vm_strict_tags_failureFailure54.75test_vm_strict_host_tags.py
test_06_deploy_vm_on_any_host_with_strict_tags_failureFailure4.69test_vm_strict_host_tags.py

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-13740)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 88337 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10632-t13740-kvm-ol8.zip
Smoke tests completed. 129 look OK, 12 have errors, 0 did not run
Only failed and skipped tests results shown below:

TestResultTime (s)Test File
test_04_autoscale_kubernetes_clusterFailure97.38test_kubernetes_clusters.py
test_nic_secondaryip_add_removeError1527.10test_multipleips_per_nic.py
ContextSuite context=TestNestedVirtualization>:setupError0.00test_nested_virtualization.py
ContextSuite context=TestNetworkACL>:setupError0.00test_network_acl.py
ContextSuite context=TestIpv6Network>:setupError0.00test_network_ipv6.py
test_delete_accountError1517.23test_network.py
test_delete_network_while_vm_on_itError1.22test_network.py
test_deploy_vm_l2networkError1.22test_network.py
test_l2network_restartError2.46test_network.py
ContextSuite context=TestPortForwarding>:setupError3.75test_network.py
ContextSuite context=TestPublicIP>:setupError13.47test_network.py
test_reboot_routerFailure0.10test_network.py
test_releaseIPError7.04test_network.py
test_releaseIP_using_IPError6.64test_network.py
ContextSuite context=TestRouterRules>:setupError6.72test_network.py
ContextSuite context=TestSharedNetworkWithConfigDrive>:setupError1522.41test_network.py
ContextSuite context=TestPrivateGwACL>:setupError0.00test_privategw_acl.py
ContextSuite context=TestAdapterTypeForNic>:setupError0.00test_nic_adapter_type.py
ContextSuite context=TestNonStrictAffinityGroups>:setupError0.00test_nonstrict_affinity_group.py
ContextSuite context=TestIsolatedNetworksPasswdServer>:setupError0.00test_password_server.py
ContextSuite context=TestPortForwardingRules>:setupError0.00test_portforwardingrules.py
ContextSuite context=TestProjectSuspendActivate>:setupError1528.69test_projects.py

@DaanHooglandDaanHoogland linked an issue Jul 10, 2025 that may be closed by this pull request
@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

@DaanHoogland I'm pretty sure these test results are not linked to this PR, could we try one more time?

Comment threadserver/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java Outdated
Comment threadserver/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java Outdated
@sureshanapartisureshanaparti moved this from Done to In Progress in Apache CloudStack 4.21.0Jul 14, 2025
@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

@slavkap I've pushed a new commit based on your suggestions. Could you check?

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✖️ debian ✔️ suse15. SL-JID 14177

@DaanHoogland

Copy link
Copy Markdown
Contributor

I checked the debian build in the background. There is nothing wrong. It was one of those timing unit-test that failed

18:11:30 [ERROR] ConfigKeyScheduledExecutionWrapperTest.scheduleDynamicTest:110 Runnable ran four times per second
18:11:30 Expected: one of {<7>, <8>}
18:11:30 but: was <6>

I think we should modify those to be more robust to virtualised environments.

@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

I checked the debian build in the background. There is nothing wrong. It was one of those timing unit-test that failed

18:11:30 [ERROR] ConfigKeyScheduledExecutionWrapperTest.scheduleDynamicTest:110 Runnable ran four times per second
18:11:30 Expected: one of {<7>, <8>}
18:11:30 but: was <6>

I think we should modify those to be more robust to virtualised environments.

Thanks for checking. I agree we should make these tests more robust.

@DaanHoogland

Copy link
Copy Markdown
Contributor

I checked the debian build in the background. There is nothing wrong. It was one of those timing unit-test that failed

fyi I ran the build in the background and it passes without issues

@JoaoJandre

Copy link
Copy Markdown
ContributorAuthor

@DaanHoogland are we good to merge then?

@DaanHoogland

Copy link
Copy Markdown
Contributor

I'm fine with it.
How about you @slavkap ?

@slavkapslavkap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM
I didn't have time to run tests with NFS except for creating/deleting VM snapshots on running and stopped VMs.
This doesn't affect other storage plug-ins, but I have executed the StorPool tests that have passed

@DaanHoogland
DaanHoogland merged commit 53eb2c5 into apache:mainJul 16, 2025
23 of 26 checks passed
@github-project-automationgithub-project-automationBot moved this from In Progress to Done in Apache CloudStack 4.21.0Jul 16, 2025
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Aug 1, 2025
Co-authored-by: João Jandre <joao@scclouds.com.br>
Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
@JoaoJandreJoaoJandre mentioned this pull request Mar 9, 2026
14 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

KVM Disk-only VM Snapshots Volume Snapshots of an Instance in a Powered Off State

9 participants

@JoaoJandre@blueorangutan@DaanHoogland@yadvr@sureshanaparti@winterhazel@hsato03@slavkap@bernardodemarco