Skip to content

rbd: replace O(n) trash list scan with O(1) ID-based trash removal (backport #6472) - #6484

Draft
mergify[bot] wants to merge 4 commits into
release-v3.17from
mergify/bp/release-v3.17/pr-6472
Draft

rbd: replace O(n) trash list scan with O(1) ID-based trash removal (backport #6472)#6484
mergify[bot] wants to merge 4 commits into
release-v3.17from
mergify/bp/release-v3.17/pr-6472

Conversation

@mergify

@mergify mergify Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Describe what this PR does

Replace ensureImageCleanup() - which scans the entire RBD trash list
to find an image by name - with direct O(1) removal by image ID using
the new removeImageFromTrash() helper.

The image ID is always available: modern volumes store it in OMAP at
creation time, and legacy volumes get it backfilled by storeImageID()
during the first generateVolumeFromVolumeID() call.

Commit 1 - rbd: capture parent image ID in getImageInfo

Add ParentImageID field to rbdImage and populate it in
getImageInfo() from GetParent().Image.ImageID. Valid even when the
parent is in trash.

Commit 2 - rbd: make trash remove idempotent and add removeImageFromTrash

Add removeImageFromTrash() as an O(1) helper that removes a trashed
image by its known ID. Make trashRemoveImage() treat ENOENT as success
on both the ceph mgr and direct paths (image already purged).

Commit 3 - rbd: avoid trash ls in DeleteVolume/DeleteSnapshot retry paths

In checkErrAndUndoReserve() and cleanUpImageAndSnapReservation(),
switch from ensureImageCleanup() to removeImageFromTrash(). Also fix
a pre-existing ErrorLog format string mismatch (2 format verbs, 3 args).

Commit 4 - rbd: remove ensureImageCleanup and use ID-based trash removal

In DeleteTempImage(), use the volume's ParentImageID to identify a
trashed temp clone instead of scanning the trash list. Remove
ensureImageCleanup() entirely - no callers remain.

Is there anything that requires special attention

  • DeleteTempImage() relies on being called before rbdVol.Delete() so
    that GetParent() data is still valid. This ordering already exists in
    cleanupRBDImage() and is now documented with a comment.
  • When parent info is unavailable in DeleteTempImage() (temp clone not
    in trash), it returns success - same behavior as the old code when the
    trash scan found nothing.

The change is backward compatible. No API or OMAP schema changes.

Future concerns

  • GetTrashList is still used in waitForCleanTrash() (e2e test helper).
    That is unrelated to production code paths.

Checklist:

  • Commit Message Formatting: Commit titles and messages follow
    guidelines in the developer
    guide
    .
  • Reviewed the developer guide on Submitting a Pull
    Request
  • Pending release
    notes

    updated with breaking and/or notable changes for the next major release.
    N/A - internal optimization, no user-facing changes.
  • Documentation has been updated, if necessary.
    N/A - no doc changes needed, internal refactor only.
  • Unit tests have been added, if necessary.
    N/A - functions require a live Ceph cluster (librbd calls), not unit-testable.
    Existing e2e delete/snapshot tests exercise these code paths.
  • Integration tests have been added, if necessary.
    N/A - existing e2e tests for DeleteVolume, DeleteSnapshot, and volume
    cloning already cover the trash cleanup paths exercised by this change.

Show available bot commands

These commands are normally not required, but in case of issues, leave any of
the following bot commands in an otherwise empty comment in this PR:

  • /retest ci/centos/<job-name>: retest the <job-name> after unrelated
    failure (please report the failure too!)

This is an automatic backport of pull request #6472 done by [Mergify](https://mergify.com).

Depends-on: #6502

@mergify mergify Bot added ok-to-test Label to trigger E2E tests component/rbd Issues related to RBD labels Aug 18, 2026
@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.33

@ceph-csi-bot ceph-csi-bot added ci/in-progress/e2e This label acts like a guard and prevents Mergify from adding the `ok-to-test` label again. and removed ok-to-test Label to trigger E2E tests labels Aug 18, 2026
@mergify mergify Bot removed the ci/in-progress/e2e This label acts like a guard and prevents Mergify from adding the `ok-to-test` label again. label Aug 18, 2026
@nixpanic
nixpanic requested a review from Rakshith-R August 19, 2026 07:04
@iPraveenParihar

Copy link
Copy Markdown
Contributor

/retest ci/centos/mini-e2e-helm/k8s-1.33

@iPraveenParihar

Copy link
Copy Markdown
Contributor

/retest ci/centos/mini-e2e-helm/k8s-1.35

@iPraveenParihar

Copy link
Copy Markdown
Contributor

/retest ci/centos/mini-e2e/k8s-1.33

@iPraveenParihar

Copy link
Copy Markdown
Contributor

/retest ci/centos/upgrade-tests-rbd

@nixpanic

Copy link
Copy Markdown
Member

/queue

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

@Mergifyio rebase

Store the parent image's ID (from GetParent().Image.ImageID) in a new
ParentImageID field on rbdImage. This ID is valid even when the parent
is in trash, enabling O(1) trash removal without scanning the entire
trash list.

Reset ParentImageID to empty when GetParent returns ErrNotFound (no
parent or parent link severed by flatten).

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 18bd880)
Make trashRemoveImage() treat ENOENT as success on both the ceph mgr
(AddTrashRemove) and direct (TrashRemove) paths - the image was already
purged from trash. The mgr path checks rados.ErrNotFound before
isCephMgrSupported to avoid misclassifying ENOENT as a mgr failure.

Add removeImageFromTrash() as an O(1) helper that removes a trashed
image by its known ID.

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 608265a)
In checkErrAndUndoReserve() and cleanUpImageAndSnapReservation(), use
removeImageFromTrash() to remove the trashed image directly by its
known ID from the OMAP journal instead of scanning the entire trash
list with ensureImageCleanup().

The image ID is always available in OMAP: modern volumes store it at
creation time, and legacy volumes get it backfilled by storeImageID()
during the first (successful) generateVolumeFromVolumeID() call while
the image is still alive.

Also fix pre-existing ErrorLog format string mismatch in
cleanUpImageAndSnapReservation (2 format verbs but 3 arguments).

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 1529daf)
@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.35

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.34

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.34

@nixpanic

Copy link
Copy Markdown
Member

even as Draft the bots continue restarting CI jobs. Added ci/skip/e2e to prevent it (hopefully!).

@mergify

mergify Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Merge Protections

🔴 1 of 2 protections blocking · waiting on ⛓️ dependency

Protection Waiting on
🔴 ⛓️ Depends-On Requirements ⛓️ dependency
🟢 🚦 Auto-queue

🔴 ⛓️ Depends-On Requirements

Waiting for

This rule is failing.

Requirement based on the presence of Depends-On in the body of the pull request


Show 1 satisfied protection

🟢 🚦 Auto-queue

When all merge protections are satisfied, this pull request will be queued automatically.

@nixpanic

Copy link
Copy Markdown
Member

Once #6502 is merged, this can be scheduled for merging with /queue.

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

Labels

ci/skip/e2e skip running e2e CI jobs component/rbd Issues related to RBD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants