[sheepdog-users] [PATCH stable-0.7] dog: add an option "-o" to vdi track for tracking object with oid

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Dec 17 02:56:01 CET 2013


This patch adds a new option "-o" to vdi track. With this option,
users can track objects with their object ids. This would be more
friendly for users than existing "-i" option of vdi track. Because
output of "vdi check" is based on object ids. Users can recover
lost/corrupted objects manually based on this tracking information
when there are no majority objects.

Example of output:
$ dog vdi track test -o 0076680700000000
Tracking the object 0x76680700000000 (the inode vid 0x766807) with 5 nodes

obj 76680700000000 locations at epoch 1, copies = 3
---------------------------------------------------
127.0.0.1:7001
127.0.0.1:7000
127.0.0.1:7002

obj 76680700000000 locations at epoch 2, copies = 3
---------------------------------------------------
127.0.0.1:7001
127.0.0.1:7000
127.0.0.1:7003

obj 76680700000000 locations at epoch 3, copies = 3
---------------------------------------------------
127.0.0.1:7001
127.0.0.1:7004
127.0.0.1:7000

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>

Conflicts:
	CHANGELOG.md
	dog/vdi.c
Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 dog/vdi.c |   77 +++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 28 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index bc18fc4..f13a31f 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -30,6 +30,7 @@ static struct sd_option vdi_options[] = {
 	{'c', "copies", true, "specify the data redundancy (number of copies)"},
 	{'F', "from", true, "create a differential backup from the snapshot"},
 	{'f', "force", false, "do operation forcibly"},
+	{'o', "oid", true, "specify the object id of the tracking object"},
 	{ 0, NULL, false, NULL },
 };
 
@@ -45,6 +46,7 @@ static struct vdi_cmd_data {
 	int from_snapshot_id;
 	char from_snapshot_tag[SD_MAX_VDI_TAG_LEN];
 	bool force;
+	uint64_t oid;
 } vdi_cmd_data = { ~0, };
 
 struct get_vdi_info {
@@ -953,6 +955,7 @@ static int vdi_track(int argc, char **argv)
 	struct get_data_oid_info oid_info = {0};
 	uint32_t vid;
 	uint8_t nr_copies;
+	uint64_t oid = vdi_cmd_data.oid;
 
 	memset(&info, 0, sizeof(info));
 	info.name = vdiname;
@@ -970,37 +973,47 @@ static int vdi_track(int argc, char **argv)
 		return EXIT_MISSING;
 	}
 
-	if (idx == ~0) {
-		printf("Tracking the inode object 0x%" PRIx32 " with %d nodes\n",
-		       vid, sd_nodes_nr);
-		return do_track_object(vid_to_vdi_oid(vid), nr_copies);
-	}
+	if (!oid) {
+		if (idx == ~0) {
+			printf("Tracking the inode object 0x%" PRIx32
+			       " with %d nodes\n", vid, sd_nodes_nr);
+			return do_track_object(vid_to_vdi_oid(vid), nr_copies);
+		}
 
-	oid_info.success = false;
-	oid_info.idx = idx;
+		oid_info.success = false;
+		oid_info.idx = idx;
 
-	if (idx >= MAX_DATA_OBJS) {
-		printf("The offset is too large!\n");
-		goto err;
-	}
+		if (idx >= MAX_DATA_OBJS) {
+			printf("The offset is too large!\n");
+			goto err;
+		}
 
-	parse_objs(vid_to_vdi_oid(vid), get_data_oid,
-		   &oid_info, SD_DATA_OBJ_SIZE);
+		parse_objs(vid_to_vdi_oid(vid), get_data_oid, &oid_info,
+			   SD_DATA_OBJ_SIZE);
+
+		if (!oid_info.success) {
+			sd_err("Failed to read the inode object 0x%" PRIx32,
+			       vid);
+			goto err;
+		}
+		if (!oid_info.data_oid) {
+			printf("The inode object 0x%"PRIx32
+			       " idx %u is not allocated\n", vid, idx);
+			goto err;
+		}
+
+		oid = oid_info.data_oid;
+
+		printf("Tracking the object 0x%" PRIx64
+		       " (the inode vid 0x%" PRIx32 " idx %u)"
+		       " with %d nodes\n", oid, vid, idx, sd_nodes_nr);
+	} else
+		printf("Tracking the object 0x%" PRIx64
+		       " (the inode vid 0x%" PRIx32 ")"
+		       " with %d nodes\n", oid, vid, sd_nodes_nr);
+
+	return do_track_object(oid, nr_copies);
 
-	if (!oid_info.success) {
-		sd_err("Failed to read the inode object 0x%" PRIx32, vid);
-		goto err;
-	}
-	if (!oid_info.data_oid) {
-		printf("The inode object 0x%"PRIx32" idx %u is not allocated\n",
-		       vid, idx);
-		goto err;
-	}
-	printf("Tracking the object 0x%" PRIx64
-	       " (the inode vid 0x%" PRIx32 " idx %u)"
-	       " with %d nodes\n",
-	       oid_info.data_oid, vid, idx, sd_nodes_nr);
-	return do_track_object(oid_info.data_oid, nr_copies);
 err:
 	return EXIT_FAILURE;
 }
@@ -2136,7 +2149,8 @@ static struct subcommand vdi_cmd[] = {
 	{"object", "<vdiname>", "isaph", "show object information in the image",
 	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_object, vdi_options},
-	{"track", "<vdiname>", "isaph", "show the object epoch trace in the image",
+	{"track", "<vdiname>", "isapho",
+	 "show the object epoch trace in the image",
 	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_track, vdi_options},
 	{"setattr", "<vdiname> <key> [value]", "dxaph", "set a VDI attribute",
@@ -2223,6 +2237,13 @@ static int vdi_parser(int ch, char *opt)
 	case 'f':
 		vdi_cmd_data.force = true;
 		break;
+	case 'o':
+		vdi_cmd_data.oid = strtoll(opt, &p, 16);
+		if (opt == p) {
+			sd_err("object id must be a hex integer");
+			exit(EXIT_FAILURE);
+		}
+		break;
 	}
 
 	return 0;
-- 
1.7.10.4




More information about the sheepdog-users mailing list