[sheepdog] [PATCH] dog: add 'vdi object map' command

Liu Yuan namei.unix at gmail.com
Thu Jan 23 09:43:02 CET 2014


This command will show inode internal 'vdi' array states, is useful to check if
cloned VDI's inode is sane or not.

usage:
yliu at ubuntu-precise:~/sheepdog$ dog/dog vdi object map clone1
Index       VID
00000000   c8f989
00000001   c8f989
00000002   c8f989
00000003   7c2b25
00000004   7c2b25
00000005   7c2b25
...

yliu at ubuntu-precise:~/sheepdog$ dog/dog vdi object map -i 4 clone1
Index       VID
00000004   7c2b25

With this patch, original 'dog vdi object' becomes 'dog vdi object location'

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/vdi.c            | 62 ++++++++++++++++++++++++++++++++++++++++++++++------
 tests/functional/028 |  4 ++--
 tests/functional/029 |  2 +-
 tests/functional/035 |  2 +-
 tests/functional/058 |  2 +-
 5 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index f26a6c3..1e175b3 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -37,7 +37,7 @@ static struct sd_option vdi_options[] = {
 };
 
 static struct vdi_cmd_data {
-	unsigned int index;
+	uint64_t index;
 	int snapshot_id;
 	char snapshot_tag[SD_MAX_VDI_TAG_LEN];
 	bool exclusive;
@@ -959,10 +959,43 @@ static int vdi_rollback(int argc, char **argv)
 	return ret;
 }
 
-static int vdi_object(int argc, char **argv)
+
+static int vdi_object_map(int argc, char **argv)
 {
 	const char *vdiname = argv[optind];
-	unsigned idx = vdi_cmd_data.index;
+	uint64_t idx = vdi_cmd_data.index;
+	struct sd_inode *inode = xmalloc(sizeof(*inode));
+	uint32_t vid;
+	int ret;
+
+	ret = read_vdi_obj(vdiname, vdi_cmd_data.snapshot_id,
+			   vdi_cmd_data.snapshot_tag, NULL, inode,
+			   SD_INODE_SIZE);
+	if (ret != EXIT_SUCCESS) {
+		sd_err("FATAL: %s not found", vdiname);
+		return ret;
+	}
+
+	printf("Index       VID\n");
+	if (idx != ~0) {
+		vid = INODE_GET_VID(inode, idx);
+		printf("%08"PRIu64" %8"PRIx32"\n", idx, vid);
+	} else {
+		uint32_t max_idx = count_data_objs(inode);
+
+		for (idx = 0; idx < max_idx; idx++) {
+			vid = INODE_GET_VID(inode, idx);
+			if (vid)
+				printf("%08"PRIu64" %8"PRIx32"\n", idx, vid);
+		}
+	}
+	return EXIT_SUCCESS;
+}
+
+static int vdi_object_location(int argc, char **argv)
+{
+	const char *vdiname = argv[optind];
+	uint64_t idx = vdi_cmd_data.index;
 	struct get_vdi_info info;
 	uint32_t vid;
 	size_t size;
@@ -1006,15 +1039,16 @@ static int vdi_object(int argc, char **argv)
 		if (oid_info.success) {
 			if (oid_info.data_oid) {
 				printf("Looking for the object 0x%" PRIx64
-				       " (vid 0x%" PRIx32 " idx %u, %u copies) "
-				       "with %d nodes\n\n",
+				       " (vid 0x%" PRIx32 " idx %"PRIu64
+				       ", %u copies) with %d nodes\n\n",
 				       oid_info.data_oid, vid, idx,
 				       info.nr_copies, sd_nodes_nr);
 
 				parse_objs(oid_info.data_oid, do_print_obj,
 					   NULL, size);
 			} else
-				printf("The inode object 0x%" PRIx32 " idx %u is not allocated\n",
+				printf("The inode object 0x%" PRIx32 " idx"
+				       "%"PRIu64" is not allocated\n",
 				       vid, idx);
 		} else
 			sd_err("Failed to read the inode object 0x%" PRIx32,
@@ -2432,6 +2466,20 @@ out:
 	return ret;
 }
 
+static struct subcommand vdi_object_cmd[] = {
+	{"location", NULL, NULL, "show object location information",
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG, vdi_object_location},
+	{"map", NULL, NULL, "show object map information",
+	 NULL, CMD_NEED_ARG, vdi_object_map},
+	{NULL},
+};
+
+static int vdi_object(int argc, char **argv)
+{
+	return do_generic_subcommand(vdi_object_cmd, argc, argv);
+}
+
+
 static struct subcommand vdi_cache_cmd[] = {
 	{"flush", NULL, NULL, "flush the cache of the vdi specified.",
 	 NULL, CMD_NEED_ARG, vdi_cache_flush},
@@ -2475,7 +2523,7 @@ static struct subcommand vdi_cmd[] = {
 	{"graph", NULL, "aph", "show images in Graphviz dot format",
 	 NULL, 0, vdi_graph, vdi_options},
 	{"object", "<vdiname>", "isaph", "show object information in the image",
-	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
+	 vdi_object_cmd, CMD_NEED_ARG,
 	 vdi_object, vdi_options},
 	{"track", "<vdiname>", "isapho",
 	 "show the object epoch trace in the image",
diff --git a/tests/functional/028 b/tests/functional/028
index ff813c5..a0e80ae 100755
--- a/tests/functional/028
+++ b/tests/functional/028
@@ -42,8 +42,8 @@ done
 $DOG vdi read test | md5sum
 $DOG vdi read test -p 7001 | md5sum
 
-$DOG vdi object test
+$DOG vdi object location test
 
 for i in `seq 0 24`; do
-    $DOG vdi object -i $i test
+    $DOG vdi object location -i $i test
 done
diff --git a/tests/functional/029 b/tests/functional/029
index 935abf4..2f3cfaa 100755
--- a/tests/functional/029
+++ b/tests/functional/029
@@ -41,6 +41,6 @@ $DOG vdi delete -s 1 test2
 _vdi_list
 
 for i in `seq 2 9`; do
-	$DOG vdi object test$i -i 1;
+	$DOG vdi object location test$i -i 1;
 done
 
diff --git a/tests/functional/035 b/tests/functional/035
index ae14da8..59261b6 100755
--- a/tests/functional/035
+++ b/tests/functional/035
@@ -38,7 +38,7 @@ _wait_for_sheep_recovery 0
 $DOG vdi read test | md5sum > $STORE/csum.1
 
 for i in `seq 0 9`; do
-	$DOG vdi object -i $i test
+	$DOG vdi object location -i $i test
 done
 
 for i in 10 11 12; do
diff --git a/tests/functional/058 b/tests/functional/058
index 57cb524..d895648 100755
--- a/tests/functional/058
+++ b/tests/functional/058
@@ -13,6 +13,6 @@ dd if=/dev/zero | $DOG vdi write -w test
 $QEMU_IO -c "discard 0 100m" sheepdog:test | _filter_qemu_io
 $DOG vdi check test
 for i in `seq 0 24`; do
-	$DOG vdi object test -i $i;
+	$DOG vdi object location test -i $i;
 done
 _node_info
-- 
1.8.1.2




More information about the sheepdog mailing list