From 41727ab01ce639a80930cc59c9597704871a2a55 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Mon, 7 Sep 2020 14:05:21 +0100 Subject: [PATCH] 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 --- src/tools/rbd_nbd/rbd-nbd.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index de6a58f51b6fe..ef4d2f41b1de3 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"); } -- 2.39.5