[Sheepdog] [PATCH 2/3] collie: add tree view option

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Jun 17 09:20:26 CEST 2010


This patch adds a tree view option to the `collie vdi' command.  This
is the same as `shepherd info -f tree' in the old syntax.

Example:

  $ qemu-img convert src.raw sheepdog:linux     # create vdi
  $ collie vdi tree                             # show vdi tree
  linux---(You Are Here)

  $ qemu-img snapshot -c name sheepdog:linux    # create snapshot
  $ qemu-img snapshot -c name sheepdog:linux    # create snapshot
  $ collie vdi tree                             # show vdi tree
  linux---[2010-06-17 15:12]---[2010-06-17 15:12]---(You Are Here)

  $ qemu-system-x86_64 sheepdog:linux:1         # boot from snapshot
  $ collie vdi tree                             # show vdi tree
  linux---[2010-06-17 15:12]-+-[2010-06-17 15:12]---[2010-06-17 15:12]
                             `-(You Are Here)

  $ qemu-img snapshot -c name sheepdog:linux    # create snapshot
  $ collie vdi tree                             # show vdi tree
  linux---[2010-06-17 15:12]-+-[2010-06-17 15:12]---[2010-06-17 15:12]
                             `-[2010-06-17 15:12]---(You Are Here)

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

diff --git a/collie/collie.c b/collie/collie.c
index 6f5b171..0e0a2a2 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -56,7 +56,7 @@ static void usage(int status)
 Command syntax:\n\
   cluster (info|format|shutdown)\n\
   node (info|list)\n\
-  vdi (list|delete|object|lock|release)\n\
+  vdi (list|tree|delete|object|lock|release)\n\
   vm list\n\
 \n\
 Common parameters:\n\
@@ -334,6 +334,26 @@ static void print_vdi_list(uint32_t vid, char *name, uint32_t tag,
 	}
 }
 
+static void print_vdi_tree(uint32_t vid, char *name, uint32_t tag,
+			   uint32_t flags, struct sheepdog_inode *i, void *data)
+{
+	time_t ti;
+	struct tm tm;
+	char buf[128];
+
+	if (is_current(i))
+		strcpy(buf, "(You Are Here)");
+	else {
+		ti = i->ctime >> 32;
+		localtime_r(&ti, &tm);
+
+		strftime(buf, sizeof(buf),
+			 "[%Y-%m-%d %H:%M]", &tm);
+	}
+
+	add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
+}
+
 struct vm_list_info {
 	struct sheepdog_vm_list_entry *vm_list_entries;
 	int nr_vms;
@@ -679,6 +699,15 @@ static int vdi_list(int argc, char **argv)
 	return 0;
 }
 
+static int vdi_tree(int argc, char **argv)
+{
+	init_tree();
+	parse_vdi(print_vdi_tree, NULL);
+	dump_tree();
+
+	return 0;
+}
+
 static int vdi_delete(int argc, char **argv)
 {
 	char *data = argv[optind];
@@ -869,6 +898,7 @@ static int vdi_release(int argc, char **argv)
 static struct subcommand vdi_cmd[] = {
 	{"delete", SUBCMD_FLAG_NEED_NOEDLIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_delete},
 	{"list", SUBCMD_FLAG_NEED_NOEDLIST, vdi_list},
+	{"tree", SUBCMD_FLAG_NEED_NOEDLIST, vdi_tree},
 	{"object", SUBCMD_FLAG_NEED_NOEDLIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_object},
 	{"lock", SUBCMD_FLAG_NEED_THIRD_ARG, vdi_lock},
 	{"release", SUBCMD_FLAG_NEED_THIRD_ARG, vdi_release},
-- 
1.5.6.5




More information about the sheepdog mailing list