Begin to implement CLI: implement listing, add help, add create stub
This commit is contained in:
+54
-14
@@ -28,10 +28,24 @@ json11::Json::object cli_tool_t::parse_args(int narg, const char *args[])
|
||||
{
|
||||
help();
|
||||
}
|
||||
else if (args[i][0] == '-' && args[i][1] == 'l')
|
||||
{
|
||||
cfg["long"] = "1";
|
||||
}
|
||||
else if (args[i][0] == '-' && args[i][1] == 'n')
|
||||
{
|
||||
cfg["count"] = args[++i];
|
||||
}
|
||||
else if (args[i][0] == '-' && args[i][1] == 'i')
|
||||
{
|
||||
cfg["interactive"] = "1";
|
||||
}
|
||||
else if (args[i][0] == '-' && args[i][1] == '-')
|
||||
{
|
||||
const char *opt = args[i]+2;
|
||||
cfg[opt] = !strcmp(opt, "json") || !strcmp(opt, "wait-list") || i == narg-1 ? "1" : args[++i];
|
||||
cfg[opt] = i == narg-1 || !strcmp(opt, "json") || !strcmp(opt, "wait-list") ||
|
||||
!strcmp(opt, "long") || !strcmp(opt, "writers-stopped") && strcmp("1", args[i+1]) != 0
|
||||
? "1" : args[++i];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -54,35 +68,54 @@ void cli_tool_t::help()
|
||||
{
|
||||
printf(
|
||||
"Vitastor command-line tool\n"
|
||||
"(c) Vitaliy Filippov, 2019+ (VNPL-1.1)\n\n"
|
||||
"(c) Vitaliy Filippov, 2019+ (VNPL-1.1)\n"
|
||||
"\n"
|
||||
"USAGE:\n"
|
||||
"%s ls [-l]\n"
|
||||
" List existing images. Also report provisioned and allocated size if -l is specified.\n"
|
||||
"\n"
|
||||
"%s create --size <size> [--parent <parent_name>[@<snapshot>]] <name>\n"
|
||||
" Create an image. You may use K/M/G/T suffixes for <size>. If --parent is specified,\n"
|
||||
" a copy-on-write image clone is created. Parent must be a snapshot (readonly image).\n"
|
||||
"\n"
|
||||
"%s snap-create <name>@<snapshot>\n"
|
||||
" Create a snapshot of image <name>. May be used live if only a single writer is active.\n"
|
||||
"\n"
|
||||
"%s set <name> [--size <size>] [--readonly | --readwrite]\n"
|
||||
" Resize image or change its readonly status. Images with children can't be made read-write.\n"
|
||||
"\n"
|
||||
"%s top [-n <MAX_COUNT>] [-i]\n"
|
||||
" Disable image list sorted by I/O load, interactive if -i specified.\n"
|
||||
"\n"
|
||||
"%s rm [OPTIONS] <from> [<to>] [--writers-stopped]\n"
|
||||
" Remove <from> or all layers between <from> and <to> (<to> must be a child of <from>),\n"
|
||||
" rebasing all their children accordingly. --writers-stopped allows merging to be a bit\n"
|
||||
" more effective in case of a single 'slim' read-write child and 'fat' removed parent:\n"
|
||||
" the child is merged into parent in that case and parent is renamed to child.\n"
|
||||
" In other cases parent layers are always merged into children.\n"
|
||||
"\n"
|
||||
"%s flatten [OPTIONS] <layer>\n"
|
||||
" Flatten a layer, i.e. merge data and detach it from parents.\n"
|
||||
"\n"
|
||||
"%s rm-data [OPTIONS] --pool <pool> --inode <inode> [--wait-list]\n"
|
||||
" Remove inode data without changing metadata.\n"
|
||||
" --wait-list means first retrieve objects listings and then remove it.\n"
|
||||
" --wait-list requires more memory, but allows to show correct stats.\n"
|
||||
" --wait-list requires more memory, but allows to show correct removal progress.\n"
|
||||
"\n"
|
||||
"%s merge-data [OPTIONS] <from> <to> [--target <target>]\n"
|
||||
" Merge layer data without changing metadata. Merge <from>..<to> to <target>.\n"
|
||||
" <to> must be a child of <from> and <target> may be one of the layers between\n"
|
||||
" <from> and <to>, including <from> and <to>.\n"
|
||||
"\n"
|
||||
"%s flatten [OPTIONS] <layer>\n"
|
||||
" Flatten a layer, i.e. merge data and detach it from parents\n"
|
||||
"\n"
|
||||
"%s rm [OPTIONS] <from> [<to>] [--writers-stopped 1]\n"
|
||||
" Remove <from> or all layers between <from> and <to> (<to> must be a child of <from>),\n"
|
||||
" rebasing all their children accordingly. One of deleted parents may be renamed to one\n"
|
||||
" of children \"to be rebased\", but only if that child itself is readonly or if\n"
|
||||
" --writers-stopped 1 is specified\n"
|
||||
"\n"
|
||||
"OPTIONS (global):\n"
|
||||
" --etcd_address <etcd_address>\n"
|
||||
" --iodepth N Send N operations in parallel to each OSD when possible (default 32)\n"
|
||||
" --parallel_osds M Work with M osds in parallel when possible (default 4)\n"
|
||||
" --progress 1|0 Report progress (default 1)\n"
|
||||
" --cas 1|0 Use online CAS writes when possible (default auto)\n"
|
||||
" --json JSON output\n"
|
||||
,
|
||||
exe_name, exe_name, exe_name, exe_name
|
||||
exe_name, exe_name, exe_name, exe_name, exe_name, exe_name, exe_name, exe_name, exe_name
|
||||
);
|
||||
exit(0);
|
||||
}
|
||||
@@ -176,6 +209,11 @@ void cli_tool_t::run(json11::Json cfg)
|
||||
fprintf(stderr, "command is missing\n");
|
||||
exit(1);
|
||||
}
|
||||
else if (cmd[0] == "ls")
|
||||
{
|
||||
// List images
|
||||
action_cb = start_ls(cfg);
|
||||
}
|
||||
else if (cmd[0] == "rm-data")
|
||||
{
|
||||
// Delete inode data
|
||||
@@ -201,6 +239,7 @@ void cli_tool_t::run(json11::Json cfg)
|
||||
fprintf(stderr, "unknown command: %s\n", cmd[0].string_value().c_str());
|
||||
exit(1);
|
||||
}
|
||||
json_output = cfg["json"].bool_value();
|
||||
iodepth = cfg["iodepth"].uint64_value();
|
||||
if (!iodepth)
|
||||
iodepth = 32;
|
||||
@@ -236,7 +275,8 @@ void cli_tool_t::run(json11::Json cfg)
|
||||
while (action_cb != NULL)
|
||||
{
|
||||
ringloop->loop();
|
||||
ringloop->wait();
|
||||
if (action_cb != NULL)
|
||||
ringloop->wait();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user