]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrub: add synchronous request to AsyncReserver API
authorRonen Friedman <rfriedma@redhat.com>
Thu, 4 Jan 2024 16:18:44 +0000 (10:18 -0600)
committerRonen Friedman <rfriedma@redhat.com>
Sun, 28 Jan 2024 15:40:02 +0000 (09:40 -0600)
To be used when handling replica reservation requests from "old"
primaries, that expect an immediate grant/deny reply.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/AsyncReserver.h

index b80f9e7df8f60810888f801d9d76454d1ec4805d..1a19dc70d1bb27bd618bfa4f4a708dd8e905d753 100644 (file)
@@ -264,6 +264,39 @@ public:
     do_queues();
   }
 
+  /**
+   * The synchronous version of request_reservation
+   * Used to handle requests from OSDs that do not support the async interface
+   * to scrub replica reservations, but still must count towards the max
+   * active reservations.
+   */
+  bool request_reservation_or_fail(
+      T item,               ///< [in] reservation key
+      Context *on_reserved   ///< [in] callback to be called on reservation
+  )
+  {
+    std::lock_guard l(lock);
+    ceph_assert(!queue_pointers.count(item) && !in_progress.count(item));
+
+    if (in_progress.size() >= max_allowed) {
+      rdout(10) << fmt::format("{}: request: {} denied", __func__, item)
+               << dendl;
+      return false;
+    }
+
+    const unsigned prio = UINT_MAX;
+    Reservation r(item, prio, on_reserved, nullptr);
+    queues[prio].push_back(r);
+    queue_pointers.insert(std::make_pair(
+       item, std::make_pair(prio, --(queues[prio]).end())));
+    do_queues();
+    // the new request should be in_progress now
+    ceph_assert(in_progress.count(item));
+    rdout(10) << fmt::format("{}: request: {} granted", __func__, item)
+             << dendl;
+    return true;
+  }
+
   /**
    * Cancels reservation
    *