From 27f7042e923366c31748c4cc9992c1a8cb37b457 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 9 Jun 2015 13:20:54 -0400 Subject: [PATCH] librbd: flush operations need to acquire owner lock Cache writeback operations will expect the owner lock to be held. Signed-off-by: Jason Dillaman (cherry picked from commit adfa2e0070ccca7b6556d3bfc5fac7ce4d43a4d0) --- src/librbd/ImageCtx.cc | 1 + src/librbd/internal.cc | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index fd1fe5b76a1be..5a88adb10348d 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -671,6 +671,7 @@ public: } void ImageCtx::flush_cache_aio(Context *onfinish) { + assert(owner_lock.is_locked()); cache_lock.Lock(); object_cacher->flush_set(object_set, onfinish); cache_lock.Unlock(); diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index f38b4512a70d4..a5c5f204dd4da 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -2399,7 +2399,8 @@ reprotect_and_return_err: if (ictx->object_cacher) { // complete pending writes before we're set to a snapshot and // get -EROFS for writes - RWLock::WLocker l(ictx->md_lock); + RWLock::RLocker owner_locker(ictx->owner_lock); + RWLock::WLocker md_locker(ictx->md_lock); ictx->flush_cache(); } int r = _snap_set(ictx, snap_name); @@ -3224,6 +3225,7 @@ reprotect_and_return_err: return; } + RWLock::RLocker owner_locker(ictx->owner_lock); ictx->user_flushed(); C_AioWrite *flush_ctx = new C_AioWrite(cct, c); @@ -3296,7 +3298,8 @@ reprotect_and_return_err: ictx->flush_async_operations(); - RWLock::WLocker l(ictx->md_lock); + RWLock::RLocker owner_locker(ictx->owner_lock); + RWLock::WLocker md_locker(ictx->md_lock); r = ictx->invalidate_cache(); return r; } -- 2.39.5