You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KVM: create an encrypted RBD volume with room for its LUKS2 header - #14725
KVM: create an encrypted RBD volume with room for its LUKS2 header
librbd keeps the LUKS2 header in the RBD image, in front of the data, so an
encrypted RBD volume created with the size of its volume showed the Instance
16 MiB less, while a qemu LUKS volume on NFS, SharedMountPoint or local
storage shows the Instance the size of its volume. Create the image of an
encrypted RBD volume with room for the header instead, so that the Instance
sees the size of the volume on every pool type, and the size of the volume
in the database is what the Instance sees.
The size of the header is the larger of 16 MiB and the object size of the
image (measured: 16 MiB with objects of 1 to 16 MiB, 32 MiB with objects of
32 MiB), so the image is grown when its objects are larger.
- LibvirtStorageAdaptor.createPhysicalDisk() creates an encrypted RBD
image with the header on top of the size it is given.
- LibvirtResizeVolumeCommandWrapper answers with the size the Instance
sees for an encrypted RBD volume, so the database no longer gets the
size of the image (the size of the volume + 16 MiB) after a resize.
- The CoW clone of a template for an encrypted ROOT volume is made from a
snapshot of the template grown by the header, and the template is shrunk
back right after the snapshot. The template used to stay 16 MiB larger, so
the next unencrypted clone of it, if its base snapshot did not exist yet,
was 16 MiB larger than its template. The clone is grown to the requested
size from its own size, and the full copy of a template makes room for a
header larger than 16 MiB as well.
Tests:
- unit test for the size of the header
- the TestVolumeEncryption smoke tests already expect the Instance to see
the size of the volume
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?
When qemu-img convert into an RBD pool failed or timed out, the half-written
image was left behind. Every later copy of the same template then failed with
"rbd create: File exists", so deployments from that template broke on the pool
until the image was removed by hand.
- check whether the destination RBD image exists before converting, and refuse
to overwrite it, as it may be a complete image used by clones
- remove the image again if the copy created it and then failed
- do not print the Ceph key in the "Failed to convert" error
librbd keeps the LUKS2 header in the RBD image, in front of the data, so an
encrypted RBD volume created with the size of its volume showed the Instance
16 MiB less, while a qemu LUKS volume on NFS, SharedMountPoint or local
storage shows the Instance the size of its volume. Create the image of an
encrypted RBD volume with room for the header instead, so that the Instance
sees the size of the volume on every pool type, and the size of the volume
in the database is what the Instance sees.
The size of the header is the larger of 16 MiB and the object size of the
image (measured: 16 MiB with objects of 1 to 16 MiB, 32 MiB with objects of
32 MiB), so the image is grown when its objects are larger.
- LibvirtStorageAdaptor.createPhysicalDisk() creates an encrypted RBD
image with the header on top of the size it is given.
- LibvirtResizeVolumeCommandWrapper answers with the size the Instance
sees for an encrypted RBD volume, so the database no longer gets the
size of the image (the size of the volume + 16 MiB) after a resize.
- The CoW clone of a template for an encrypted ROOT volume is made from a
snapshot of the template grown by the header, and the template is shrunk
back right after the snapshot. The template used to stay 16 MiB larger, so
the next unencrypted clone of it, if its base snapshot did not exist yet,
was 16 MiB larger than its template. The clone is grown to the requested
size from its own size, and the full copy of a template makes room for a
header larger than 16 MiB as well.
Tests:
- unit test for the size of the header
- the TestVolumeEncryption smoke tests already expect the Instance to see
the size of the volume
Thanks for your work on encrypted RBD volumes. Great work!
I have created this PR to allocate an additional 16 MiB or 32 MiB for the LUKS2 header of encrypted volumes on Ceph RBD. This ensures that the guest VM sees the exact volume size reported by CloudStack, keeping the behaviour consistent with encrypted volumes on NFS, Local and StorPool.
With the current implementation, the size visible inside the guest OS is the RBD volume size minus the 16 MiB LUKS2 header.
Please note that this change might affect your PR #14656.
❌ Patch coverage is 4.08163% with 141 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.81%. Comparing base (c5bd11a) to head (d3521a7). ⚠️ Report is 13 commits behind head on main.
@nvazquez
I added this to 24.0.
I think it would be better to address the issue before a major release, otherwise it might be difficult to update existing volumes created before this fix
@weizhouapache 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.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Active moderate and critical findings remain in LibvirtStorageAdaptor, including invalid Ceph monitor-port handling, incomplete legacy snapshot migration, and a race that can delete another operation’s image.
This PR updates KVM RBD volume handling so librbd LUKS2 encryption reserves space for the encryption header while instances and CloudStack consistently see the requested usable volume size.
Changes:
Adds object-size-aware LUKS2 header reservation for encrypted RBD images.
Adjusts encrypted RBD resize reporting and template clone/full-copy sizing.
Adds RBD key masking, copy cleanup handling, and unit tests for header sizing and error sanitization.
- leave the monitor port out of mon_host when the pool has none
- copy into a staging RBD image and rename it, so that an image created by
another operation is neither overwritten nor removed when the copy fails
@weizhouapache 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.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical unresolved race and size-mismatch issues can leave templates oversized and produce clones larger than requested, while the review also lacks the requested smoke-test evidence.
The PR description lists tests and notes that the smoke suite expects this behavior, but it does not include evidence of an independent test run. Please add a test-run link and result showing this change was exercised by someone other than the PR author; the tester may also be an approver.
Link the successful TestVolumeEncryption smoke run
The PR description identifies TestVolumeEncryption as the relevant smoke suite but provides no run result. Please add a link to the successful smoke run and its TestVolumeEncryption result to the PR description.
…he requested size
- when another deployment prepares the reserved snapshot first, restore the template to the size its snapshot tells
instead of the size this deployment saw
- resize the encrypted clone when its size differs from the requested one, shrinking it if the header of the clone
is smaller than the one reserved in the snapshot
I have merged this PR into #14426 , and handled volume migration between RBD and other storage pools to ensure that the volume size remains consistent inside the guest OS.
…tate
Record the connectToCeph unification, the radosConnect removal, and
the checkstyle fixup cherry-picked onto 4.23.0-ceph as commits 112
to 114, all owned by apache#14426. Also reflect that apache#14725 was closed on
GitHub with its content folded into apache#14426, rather than merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?