Skip to content

Commit

Permalink
rbd: return CSI expected errors while flattening a snapshot or volume
Browse files Browse the repository at this point in the history
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 <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Dec 1, 2023
1 parent b8a5675 commit a29bea6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -1205,7 +1211,7 @@ func (cs *ControllerServer) CreateSnapshot(
SnapshotId: vol.VolID,
SourceVolumeId: req.GetSourceVolumeId(),
CreationTime: vol.CreatedAt,
ReadyToUse: true,
ReadyToUse: readyToUse,
},
}, nil
}
Expand Down Expand Up @@ -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 {
Expand All @@ -1265,7 +1273,7 @@ func cloneFromSnapshot(
SnapshotId: rbdSnap.VolID,
SourceVolumeId: rbdSnap.SourceVolumeID,
CreationTime: rbdSnap.CreatedAt,
ReadyToUse: true,
ReadyToUse: readyToUse,
},
}, nil
}
Expand Down

0 comments on commit a29bea6

Please sign in to comment.