[sheepdog] [PATCH] dog/vdi: add data object reference support to vdi list command
Ruoyu
liangry at ucweb.com
Tue Jul 15 04:45:38 CEST 2014
Once I found the error message in sheep.log:
recover_replication_object(412) can not recover oid 3d211c0000025a
And I do want to know the data object is referenced by which vdi
or vdis. It seems no command support it, so I create a new one.
Usage: dog vdi list -o <oid>
Signed-off-by: Ruoyu <liangry at ucweb.com>
---
dog/vdi.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/dog/vdi.c b/dog/vdi.c
index 1443cf4..9498af3 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -256,6 +256,21 @@ static void for_each_node_print(uint64_t oid)
}
}
+static void print_obj_ref(uint32_t vid, const char *name, const char *tag,
+ uint32_t snapid, uint32_t flags,
+ const struct sd_inode *i, void *data)
+{
+ uint64_t oid = *(uint64_t *)data;
+ uint64_t idx = data_oid_to_idx(oid);
+ struct get_vdi_info info;
+
+ if (i->data_vdi_id[idx] == oid_to_vid(oid)) {
+ memset(&info, 0, sizeof(info));
+ info.name = name;
+ print_vdi_list(vid, name, tag, snapid, flags, i, &info);
+ }
+}
+
static int vdi_list(int argc, char **argv)
{
const char *vdiname = argv[optind];
@@ -270,11 +285,20 @@ static int vdi_list(int argc, char **argv)
if (parse_vdi(print_vdi_list, SD_INODE_SIZE, &info) < 0)
return EXIT_SYSFAIL;
return EXIT_SUCCESS;
- } else {
- if (parse_vdi(print_vdi_list, SD_INODE_SIZE, NULL) < 0)
+ }
+
+ if (vdi_cmd_data.oid) {
+ if (!is_data_obj(vdi_cmd_data.oid))
+ return EXIT_FAILURE;
+ if (parse_vdi(print_obj_ref, SD_INODE_SIZE,
+ &vdi_cmd_data.oid) < 0)
return EXIT_SYSFAIL;
return EXIT_SUCCESS;
}
+
+ if (parse_vdi(print_vdi_list, SD_INODE_SIZE, NULL) < 0)
+ return EXIT_SYSFAIL;
+ return EXIT_SUCCESS;
}
static int vdi_tree(int argc, char **argv)
@@ -2476,7 +2500,7 @@ static struct subcommand vdi_cmd[] = {
{"rollback", "<vdiname>", "saphfrvt", "rollback to a snapshot",
NULL, CMD_NEED_ARG,
vdi_rollback, vdi_options},
- {"list", "[vdiname]", "aprht", "list images",
+ {"list", "[vdiname]", "aprhot", "list images",
NULL, 0, vdi_list, vdi_options},
{"tree", NULL, "apht", "show images in tree view format",
NULL, 0, vdi_tree, vdi_options},
--
1.8.3.2
More information about the sheepdog
mailing list