Skip to content

CLVM-NG: Support VM snapshots - #14926

Draft
Pearl1594 wants to merge 4 commits into
mainfrom
clvm-ng-vm-snapshots
Draft

Pearl1594 wants to merge 4 commits into
mainfrom
clvm-ng-vm-snapshots

Conversation

@Pearl1594

Copy link
Copy Markdown
Contributor

Description

This PR adds VM snapshot support for the CLVM_NG storage pool type on KVM. Disk-only snapshots work on running and stopped VMs, with UEFI support. Disk+memory snapshots are included as an experimental feature, off by default.

Approach

CLVM_NG volumes are qcow2 images on LVs in a shared VG. A VM snapshot uses external qcow2 overlays, one LV each.

  • Taking a snapshot freezes the volume's current LV as a layer and creates a new delta LV on top, with the layer as its backing file.
  • The agent pre-creates the delta LVs (lvcreate plus qemu-img create -b) before the guest is touched, because libvirt can't create block-backed overlays itself. It then calls snapshotCreateXML with block-typed disks and DISK_ONLY | ATOMIC | NO_METADATA | REUSE_EXT.
  • Revert creates a new overlay on the snapshot layer. Delete merges the delta into its parent: blockcommit --active --pivot for a running VM, qemu-img commit for a stopped one.
  • KvmFileBasedStorageVmSnapshotStrategy handles CLVM_NG. DefaultVMSnapshotStrategy now refuses any VM with a CLVM_NG volume, so no internal snapshot is ever taken on an LV.
  • The storage-specific steps (delta create/delete, sidecars, memory LV) are default methods on StorageAdaptor, implemented by ClvmStorageAdaptor. File-based pools keep their existing behaviour.

UEFI

The guest NVRAM is saved into a small sidecar LV (vmsnapshot-nvram-). Revert restores it, and delete or expunge removes it.

Locking and migration

  • Layers are exclusive after a snapshot and shared while the VM runs.
  • Live migration walks the backing chain (ClvmBackingChain) and activates every layer shared on both hosts, then makes them exclusive on the destination.
  • Stop followed by start on another host releases the old host's layers through ClvmLockTransferCommand DEACTIVATE.
  • Activating a layer retries for up to 180 s while another host holds its lock.
  • Merging first makes the parent layer exclusive.

Experimental: disk+memory

  • The memory goes into its own LV (vmsnapshot-memory-), sized at the VM's maximum memory plus 128 MiB. It is written by libvirt's external memory snapshot.
  • Revert needs a running VM. It creates new overlays, restores the NVRAM for UEFI, and runs virsh restore with the disk paths swapped.
  • It is gated by the zone setting kvm.clvmng.vmsnapshot.memory.enabled (default false).
  • External snapshots were chosen over internal ones. Internal snapshots put RAM in the qcow2, so later writes grow the file on a fixed-size LV and can hit ENOSPC. In a benchmark they were also about 5x slower on first overwrite.

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?

How did you try to break this feature and the system with this change?

@Pearl1594

Copy link
Copy Markdown
Contributor Author

keeping it in draft until QA completes.

@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.58974% with 308 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.08%. Comparing base (85ca17a) to head (1e23cb2).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...oud/hypervisor/kvm/storage/ClvmStorageAdaptor.java 36.76% 80 Missing and 6 partials ⚠️
...LibvirtRevertDiskOnlyVMSnapshotCommandWrapper.java 20.00% 47 Missing and 1 partial ⚠️
...ervisor/kvm/resource/LibvirtComputingResource.java 28.33% 38 Missing and 5 partials ⚠️
...LibvirtCreateDiskOnlyVMSnapshotCommandWrapper.java 46.75% 32 Missing and 9 partials ⚠️
...m/cloud/hypervisor/kvm/storage/StorageAdaptor.java 0.00% 24 Missing ⚠️
.../hypervisor/kvm/storage/clvm/ClvmBackingChain.java 57.89% 18 Missing and 6 partials ⚠️
...napshot/KvmFileBasedStorageVmSnapshotStrategy.java 56.41% 11 Missing and 6 partials ⚠️
.../hypervisor/kvm/storage/KVMStoragePoolManager.java 78.84% 10 Missing and 1 partial ⚠️
...LibvirtDeleteDiskOnlyVMSnapshotCommandWrapper.java 58.33% 4 Missing and 1 partial ⚠️
...a/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java 0.00% 3 Missing and 2 partials ⚠️
... and 2 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14926      +/-   ##
============================================
+ Coverage     20.92%   21.08%   +0.15%     
- Complexity    21142    21332     +190     
============================================
  Files          6057     6059       +2     
  Lines        549556   550282     +726     
  Branches      73477    73578     +101     
============================================
+ Hits         114991   116008    +1017     
+ Misses       421116   420666     -450     
- Partials      13449    13608     +159     
Flag Coverage Δ
uitests 3.86% <ø> (-0.01%) ⬇️
unittests 22.53% <43.58%> (+0.16%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Security Rating on New Code (required ≥ B)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

KVMStoragePool pool = resource.getLibvirtUtilitiesHelper().getPrimaryPoolFromDataTo(snapshotAndNewDelta.getKey(), storagePoolMgr);
domainXml = replaceDiskPath(domainXml, pool.getLocalPathFor(snapshotAndNewDelta.getKey().getPath()), pool.getLocalPathFor(snapshotAndNewDelta.getValue()));
}
Path domainXmlFile = Files.createTempFile("vm-snapshot-restore-", ".xml");
@github-actions

Copy link
Copy Markdown

🔴 Test Coverage Grade: D — Marginal

Metric Value
Line coverage 26.09%
Branch coverage 21.28%

Grade Scale

Grade Line Coverage Meaning
🟢 A ≥ 80% Excellent - this code sleeps well at night 😴
🟡 B 60-79% Good - almost there, don't stop now 😉
🟠 C 40-59% Acceptable - your code is wearing a seatbelt, but no airbags 😬
🔴 D 20-39% Marginal - boldly shipping where no test has gone before 🖖
⛔ F < 20% Failing - tests? what tests? 🔥

Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run

@blueorangutan

Copy link
Copy Markdown

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

@weizhouapache

Copy link
Copy Markdown
Member

great improvement !

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants