From dc9ee9ba0b7d015b7fa0ba1e4277feb110d1ce7b Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Mon, 7 Sep 2020 16:16:11 +0100 Subject: [PATCH] rbd-nbd: return quiesce hook exit code Signed-off-by: Mykola Golub --- qa/workunits/rbd/rbd-nbd.sh | 18 +++++++++--------- src/tools/rbd_nbd/rbd-nbd.cc | 32 +++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/qa/workunits/rbd/rbd-nbd.sh b/qa/workunits/rbd/rbd-nbd.sh index ae4c093b00430..d6e15999682f6 100755 --- a/qa/workunits/rbd/rbd-nbd.sh +++ b/qa/workunits/rbd/rbd-nbd.sh @@ -245,9 +245,9 @@ rbd-nbd list-mapped | expect_false grep "^${PID} *${POOL} *${IMAGE}" QUIESCE_HOOK=${TEMPDIR}/quiesce.sh DEV=`_sudo rbd-nbd map --quiesce --quiesce-hook ${QUIESCE_HOOK} ${POOL}/${IMAGE}` -# test it does not fail if the hook does not exists +# test it fails if the hook does not exists test ! -e ${QUIESCE_HOOK} -rbd snap create ${POOL}/${IMAGE}@quiesce1 +expect_false rbd snap create ${POOL}/${IMAGE}@quiesce1 _sudo dd if=${DATA} of=${DEV} bs=1M count=1 oflag=direct # test the hook is executed @@ -258,20 +258,20 @@ cat > ${QUIESCE_HOOK} <&2 echo \$1 > ${TEMPDIR}/\$2 EOF -rbd snap create ${POOL}/${IMAGE}@quiesce2 +rbd snap create ${POOL}/${IMAGE}@quiesce1 _sudo dd if=${DATA} of=${DEV} bs=1M count=1 oflag=direct test "$(cat ${TEMPDIR}/quiesce)" = ${DEV} test "$(cat ${TEMPDIR}/unquiesce)" = ${DEV} -# test it does not fail if the hook fails +# test snap create fails if the hook fails touch ${QUIESCE_HOOK} chmod +x ${QUIESCE_HOOK} cat > ${QUIESCE_HOOK} <&2 -exit 1 +echo "test snap create fails if the hook fails" >&2 +exit 22 EOF -rbd snap create ${POOL}/${IMAGE}@quiesce3 +expect_false rbd snap create ${POOL}/${IMAGE}@quiesce2 _sudo dd if=${DATA} of=${DEV} bs=1M count=1 oflag=direct # test the hook is slow @@ -280,7 +280,7 @@ cat > ${QUIESCE_HOOK} <&2 sleep 7 EOF -rbd snap create ${POOL}/${IMAGE}@quiesce4 +rbd snap create ${POOL}/${IMAGE}@quiesce2 _sudo dd if=${DATA} of=${DEV} bs=1M count=1 oflag=direct # test rbd-nbd_quiesce hook that comes with distribution @@ -296,7 +296,7 @@ fi _sudo mkfs ${DEV} mkdir ${TEMPDIR}/mnt _sudo mount ${DEV} ${TEMPDIR}/mnt -rbd snap create ${POOL}/${IMAGE}@quiesce5 +rbd snap create ${POOL}/${IMAGE}@quiesce3 _sudo dd if=${DATA} of=${TEMPDIR}/mnt/test bs=1M count=1 oflag=direct _sudo umount ${TEMPDIR}/mnt unmap_device ${DEV} diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index ef4d2f41b1de3..e39c2eb31a88c 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -148,9 +148,9 @@ static int parse_args(vector& args, std::ostream *err_msg, Command *command, Config *cfg); static int netlink_resize(int nbd_index, uint64_t size); -static void run_quiesce_hook(const std::string &quiesce_hook, - const std::string &devpath, - const std::string &command); +static int run_quiesce_hook(const std::string &quiesce_hook, + const std::string &devpath, + const std::string &command); class NBDServer { @@ -461,15 +461,20 @@ signal: while (wait_quiesce()) { - run_quiesce_hook(cfg->quiesce_hook, cfg->devpath, "quiesce"); + int r = run_quiesce_hook(cfg->quiesce_hook, cfg->devpath, "quiesce"); wait_inflight_io(); { std::unique_lock locker{lock}; + ceph_assert(quiesce == true); - // TODO: return quiesce hook exit code - image.quiesce_complete(quiesce_watch_handle, 0); + image.quiesce_complete(quiesce_watch_handle, r); + + if (r < 0) { + quiesce = false; + continue; + } wait_unquiesce(locker); } @@ -1193,9 +1198,9 @@ static int try_netlink_setup(Config *cfg, int fd, uint64_t size, uint64_t flags) return 0; } -static void run_quiesce_hook(const std::string &quiesce_hook, - const std::string &devpath, - const std::string &command) { +static int run_quiesce_hook(const std::string &quiesce_hook, + const std::string &devpath, + const std::string &command) { dout(10) << __func__ << ": " << quiesce_hook << " " << devpath << " " << command << dendl; @@ -1204,18 +1209,23 @@ static void run_quiesce_hook(const std::string &quiesce_hook, hook.add_cmd_args(devpath.c_str(), command.c_str(), NULL); bufferlist err; int r = hook.spawn(); - if (r != 0) { + if (r < 0) { err.append("subprocess spawn failed"); } else { err.read_fd(hook.get_stderr(), 16384); r = hook.join(); + if (r > 0) { + r = -r; + } } - if (r != 0) { + if (r < 0) { derr << __func__ << ": " << quiesce_hook << " " << devpath << " " << command << " failed: " << err.to_str() << dendl; } else { dout(10) << " succeeded: " << err.to_str() << dendl; } + + return r; } static void handle_signal(int signum) -- 2.39.5