]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: allow snapshots to be mapped
authorJosh Durgin <josh.durgin@dreamhost.com>
Wed, 23 Nov 2011 21:54:08 +0000 (13:54 -0800)
committerJosh Durgin <josh.durgin@dreamhost.com>
Tue, 6 Dec 2011 18:26:24 +0000 (10:26 -0800)
unmap and showmapped already support snapshots. map should too.

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

index 47b556d0d0b17ec3647273a17764f11387fa81bc..4abc9552a5d155ad94955bbffc3b78b22440d1cd 100644 (file)
@@ -567,7 +567,9 @@ static int do_watch(librados::IoCtx& pp, const char *imgname)
   return 0;
 }
 
-static int do_kernel_add(const char *poolname, const char *imgname, const char *secretfile, const char *user)
+static int do_kernel_add(const char *poolname, const char *imgname,
+                        const char *snapname, const char *secretfile,
+                        const char *user)
 {
   MonMap monmap;
   int r = MonClient::build_initial_monmap(g_ceph_context, monmap);
@@ -602,6 +604,10 @@ static int do_kernel_add(const char *poolname, const char *imgname, const char *
 
   oss << " " << poolname << " " << imgname;
 
+  if (snapname) {
+    oss << " " << snapname;
+  }
+
   // write to /sys/bus/rbd/add
   int fd = open("/sys/bus/rbd/add", O_WRONLY);
   if (fd < 0) {
@@ -1022,7 +1028,8 @@ int main(int argc, const char **argv)
                      (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) {
+      opt_cmd != OPT_EXPORT && opt_cmd != OPT_COPY &&
+      opt_cmd != OPT_MAP) {
     cerr << "error: snapname specified for a command that doesn't use it" << std::endl;
     usage_exit();
   }
@@ -1250,7 +1257,7 @@ int main(int argc, const char **argv)
     break;
 
   case OPT_MAP:
-    r = do_kernel_add(poolname, imgname, secretfile, user);
+    r = do_kernel_add(poolname, imgname, snapname, secretfile, user);
     if (r < 0) {
       cerr << "add failed: " << cpp_strerror(-r) << std::endl;
       exit(1);