]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: return quiesce hook exit code
authorMykola Golub <mgolub@suse.com>
Mon, 7 Sep 2020 15:16:11 +0000 (16:16 +0100)
committerMykola Golub <mgolub@suse.com>
Fri, 11 Sep 2020 13:51:51 +0000 (14:51 +0100)
Signed-off-by: Mykola Golub <mgolub@suse.com>
qa/workunits/rbd/rbd-nbd.sh
src/tools/rbd_nbd/rbd-nbd.cc

index ae4c093b0043026811f900026e64101b396d6c2d..d6e15999682f6c30945b6c80cb5a0752cd2347ad 100755 (executable)
@@ -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} <<EOF
 echo "test the hook is executed" >&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} <<EOF
 #/bin/sh
-echo "test it does not fail if the hook fails" >&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} <<EOF
 echo "test the hook is slow" >&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}
index ef4d2f41b1de3f38631e7b44c4a7cc3deb95fc3d..e39c2eb31a88ccde3620973a33f8189cb4074479 100644 (file)
@@ -148,9 +148,9 @@ static int parse_args(vector<const char*>& 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)