From 0e6a032c9e6ddae20be82df7500a0758d2cd8e74 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 7 Apr 2015 15:39:13 -0400 Subject: [PATCH] librbd: moved snap_create header update notification to initiator When handling a proxied snap_create operation, the client which invoked the snap_create should send the header update notification to avoid a possible race condition where snap_create completes but the client doesn't see the new snapshot (since it didn't yet receive the notification). Fixes: #11342 Signed-off-by: Jason Dillaman (cherry picked from commit 6e20ed6834912ccd979d16e3f3b340c239e05288) --- src/librbd/ImageWatcher.cc | 15 --------------- src/librbd/ImageWatcher.h | 2 -- src/librbd/internal.cc | 3 ++- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index 142c2db8423..fd400054766 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -389,11 +389,6 @@ void ImageWatcher::release_lock() unlock(); } -void ImageWatcher::finalize_header_update() { - librbd::notify_change(m_image_ctx.md_ctx, m_image_ctx.header_oid, - &m_image_ctx); -} - void ImageWatcher::assert_header_locked(librados::ObjectWriteOperation *op) { rados::cls::lock::assert_locked(op, RBD_LOCK_NAME, LOCK_EXCLUSIVE, encode_lock_cookie(), WATCHER_LOCK_TAG); @@ -898,16 +893,6 @@ void ImageWatcher::handle_payload(const SnapCreatePayload &payload, int r = librbd::snap_create(&m_image_ctx, payload.snap_name.c_str(), false); ::encode(ResponseMessage(r), *out); - if (r == 0) { - // increment now to avoid race due to the delayed notification - Mutex::Locker lictx(m_image_ctx.refresh_lock); - ++m_image_ctx.refresh_seq; - - // cannot notify within a notificiation - FunctionContext *ctx = new FunctionContext( - boost::bind(&ImageWatcher::finalize_header_update, this)); - m_task_finisher->queue(TASK_CODE_HEADER_UPDATE, ctx); - } } } diff --git a/src/librbd/ImageWatcher.h b/src/librbd/ImageWatcher.h index 2ffe9656972..d75e2fe2222 100644 --- a/src/librbd/ImageWatcher.h +++ b/src/librbd/ImageWatcher.h @@ -74,7 +74,6 @@ namespace librbd { TASK_CODE_RELEASED_LOCK, TASK_CODE_RETRY_AIO_REQUESTS, TASK_CODE_CANCEL_ASYNC_REQUESTS, - TASK_CODE_HEADER_UPDATE, TASK_CODE_REREGISTER_WATCH, TASK_CODE_ASYNC_REQUEST, TASK_CODE_ASYNC_PROGRESS @@ -212,7 +211,6 @@ namespace librbd { int lock(); void release_lock(); bool try_request_lock(); - void finalize_header_update(); void schedule_retry_aio_requests(bool use_timer); void retry_aio_requests(); diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index c356c79fe3b..727ddb00e96 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -502,7 +502,8 @@ namespace librbd { } r = ictx->image_watcher->notify_snap_create(snap_name); - if (r == -EEXIST) { + if (r == 0 || r == -EEXIST) { + notify_change(ictx->md_ctx, ictx->header_oid, ictx); return 0; } else if (r != -ETIMEDOUT) { return r; -- 2.47.3