From 12e8e46bcf904e90de0b55a6b60779d3c08e8653 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 21 Dec 2021 10:33:41 +0530 Subject: [PATCH] revert: remove explicit size setting of cloned volume The ceph changes are done on the both server and the client side this change is not enough for remove setting the size of cloned volumes. this caused the regression like #2719 #2720 #2721 #2722. This reverts commit 3565a342d5ff2006e61ca1641d788547efac4b53. Signed-off-by: Madhu Rajanna --- internal/cephfs/controllerserver.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index b7661b2de..a5fce7742 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -149,7 +149,7 @@ func checkContentSource( } // CreateVolume creates a reservation and the volume in backend, if it is not already present. -// nolint:gocyclo,cyclop // TODO: reduce complexity +// nolint:gocognit,gocyclo,nestif,cyclop // TODO: reduce complexity func (cs *ControllerServer) CreateVolume( ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { @@ -210,6 +210,31 @@ func (cs *ControllerServer) CreateVolume( // TODO return error message if requested vol size greater than found volume return error if vID != nil { + if sID != nil || pvID != nil { + // while cloning the volume the size is not populated properly to the new volume now. + // it will be fixed in cephfs soon with the parentvolume size. Till then by below + // resize we are making sure we return or satisfy the requested size by setting the size + // explicitly + err = volOptions.ResizeVolume(ctx, fsutil.VolumeID(vID.FsSubvolName), volOptions.Size) + if err != nil { + purgeErr := volOptions.PurgeVolume(ctx, fsutil.VolumeID(vID.FsSubvolName), false) + if purgeErr != nil { + log.ErrorLog(ctx, "failed to delete volume %s: %v", requestName, purgeErr) + // All errors other than ErrVolumeNotFound should return an error back to the caller + if !errors.Is(purgeErr, cerrors.ErrVolumeNotFound) { + return nil, status.Error(codes.Internal, purgeErr.Error()) + } + } + errUndo := core.UndoVolReservation(ctx, volOptions, *vID, secret) + if errUndo != nil { + log.WarningLog(ctx, "failed undoing reservation of volume: %s (%s)", + requestName, errUndo) + } + log.ErrorLog(ctx, "failed to expand volume %s: %v", fsutil.VolumeID(vID.FsSubvolName), err) + + return nil, status.Error(codes.Internal, err.Error()) + } + } volumeContext := req.GetParameters() volumeContext["subvolumeName"] = vID.FsSubvolName volumeContext["subvolumePath"] = volOptions.RootPath