]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrub: use OpCarryingEvent for scrub events carrying common data
authorRonen Friedman <rfriedma@redhat.com>
Wed, 29 Nov 2023 13:16:24 +0000 (07:16 -0600)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 29 Nov 2023 13:30:40 +0000 (07:30 -0600)
Copied from a similar implementation in Crimson.
The payload includes the MOSDScrub* op, and the 'from' id.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
Split from "osd/scrub: move responsibility for clearing the 'being reserved' state"

src/osd/scrubber/scrub_machine.h

index a67a85b8e112bf954a7ed09ca6d22b3f21215330..fcca0d2cc40d84bcfe39f75fc516d9e20842c746 100644 (file)
@@ -48,39 +48,54 @@ namespace mpl = ::boost::mpl;
 void on_event_creation(std::string_view nm);
 void on_event_discard(std::string_view nm);
 
-// reservation grant/reject events carry the peer's response:
 
-/// a replica has granted our reservation request
-struct ReplicaGrant : sc::event<ReplicaGrant> {
-  OpRequestRef m_op;
-  pg_shard_t m_from;
-  ReplicaGrant(OpRequestRef op, pg_shard_t from) : m_op{op}, m_from{from}
+template <typename EV>
+struct OpCarryingEvent : sc::event<EV> {
+  static constexpr const char* event_name = "<>";
+  const OpRequestRef m_op;
+  const pg_shard_t m_from;
+  OpCarryingEvent(OpRequestRef op, pg_shard_t from) : m_op{op}, m_from{from}
   {
-    on_event_creation("ReplicaGrant");
+    on_event_creation(static_cast<EV*>(this)->event_name);
   }
+
+  OpCarryingEvent(const OpCarryingEvent&) = default;
+  OpCarryingEvent(OpCarryingEvent&&) = default;
+  OpCarryingEvent& operator=(const OpCarryingEvent&) = default;
+  OpCarryingEvent& operator=(OpCarryingEvent&&) = default;
+
   void print(std::ostream* out) const
   {
-    *out << fmt::format("ReplicaGrant(from: {})", m_from);
+    *out << fmt::format("{} (from: {})", EV::event_name, m_from);
   }
-  std::string_view print() const { return "ReplicaGrant"; }
-  ~ReplicaGrant() { on_event_discard("ReplicaGrant"); }
+  std::string_view print() const { return EV::event_name; }
+  ~OpCarryingEvent() { on_event_discard(EV::event_name); }
 };
 
-/// a replica has denied our reservation request
-struct ReplicaReject : sc::event<ReplicaReject> {
-  OpRequestRef m_op;
-  pg_shard_t m_from;
-  ReplicaReject(OpRequestRef op, pg_shard_t from) : m_op{op}, m_from{from}
-  {
-    on_event_creation("ReplicaReject");
+#define OP_EV(T)                                                     \
+  struct T : OpCarryingEvent<T> {                                    \
+    static constexpr const char* event_name = #T;                    \
+    template <typename... Args>                                      \
+    T(Args&&... args) : OpCarryingEvent(std::forward<Args>(args)...) \
+    {                                                                \
+    }                                                                \
   }
-  void print(std::ostream* out) const
-  {
-    *out << fmt::format("ReplicaReject(from: {})", m_from);
-  }
-  std::string_view print() const { return "ReplicaReject"; }
-  ~ReplicaReject() { on_event_discard("ReplicaReject"); }
-};
+
+
+// reservation events carry peer's request/response data:
+
+/// a replica has granted our reservation request
+OP_EV(ReplicaGrant);
+
+/// a replica has denied our reservation request
+OP_EV(ReplicaReject);
+
+/// received Primary request for scrub reservation
+OP_EV(ReplicaReserveReq);
+
+/// explicit release request from the Primary
+OP_EV(ReplicaRelease);
+
 
 #define MEV(E)                                          \
   struct E : sc::event<E> {                             \