From a1cfc9c9cee9a520bccb6957acb3a371a0065769 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Fri, 11 Oct 2019 13:56:10 +0530 Subject: [PATCH] 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 (cherry picked from commit 239822f1476af6bbcc195a33b42128fdc33ddf72) --- pkg/util/util.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/util/util.go b/pkg/util/util.go index 48d5e838a..ca7d5784f 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -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)