[Sheepdog] [PATCH] shepherd: fix showing wrong vdi size

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Apr 22 09:18:59 CEST 2010


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 shepherd/shepherd.c |   17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index e16a952..beb072a 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -106,28 +106,23 @@ static int is_current(struct sheepdog_inode *i)
 	return !i->snap_ctime;
 }
 
-static char *size_to_str(uint64_t size, char *str, int str_size)
+static char *size_to_str(uint64_t _size, char *str, int str_size)
 {
 	char *units[] = {"MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
-	int i = 0, frac = 0;
+	int i = 0;
+	double size = (double)_size;
 
 	size /= 1024 * 1024;
 	while (i < ARRAY_SIZE(units) && size >= 1024) {
 		i++;
 
-		frac = size % 1024;
-		if (frac > 1000)
-			frac -= 100;
-		while (frac > 10)
-			frac /= 10;
-
 		size /= 1024;
 	}
 
-	if (size > 9)
-		snprintf(str, str_size, "%" PRId64 " %s", size, units[i]);
+	if (size >= 10)
+		snprintf(str, str_size, "%.0lf %s", size, units[i]);
 	else
-		snprintf(str, str_size, "%" PRId64 ".%d %s", size, frac, units[i]);
+		snprintf(str, str_size, "%.1lf %s", size, units[i]);
 
 	return str;
 }
-- 
1.5.6.5




More information about the sheepdog mailing list