]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: check command before opening the image
authorJosh Durgin <josh.durgin@dreamhost.com>
Tue, 18 Oct 2011 23:50:08 +0000 (16:50 -0700)
committerJosh Durgin <josh.durgin@dreamhost.com>
Mon, 24 Oct 2011 22:32:47 +0000 (15:32 -0700)
Now map/unmap won't use librbd, and commands that don't take --snap
will give an error when it's used.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
src/rbd.cc

index ca8a055f5943f15893164b4aad4974007e1383d7..cdd8bbccf0e4e3be0f221ee14cffcdc4c77ca2ba 100644 (file)
@@ -1007,8 +1007,12 @@ int main(int argc, const char **argv)
       opt_cmd == OPT_SNAP_CREATE || opt_cmd == OPT_SNAP_ROLLBACK ||
       opt_cmd == OPT_SNAP_REMOVE ||
       opt_cmd == OPT_MAP || opt_cmd == OPT_UNMAP) {
-    set_pool_image_name(poolname, imgname, (char **)&poolname, (char **)&imgname, (char **)&snapname);
-  } else if (snapname) {
+    set_pool_image_name(poolname, imgname, (char **)&poolname,
+                       (char **)&imgname, (char **)&snapname);
+  }
+  if (snapname && opt_cmd != OPT_SNAP_CREATE && opt_cmd != OPT_SNAP_ROLLBACK &&
+      opt_cmd != OPT_SNAP_REMOVE && opt_cmd != OPT_INFO &&
+      opt_cmd != OPT_EXPORT && opt_cmd != OPT_COPY) {
     cerr << "error: snapname specified for a command that doesn't use it" << std::endl;
     usage_exit();
   }
@@ -1053,7 +1057,7 @@ int main(int argc, const char **argv)
     }
   }
 
-  if (imgname &&
+  if (imgname && talk_to_cluster &&
       (opt_cmd == OPT_RESIZE || opt_cmd == OPT_INFO || opt_cmd == OPT_SNAP_LIST ||
        opt_cmd == OPT_SNAP_CREATE || opt_cmd == OPT_SNAP_ROLLBACK ||
        opt_cmd == OPT_SNAP_REMOVE || opt_cmd == OPT_EXPORT || opt_cmd == OPT_WATCH ||
@@ -1065,7 +1069,8 @@ int main(int argc, const char **argv)
     }
   }
 
-  if (snapname) {
+  if (snapname && talk_to_cluster &&
+      (opt_cmd == OPT_INFO || opt_cmd == OPT_EXPORT || opt_cmd == OPT_COPY)) {
     r = image.snap_set(snapname);
     if (r < 0 && !(r == -ENOENT && opt_cmd == OPT_SNAP_CREATE)) {
       cerr << "error setting snapshot context: " << cpp_strerror(-r) << std::endl;