]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: support disabling auto-exclusive lock transition logic 11438/head
authorMykola Golub <mgolub@mirantis.com>
Tue, 11 Oct 2016 13:35:38 +0000 (16:35 +0300)
committerMykola Golub <mgolub@mirantis.com>
Wed, 12 Oct 2016 18:00:25 +0000 (21:00 +0300)
Fixes: http://tracker.ceph.com/issues/17488
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
qa/workunits/rbd/rbd-nbd.sh
src/test/cli/rbd/help.t
src/tools/rbd/action/Nbd.cc
src/tools/rbd_nbd/rbd-nbd.cc

index 1e08adee81fa964f936f5c9707d1b0adf6069c26..e9ee22b3ab336b05799e0d784e92c11e4324e47a 100755 (executable)
@@ -32,7 +32,7 @@ function cleanup()
        ${SUDO} rbd-nbd unmap ${DEV}
     fi
     if rbd -p ${POOL} status ${IMAGE} 2>/dev/null; then
-       for s in 0.1 0.2 0.4 0.8 1.6 3.2 6.4 12.8; do
+       for s in 0.5 1 2 4 8 16 32; do
            sleep $s
            rbd -p ${POOL} status ${IMAGE} | grep 'Watchers: none' && break
        done
@@ -112,4 +112,22 @@ blocks2=$(awk -v dev=${devname} '$4 == dev {print $3}' /proc/partitions)
 test -n "${blocks2}"
 test ${blocks2} -eq ${blocks}
 
+# read-only option test
+${SUDO} rbd-nbd unmap ${DEV}
+DEV=`${SUDO} rbd-nbd map --read-only ${POOL}/${IMAGE}`
+${SUDO} rbd-nbd list-mapped | grep "^${DEV}$"
+${SUDO} dd if=${DEV} of=/dev/null bs=1M
+expect_false ${SUDO} dd if=${DATA} of=${DEV} bs=1M oflag=direct
+${SUDO} rbd-nbd unmap ${DEV}
+
+# exclusive option test
+DEV=`${SUDO} rbd-nbd map --exclusive ${POOL}/${IMAGE}`
+${SUDO} rbd-nbd list-mapped | grep "^${DEV}$"
+${SUDO} dd if=${DATA} of=${DEV} bs=1M oflag=direct
+expect_false timeout 10 \
+       rbd bench ${IMAGE} --io-type write --io-size=1024 --io-total=1024
+${SUDO} rbd-nbd unmap ${DEV}
+DEV=
+rbd bench ${IMAGE} --io-type write --io-size=1024 --io-total=1024
+
 echo OK
index ea9e6eeacad3a080520208df370440680a84ca8d..92e2aa8bae6affff9a7da4ea235fdec0d3293625 100644 (file)
   
   rbd help nbd map
   usage: rbd nbd map [--pool <pool>] [--image <image>] [--snap <snap>] 
-                     [--read-only] [--device <device>] 
+                     [--read-only] [--exclusive] [--device <device>] 
                      <image-or-snap-spec> 
   
   Map image to a nbd device.
     --image arg           image name
     --snap arg            snapshot name
     --read-only           mount read-only
+    --exclusive           forbid other clients write
     --device arg          specify nbd device
   
   rbd help nbd unmap
index 478e42ae9648996f4f2d6158b1c5c9cf74632f72..adc10110ff562331e5a05a88ea0f5f5ddd0223e1 100644 (file)
@@ -100,6 +100,7 @@ void get_map_arguments(po::options_description *positional,
                                      at::ARGUMENT_MODIFIER_NONE);
   options->add_options()
     ("read-only", po::bool_switch(), "mount read-only")
+    ("exclusive", po::bool_switch(), "forbid other clients write")
     ("device", po::value<std::string>(), "specify nbd device");
 }
 
@@ -133,6 +134,9 @@ int execute_map(const po::variables_map &vm)
   if (vm["read-only"].as<bool>())
     args.push_back("--read-only");
 
+  if (vm["exclusive"].as<bool>())
+    args.push_back("--exclusive");
+
   if (vm.count("device")) {
     args.push_back("--device");
     args.push_back(vm["device"].as<std::string>().c_str());
index 2db9dfacb9a7b2a43c14d46e1087a6b3e0de88b0..76d52eede457b3a6a67236a05a4af2851f65b070 100644 (file)
@@ -64,6 +64,7 @@ static void usage()
             << "  --device <device path>                    Specify nbd device path\n"
             << "  --read-only                               Map readonly\n"
             << "  --nbds_max <limit>                        Override for module param\n"
+            << "  --exclusive                               Forbid other clients write\n"
             << std::endl;
   generic_server_usage();
 }
@@ -71,6 +72,7 @@ static void usage()
 static std::string devpath, poolname("rbd"), imgname, snapname;
 static bool readonly = false;
 static int nbds_max = 0;
+static bool exclusive = false;
 
 #ifdef CEPH_BIG_ENDIAN
 #define ntohll(a) (a)
@@ -566,6 +568,15 @@ static int do_map()
   if (r < 0)
     goto close_nbd;
 
+  if (exclusive) {
+    r = image.lock_acquire(RBD_LOCK_MODE_EXCLUSIVE);
+    if (r < 0) {
+      cerr << "rbd-nbd: failed to acquire exclusive lock: " << cpp_strerror(r)
+           << std::endl;
+      goto close_nbd;
+    }
+  }
+
   if (!snapname.empty()) {
     r = image.snap_set(snapname.c_str());
     if (r < 0)
@@ -758,6 +769,8 @@ static int rbd_nbd(int argc, const char *argv[])
       }
     } else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) {
       readonly = true;
+    } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) {
+      exclusive = true;
     } else {
       ++i;
     }