diff --git a/internal/rbd/clone.go b/internal/rbd/clone.go index 3b91e47be..1fe0e42d8 100644 --- a/internal/rbd/clone.go +++ b/internal/rbd/clone.go @@ -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 } diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 10acab35e..640079a54 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -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 diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index eed7b7924..3b18c8e2c 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -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 {