mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
reuse existing code for size Roundoff
This PR addresses the review comments in
https://github.com/ceph/ceph-csi/pull/644
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit 239822f147
)
This commit is contained in:
parent
8de7d9c90d
commit
a1cfc9c9ce
@ -42,26 +42,14 @@ const (
|
||||
|
||||
// RoundOffVolSize rounds up given quantity upto chunks of MiB/GiB
|
||||
func RoundOffVolSize(size int64) int64 {
|
||||
requestBytes := size
|
||||
if requestBytes < GiB {
|
||||
return roundUpSize(requestBytes, MiB)
|
||||
}
|
||||
size = roundUpSize(requestBytes, GiB)
|
||||
size = RoundOffBytes(size)
|
||||
// convert size back to MiB for rbd CLI
|
||||
return size * GiB / MiB
|
||||
}
|
||||
|
||||
func roundUpSize(volumeSizeBytes, allocationUnitBytes int64) int64 {
|
||||
roundedUp := volumeSizeBytes / allocationUnitBytes
|
||||
if volumeSizeBytes%allocationUnitBytes > 0 {
|
||||
roundedUp++
|
||||
}
|
||||
return roundedUp
|
||||
return size / MiB
|
||||
}
|
||||
|
||||
// RoundOffBytes converts roundoff the size
|
||||
// 1.1Mib will be round off to 2Mib same for GiB
|
||||
// size less than will be round off to 1MiB
|
||||
// size less than 1MiB will be round off to 1MiB
|
||||
func RoundOffBytes(bytes int64) int64 {
|
||||
var num int64
|
||||
floatBytes := float64(bytes)
|
||||
|
Loading…
Reference in New Issue
Block a user