@@ -477,7 +477,7 @@ func getBoolParameter(params map[string]string, key string) bool {
477477 return exists && (valueStr == "true" || valueStr == "True" )
478478}
479479
480- func prepareCreateVolumeReq (ctx context.Context , req * csi.CreateVolumeRequest , sizeMiB int64 ) (* util.CreateLVolData , error ) {
480+ func prepareCreateVolumeReq (ctx context.Context , req * csi.CreateVolumeRequest , capacityBytes int64 ) (* util.CreateLVolData , error ) {
481481 params := req .GetParameters ()
482482
483483 distrNdcs , err := getIntParameter (params , "distr_ndcs" , 1 )
@@ -547,7 +547,7 @@ func prepareCreateVolumeReq(ctx context.Context, req *csi.CreateVolumeRequest, s
547547
548548 createVolReq := util.CreateLVolData {
549549 LvolName : req .GetName (),
550- Size : fmt . Sprintf ( "%dM" , sizeMiB ),
550+ Size : strconv . FormatInt ( capacityBytes , 10 ),
551551 LvsName : params ["pool_name" ],
552552 Fabric : params ["fabric" ],
553553 MaxRWIOPS : params ["qos_rw_iops" ],
@@ -588,10 +588,9 @@ func (cs *controllerServer) createVolume(ctx context.Context, req *csi.CreateVol
588588 size = 1024 * 1024 * 1024
589589 }
590590
591- sizeGiB := util .ToGiB (size )
592- sizeMiB := sizeGiB * 1024
591+ capacityBytes := util .AlignToGiBBytes (size )
593592 vol := csi.Volume {
594- CapacityBytes : sizeMiB * 1024 * 1024 ,
593+ CapacityBytes : capacityBytes ,
595594 VolumeContext : req .GetParameters (),
596595 ContentSource : req .GetVolumeContentSource (),
597596 }
@@ -604,7 +603,7 @@ func (cs *controllerServer) createVolume(ctx context.Context, req *csi.CreateVol
604603 }
605604
606605 if req .GetVolumeContentSource () != nil {
607- clonedVolume , clonedErr := cs .handleVolumeContentSource (req , poolName , & vol , sizeMiB )
606+ clonedVolume , clonedErr := cs .handleVolumeContentSource (req , poolName , & vol , capacityBytes )
608607 if clonedErr != nil {
609608 return nil , clonedErr
610609 }
@@ -613,7 +612,7 @@ func (cs *controllerServer) createVolume(ctx context.Context, req *csi.CreateVol
613612 }
614613 }
615614
616- createVolReq , err := prepareCreateVolumeReq (ctx , req , sizeMiB )
615+ createVolReq , err := prepareCreateVolumeReq (ctx , req , capacityBytes )
617616 if err != nil {
618617 return nil , err
619618 }
@@ -708,6 +707,10 @@ func (cs *controllerServer) unpublishVolume(volumeID string) error {
708707func (cs * controllerServer ) ControllerExpandVolume (_ context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
709708 volumeID := req .GetVolumeId ()
710709 updatedSize := req .GetCapacityRange ().GetRequiredBytes ()
710+
711+ // Simplyblock backends are GiB aligned, so we round up to GiB.
712+ capacityBytes := util .AlignToGiBBytes (updatedSize )
713+
711714 spdkVol , err := getSPDKVol (volumeID )
712715 if err != nil {
713716 return nil , err
@@ -718,13 +721,13 @@ func (cs *controllerServer) ControllerExpandVolume(_ context.Context, req *csi.C
718721 return nil , err
719722 }
720723
721- _ , err = sbclient .ResizeVolume (spdkVol .lvolID , updatedSize )
724+ _ , err = sbclient .ResizeVolume (spdkVol .lvolID , capacityBytes )
722725 if err != nil {
723726 klog .Errorf ("failed to resize lvol, LVolID: %s err: %v" , spdkVol .lvolID , err )
724727 return nil , err
725728 }
726729 return & csi.ControllerExpandVolumeResponse {
727- CapacityBytes : updatedSize ,
730+ CapacityBytes : capacityBytes ,
728731 NodeExpansionRequired : true ,
729732 }, nil
730733}
@@ -885,19 +888,19 @@ func newControllerServer(d *csicommon.CSIDriver) (*controllerServer, error) {
885888 return & server , nil
886889}
887890
888- func (cs * controllerServer ) handleVolumeContentSource (req * csi.CreateVolumeRequest , poolName string , vol * csi.Volume , sizeMiB int64 ) (* csi.Volume , error ) {
891+ func (cs * controllerServer ) handleVolumeContentSource (req * csi.CreateVolumeRequest , poolName string , vol * csi.Volume , sizeBytes int64 ) (* csi.Volume , error ) {
889892 volumeSource := req .GetVolumeContentSource ()
890893 switch volumeSource .GetType ().(type ) {
891894 case * csi.VolumeContentSource_Snapshot :
892- return cs .handleSnapshotSource (volumeSource .GetSnapshot (), req , poolName , vol , sizeMiB )
895+ return cs .handleSnapshotSource (volumeSource .GetSnapshot (), req , poolName , vol , sizeBytes )
893896 case * csi.VolumeContentSource_Volume :
894- return cs .handleVolumeSource (volumeSource .GetVolume (), req , poolName , vol , sizeMiB )
897+ return cs .handleVolumeSource (volumeSource .GetVolume (), req , poolName , vol , sizeBytes )
895898 default :
896899 return nil , status .Errorf (codes .InvalidArgument , "%v not a proper volume source" , volumeSource )
897900 }
898901}
899902
900- func (cs * controllerServer ) handleSnapshotSource (snapshot * csi.VolumeContentSource_SnapshotSource , req * csi.CreateVolumeRequest , poolName string , vol * csi.Volume , sizeMiB int64 ) (* csi.Volume , error ) {
903+ func (cs * controllerServer ) handleSnapshotSource (snapshot * csi.VolumeContentSource_SnapshotSource , req * csi.CreateVolumeRequest , poolName string , vol * csi.Volume , sizeBytes int64 ) (* csi.Volume , error ) {
901904 if snapshot == nil {
902905 return nil , nil
903906 }
@@ -917,7 +920,8 @@ func (cs *controllerServer) handleSnapshotSource(snapshot *csi.VolumeContentSour
917920 snapshotName := req .GetName ()
918921 params := req .GetParameters ()
919922 pvcName , _ := params [CSIStorageNameKey ]
920- newSize := fmt .Sprintf ("%dM" , sizeMiB )
923+ // Use raw bytes to avoid decimal/binary unit ambiguity in clone sizing.
924+ newSize := strconv .FormatInt (sizeBytes , 10 )
921925 volumeID , err := sbclient .CloneSnapshot (sbSnapshot .snapshotID , snapshotName , newSize , pvcName )
922926 if err != nil {
923927 klog .Errorf ("error creating simplyBlock volume: %v" , err )
@@ -929,7 +933,7 @@ func (cs *controllerServer) handleSnapshotSource(snapshot *csi.VolumeContentSour
929933 return vol , nil
930934}
931935
932- func (cs * controllerServer ) handleVolumeSource (srcVolume * csi.VolumeContentSource_VolumeSource , req * csi.CreateVolumeRequest , poolName string , vol * csi.Volume , sizeMiB int64 ) (* csi.Volume , error ) {
936+ func (cs * controllerServer ) handleVolumeSource (srcVolume * csi.VolumeContentSource_VolumeSource , req * csi.CreateVolumeRequest , poolName string , vol * csi.Volume , sizeBytes int64 ) (* csi.Volume , error ) {
933937 if srcVolume == nil {
934938 return nil , nil
935939 }
@@ -959,7 +963,8 @@ func (cs *controllerServer) handleVolumeSource(srcVolume *csi.VolumeContentSourc
959963 klog .Errorf ("failed to create snapshot, srcVolumeID: %s snapshotName: %s err: %v" , srcVolumeID , snapshotName , err )
960964 return nil , status .Error (codes .Internal , err .Error ())
961965 }
962- newSize := fmt .Sprintf ("%dM" , sizeMiB )
966+ // Use raw bytes to avoid decimal/binary unit ambiguity in clone sizing.
967+ newSize := strconv .FormatInt (sizeBytes , 10 )
963968 klog .Infof ("CloneSnapshot : snapshotName=%s" , snapshotName )
964969 snapshot , err := getSnapshot (snapshotID )
965970 if err != nil {
0 commit comments