mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-30 10:10:21 +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
|
// RoundOffVolSize rounds up given quantity upto chunks of MiB/GiB
|
||||||
func RoundOffVolSize(size int64) int64 {
|
func RoundOffVolSize(size int64) int64 {
|
||||||
requestBytes := size
|
size = RoundOffBytes(size)
|
||||||
if requestBytes < GiB {
|
|
||||||
return roundUpSize(requestBytes, MiB)
|
|
||||||
}
|
|
||||||
size = roundUpSize(requestBytes, GiB)
|
|
||||||
// convert size back to MiB for rbd CLI
|
// convert size back to MiB for rbd CLI
|
||||||
return size * GiB / MiB
|
return size / MiB
|
||||||
}
|
|
||||||
|
|
||||||
func roundUpSize(volumeSizeBytes, allocationUnitBytes int64) int64 {
|
|
||||||
roundedUp := volumeSizeBytes / allocationUnitBytes
|
|
||||||
if volumeSizeBytes%allocationUnitBytes > 0 {
|
|
||||||
roundedUp++
|
|
||||||
}
|
|
||||||
return roundedUp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RoundOffBytes converts roundoff the size
|
// RoundOffBytes converts roundoff the size
|
||||||
// 1.1Mib will be round off to 2Mib same for GiB
|
// 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 {
|
func RoundOffBytes(bytes int64) int64 {
|
||||||
var num int64
|
var num int64
|
||||||
floatBytes := float64(bytes)
|
floatBytes := float64(bytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user