Skip to content

Commit

Permalink
Roundup volume size to Mib for rbd
Browse files Browse the repository at this point in the history
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
  • Loading branch information
Madhu-1 committed Mar 1, 2019
1 parent e03ad6b commit cff46bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
15 changes: 7 additions & 8 deletions pkg/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"strconv"
"syscall"

"github.com/ceph/ceph-csi/pkg/csi-common"
csicommon "github.com/ceph/ceph-csi/pkg/csi-common"
"github.com/ceph/ceph-csi/pkg/util"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -108,7 +108,8 @@ func parseVolCreateRequest(req *csi.CreateVolumeRequest) (*rbdVolume, error) {
if req.GetCapacityRange() != nil {
volSizeBytes = req.GetCapacityRange().GetRequiredBytes()
}
rbdVol.VolSize = volSizeBytes

rbdVol.VolSize = util.RoundUpToMiB(volSizeBytes)

return rbdVol, nil
}
Expand Down Expand Up @@ -165,10 +166,8 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, err
}

volSizeGB := int(rbdVol.VolSize / 1024 / 1024 / 1024)

// Check if there is already RBD image with requested name
err = cs.checkRBDStatus(rbdVol, req, volSizeGB)
err = cs.checkRBDStatus(rbdVol, req, int(rbdVol.VolSize))
if err != nil {
return nil, err
}
Expand All @@ -182,13 +181,13 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
VolumeId: rbdVol.VolID,
CapacityBytes: rbdVol.VolSize,
CapacityBytes: rbdVol.VolSize * util.MiB,
VolumeContext: req.GetParameters(),
},
}, nil
}

func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVolumeRequest, volSizeGB int) error {
func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVolumeRequest, volSizeMB int) error {
var err error
// Check if there is already RBD image with requested name
found, _, _ := rbdStatus(rbdVol, rbdVol.UserID, req.GetSecrets()) // #nosec
Expand All @@ -199,7 +198,7 @@ func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVol
return err
}
} else {
err = createRBDImage(rbdVol, volSizeGB, rbdVol.AdminID, req.GetSecrets())
err = createRBDImage(rbdVol, volSizeMB, rbdVol.AdminID, req.GetSecrets())
if err != nil {
klog.Warningf("failed to create volume: %v", err)
return err
Expand Down
8 changes: 4 additions & 4 deletions pkg/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ func createRBDImage(pOpts *rbdVolume, volSz int, adminID string, credentials map
}

image := pOpts.VolName
volSzGB := fmt.Sprintf("%dG", volSz)
volSzMB := fmt.Sprintf("%dM", volSz)

key, err := getRBDKey(adminID, credentials)
if err != nil {
return err
}
if pOpts.ImageFormat == rbdImageFormat2 {
klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s ", image, volSzGB, pOpts.ImageFormat, pOpts.ImageFeatures, mon, pOpts.Pool)
klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s ", image, volSzMB, pOpts.ImageFormat, pOpts.ImageFeatures, mon, pOpts.Pool)
} else {
klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s", image, volSzGB, pOpts.ImageFormat, mon, pOpts.Pool)
klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s", image, volSzMB, pOpts.ImageFormat, mon, pOpts.Pool)
}
args := []string{"create", image, "--size", volSzGB, "--pool", pOpts.Pool, "--id", adminID, "-m", mon, "--key=" + key, "--image-format", pOpts.ImageFormat}
args := []string{"create", image, "--size", volSzMB, "--pool", pOpts.Pool, "--id", adminID, "-m", mon, "--key=" + key, "--image-format", pOpts.ImageFormat}
if pOpts.ImageFormat == rbdImageFormat2 {
args = append(args, "--image-feature", pOpts.ImageFeatures)
}
Expand Down
14 changes: 1 addition & 13 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,11 @@ import (
"k8s.io/klog"
)

// remove this once kubernetes v1.14.0 release is done
// remove this once kubernetes v1.14.0 release is done
// https://github.com/kubernetes/cloud-provider/blob/master/volume/helpers/rounding.go
const (
// GB - GigaByte size
GB = 1000 * 1000 * 1000
// GiB - GibiByte size
GiB = 1024 * 1024 * 1024

// MB - MegaByte size
MB = 1000 * 1000
// MiB - MebiByte size
MiB = 1024 * 1024

// KB - KiloByte size
KB = 1000
// KiB - KibiByte size
KiB = 1024
)

// RoundUpToMiB rounds up given quantity upto chunks of MiB
Expand Down

0 comments on commit cff46bc

Please sign in to comment.