From 51defeada069c0e33b03b96be962f155ce3df295 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 22 Jun 2016 18:19:52 -0400 Subject: [PATCH] librbd: fix crash while using advisory locks with R/O image Fixes: http://tracker.ceph.com/issues/16364 Signed-off-by: Jason Dillaman (cherry picked from commit 1007aea3d78ca5aead8a11f932da0c1d9d67259e) --- src/librbd/ImageCtx.cc | 5 +---- src/librbd/ImageWatcher.cc | 8 ++++++++ src/librbd/ImageWatcher.h | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 564996985f9c6..87c710e9be447 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -1019,10 +1019,7 @@ struct C_InvalidateCache : public Context { void ImageCtx::notify_update() { state->handle_update_notification(); - - C_SaferCond ctx; - image_watcher->notify_header_update(&ctx); - ctx.wait(); + ImageWatcher::notify_header_update(md_ctx, header_oid); } void ImageCtx::notify_update(Context *on_finish) { diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index d3d4e701a736e..d9c6bfe6e3f9b 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -317,6 +317,14 @@ void ImageWatcher::notify_header_update(Context *on_finish) { m_notifier.notify(bl, nullptr, on_finish); } +void ImageWatcher::notify_header_update(librados::IoCtx &io_ctx, + const std::string &oid) { + // supports legacy (empty buffer) clients + bufferlist bl; + ::encode(NotifyMessage(HeaderUpdatePayload()), bl); + io_ctx.notify2(oid, bl, image_watcher::Notifier::NOTIFY_TIMEOUT, nullptr); +} + void ImageWatcher::schedule_cancel_async_requests() { FunctionContext *ctx = new FunctionContext( boost::bind(&ImageWatcher::cancel_async_requests, this)); diff --git a/src/librbd/ImageWatcher.h b/src/librbd/ImageWatcher.h index da1c11b332b5b..0ae5245a23908 100644 --- a/src/librbd/ImageWatcher.h +++ b/src/librbd/ImageWatcher.h @@ -54,6 +54,8 @@ class ImageWatcher { void notify_request_lock(); void notify_header_update(Context *on_finish); + static void notify_header_update(librados::IoCtx &io_ctx, + const std::string &oid); uint64_t get_watch_handle() const { RWLock::RLocker watch_locker(m_watch_lock);