mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-26 08:10:20 +00:00
commit
b07211739c
@ -118,7 +118,8 @@ func parseVolCreateRequest(req *csi.CreateVolumeRequest) (*rbdVolume, error) {
|
|||||||
if req.GetCapacityRange() != nil {
|
if req.GetCapacityRange() != nil {
|
||||||
volSizeBytes = req.GetCapacityRange().GetRequiredBytes()
|
volSizeBytes = req.GetCapacityRange().GetRequiredBytes()
|
||||||
}
|
}
|
||||||
rbdVol.VolSize = volSizeBytes
|
|
||||||
|
rbdVol.VolSize = util.RoundUpToMiB(volSizeBytes)
|
||||||
|
|
||||||
return rbdVol, nil
|
return rbdVol, nil
|
||||||
}
|
}
|
||||||
@ -175,10 +176,8 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
volSizeGB := int(rbdVol.VolSize / 1024 / 1024 / 1024)
|
|
||||||
|
|
||||||
// Check if there is already RBD image with requested name
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -192,13 +191,13 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
|||||||
return &csi.CreateVolumeResponse{
|
return &csi.CreateVolumeResponse{
|
||||||
Volume: &csi.Volume{
|
Volume: &csi.Volume{
|
||||||
VolumeId: rbdVol.VolID,
|
VolumeId: rbdVol.VolID,
|
||||||
CapacityBytes: rbdVol.VolSize,
|
CapacityBytes: rbdVol.VolSize * util.MiB,
|
||||||
VolumeContext: req.GetParameters(),
|
VolumeContext: req.GetParameters(),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVolumeRequest, volSizeGB int) error {
|
func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVolumeRequest, volSizeMiB int) error {
|
||||||
var err error
|
var err error
|
||||||
// Check if there is already RBD image with requested name
|
// Check if there is already RBD image with requested name
|
||||||
//nolint
|
//nolint
|
||||||
@ -210,7 +209,7 @@ func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVol
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = createRBDImage(rbdVol, volSizeGB, rbdVol.AdminID, req.GetSecrets())
|
err = createRBDImage(rbdVol, volSizeMiB, rbdVol.AdminID, req.GetSecrets())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Warningf("failed to create volume: %v", err)
|
klog.Warningf("failed to create volume: %v", err)
|
||||||
return err
|
return err
|
||||||
|
@ -121,18 +121,18 @@ func createRBDImage(pOpts *rbdVolume, volSz int, adminID string, credentials map
|
|||||||
}
|
}
|
||||||
|
|
||||||
image := pOpts.VolName
|
image := pOpts.VolName
|
||||||
volSzGB := fmt.Sprintf("%dG", volSz)
|
volSzMiB := fmt.Sprintf("%dM", volSz)
|
||||||
|
|
||||||
key, err := getRBDKey(adminID, credentials)
|
key, err := getRBDKey(adminID, credentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if pOpts.ImageFormat == rbdImageFormat2 {
|
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, volSzMiB, pOpts.ImageFormat, pOpts.ImageFeatures, mon, pOpts.Pool)
|
||||||
} else {
|
} 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, volSzMiB, 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", volSzMiB, "--pool", pOpts.Pool, "--id", adminID, "-m", mon, "--key=" + key, "--image-format", pOpts.ImageFormat}
|
||||||
if pOpts.ImageFormat == rbdImageFormat2 {
|
if pOpts.ImageFormat == rbdImageFormat2 {
|
||||||
args = append(args, "--image-feature", pOpts.ImageFeatures)
|
args = append(args, "--image-feature", pOpts.ImageFeatures)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,27 @@ import (
|
|||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// remove this once kubernetes v1.14.0 release is done
|
||||||
|
// https://github.com/kubernetes/cloud-provider/blob/master/volume/helpers/rounding.go
|
||||||
|
const (
|
||||||
|
// MiB - MebiByte size
|
||||||
|
MiB = 1024 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
|
// RoundUpToMiB rounds up given quantity upto chunks of MiB
|
||||||
|
func RoundUpToMiB(size int64) int64 {
|
||||||
|
requestBytes := size
|
||||||
|
return roundUpSize(requestBytes, MiB)
|
||||||
|
}
|
||||||
|
|
||||||
|
func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
|
||||||
|
roundedUp := volumeSizeBytes / allocationUnitBytes
|
||||||
|
if volumeSizeBytes%allocationUnitBytes > 0 {
|
||||||
|
roundedUp++
|
||||||
|
}
|
||||||
|
return roundedUp
|
||||||
|
}
|
||||||
|
|
||||||
// CreatePersistanceStorage creates storage path and initializes new cache
|
// CreatePersistanceStorage creates storage path and initializes new cache
|
||||||
func CreatePersistanceStorage(sPath, metaDataStore, driverName string) (CachePersister, error) {
|
func CreatePersistanceStorage(sPath, metaDataStore, driverName string) (CachePersister, error) {
|
||||||
var err error
|
var err error
|
||||||
|
Loading…
Reference in New Issue
Block a user