mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
use VolSize from rbdVolume instead of separate parameter
This commit is contained in:
parent
8da7e4bbf9
commit
ca8dd2d8f2
@ -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 {
|
||||
return nil, err
|
||||
}
|
||||
@ -212,7 +212,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
||||
}, 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
|
||||
|
||||
// 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()
|
||||
|
||||
err = createImage(ctx, rbdVol, volSize, cr)
|
||||
err = createImage(ctx, rbdVol, cr)
|
||||
if err != nil {
|
||||
klog.Errorf(util.Log(ctx, "failed to create volume: %v"), err)
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
@ -767,11 +767,10 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
|
||||
// resize volume if required
|
||||
nodeExpansion := false
|
||||
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)
|
||||
rbdVol.VolSize = volSize
|
||||
nodeExpansion = true
|
||||
err = resizeRBDImage(rbdVol, volSizeVal, cr)
|
||||
err = resizeRBDImage(rbdVol, cr)
|
||||
if err != nil {
|
||||
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())
|
||||
|
@ -115,11 +115,11 @@ var (
|
||||
)
|
||||
|
||||
// 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
|
||||
|
||||
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 "
|
||||
if pOpts.DataPool != "" {
|
||||
@ -861,12 +861,12 @@ func cleanupRBDImageMetadataStash(path string) error {
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
mon := rbdVol.Monitors
|
||||
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}
|
||||
output, err := execCommand("rbd", args)
|
||||
|
Loading…
Reference in New Issue
Block a user