Skip to content

Commit

Permalink
rbd-nbd: fix potential race when waiting unqiesce
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
trociny committed Sep 11, 2020
1 parent 251ccb8 commit 41727ab
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/tools/rbd_nbd/rbd-nbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,9 @@ class NBDServer
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;
Expand Down Expand Up @@ -466,10 +465,14 @@ class NBDServer

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");
}
Expand Down

0 comments on commit 41727ab

Please sign in to comment.