mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-31 00:59:30 +00:00
rbd: move cleanUpImageAndSnapReservation()
into rbdSnapshot.Delete()
Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
762e15d89f
commit
ffb47a88d6
@ -1471,7 +1471,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
if errors.Is(err, ErrImageNotFound) {
|
||||
log.UsefulLog(ctx, "cleaning up leftovers of snapshot %s: %v", snapshotID, err)
|
||||
|
||||
err = cleanUpImageAndSnapReservation(ctx, rbdSnap, cr)
|
||||
err = rbdSnap.Delete(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
@ -1510,34 +1510,6 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
return &csi.DeleteSnapshotResponse{}, nil
|
||||
}
|
||||
|
||||
// cleanUpImageAndSnapReservation cleans up the image from the trash and
|
||||
// snapshot reservation in rados OMAP.
|
||||
func cleanUpImageAndSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credentials) error {
|
||||
rbdVol := rbdSnap.toVolume()
|
||||
err := rbdVol.Connect(cr)
|
||||
if err != nil {
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
defer rbdVol.Destroy(ctx)
|
||||
|
||||
// cleanup the image from trash if the error is image not found.
|
||||
err = rbdVol.ensureImageCleanup(ctx)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to delete rbd image: %q with error: %v", rbdVol.Pool, rbdVol.VolName, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
err = undoSnapReservation(ctx, rbdSnap, cr)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap %q",
|
||||
rbdSnap.requestName, rbdSnap, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ControllerExpandVolume expand RBD Volumes on demand based on resizer request.
|
||||
func (cs *ControllerServer) ControllerExpandVolume(
|
||||
ctx context.Context,
|
||||
|
@ -177,6 +177,14 @@ func (rbdSnap *rbdSnapshot) Delete(ctx context.Context) error {
|
||||
}
|
||||
defer rbdVol.Destroy(ctx)
|
||||
|
||||
// cleanup the image from trash if the error is image not found.
|
||||
err = rbdVol.ensureImageCleanup(ctx)
|
||||
if err != nil {
|
||||
log.ErrorLog(ctx, "failed to delete rbd image %q: %v", rbdVol, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
rbdVol.ImageID = rbdSnap.ImageID
|
||||
// update parent name to delete the snapshot
|
||||
rbdSnap.RbdImageName = rbdVol.RbdImageName
|
||||
|
Loading…
Reference in New Issue
Block a user