[PATCH] dog: add inferface to list the single fully matched vdi quickly

14 views
Skip to first unread message

Meng Lingkun

unread,
Dec 2, 2016, 5:18:45 AM12/2/16
to sheep...@googlegroups.com, Meng Lingkun
As designed before, it will read all the vdi inodes even if a vdiname
is specified. It's time-consuming, especially when the cluster is in
recovery and inodes are not cached in memory.

Signed-off-by: Meng Lingkun <mengl...@cmss.chinamobile.com>
---
dog/vdi.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index f0e8a1c..775f942 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -38,6 +38,7 @@ static struct sd_option vdi_options[] = {
{'e', "exist", false, "only check objects exist or not,\n"
" neither comparing nor repairing"},
{'A', "async", false, "delete vdi asynchronously"},
+ {'S', "single", false, "only list the single fully matched vdi"},
{ 0, NULL, false, NULL },
};

@@ -57,6 +58,7 @@ static struct vdi_cmd_data {
bool no_share;
bool exist;
bool async;
+ bool single;
} vdi_cmd_data = { ~0, };

struct get_vdi_info {
@@ -288,6 +290,30 @@ static int vdi_list(int argc, char **argv)
if (!raw_output)
printf(" Name Id Size Used Shared Creation time VDI id Copies Tag\n");

+ if (vdi_cmd_data.single && vdiname) {
+ struct sd_inode *inode = NULL;
+ int ret;
+ struct get_vdi_info info;
+ uint32_t snapid;
+
+ memset(&info, 0, sizeof(info));
+ info.name = vdiname;
+
+ inode = malloc(sizeof(*inode));
+ ret = read_vdi_obj(vdiname, vdi_cmd_data.snapshot_id,
+ vdi_cmd_data.snapshot_tag, NULL, inode, SD_INODE_SIZE);
+ if (ret != EXIT_SUCCESS) {
+ free(inode);
+ return ret;
+ }
+
+ snapid = vdi_is_snapshot(inode) ? inode->snap_id : 0;
+ print_vdi_list(inode->vdi_id, vdiname,
+ vdi_cmd_data.snapshot_tag, snapid, 0, inode, &info);
+
+ return EXIT_SUCCESS;
+ }
+
if (vdiname) {
struct get_vdi_info info;
memset(&info, 0, sizeof(info));
@@ -2610,7 +2636,7 @@ static struct subcommand vdi_cmd[] = {
{"rollback", "<vdiname>", "saphfrvT", "rollback to a snapshot",
NULL, CMD_NEED_ARG,
vdi_rollback, vdi_options},
- {"list", "[vdiname]", "aprhoT", "list images",
+ {"list", "[vdiname]", "aprhoTSs", "list images",
NULL, 0, vdi_list, vdi_options},
{"tree", NULL, "aphT", "show images in tree view format",
NULL, 0, vdi_tree, vdi_options},
@@ -2725,6 +2751,9 @@ static int vdi_parser(int ch, const char *opt)
case 'A':
vdi_cmd_data.async = true;
break;
+ case 'S':
+ vdi_cmd_data.single = true;
+ break;
}

return 0;
--
1.8.3.1



Liu Yuan

unread,
Dec 4, 2016, 10:00:03 PM12/4/16
to Meng Lingkun, sheep...@googlegroups.com
On Fri, Dec 02, 2016 at 06:17:32PM +0800, Meng Lingkun wrote:
> As designed before, it will read all the vdi inodes even if a vdiname
> is specified. It's time-consuming, especially when the cluster is in
> recovery and inodes are not cached in memory.

There is no need to add one more option,

dog vdi list requested_name

should only read the inode of requested_name.

Thanks,
Yuan

smallp...@gmail.com

unread,
Dec 4, 2016, 10:34:04 PM12/4/16
to sheepdog-ng, mengl...@cmss.chinamobile.com
As designed before, 
1. "dog vdi list" will list all the vdis including snapshots;
2. "dog vdi list requested_name" will list the vdi and all its snapshots;
They are useful, and need to iterate the vdi_inuse.

Add the new option:
dog vdi list vdi_name -s tag -S
could list the single fully matched vdi or snapshot by reading inode directly.

Liu Yuan

unread,
Dec 5, 2016, 10:45:07 PM12/5/16
to smallp...@gmail.com, sheepdog-ng, mengl...@cmss.chinamobile.com
On Sun, Dec 04, 2016 at 07:34:04PM -0800, smallp...@gmail.com wrote:
> As designed before,
> 1. "dog vdi list" will list all the vdis including snapshots;
> 2. "dog vdi list requested_name" will list the vdi and all its snapshots;
> They are useful, and need to iterate the vdi_inuse.
>
> Add the new option:
> dog vdi list vdi_name -s tag -S
> could list the single fully matched vdi or snapshot by reading inode
> directly.

Okay, make sense.

Yuan

Reply all
Reply to author
Forward
0 new messages