Skip to content

kvm: treat an RBD snapshot whose image is gone as deleted - #14932

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:kvm-rbd-snapshot-image-gone
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:kvm-rbd-snapshot-image-gone

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Contributor

Description

On KVM with Ceph RBD and snapshot.backup.to.secondary=false, deleting a volume that has snapshots takes about 5 minutes, and the snapshots stay listed as BackedUp afterwards. They can't be used, and every deleteSnapshot on them fails after another 5 minutes with "Failed to delete snapshot chain". Expunging a VM goes through the same path for its ROOT volume.

Deleting the volume removes its RBD snapshots together with the image. The management server then deletes each primary-only snapshot of the volume, and the agent's KVMStorageProcessor.deleteSnapshot looked the image up through KVMStoragePoolManager.getPhysicalDisk. That call retries a missing volume 100 times, 3 seconds apart, to wait for volumes created on another host. The image never comes back, so the delete fails, and deleteVolumeCallback ignores the failure without marking the snapshots destroyed.

The agent now looks the snapshot's own image (the middle part of its <pool>/<image>/<snapshot> path) up once before anything else. If librbd reports the image as not found, the snapshot went with it and the delete succeeds at once. Any other error, including librados reporting the pool as missing, falls through to the existing path unchanged. Snapshots already left behind this way become deletable with a plain deleteSnapshot once the agents run this code.

Fixes: #14931

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 in KVMStorageProcessorTest: the image lookup reports gone only for an RbdException with ENOENT in the cause chain (not for other RBD errors, and not for a librados ENOENT, which means the pool is missing); deleteSnapshot answers success without the retrying lookup when the image is gone, and takes the existing path when it is not. 45 passed (of 45). With the early return disabled, the gone-image test fails.

A lab test on a nested KVM + Ceph setup will follow in a comment.

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

  • A snapshot whose volume moved to another image: the check uses the snapshot's own image, not the volume's current path, so a surviving old image is not reported as gone.
  • A missing pool, or Ceph errors other than ENOENT: not treated as gone; the delete takes the existing path.
  • Normal snapshot deletes with the image present: unchanged apart from one extra read-only open of the image.
Deleting a volume on RBD removes its snapshots with the image. When
snapshots are kept only on primary storage, the management server then
deletes each of the volume's snapshots, and the agent looked up the image
through KVMStoragePoolManager.getPhysicalDisk, which retries a missing
volume 100 times, 3 seconds apart. After about 5 minutes the delete failed,
so the volume delete took 5 minutes and its snapshots stayed listed as
BackedUp: they could not be used, and every later deleteSnapshot failed the
same way.

Look the snapshot's image up once. If librbd reports it as not found, the
snapshot is gone with it and the delete succeeds.

Fixes apache#14931

Signed-off-by: Brad House <bhouse@nexthop.ai>
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 18.34%. Comparing base (069ac79) to head (e17ca0e).

Files with missing lines Patch % Lines
...ud/hypervisor/kvm/storage/KVMStorageProcessor.java 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #14932   +/-   ##
=========================================
  Coverage     18.34%   18.34%           
- Complexity    16670    16672    +2     
=========================================
  Files          5939     5939           
  Lines        537814   537827   +13     
  Branches      65937    65940    +3     
=========================================
+ Hits          98637    98661   +24     
+ Misses       427953   427942   -11     
  Partials      11224    11224           
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.43% <92.30%> (+<0.01%) ⬆️

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.
@bhouse-nexthop

Copy link
Copy Markdown
Contributor Author

Tested on a nested lab: one management server, three KVM hosts, Ceph RBD primary storage, snapshot.backup.to.secondary=false and kvm.incremental.snapshot=true. The lab runs a build of main with this change cherry-picked (the code is the same as on 4.22).

Control on the build without the change: a data volume with one RBD-only snapshot, detached, then deleteVolume. It returned after 306 s; the image was gone, and the snapshot was left BackedUp with a Ready Primary store ref.

With the change installed on all three agents:

Case Before After
deleteSnapshot of the snapshot left behind by the control fails after ~5 min succeeds in 2 s: Destroyed, not listed, no Ready ref
deleteVolume of a volume with an RBD-only snapshot 306 s, snapshot left behind 3 s, snapshot Destroyed, not listed
Destroy with expunge of a VM with a ROOT snapshot (stopped first) same path as above 11 s, snapshot Destroyed, not listed
Snapshot delete with the image present: one snapshot, and the middle of three (others keep their data, revert to first and last) unchanged: the RBD snapshot is removed, 14/14 and 44/44 checks

In every case Ceph was left with no RBD snapshots beyond the baseline and nothing was written to secondary storage. The agent logs show the new path taken once per gone-image delete:

INFO  [kvm.storage.KVMStorageProcessor] RBD image cloudstack/<image> no longer exists, so its snapshot <snapshot> was removed with it.

Not tested: the 4.22 build itself on the lab (the unit tests pass on 4.22), and pools other than RBD, which this change does not touch.

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

2 participants