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>
This commit is contained in:
Madhu Rajanna 2019-10-11 13:56:10 +05:30 committed by mergify[bot]
parent 7274bd09e5
commit 239822f147

View File

@ -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)