${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
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
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
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");
}
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());
<< " --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();
}
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)
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)
}
} 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;
}