rbd: implement rbdVolume.resize() with go-ceph

Replaced command execution with go-ceph Resize() function.
Volsize is being updated before waiting for resize() to return,
fixed it to get updated only after resize() is successful.

Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
Mudit Agarwal 2020-07-30 11:58:51 +05:30 committed by mergify[bot]
parent 1eff20590d
commit 9ed0811422
2 changed files with 14 additions and 11 deletions

View File

@ -1090,13 +1090,12 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
nodeExpansion := false nodeExpansion := false
if rbdVol.VolSize < volSize { if rbdVol.VolSize < volSize {
util.DebugLog(ctx, "rbd volume %s size is %v,resizing to %v", rbdVol, rbdVol.VolSize, volSize) util.DebugLog(ctx, "rbd volume %s size is %v,resizing to %v", rbdVol, rbdVol.VolSize, volSize)
rbdVol.VolSize = volSize err = rbdVol.resize(volSize)
nodeExpansion = true
err = rbdVol.resize(ctx, cr)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s with error: %v"), rbdVol, err) klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s with error: %v"), rbdVol, err)
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
nodeExpansion = true
} }
return &csi.ControllerExpandVolumeResponse{ return &csi.ControllerExpandVolumeResponse{

View File

@ -1043,17 +1043,21 @@ func cleanupRBDImageMetadataStash(path string) error {
} }
// resize the given volume to new size. // resize the given volume to new size.
func (rv *rbdVolume) resize(ctx context.Context, cr *util.Credentials) error { // updates Volsize of rbdVolume object to newSize in case of success.
mon := rv.Monitors func (rv *rbdVolume) resize(newSize int64) error {
volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(rv.VolSize)) image, err := rv.open()
args := []string{"resize", rv.String(), "--size", volSzMiB, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile}
_, stderr, err := util.ExecCommand(ctx, "rbd", args...)
if err != nil { if err != nil {
return fmt.Errorf("failed to resize rbd image (%w), command output: %s", err, stderr) return err
}
defer image.Close()
err = image.Resize(uint64(util.RoundOffVolSize(newSize) * helpers.MiB))
if err != nil {
return err
} }
// update Volsize of rbdVolume object to newSize.
rv.VolSize = newSize
return nil return nil
} }