From: Ronen Friedman Date: Thu, 4 Jan 2024 16:18:44 +0000 (-0600) Subject: osd/scrub: add synchronous request to AsyncReserver API X-Git-Tag: v19.1.0~421^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c6c05ab639f90d86bc65d5324fcfc87077b9a62b;p=ceph.git osd/scrub: add synchronous request to AsyncReserver API To be used when handling replica reservation requests from "old" primaries, that expect an immediate grant/deny reply. Signed-off-by: Ronen Friedman --- diff --git a/src/common/AsyncReserver.h b/src/common/AsyncReserver.h index b80f9e7df8f60..1a19dc70d1bb2 100644 --- a/src/common/AsyncReserver.h +++ b/src/common/AsyncReserver.h @@ -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 *