From 6ea163082973c0fa0c5afec96e2f3d3d3483f5b9 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 1 Dec 2023 12:08:44 +0100 Subject: [PATCH] rbd: return CSI expected errors while flattening a snapshot or volume By returned `ABORTED` or `PRECONDITION_FAILED` in the right places, the CO will retry with the same arguments until the snapshot is `ReadyToUse`. This causes restoring a volume from a snapshot to be delayed, until the snapshot can be used. Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 7ad5378ea8f3..b39ad1d99254 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -559,7 +559,9 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut rbdVol.Monitors, rbdVol.RbdImageName, cr) - if err != nil { + if errors.Is(err, ErrFlattenInProgress) { + return status.Error(codes.Aborted, err.Error()) + } else if err != nil { return status.Error(codes.Internal, err.Error()) } @@ -995,7 +997,7 @@ func cleanupRBDImage(ctx context.Context, if inUse { log.ErrorLog(ctx, "rbd %s is still being used", rbdVol) - return nil, status.Errorf(codes.Internal, "rbd %s is still being used", rbdVol.RbdImageName) + return nil, status.Errorf(codes.FailedPrecondition, "rbd %s is still being used", rbdVol.RbdImageName) } // delete the temporary rbd image created as part of volume clone during @@ -1167,8 +1169,12 @@ func (cs *ControllerServer) CreateSnapshot( } }() + readyToUse := true + vol, err := cs.doSnapshotClone(ctx, rbdVol, rbdSnap, cr) - if err != nil { + if errors.Is(err, ErrFlattenInProgress) { + readyToUse = false + } else if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -1205,7 +1211,7 @@ func (cs *ControllerServer) CreateSnapshot( SnapshotId: vol.VolID, SourceVolumeId: req.GetSourceVolumeId(), CreationTime: vol.CreatedAt, - ReadyToUse: true, + ReadyToUse: readyToUse, }, }, nil } @@ -1236,10 +1242,12 @@ func cloneFromSnapshot( return nil, status.Error(codes.Internal, err.Error()) } + readyToUse := true + err = vol.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth) if errors.Is(err, ErrFlattenInProgress) { // if flattening is in progress, return error and do not cleanup - return nil, status.Errorf(codes.Internal, err.Error()) + readyToUse = false } else if err != nil { uErr := undoSnapshotCloning(ctx, rbdVol, rbdSnap, vol, cr) if uErr != nil { @@ -1265,7 +1273,7 @@ func cloneFromSnapshot( SnapshotId: rbdSnap.VolID, SourceVolumeId: rbdSnap.SourceVolumeID, CreationTime: rbdSnap.CreatedAt, - ReadyToUse: true, + ReadyToUse: readyToUse, }, }, nil }