From 22365ab77f6650f2ba3723829509ef55dbf523a2 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 15 Dec 2021 11:10:50 +0530 Subject: [PATCH] cleanup: add cleanup helper for incorrect thick volume added a new helper function called cleanupThickClone to cleanup the snapshot and clone if the thick provisioning is not fully completed. Signed-off-by: Madhu Rajanna --- internal/rbd/controllerserver.go | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 7e14b27e1..0cd9dcc0b 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -403,18 +403,7 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C rbdVol, err) } else if !thick { - err = cleanUpSnapshot(ctx, parentVol, rbdSnap, rbdVol, cr) - if err != nil { - return nil, status.Errorf(codes.Internal, "failed to remove partially cloned volume %q: %s", rbdVol, err) - } - err = undoVolReservation(ctx, rbdVol, cr) - if err != nil { - return nil, status.Errorf(codes.Internal, "failed to remove volume %q from journal: %s", rbdVol, err) - } - - return nil, status.Errorf( - codes.Internal, - "cloning thick-provisioned volume %q has been interrupted, please retry", rbdVol) + return nil, cleanupThickClone(ctx, parentVol, rbdVol, rbdSnap, cr) } } } @@ -422,6 +411,26 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C return buildCreateVolumeResponse(req, rbdVol), nil } +// cleanupThickClone will delete the snapshot and volume and undo the reservation. +func cleanupThickClone(ctx context.Context, + rbdVol, + parentVol *rbdVolume, + rbdSnap *rbdSnapshot, + cr *util.Credentials) error { + err := cleanUpSnapshot(ctx, parentVol, rbdSnap, rbdVol, cr) + if err != nil { + return status.Errorf(codes.Internal, "failed to remove partially cloned volume %q: %s", rbdVol, err) + } + err = undoVolReservation(ctx, rbdVol, cr) + if err != nil { + return status.Errorf(codes.Internal, "failed to remove volume %q from journal: %s", rbdVol, err) + } + + return status.Errorf( + codes.Internal, + "cloning thick-provisioned volume %q has been interrupted, please retry", rbdVol) +} + // check snapshots on the rbd image, as we have limit from krbd that an image // cannot have more than 510 snapshot at a given point of time. If the // snapshots are more than the `maxSnapshotsOnImage` Add a task to flatten all