Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: include trashed parent images while calculating the clone depth #4029

Draft
wants to merge 8 commits into
base: devel
Choose a base branch
from
Prev Previous commit
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 <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Dec 1, 2023
commit a29bea631de961a3d94cfc80a3e66876834cfa4e
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