1
0
mirror of https://github.com/ceph/ceph-csi.git synced 2024-12-19 11:30:24 +00:00

rbd: resize the volume created from volume

If the requested volume size is greater than
the parent volume size, resize the cloned volume
after creating a final clone from a parent volume.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-12-15 11:14:24 +05:30 committed by mergify[bot]
parent f7f662678a
commit a28a4a4285
3 changed files with 25 additions and 0 deletions

View File

@ -181,6 +181,14 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol
return err
}
// expand the image if the requested size is greater than the current size
err = rv.expand()
if err != nil {
log.ErrorLog(ctx, "failed to resize volume %s: %v", rv, err)
return err
}
return nil
}

View File

@ -408,6 +408,13 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C
return nil, cleanupThickClone(ctx, parentVol, rbdVol, rbdSnap, cr)
}
}
// expand the image if the requested size is greater than the current size
err := rbdVol.expand()
if err != nil {
log.ErrorLog(ctx, "failed to resize volume %s: %v", rbdVol, err)
return nil, err
}
}
return buildCreateVolumeResponse(req, rbdVol), nil

View File

@ -1703,6 +1703,16 @@ func cleanupRBDImageMetadataStash(metaDataPath string) error {
return nil
}
// expand checks if the requestedVolume size and the existing image size both
// are same. If they are same, it returns nil else it resizes the image.
func (rv *rbdVolume) expand() error {
if rv.RequestedVolSize == rv.VolSize {
return nil
}
return rv.resize(rv.RequestedVolSize)
}
// resize the given volume to new size.
// updates Volsize of rbdVolume object to newSize in case of success.
func (rv *rbdVolume) resize(newSize int64) error {