Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: validate IOContext before getting the list of trashed images #4884

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,9 @@ func (cs *ControllerServer) checkErrAndUndoReserve(
}

if errors.Is(err, ErrImageNotFound) {
err = rbdVol.ensureImageCleanup(ctx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
notFoundErr := rbdVol.ensureImageCleanup(ctx)
if notFoundErr != nil {
return nil, status.Errorf(codes.Internal, "failed to cleanup image %q: %v", rbdVol, notFoundErr)
}
} else {
// All errors other than ErrImageNotFound should return an error back to the caller
Expand Down Expand Up @@ -1538,11 +1538,6 @@ func cleanUpImageAndSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, c
}
defer rbdVol.Destroy(ctx)

err = rbdVol.openIoctx()
if err != nil {
return status.Error(codes.Internal, err.Error())
}

// cleanup the image from trash if the error is image not found.
err = rbdVol.ensureImageCleanup(ctx)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ func isCephMgrSupported(ctx context.Context, clusterID string, err error) bool {
// ensureImageCleanup finds image in trash and if found removes it
// from trash.
func (ri *rbdImage) ensureImageCleanup(ctx context.Context) error {
err := ri.openIoctx()
if err != nil {
return err
}

trashInfoList, err := librbd.GetTrashList(ri.ioctx)
if err != nil {
log.ErrorLog(ctx, "failed to list images in trash: %v", err)
Expand Down