[sheepdog] [PATCH v2] dog/vdi: add data object reference support to vdi list command

Hitoshi Mitake mitake.hitoshi at gmail.com
Sun Jul 27 11:13:27 CEST 2014


On Tue, Jul 15, 2014 at 12:03 PM, Ruoyu <liangry at ucweb.com> wrote:
> 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 | 31 ++++++++++++++++++++++++++++---
>  1 file changed, 28 insertions(+), 3 deletions(-)

Applied, thanks.
Hitoshi

>
> diff --git a/dog/vdi.c b/dog/vdi.c
> index 1443cf4..b61849f 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -256,6 +256,22 @@ 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] != 0 &&
> +                       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 +286,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 +2501,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
>
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list