From: Christopher Hoffman Date: Thu, 14 Jul 2022 18:20:29 +0000 (-0600) Subject: librbd: bail from schedule_request_lock() if already lock owner X-Git-Tag: v15.2.17~2^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=199159cc9ddece9e5723a5f72e19fbe87b220165;p=ceph.git librbd: bail from schedule_request_lock() if already lock owner Race condition may be hit if there are multiple pending locks for the same image and pending callbacks. Abort exclusive lock process if already exclusive lock owner. Fixes: https://tracker.ceph.com/issues/56549 Signed-off-by: Christopher Hoffman (cherry picked from commit 3527d2c764626c09c5ede80ae844551fd8845756) --- diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index 50ac0facc4e..483e67d67f8 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -397,12 +397,11 @@ template void ImageWatcher::schedule_request_lock(bool use_timer, int timer_delay) { ceph_assert(ceph_mutex_is_locked(m_image_ctx.owner_lock)); - if (m_image_ctx.exclusive_lock == nullptr) { - // exclusive lock dynamically disabled via image refresh + // see notify_request_lock() + if (m_image_ctx.exclusive_lock == nullptr || + m_image_ctx.exclusive_lock->is_lock_owner()) { return; } - ceph_assert(m_image_ctx.exclusive_lock && - !m_image_ctx.exclusive_lock->is_lock_owner()); std::shared_lock watch_locker{this->m_watch_lock}; if (this->is_registered(this->m_watch_lock)) {