From e85a238303666caf68a70f49580a87529eb9cd4f Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Tue, 21 Aug 2012 16:07:25 -0700 Subject: [PATCH] rbd: add "children" command, update cli test files Fixes: #2720 Signed-off-by: Dan Mick Reviewed-by: Josh Durgin --- doc/man/8/rbd.rst | 4 +++ src/rbd.cc | 42 +++++++++++++++++++++++---- src/test/cli/rbd/help.t | 1 + src/test/cli/rbd/invalid-snap-usage.t | 9 ++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index 97195865f7055..5ccfefbfa9fbc 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -96,6 +96,10 @@ Commands parent snap and child. The parent snapshot can be unprotected and deleted if it has no further dependent clones. +:command:`children` [*image-name*] + List the clones of the image at the given snapshot. This checks + every pool, and outputs the resulting poolname/imagename. + :command:`resize` [*image-name*] Resizes rbd image. The size parameter also needs to be specified. diff --git a/src/rbd.cc b/src/rbd.cc index a1a36fdd990af..9c56c5959c832 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -73,6 +73,7 @@ void usage() " clone [--order ] \n" " clone a snapshot into a COW\n" " child image\n" +" children display children of snapshot\n" " flatten fill clone with parent data\n" " (make it independent)\n" " resize --size resize (expand or contract) image\n" @@ -382,6 +383,20 @@ static int do_unprotect_snap(librbd::Image& image, const char *snapname) return 0; } +static int do_list_children(librbd::Image &image) +{ + set > children; + int r = image.list_children(&children); + if (r < 0) + return r; + + for (set >::const_iterator child_it = children.begin(); + child_it != children.end(); child_it++) { + cout << child_it->first << "/" << child_it->second << std::endl; + } + return 0; +} + struct ExportContext { int fd; MyProgressContext pc; @@ -970,6 +985,7 @@ enum { OPT_CREATE, OPT_CLONE, OPT_FLATTEN, + OPT_CHILDREN, OPT_RESIZE, OPT_RM, OPT_EXPORT, @@ -1003,6 +1019,8 @@ static int get_cmd(const char *cmd, bool snapcmd) return OPT_CLONE; if (strcmp(cmd, "flatten") == 0) return OPT_FLATTEN; + if (strcmp(cmd, "children") == 0) + return OPT_CHILDREN; if (strcmp(cmd, "resize") == 0) return OPT_RESIZE; if (strcmp(cmd, "rm") == 0) @@ -1195,6 +1213,9 @@ int main(int argc, const char **argv) case OPT_SHOWMAPPED: usage(); return EXIT_FAILURE; + case OPT_CHILDREN: + set_conf_param(v, &imgname, NULL); + break; default: assert(0); break; @@ -1231,15 +1252,16 @@ int main(int argc, const char **argv) opt_cmd != OPT_SNAP_REMOVE && opt_cmd != OPT_INFO && opt_cmd != OPT_EXPORT && opt_cmd != OPT_COPY && opt_cmd != OPT_MAP && opt_cmd != OPT_CLONE && - opt_cmd != OPT_SNAP_PROTECT && opt_cmd != OPT_SNAP_UNPROTECT) { + opt_cmd != OPT_SNAP_PROTECT && opt_cmd != OPT_SNAP_UNPROTECT && + opt_cmd != OPT_CHILDREN) { cerr << "error: snapname specified for a command that doesn't use it" << std::endl; usage(); return EXIT_FAILURE; } if ((opt_cmd == OPT_SNAP_CREATE || opt_cmd == OPT_SNAP_ROLLBACK || opt_cmd == OPT_SNAP_REMOVE || opt_cmd == OPT_CLONE || - opt_cmd == OPT_SNAP_PROTECT || opt_cmd == OPT_SNAP_UNPROTECT) && - !snapname) { + opt_cmd == OPT_SNAP_PROTECT || opt_cmd == OPT_SNAP_UNPROTECT || + opt_cmd == OPT_CHILDREN) && !snapname) { cerr << "error: snap name was not specified" << std::endl; usage(); return EXIT_FAILURE; @@ -1308,7 +1330,8 @@ int main(int argc, const char **argv) opt_cmd == OPT_SNAP_ROLLBACK || opt_cmd == OPT_SNAP_REMOVE || opt_cmd == OPT_SNAP_PURGE || opt_cmd == OPT_EXPORT || opt_cmd == OPT_SNAP_PROTECT || opt_cmd == OPT_SNAP_UNPROTECT || - opt_cmd == OPT_WATCH || opt_cmd == OPT_COPY || opt_cmd == OPT_FLATTEN)) { + opt_cmd == OPT_WATCH || opt_cmd == OPT_COPY || + opt_cmd == OPT_FLATTEN || opt_cmd == OPT_CHILDREN)) { r = rbd.open(io_ctx, image, imgname); if (r < 0) { cerr << "error opening image " << imgname << ": " << cpp_strerror(-r) << std::endl; @@ -1317,7 +1340,8 @@ int main(int argc, const char **argv) } if (snapname && talk_to_cluster && - (opt_cmd == OPT_INFO || opt_cmd == OPT_EXPORT || opt_cmd == OPT_COPY)) { + (opt_cmd == OPT_INFO || opt_cmd == OPT_EXPORT || opt_cmd == OPT_COPY || + opt_cmd == OPT_CHILDREN)) { r = image.snap_set(snapname); if (r < 0) { cerr << "error setting snapshot context: " << cpp_strerror(-r) << std::endl; @@ -1522,6 +1546,14 @@ int main(int argc, const char **argv) } break; + case OPT_CHILDREN: + r = do_list_children(image); + if (r < 0) { + cerr << "listing children failed: " << cpp_strerror(-r) << std::endl; + return EXIT_FAILURE; + } + break; + case OPT_EXPORT: if (!path) { cerr << "pathname should be specified" << std::endl; diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 4afecec2dc4e3..55217fb677cf8 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -8,6 +8,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image diff --git a/src/test/cli/rbd/invalid-snap-usage.t b/src/test/cli/rbd/invalid-snap-usage.t index 8b657c83c2c81..e6ae9671d3266 100644 --- a/src/test/cli/rbd/invalid-snap-usage.t +++ b/src/test/cli/rbd/invalid-snap-usage.t @@ -9,6 +9,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -63,6 +64,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -117,6 +119,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -171,6 +174,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -225,6 +229,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -279,6 +284,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -333,6 +339,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -387,6 +394,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image @@ -441,6 +449,7 @@ clone [--order ] clone a snapshot into a COW child image + children display children of snapshot flatten fill clone with parent data (make it independent) resize --size resize (expand or contract) image -- 2.39.5