]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add "children" command, update cli test files
authorDan Mick <dan.mick@inktank.com>
Tue, 21 Aug 2012 23:07:25 +0000 (16:07 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Sep 2012 22:18:50 +0000 (15:18 -0700)
Fixes: #2720
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
doc/man/8/rbd.rst
src/rbd.cc
src/test/cli/rbd/help.t
src/test/cli/rbd/invalid-snap-usage.t

index 97195865f7055252c65a892af32c834b6381d131..5ccfefbfa9fbce223e2b401539f59ce4e2ccd9da 100644 (file)
@@ -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.
 
index a1a36fdd990afc7e1aa4927de1a7b91373c42a91..9c56c5959c8326bf0235aa6add1fed11257c2db2 100644 (file)
@@ -73,6 +73,7 @@ void usage()
 "  clone [--order <bits>] <parentsnap> <clonename>\n"
 "                                              clone a snapshot into a COW\n"
 "                                               child image\n"
+"  children <snap-name>                        display children of snapshot\n"
 "  flatten <image-name>                        fill clone with parent data\n"
 "                                              (make it independent)\n"
 "  resize --size <MB> <image-name>             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<pair<string, string> > children;
+  int r = image.list_children(&children);
+  if (r < 0)
+    return r;
+
+  for (set<pair<string, string> >::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;
index 4afecec2dc4e3c937eac2bdb4ea363aec9c098d8..55217fb677cf89b2f4adbfc7d7f371f380bcd3ec 100644 (file)
@@ -8,6 +8,7 @@
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
index 8b657c83c2c81f04c8f37907bc788d6f5c8ea0af..e6ae9671d3266ff0c13fdf010e14888775ccf473 100644 (file)
@@ -9,6 +9,7 @@
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
@@ -63,6 +64,7 @@
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
                                                  child image
+    children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     resize --size <MB> <image-name>             resize (expand or contract) image