From ef14ea77236d490153ceb329a0ebd2878c853fa6 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 10 Jan 2022 10:26:28 +0530 Subject: [PATCH] cephfs: resize cloned, restored volume if required Currently, as a workaround, we are calling the resize volume on the cloned, restore volumes to adjust the cloned, restored volumes. With this fix, we are calling the resize volume only if there is a size mismatch with requested and the volume from which the new volume needs to be created. Signed-off-by: Madhu Rajanna --- internal/cephfs/controllerserver.go | 7 ++----- internal/cephfs/core/clone.go | 11 +++++------ internal/cephfs/core/volume.go | 17 +++++++++++++++++ internal/cephfs/core/volumeoptions.go | 2 ++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index a5fce7742..c21754b0d 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -211,11 +211,7 @@ func (cs *ControllerServer) CreateVolume( 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) + err = volOptions.ExpandVolume(ctx, fsutil.VolumeID(vID.FsSubvolName), volOptions.Size) if err != nil { purgeErr := volOptions.PurgeVolume(ctx, fsutil.VolumeID(vID.FsSubvolName), false) if purgeErr != nil { @@ -235,6 +231,7 @@ func (cs *ControllerServer) CreateVolume( return nil, status.Error(codes.Internal, err.Error()) } } + volumeContext := req.GetParameters() volumeContext["subvolumeName"] = vID.FsSubvolName volumeContext["subvolumePath"] = volOptions.RootPath diff --git a/internal/cephfs/core/clone.go b/internal/cephfs/core/clone.go index 627e114fc..b821d0aa7 100644 --- a/internal/cephfs/core/clone.go +++ b/internal/cephfs/core/clone.go @@ -131,13 +131,14 @@ func CreateCloneFromSubvolume( return cloneState.toError() } - // This is a work around to fix sizing issue for cloned images - err = volOpt.ResizeVolume(ctx, cloneID, volOpt.Size) + + err = volOpt.ExpandVolume(ctx, cloneID, volOpt.Size) if err != nil { log.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err) return err } + // As we completed clone, remove the intermediate snap if err = parentvolOpt.UnprotectSnapshot(ctx, snapshotID, volID); err != nil { // In case the snap is already unprotected we get ErrSnapProtectionExist error code @@ -227,10 +228,8 @@ func CreateCloneFromSnapshot( if cloneState != cephFSCloneComplete { return cloneState.toError() } - // The clonedvolume currently does not reflect the proper size due to an issue in cephfs - // however this is getting addressed in cephfs and the parentvolume size will be reflected - // in the new cloned volume too. Till then we are explicitly making the size set - err = volOptions.ResizeVolume(ctx, fsutil.VolumeID(vID.FsSubvolName), volOptions.Size) + + err = volOptions.ExpandVolume(ctx, fsutil.VolumeID(vID.FsSubvolName), volOptions.Size) if err != nil { log.ErrorLog(ctx, "failed to expand volume %s with error: %v", vID.FsSubvolName, err) diff --git a/internal/cephfs/core/volume.go b/internal/cephfs/core/volume.go index 9ea3bbc2f..a21c0d2fa 100644 --- a/internal/cephfs/core/volume.go +++ b/internal/cephfs/core/volume.go @@ -191,6 +191,23 @@ func CreateVolume(ctx context.Context, volOptions *VolumeOptions, volID fsutil.V return nil } +// ExpandVolume will expand the volume if the requested size is greater than +// the subvolume size. +func (vo *VolumeOptions) ExpandVolume(ctx context.Context, volID fsutil.VolumeID, bytesQuota int64) error { + // get the subvolume size for comparison with the requested size. + info, err := vo.GetSubVolumeInfo(ctx, volID) + if err != nil { + return err + } + // resize if the requested size is greater than the current size. + if vo.Size > info.BytesQuota { + log.DebugLog(ctx, "clone %s size %d is greater than requested size %d", volID, info.BytesQuota, bytesQuota) + err = vo.ResizeVolume(ctx, volID, bytesQuota) + } + + return err +} + // ResizeVolume will try to use ceph fs subvolume resize command to resize the // subvolume. If the command is not available as a fallback it will use // CreateVolume to resize the subvolume. diff --git a/internal/cephfs/core/volumeoptions.go b/internal/cephfs/core/volumeoptions.go index 3dc7109f7..485cac788 100644 --- a/internal/cephfs/core/volumeoptions.go +++ b/internal/cephfs/core/volumeoptions.go @@ -361,6 +361,7 @@ func NewVolumeOptionsFromVolID( if err == nil { volOptions.RootPath = info.Path volOptions.Features = info.Features + volOptions.Size = info.BytesQuota } if errors.Is(err, cerrors.ErrInvalidCommand) { @@ -580,6 +581,7 @@ func NewSnapshotOptionsFromID( return &volOptions, nil, &sid, err } volOptions.Features = subvolInfo.Features + volOptions.Size = subvolInfo.BytesQuota info, err := volOptions.GetSnapshotInfo(ctx, fsutil.VolumeID(sid.FsSnapshotName), fsutil.VolumeID(sid.FsSubvolName)) if err != nil {