]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.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>
Mon, 9 Feb 2026 23:24:21 +0000 (00:24 +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>
(cherry picked from commit 1f9396ff8208accdf334c088745d2734225b34c1)

src/librbd/internal.cc

index c491e7c2a6997c1df72ea373150f56d4c41727e0..8d7bbe2e8b3b0dedc8c06bffa4d24e7a8bc27938 100644 (file)
@@ -38,7 +38,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"
@@ -940,10 +939,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};
@@ -953,9 +948,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()) {