rbd: remove checkFlatten() function

CephCSI should not flatten image that can be mounted
for use by the user.
`checkFlatten()` was called in a recovery code flow
of PVC restored from snapshot and was missed while
refractoring in https://github.com/ceph/ceph-csi/pull/2900

refer: #2900

Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
Rakshith R 2024-11-14 14:10:36 +05:30 committed by mergify[bot]
parent 3e9b438e7c
commit eea64fe1f9

View File

@ -389,7 +389,7 @@ func (cs *ControllerServer) CreateVolume(
if err != nil { if err != nil {
return nil, getGRPCErrorForCreateVolume(err) return nil, getGRPCErrorForCreateVolume(err)
} else if found { } else if found {
return cs.repairExistingVolume(ctx, req, cr, rbdVol, rbdSnap) return cs.repairExistingVolume(ctx, req, rbdVol, rbdSnap)
} }
err = checkValidCreateVolumeRequest(rbdVol, parentVol, rbdSnap) err = checkValidCreateVolumeRequest(rbdVol, parentVol, rbdSnap)
@ -516,21 +516,14 @@ func flattenParentImage(
// that the state is corrected to what was requested. It is needed to call this // that the state is corrected to what was requested. It is needed to call this
// when the process of creating a volume was interrupted. // when the process of creating a volume was interrupted.
func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.CreateVolumeRequest, func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.CreateVolumeRequest,
cr *util.Credentials, rbdVol *rbdVolume, rbdSnap *rbdSnapshot, rbdVol *rbdVolume, rbdSnap *rbdSnapshot,
) (*csi.CreateVolumeResponse, error) { ) (*csi.CreateVolumeResponse, error) {
vcs := req.GetVolumeContentSource() vcs := req.GetVolumeContentSource()
switch { switch {
// rbdVol is a restore from snapshot, rbdSnap is passed // rbdVol is a restore from snapshot, rbdSnap is passed
case vcs.GetSnapshot() != nil: case vcs.GetSnapshot() != nil:
// restore from snapshot implies rbdSnap != nil err := rbdSnap.repairEncryptionConfig(ctx, &rbdVol.rbdImage)
// check if image depth is reached limit and requires flatten
err := checkFlatten(ctx, rbdVol, cr)
if err != nil {
return nil, err
}
err = rbdSnap.repairEncryptionConfig(ctx, &rbdVol.rbdImage)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -636,32 +629,6 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut
return nil return nil
} }
// checkFlatten ensures that the image chain depth is not reached
// hardlimit or softlimit. if the softlimit is reached it adds a task and
// return success,the hardlimit is reached it starts a task to flatten the
// image and return Aborted.
func checkFlatten(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
err := rbdVol.flattenRbdImage(ctx, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
if err != nil {
if errors.Is(err, ErrFlattenInProgress) {
return status.Error(codes.Aborted, err.Error())
}
if errDefer := rbdVol.Delete(ctx); errDefer != nil {
log.ErrorLog(ctx, "failed to delete rbd image: %s with error: %v", rbdVol, errDefer)
return status.Error(codes.Internal, err.Error())
}
errDefer := undoVolReservation(ctx, rbdVol, cr)
if errDefer != nil {
log.WarningLog(ctx, "failed undoing reservation of volume: %s (%s)", rbdVol.RequestName, errDefer)
}
return status.Error(codes.Internal, err.Error())
}
return nil
}
func (cs *ControllerServer) createVolumeFromSnapshot( func (cs *ControllerServer) createVolumeFromSnapshot(
ctx context.Context, ctx context.Context,
cr *util.Credentials, cr *util.Credentials,