Skip to content

Commit

Permalink
rbd: validate IOContext before getting the list of trashed images
Browse files Browse the repository at this point in the history
`ensureImageCleanup()` can cause a panic when an image was deleted, but
the journal still contained a reference. By opening the IOContext before
using, an error may be returned instead of a panic when using a `nil` or
freed IOContext.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Oct 4, 2024
1 parent 9267210 commit d33e6b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit d33e6b1

Please sign in to comment.