From: Mykola Golub Date: Tue, 11 Oct 2016 13:35:38 +0000 (+0300) Subject: rbd-nbd: support disabling auto-exclusive lock transition logic X-Git-Tag: v11.1.0~578^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=300a2810ac166b2bc56712e532951db322ac966d;p=ceph.git rbd-nbd: support disabling auto-exclusive lock transition logic Fixes: http://tracker.ceph.com/issues/17488 Signed-off-by: Mykola Golub --- diff --git a/qa/workunits/rbd/rbd-nbd.sh b/qa/workunits/rbd/rbd-nbd.sh index 1e08adee81fa..e9ee22b3ab33 100755 --- a/qa/workunits/rbd/rbd-nbd.sh +++ b/qa/workunits/rbd/rbd-nbd.sh @@ -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 diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index ea9e6eeacad3..92e2aa8bae6a 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -1086,7 +1086,7 @@ rbd help nbd map usage: rbd nbd map [--pool ] [--image ] [--snap ] - [--read-only] [--device ] + [--read-only] [--exclusive] [--device ] Map image to a nbd device. @@ -1100,6 +1100,7 @@ --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 diff --git a/src/tools/rbd/action/Nbd.cc b/src/tools/rbd/action/Nbd.cc index 478e42ae9648..adc10110ff56 100644 --- a/src/tools/rbd/action/Nbd.cc +++ b/src/tools/rbd/action/Nbd.cc @@ -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(), "specify nbd device"); } @@ -133,6 +134,9 @@ int execute_map(const po::variables_map &vm) if (vm["read-only"].as()) args.push_back("--read-only"); + if (vm["exclusive"].as()) + args.push_back("--exclusive"); + if (vm.count("device")) { args.push_back("--device"); args.push_back(vm["device"].as().c_str()); diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 2db9dfacb9a7..76d52eede457 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -64,6 +64,7 @@ static void usage() << " --device Specify nbd device path\n" << " --read-only Map readonly\n" << " --nbds_max 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; }