[sheepdog] [PATCH] dog: show actual redundancy scheme for 'vdi list'

Liu Yuan namei.unix at gmail.com
Tue Jan 21 09:02:35 CET 2014


With this patch, 'vdi list' will show actual redundancy as follow:

yliu at ubuntu-precise:~/sheepdog$ dog/dog vdi list
  Name        Id    Size    Used  Shared    Creation time   VDI id  Copies  Tag
  test         0   10 MB  0.0 MB  0.0 MB 2014-01-21 15:54   7c2b25    4:2
  test1        0   20 MB  0.0 MB  0.0 MB 2014-01-21 15:59   fd32fc      3

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/vdi.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index 8fd4664..d487234 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -181,6 +181,20 @@ static void stat_data_objs(const struct sd_inode *inode, uint64_t *my_objs,
 		stat_data_objs_btree(inode, my_objs, cow_objs);
 }
 
+static char *redundancy_scheme(uint8_t copy_nr, uint8_t policy)
+{
+	static char str[10];
+
+	if (policy > 0) {
+		int d, p;
+		ec_policy_to_dp(policy, &d, &p);
+		snprintf(str, sizeof(str), "%d:%d", d, p);
+	} else {
+		snprintf(str, sizeof(str), "%d", copy_nr);
+	}
+	return str;
+}
+
 static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
 			   uint32_t snapid, uint32_t flags,
 			   const struct sd_inode *i, void *data)
@@ -216,19 +230,23 @@ static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
 				putchar('\\');
 			putchar(*name++);
 		}
-		printf(" %d %s %s %s %s %" PRIx32 " %d %s\n", snapid,
+		printf(" %d %s %s %s %s %" PRIx32 " %s %s\n", snapid,
 		       strnumber(i->vdi_size),
 		       strnumber(my_objs * SD_DATA_OBJ_SIZE),
 		       strnumber(cow_objs * SD_DATA_OBJ_SIZE),
-		       dbuf, vid, i->nr_copies, i->tag);
+		       dbuf, vid,
+		       redundancy_scheme(i->nr_copies, i->copy_policy),
+		       i->tag);
 	} else {
-		printf("%c %-8s %5d %7s %7s %7s %s  %7" PRIx32 " %5d %13s\n",
+		printf("%c %-8s %5d %7s %7s %7s %s  %7" PRIx32 " %6s %13s\n",
 		       vdi_is_snapshot(i) ? 's' : (is_clone ? 'c' : ' '),
 		       name, snapid,
 		       strnumber(i->vdi_size),
 		       strnumber(my_objs * SD_DATA_OBJ_SIZE),
 		       strnumber(cow_objs * SD_DATA_OBJ_SIZE),
-		       dbuf, vid, i->nr_copies, i->tag);
+		       dbuf, vid,
+		       redundancy_scheme(i->nr_copies, i->copy_policy),
+		       i->tag);
 	}
 }
 
-- 
1.8.1.2




More information about the sheepdog mailing list