]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: should set read_only when --readonly is set. 13944/head
authorPan Liu <liupan1111@gmail.com>
Tue, 14 Mar 2017 12:38:40 +0000 (20:38 +0800)
committerPan Liu <liupan1111@gmail.com>
Tue, 14 Mar 2017 12:38:40 +0000 (20:38 +0800)
Signed-off-by: Pan Liu <liupan1111@gmail.com>
src/tools/rbd_nbd/rbd-nbd.cc

index 32bd6da7e9ebc6bbf341375beec29ad29bf031e2..c16df03e23a986cfbf25091bc0948a3f4070eb45 100644 (file)
@@ -514,7 +514,7 @@ static int do_map(int argc, const char *argv[])
   librados::IoCtx io_ctx;
   librbd::Image image;
 
-  int read_only;
+  int read_only = 0;
   unsigned long flags;
   unsigned long size;
 
@@ -608,8 +608,10 @@ static int do_map(int argc, const char *argv[])
   }
 
   flags = NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_TRIM | NBD_FLAG_HAS_FLAGS;
-  if (!snapname.empty() || readonly)
+  if (!snapname.empty() || readonly) {
     flags |= NBD_FLAG_READ_ONLY;
+    read_only = 1;
+  }
 
   r = rados.init_with_context(g_ceph_context);
   if (r < 0)
@@ -674,7 +676,6 @@ static int do_map(int argc, const char *argv[])
 
   ioctl(nbd, NBD_SET_FLAGS, flags);
 
-  read_only = snapname.empty() ? 0 : 1;
   r = ioctl(nbd, BLKROSET, (unsigned long) &read_only);
   if (r < 0) {
     r = -errno;