]> 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>
Thu, 12 Feb 2026 17:04:09 +0000 (18:04 +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 afe0bb96abb4ecf01285e946d2d3da0382db7de1..9a2f75e658440ea4ddbd171a2efcfda615866892 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"
@@ -947,10 +946,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};
@@ -960,9 +955,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()) {