Skip to content

Allow offline migration of encrypted volumes between KVM file pools - #8

Merged
Kukunin merged 3 commits into
4.22-testingfrom
feature/encrypted-volume-migration
Nov 14, 2026
Merged

Kukunin merged 3 commits into
4.22-testingfrom
feature/encrypted-volume-migration

Conversation

@Kukunin

@Kukunin Kukunin commented Nov 14, 2026

Copy link
Copy Markdown

Why

Encrypted volumes cannot be migrated between storage pools at all. VolumeApiServiceImpl refuses unless both ends are StorPool or the source is PowerFlex, so on NFS/local pools every attempt fails with "Migration of encrypted volumes is unsupported".

This blocks us-central1: every production root volume there is LUKS-encrypted on NFS, so moving them to local primary storage is impossible and the region would otherwise have to be rebuilt VM-by-VM rather than migrated.

What was actually broken

One unimplemented method. LibvirtStorageAdaptor.copyPhysicalDisk(...) declares srcPassphrase/dstPassphrase and never reads them — the destination is created unencrypted and qemu-img convert is invoked with no --object secret and no encrypt.* options.

Everything above it already works: KVMStorageProcessor.copyVolumeFromPrimaryToPrimary sets QemuEncryptFormat.LUKS and passes both passphrases, KVMStoragePoolManager plumbs them through, and AncientDataMotionStrategy already selects an encryption-capable endpoint.

Upstream acknowledges this gap verbatim in apache#14453: "offline storage migration of an encrypted volume on NFS/local storage fails because LibvirtStorageAdaptor.copyPhysicalDisk ignores the passphrases."

ScaleIOStorageAdaptor.copyPhysicalDisk already implements the identical signature correctly and is the pattern followed here.

Approach

qemu-img convert with a secret for each side (sec0 source, sec1 destination). The same passphrase bytes are used on both — duplicateVolumeOnAnotherStorage copies passphrase_id — so this re-wraps the master key under the same user passphrase and the DB relationship is unchanged.

Verified beforehand on real volumes that encrypted roots are qcow2 overlays with a template backing file:

file format:  qcow2
encrypted:    yes
backing file: /mnt/<nfs-pool>/<template-uuid>

The backing file does not exist on the destination pool, so a header-preserving file copy is not viable — a flattening convert is required, which this does as a side effect.

Scope

Offline (stopped VM) only, KVM, between NetworkFilesystem / Filesystem / SharedMountPoint. Live volume migration is untouched: KVM already refuses it for these pool types independently of encryption, and that path uses the TO-less MigrateVolumeCommand, which carries no passphrase at all.

Also fixed

DataMotionServiceImpl.cleanUpVolumesForFailedMigrations removed the destination volume's passphrase unconditionally — but source and destination share passphrase_id. Had it fired it would have left the live source volume permanently undecryptable. Now refcount-checked, mirroring VolumeObject.deletePassphrase.

Tests

VolumeApiServiceImplTest     150 tests  0 failures   (+5)
LibvirtStorageAdaptorTest     15 tests  0 failures   (+8, class had no copyPhysicalDisk coverage)
DataMotionServiceImplTest      4 tests  0 failures   (new file)
datamotion module             62 tests  0 failures
kvm module                   696 tests  0 failures, 3 skipped
BUILD SUCCESS (JDK 17.0.20.1)

Unencrypted copies assert argument-level equivalence with the previous call, so the existing path is unchanged.

Note for rebasing

apache#14426 (draft) touches the same four files for online and offline encrypted migration. The diff here is deliberately kept to distinct hunks with no reindentation to keep that rebase cheap.

🤖 Generated with Claude Code

Kukunin and others added 3 commits November 14, 2026 21:00
LibvirtStorageAdaptor.copyPhysicalDisk has declared srcPassphrase and
dstPassphrase since encryption was introduced, but never read them: it
created the destination disk unencrypted and ran a bare qemu-img convert.
Everything above it already carries the passphrase - KVMStorageProcessor
sets LUKS and passes both, KVMStoragePoolManager plumbs them through - so
an encrypted volume copied between two file-based pools landed on the
destination as plaintext-headed garbage.

Open a KeyFile for each passphrase, hand the destination passphrase to
createPhysicalDisk, and pass the source secret as sec0 (via image options,
so it stays out of the destination -o options) and the destination secret
as sec1 with encrypt.format=luks. This mirrors ScaleIOStorageAdaptor.

The qcow2 "cp -f" fast path is skipped when either side is encrypted,
since a file copy cannot re-encrypt. --bitmaps is dropped for an encrypted
source. Copies to or from RBD, and TAR/DIR sources, are rejected outright
rather than silently losing the encryption.

With both passphrases null the qemu-img command is unchanged: the empty
options map and object list render identically to the nulls they replace.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…e pools

migrateVolume refused any encrypted volume unless both ends were StorPool
or the source was PowerFlex. Now that the KVM storage adaptor re-encrypts
during the convert, the file-based pool types can do this too.

Allow it for KVM when both the source and destination pool are one of
NetworkFilesystem, Filesystem or SharedMountPoint and the volume is not
being live migrated. Everything else still throws. The destination pool is
otherwise only resolved below this check, so look it up the same way the
live-migration branch above already does.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ssphrase

cleanUpVolumesForFailedMigrations removed the passphrase row outright, but
VolumeServiceImpl.duplicateVolumeOnAnotherStorage gives the destination
volume the *same* passphrase_id as the source. Removing it would leave the
live source volume permanently undecryptable.

Check for remaining references before removing, the way
VolumeObject.deletePassphrase already does: the destination's own
reference is cleared first, so a non-empty result means the source still
needs the key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Kukunin
Kukunin merged commit dfecae8 into 4.22-testing Nov 14, 2026
14 checks passed
@Kukunin
Kukunin deleted the feature/encrypted-volume-migration branch November 14, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant