From 1f9396ff8208accdf334c088745d2734225b34c1 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Mon, 19 Jan 2026 17:43:41 +0100 Subject: [PATCH] librbd: prepare lock_acquire() for changing between policies In preparation for adding a new TransientPolicy, get rid of the check implemented in terms of exclusive_lock::Policy::may_auto_request_lock() that essentially makes it so that exclusive lock policy on a given image handle can be changed from the default AutomaticPolicy only once. In order to effect another change a new image handle would have been needed which is pretty suboptimal. Signed-off-by: Ilya Dryomov --- src/librbd/internal.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 65e569b4ca3..63a40df6826 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -39,7 +39,6 @@ #include "librbd/api/Image.h" #include "librbd/api/Io.h" #include "librbd/cache/Utils.h" -#include "librbd/exclusive_lock/AutomaticPolicy.h" #include "librbd/exclusive_lock/StandardPolicy.h" #include "librbd/deep_copy/MetadataCopyRequest.h" #include "librbd/image/CloneRequest.h" @@ -948,10 +947,6 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { ldout(cct, 20) << __func__ << ": ictx=" << ictx << ", " << "lock_mode=" << lock_mode << dendl; - if (lock_mode != RBD_LOCK_MODE_EXCLUSIVE) { - return -EOPNOTSUPP; - } - C_SaferCond lock_ctx; { std::unique_lock l{ictx->owner_lock}; @@ -961,9 +956,11 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return -EINVAL; } - if (ictx->get_exclusive_lock_policy()->may_auto_request_lock()) { + if (lock_mode == RBD_LOCK_MODE_EXCLUSIVE) { ictx->set_exclusive_lock_policy( new exclusive_lock::StandardPolicy(ictx)); + } else { + return -EOPNOTSUPP; } if (ictx->exclusive_lock->is_lock_owner()) { -- 2.47.3