Skip to content

KVM: migrate volumes without a backing file as full clones - #14974

Open
Alpha162 wants to merge 1 commit into
apache:4.22from
Alpha162:kvm-live-migration-flat-volume
Open

Alpha162 wants to merge 1 commit into
apache:4.22from
Alpha162:kvm-live-migration-flat-volume

Conversation

@Alpha162

@Alpha162 Alpha162 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes #14963.

On KVM, migrateVirtualMachineWithVolume treats a volume as a linked clone whenever it has a template ID and that template is cached on the volume's current pool (getVolumeBackingFile() reads template_spool_ref). It never looks at the disk. A volume with no backing file is then created on the destination on top of the template and copied incrementally (migrateNonSharedInc), so every region that isn't allocated in the source file reads template data afterwards. The job reports success.

A volume has no backing file after an offline migrateVolume between pools, which flattens it and turns ranges the guest zeroed into holes, or when it was created with create.full.clone=true. #14963 has the details, including a Windows guest that failed to boot after this.

With this change, before choosing the linked-clone path for a volume on a file-based pool (NFS, SharedMountPoint or local), the management server asks the source host for the volume's backing file. It uses the existing GetVolumesOnStorageCommand, so the agent doesn't change. A volume without a backing file is migrated as a full clone. Other pool types keep the current behaviour.

If the host can't answer, or doesn't find the volume, the migration fails with an error before anything is created for that volume. Falling back to a full clone would also be safe for the data, just slower. I chose to stop because a host that can't run qemu-img info on the disk is unlikely to migrate it, but I'm happy to switch if reviewers prefer.

Fixes: #14963

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?

Unit tests: seven new tests in StorageSystemDataMotionStrategyTest for hasBackingFileOnSourceHost (backing file present, backing file absent, local and SharedMountPoint pools, a pool type that isn't asked, no answer, a failed answer, volume not found). All 65 tests in org.apache.cloudstack.storage.motion pass.

Lab: CloudStack 4.22.0.1 on Ubuntu 24.04 (QEMU 8.2.2, libvirt 10.0.0), two KVM hosts in one cluster, two cluster-wide NFS primary pools and the built-in CentOS 5.5 template. This diff applies cleanly to the 4.22.0.1 tag, so I built it there and swapped only this class on the management server. I ran the same steps on a fresh VM with each build, and checked two 1 MiB regions that hold template data by reading them with qemu-io -r -U on the host.

Step 4.22.0.1 With this PR
Live migration with storage of a normal linked clone to the other host and pool Linked clone, backing file kept Same. The host check returned the backing file in about 50 ms
Stop the VM, zero both regions (write -P 0 and discard), offline migrateVolume to the other pool, start the VM No backing file, and both regions are holes that read zeros Same
Live migration with storage to the other host and pool Job succeeds. The template is the backing file again, and both regions read template data Job succeeds. No backing file, and both regions still read zeros. The management log says the volume "will be migrated as a full clone"

I didn't repeat the create.full.clone=true case with this build. Those volumes have no backing file either, so they take the same path as the flattened one.

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

  • A volume path with the .qcow2 suffix that an offline move adds: the host found it.
  • Data disks and ISO-based volumes have no template ID, so the host isn't asked.
  • Managed storage, and pools that don't keep volumes as files, skip the check and behave as before.
  • On main this applies with two small conflicts, both next to the new CLVM code.
  • kvm: fix direct-download live storage migration #14101 changes the same decision for direct-download templates. The two touch nearby lines, so whichever lands second needs a small merge.

AI assistance: I used Claude Code and Mythos to help investigate, write and test this change. The tests ran on our own labs, and I've checked the results.

migrateVirtualMachineWithVolume treated a volume as a linked clone
whenever it had a template ID and that template was cached on the
volume's current pool. It never looked at the disk. A volume with no
backing file, because an offline migrateVolume flattened it or it was
created with create.full.clone=true, was then created on the
destination on top of the template and copied incrementally. Every
region that wasn't allocated in the source file, including ranges the
guest had zeroed, read template data afterwards, and the job reported
success.

Before choosing the linked-clone path for a volume on a file-based pool
(NFS, SharedMountPoint or local), the management server now asks the
source host for the volume's backing file with GetVolumesOnStorageCommand.
A volume without one is migrated as a full clone. If the host can't
answer, the migration fails with an error before anything is created
for that volume.

Fixes apache#14963

Generated-by: Claude Code (claude-mythos-5-2)

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.

1 participant