[Sheepdog] [PATCH 3/3] collie: add graph view option

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


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

The output text is parsable by Graphviz (graph drawing tools developed
by AT&T Research Labs) and help us debugging VDI relation bugs.

Example:

  $ qemu-img convert src.raw sheepdog:linux     # create volume
  $ qemu-img snapshot -c name sheepdog:linux    # create snapshot
  $ qemu-system-x86_64 sheepdog:linux:1         # boot from snapshot
  $ collie vdi graph                            # show graph
  digraph G {
    node [shape = "box", fontname = "Courier"];

    "0" [shape = "ellipse", label = "root"];

    "0" -> "a5d05d";
    "a5d05d" [
      group = "linux",
      label = "name:      linux\ntag :          1\nsize:      20 MB\ndate: 2010-06-17\ntime:   15:12:09"
    ];

    "a5d05d" -> "a5d05e";
    "a5d05e" [
      group = "linux",
      label = "name:      linux\ntag :          2\nsize:      20 MB\ndate: 2010-06-17\ntime:   15:12:35"
    ];

    "a5d05d" -> "a5d060";
    "a5d060" [
      group = "linux",
      label = "name:      linux\ntag :          3\nsize:      20 MB\ndate: 2010-06-17\ntime:   15:12:53"
      color="red"
    ];
  }

  $ collie vdi graph | dotty -                  # show graph with graphviz

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

diff --git a/collie/collie.c b/collie/collie.c
index 0e0a2a2..f493d05 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|tree|delete|object|lock|release)\n\
+  vdi (list|tree|graph|delete|object|lock|release)\n\
   vm list\n\
 \n\
 Common parameters:\n\
@@ -354,6 +354,39 @@ static void print_vdi_tree(uint32_t vid, char *name, uint32_t tag,
 	add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
 }
 
+static void print_vdi_graph(uint32_t vid, char *name, uint32_t tag,
+			    uint32_t flags, struct sheepdog_inode *i, void *data)
+{
+	time_t ti;
+	struct tm tm;
+	char dbuf[128], tbuf[128], size_str[128];
+
+	ti = i->ctime >> 32;
+	localtime_r(&ti, &tm);
+
+	strftime(dbuf, sizeof(dbuf), "%Y-%m-%d", &tm);
+	strftime(tbuf, sizeof(tbuf), "%H:%M:%S", &tm);
+	size_to_str(i->vdi_size, size_str, sizeof(size_str));
+
+	printf("  \"%x\" -> \"%x\";\n", i->parent_vdi_id, vid);
+	printf("  \"%x\" [\n"
+	       "    group = \"%s\",\n"
+	       "    label = \"",
+	       vid, name);
+	printf("name: %10s\\n"
+	       "tag : %10x\\n"
+	       "size: %10s\\n"
+	       "date: %10s\\n"
+	       "time: %10s",
+	       name, tag, size_str, dbuf, tbuf);
+
+	if (is_current(i))
+		printf("\",\n    color=\"red\"\n  ];\n\n");
+	else
+		printf("\"\n  ];\n\n");
+
+}
+
 struct vm_list_info {
 	struct sheepdog_vm_list_entry *vm_list_entries;
 	int nr_vms;
@@ -708,6 +741,21 @@ static int vdi_tree(int argc, char **argv)
 	return 0;
 }
 
+static int vdi_graph(int argc, char **argv)
+{
+	/* print a header */
+	printf("digraph G \{\n");
+	printf("  node [shape = \"box\", fontname = \"Courier\"];\n\n");
+	printf("  \"0\" [shape = \"ellipse\", label = \"root\"];\n\n");
+
+	parse_vdi(print_vdi_graph, NULL);
+
+	/* print a footer */
+	printf("}\n");
+
+	return 0;
+}
+
 static int vdi_delete(int argc, char **argv)
 {
 	char *data = argv[optind];
@@ -899,6 +947,7 @@ 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},
+	{"graph", SUBCMD_FLAG_NEED_NOEDLIST, vdi_graph},
 	{"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