mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
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 <madhupr007@gmail.com>
This commit is contained in:
parent
0bd1d44dc0
commit
ef14ea7723
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user