From f4a039278f1dd5fcfbd82c3b50cbed6f4332d6b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Zarzy=C5=84ski?= Date: Fri, 1 Apr 2022 20:55:42 +0200 Subject: [PATCH] crimson/osd: move with_blocking_future from Operation to OperationT. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Buildability of this commit proves all users of `with_blocking_future()` have the concrete operation type which is necessary on the the way to the compile-time defined op's blocker registry. Signed-off-by: Radosław Zarzyński --- src/crimson/common/operation.cc | 5 +++ src/crimson/common/operation.h | 60 ++------------------------------- src/crimson/osd/osd_operation.h | 58 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/crimson/common/operation.cc b/src/crimson/common/operation.cc index 3f00b5c49a050..fc49046963fa6 100644 --- a/src/crimson/common/operation.cc +++ b/src/crimson/common/operation.cc @@ -16,10 +16,15 @@ void Operation::dump(ceph::Formatter* f) const dump_detail(f); f->close_section(); } +#if 0 + // TODO: implement when necessary at the leaf class layer + // as that's the place that will be aware about the exact + // type of an event container. f->open_array_section("blockers"); for (auto &blocker : blockers) { blocker->dump(f); } +#endif f->close_section(); f->close_section(); } diff --git a/src/crimson/common/operation.h b/src/crimson/common/operation.h index 296c9e8590224..59016db1a2daf 100644 --- a/src/crimson/common/operation.h +++ b/src/crimson/common/operation.h @@ -39,7 +39,8 @@ class Blocker; */ template class blocking_future_detail { - friend class Operation; +// just as a scaffolding for the transition from blocking_future +public: friend class Blocker; Blocker *blocker; Fut fut; @@ -361,51 +362,6 @@ class Operation : public boost::intrusive_ref_counter< virtual const char *get_type_name() const = 0; virtual void print(std::ostream &) const = 0; - template - seastar::future with_blocking_future(blocking_future &&f) { - if (f.fut.available()) { - return std::move(f.fut); - } - assert(f.blocker); - add_blocker(f.blocker); - return std::move(f.fut).then_wrapped([this, blocker=f.blocker](auto &&arg) { - clear_blocker(blocker); - return std::move(arg); - }); - } - - template - ::crimson::interruptible::interruptible_future - with_blocking_future_interruptible(blocking_future &&f) { - if (f.fut.available()) { - return std::move(f.fut); - } - assert(f.blocker); - add_blocker(f.blocker); - auto fut = std::move(f.fut).then_wrapped([this, blocker=f.blocker](auto &&arg) { - clear_blocker(blocker); - return std::move(arg); - }); - return ::crimson::interruptible::interruptible_future< - InterruptCond, T>(std::move(fut)); - } - - template - ::crimson::interruptible::interruptible_future - with_blocking_future_interruptible( - blocking_interruptible_future &&f) { - if (f.fut.available()) { - return std::move(f.fut); - } - assert(f.blocker); - add_blocker(f.blocker); - return std::move(f.fut).template then_wrapped_interruptible( - [this, blocker=f.blocker](auto &&arg) { - clear_blocker(blocker); - return std::move(arg); - }); - } - void dump(ceph::Formatter *f) const; void dump_brief(ceph::Formatter *f) const; virtual ~Operation() = default; @@ -415,23 +371,11 @@ class Operation : public boost::intrusive_ref_counter< registry_hook_t registry_hook; - std::vector blockers; uint64_t id = 0; void set_id(uint64_t in_id) { id = in_id; } - void add_blocker(Blocker *b) { - blockers.push_back(b); - } - - void clear_blocker(Blocker *b) { - auto iter = std::find(blockers.begin(), blockers.end(), b); - if (iter != blockers.end()) { - blockers.erase(iter); - } - } - friend class OperationRegistryI; template friend class OperationRegistryT; diff --git a/src/crimson/osd/osd_operation.h b/src/crimson/osd/osd_operation.h index 45694acf4896f..c9cba7e7eb607 100644 --- a/src/crimson/osd/osd_operation.h +++ b/src/crimson/osd/osd_operation.h @@ -52,7 +52,65 @@ struct InterruptibleOperation : Operation { template class OperationT : public InterruptibleOperation { + std::vector blockers; + + void add_blocker(Blocker *b) { + blockers.push_back(b); + } + + void clear_blocker(Blocker *b) { + auto iter = std::find(blockers.begin(), blockers.end(), b); + if (iter != blockers.end()) { + blockers.erase(iter); + } + } + public: + template + seastar::future with_blocking_future(blocking_future &&f) { + if (f.fut.available()) { + return std::move(f.fut); + } + assert(f.blocker); + add_blocker(f.blocker); + return std::move(f.fut).then_wrapped([this, blocker=f.blocker](auto &&arg) { + clear_blocker(blocker); + return std::move(arg); + }); + } + + template + ::crimson::interruptible::interruptible_future + with_blocking_future_interruptible(blocking_future &&f) { + if (f.fut.available()) { + return std::move(f.fut); + } + assert(f.blocker); + add_blocker(f.blocker); + auto fut = std::move(f.fut).then_wrapped([this, blocker=f.blocker](auto &&arg) { + clear_blocker(blocker); + return std::move(arg); + }); + return ::crimson::interruptible::interruptible_future< + InterruptCond, U>(std::move(fut)); + } + + template + ::crimson::interruptible::interruptible_future + with_blocking_future_interruptible( + blocking_interruptible_future &&f) { + if (f.fut.available()) { + return std::move(f.fut); + } + assert(f.blocker); + add_blocker(f.blocker); + return std::move(f.fut).template then_wrapped_interruptible( + [this, blocker=f.blocker](auto &&arg) { + clear_blocker(blocker); + return std::move(arg); + }); + } + static constexpr const char *type_name = OP_NAMES[static_cast(T::type)]; using IRef = boost::intrusive_ptr; -- 2.39.5