Skip to content

Commit

Permalink
Merge pull request #10974 from dillaman/wip-17210
Browse files Browse the repository at this point in the history
librbd: potential double-unwatch of watch handle upon error

Reviewed-by: Mykola Golub <mgolub@mirantis.com>
  • Loading branch information
Mykola Golub committed Sep 6, 2016
2 parents 9fda6d1 + 1068ded commit 9a95536
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/librbd/ImageWatcher.cc
Expand Up @@ -140,16 +140,15 @@ void ImageWatcher<I>::unregister_watch(Context *on_finish) {

gather_ctx = new C_Gather(m_image_ctx.cct, create_async_context_callback(
m_image_ctx, on_finish));
if (m_watch_state == WATCH_STATE_REGISTERED) {
if (m_watch_state == WATCH_STATE_REGISTERED ||
m_watch_state == WATCH_STATE_ERROR) {
m_watch_state = WATCH_STATE_UNREGISTERED;

librados::AioCompletion *aio_comp = create_rados_safe_callback(
new C_UnwatchAndFlush(m_image_ctx.md_ctx, gather_ctx->new_sub()));
int r = m_image_ctx.md_ctx.aio_unwatch(m_watch_handle, aio_comp);
assert(r == 0);
aio_comp->release();
} else if (m_watch_state == WATCH_STATE_ERROR) {
m_watch_state = WATCH_STATE_UNREGISTERED;
}
}

Expand Down Expand Up @@ -1007,7 +1006,6 @@ void ImageWatcher<I>::handle_error(uint64_t handle, int err) {

RWLock::WLocker l(m_watch_lock);
if (m_watch_state == WATCH_STATE_REGISTERED) {
m_image_ctx.md_ctx.unwatch2(m_watch_handle);
m_watch_state = WATCH_STATE_ERROR;

FunctionContext *ctx = new FunctionContext(
Expand Down Expand Up @@ -1047,7 +1045,9 @@ void ImageWatcher<I>::handle_rewatch(int r) {

WatchState next_watch_state = WATCH_STATE_REGISTERED;
if (r < 0) {
next_watch_state = WATCH_STATE_ERROR;
// only EBLACKLISTED or ENOENT can be returned
assert(r == -EBLACKLISTED || r == -ENOENT);
next_watch_state = WATCH_STATE_UNREGISTERED;
}

Context *unregister_watch_ctx = nullptr;
Expand Down

0 comments on commit 9a95536

Please sign in to comment.