[Sheepdog] [PATCH 1/2] shepherd: change the output of vdi list

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Jan 9 14:58:29 CET 2010


simplify the output of `shepherd info -t vdi` because its line-length
was too long.

New output is

  name     tag         size    used  shared    creation time  object id
-----------------------------------------------------------------------
  windows  4b481bd0    4 GB    0 MB    0 MB 2010-01-09 15:01      80000
  linux    4b481c03    4 GB    0 MB    0 MB 2010-01-09 15:02      c0000
s linux    4b481bc6    4 GB    0 MB    0 MB 2010-01-09 15:01      40000

Lines of snapshot vdis start with 's'.

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

diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index 5bbf29d..e66c7e7 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -99,6 +99,22 @@ static struct sheepdog_node_list_entry *node_list_entries;
 static int nr_nodes;
 static unsigned master_idx;
 
+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;
+
+	size /= 1024 * 1024;
+	while (i < ARRAY_SIZE(units) && size >= 1024) {
+		i++;
+		size /= 1024;
+	}
+
+	snprintf(str, str_size, "%" PRId64 " %s", size, units[i]);
+
+	return str;
+}
+
 static int update_node_list(int max_nodes, int epoch)
 {
 	int fd, ret;
@@ -555,6 +571,7 @@ static void print_vdi_list(uint64_t oid, char *name, uint32_t tag,
 {
 	int idx;
 	uint64_t my_objs, cow_objs;
+	char vdi_size_str[8], my_objs_str[8], cow_objs_str[8];
 	time_t ti;
 	struct tm tm;
 	char dbuf[128];
@@ -563,7 +580,7 @@ static void print_vdi_list(uint64_t oid, char *name, uint32_t tag,
 	localtime_r(&ti, &tm);
 
 	strftime(dbuf, sizeof(dbuf),
-		 "%Y-%m-%d %H:%M:%S", &tm);
+		 "%Y-%m-%d %H:%M", &tm);
 
 	my_objs = 0;
 	cow_objs = 0;
@@ -576,13 +593,14 @@ static void print_vdi_list(uint64_t oid, char *name, uint32_t tag,
 			cow_objs++;
 	}
 
+	size_to_str(i->vdi_size, vdi_size_str, sizeof(vdi_size_str));
+	size_to_str(my_objs * SD_DATA_OBJ_SIZE, my_objs_str, sizeof(my_objs_str));
+	size_to_str(cow_objs * SD_DATA_OBJ_SIZE, cow_objs_str, sizeof(cow_objs_str));
+
 	if (!data || strcmp(name, data) == 0) {
-		printf("%8" PRIx64 " : %-8s\t%" PRIu64 " MB (allocated: %" PRIu64
-		       " MB, shared: %" PRIu64 " MB), %s, tag: %8x, %s\n",
-		       oid, name, i->vdi_size / 1024 / 1024,
-		       my_objs * SD_DATA_OBJ_SIZE / 1024 / 1024,
-		       cow_objs * SD_DATA_OBJ_SIZE / 1024 / 1024, dbuf, tag,
-		       flags & FLAG_CURRENT ? "current" : "not current");
+		printf("%c %-8s %8x %7s %7s %7s %s  %9" PRIx64 "\n",
+		       flags & FLAG_CURRENT ? ' ' : 's', name, tag,
+		       vdi_size_str, my_objs_str, cow_objs_str, dbuf, oid);
 	}
 }
 
@@ -843,6 +861,8 @@ rerun:
 	case INFO_VDI:
 		switch (format) {
 		case FORMAT_LIST:
+			printf("  name     tag         size    used  shared    creation time  object id\n");
+			printf("-----------------------------------------------------------------------\n");
 			ret = parse_vdi(print_vdi_list, name);
 			break;
 		case FORMAT_TREE:
-- 
1.5.6.5




More information about the sheepdog mailing list