use VolSize from rbdVolume instead of separate parameter

This commit is contained in:
Reinier Schoof 2020-02-26 10:35:18 +01:00 committed by mergify[bot]
parent 8da7e4bbf9
commit ca8dd2d8f2
2 changed files with 8 additions and 9 deletions

View File

@ -183,7 +183,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
} }
}() }()
err = cs.createBackingImage(ctx, rbdVol, req, util.RoundOffVolSize(rbdVol.VolSize)) err = cs.createBackingImage(ctx, rbdVol, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -212,7 +212,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}, nil }, nil
} }
func (cs *ControllerServer) createBackingImage(ctx context.Context, rbdVol *rbdVolume, req *csi.CreateVolumeRequest, volSize int64) error { func (cs *ControllerServer) createBackingImage(ctx context.Context, rbdVol *rbdVolume, req *csi.CreateVolumeRequest) error {
var err error var err error
// if VolumeContentSource is not nil, this request is for snapshot // if VolumeContentSource is not nil, this request is for snapshot
@ -227,7 +227,7 @@ func (cs *ControllerServer) createBackingImage(ctx context.Context, rbdVol *rbdV
} }
defer cr.DeleteCredentials() defer cr.DeleteCredentials()
err = createImage(ctx, rbdVol, volSize, cr) err = createImage(ctx, rbdVol, cr)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to create volume: %v"), err) klog.Errorf(util.Log(ctx, "failed to create volume: %v"), err)
return status.Error(codes.Internal, err.Error()) return status.Error(codes.Internal, err.Error())
@ -767,11 +767,10 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
// resize volume if required // resize volume if required
nodeExpansion := false nodeExpansion := false
if rbdVol.VolSize < volSize { if rbdVol.VolSize < volSize {
volSizeVal := util.RoundOffVolSize(volSize)
klog.V(4).Infof(util.Log(ctx, "rbd volume %s/%s size is %v,resizing to %v"), rbdVol.Pool, rbdVol.RbdImageName, rbdVol.VolSize, volSize) klog.V(4).Infof(util.Log(ctx, "rbd volume %s/%s size is %v,resizing to %v"), rbdVol.Pool, rbdVol.RbdImageName, rbdVol.VolSize, volSize)
rbdVol.VolSize = volSize rbdVol.VolSize = volSize
nodeExpansion = true nodeExpansion = true
err = resizeRBDImage(rbdVol, volSizeVal, cr) err = resizeRBDImage(rbdVol, cr)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s/%s with error: %v"), rbdVol.Pool, rbdVol.RbdImageName, err) klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s/%s with error: %v"), rbdVol.Pool, rbdVol.RbdImageName, err)
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())

View File

@ -115,11 +115,11 @@ var (
) )
// createImage creates a new ceph image with provision and volume options. // createImage creates a new ceph image with provision and volume options.
func createImage(ctx context.Context, pOpts *rbdVolume, volSz int64, cr *util.Credentials) error { func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
var output []byte var output []byte
image := pOpts.RbdImageName image := pOpts.RbdImageName
volSzMiB := fmt.Sprintf("%dM", volSz) volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(pOpts.VolSize))
logMsg := "rbd: create %s size %s format 2 (features: %s) using mon %s, pool %s " logMsg := "rbd: create %s size %s format 2 (features: %s) using mon %s, pool %s "
if pOpts.DataPool != "" { if pOpts.DataPool != "" {
@ -861,12 +861,12 @@ func cleanupRBDImageMetadataStash(path string) error {
} }
// resizeRBDImage resizes the given volume to new size // resizeRBDImage resizes the given volume to new size
func resizeRBDImage(rbdVol *rbdVolume, newSize int64, cr *util.Credentials) error { func resizeRBDImage(rbdVol *rbdVolume, cr *util.Credentials) error {
var output []byte var output []byte
mon := rbdVol.Monitors mon := rbdVol.Monitors
image := rbdVol.RbdImageName image := rbdVol.RbdImageName
volSzMiB := fmt.Sprintf("%dM", newSize) volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(rbdVol.VolSize))
args := []string{"resize", image, "--size", volSzMiB, "--pool", rbdVol.Pool, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile} args := []string{"resize", image, "--size", volSzMiB, "--pool", rbdVol.Pool, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile}
output, err := execCommand("rbd", args) output, err := execCommand("rbd", args)