]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: prepare lock_acquire() for changing between policies
authorIlya Dryomov <idryomov@gmail.com>
Mon, 19 Jan 2026 16:43:41 +0000 (17:43 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 20 Jan 2026 00:13:21 +0000 (01:13 +0100)
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 <idryomov@gmail.com>
src/librbd/internal.cc

index 65e569b4ca397e9cb8641eaecd192d6cb29a570c..63a40df68261d3963dccdf149c3cc30cd7d944db 100644 (file)
@@ -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()) {