From: Mykola Golub Date: Mon, 7 Sep 2020 13:05:21 +0000 (+0100) Subject: rbd-nbd: fix potential race when waiting unqiesce X-Git-Tag: v16.1.0~1096^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=41727ab01ce639a80930cc59c9597704871a2a55;p=ceph.git rbd-nbd: fix potential race when waiting unqiesce 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 --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index de6a58f51b6f..ef4d2f41b1de 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -424,10 +424,9 @@ signal: return true; } - void wait_unquiesce() { + void wait_unquiesce(std::unique_lock &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"); }