]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: fix potential race when waiting unqiesce
authorMykola Golub <mgolub@suse.com>
Mon, 7 Sep 2020 13:05:21 +0000 (14:05 +0100)
committerMykola Golub <mgolub@suse.com>
Fri, 11 Sep 2020 13:51:51 +0000 (14:51 +0100)
There was a window between issuing quiesce_complete and checking
the quiesce variable unset by the unqiesce callback, when the lock
was not holding. If during that window the unquiesce following the
next quiesce callbacks were called we would miss unquiesce event.

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/tools/rbd_nbd/rbd-nbd.cc

index de6a58f51b6feb7fab10e3149332d09ec136e44a..ef4d2f41b1de3f38631e7b44c4a7cc3deb95fc3d 100644 (file)
@@ -424,10 +424,9 @@ signal:
     return true;
   }
 
-  void wait_unquiesce() {
+  void wait_unquiesce(std::unique_lock<ceph::mutex> &locker) {
     dout(20) << __func__ << dendl;
 
-    std::unique_lock locker{lock};
     cond.wait(locker, [this] { return !quiesce || terminated; });
 
     dout(20) << __func__ << ": got unquiesce request" << dendl;
@@ -466,10 +465,14 @@ signal:
 
       wait_inflight_io();
 
-      // TODO: return quiesce hook exit code
-      image.quiesce_complete(quiesce_watch_handle, 0);
+      {
+        std::unique_lock locker{lock};
+
+        // TODO: return quiesce hook exit code
+        image.quiesce_complete(quiesce_watch_handle, 0);
 
-      wait_unquiesce();
+        wait_unquiesce(locker);
+      }
 
       run_quiesce_hook(cfg->quiesce_hook, cfg->devpath, "unquiesce");
     }