]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: formatters for watch_info_t
authorRonen Friedman <rfriedma@redhat.com>
Mon, 7 Aug 2023 16:52:12 +0000 (11:52 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Tue, 15 Aug 2023 12:32:46 +0000 (07:32 -0500)
...and entity_addr_t

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/msg/msg_types.cc
src/msg/msg_types.h
src/osd/osd_types.cc
src/osd/osd_types.h
src/osd/osd_types_fmt.h

index d4114b06e5975cf20a45acf8d9e78f43c69a710a..8d94c955527ced0f27c4407d8109756db29cdc1a 100644 (file)
@@ -229,6 +229,21 @@ std::ostream& operator<<(std::ostream& out, const entity_addr_t &addr)
   return out;
 }
 
+std::string entity_addr_t::fmt_print() const
+{
+  if (type == entity_addr_t::TYPE_NONE) {
+    return "-";
+  }
+  std::ostringstream out;  //< \todo use fmt::format
+  out << get_sockaddr();
+
+  if (type == entity_addr_t::TYPE_ANY) {
+    return fmt::format("{}/{}", out.str(), nonce);
+  } else {
+    return fmt::format("{}:{}/{}", get_type_name(type), out.str(), nonce);
+  }
+}
+
 std::ostream& operator<<(std::ostream& out, const sockaddr *psa)
 {
   char buf[NI_MAXHOST] = { 0 };
index 8420ff83e1adc6036ad00d279f092d725e995288..b39120cc08d4d51891c8ebee629cc3caa553262e 100644 (file)
@@ -18,7 +18,7 @@
 #include <sstream>
 
 #include <netinet/in.h>
-#include <fmt/format.h>
+#include "common/fmt_common.h"
 #if FMT_VERSION >= 90000
 #include <fmt/ostream.h>
 #endif
@@ -545,15 +545,13 @@ struct entity_addr_t {
   }
 
   void dump(ceph::Formatter *f) const;
+  std::string fmt_print() const; ///< used by the default fmt formatter
 
   static void generate_test_instances(std::list<entity_addr_t*>& o);
 };
 WRITE_CLASS_ENCODER_FEATURES(entity_addr_t)
 
 std::ostream& operator<<(std::ostream& out, const entity_addr_t &addr);
-#if FMT_VERSION >= 90000
-template <> struct fmt::formatter<entity_addr_t> : fmt::ostream_formatter {};
-#endif
 
 inline bool operator==(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) == 0; }
 inline bool operator!=(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) != 0; }
index 1f78e767e8f2b7169fb3cf372a6f2d820ba9a6e4..664d8a28740652cf475c280d649d4f4df68c7c4b 100644 (file)
@@ -5995,6 +5995,13 @@ void watch_info_t::dump(Formatter *f) const
   f->close_section();
 }
 
+std::string watch_info_t::fmt_print() const
+{
+  return fmt::format(
+      "watch(cookie {} {}s {})", cookie, timeout_seconds, addr);
+}
+
+
 void watch_info_t::generate_test_instances(list<watch_info_t*>& o)
 {
   o.push_back(new watch_info_t);
index b258eeb944e08d4e480991042fb73eabe4c91679..16955ef5ef4d7b330f4588665f4184a02910d652 100644 (file)
@@ -5519,11 +5519,11 @@ struct SnapSet {
 
   /// get space accounted to clone
   uint64_t get_clone_bytes(snapid_t clone) const;
-    
+
   void encode(ceph::buffer::list& bl) const;
   void decode(ceph::buffer::list::const_iterator& bl);
   void dump(ceph::Formatter *f) const;
-  static void generate_test_instances(std::list<SnapSet*>& o);  
+  static void generate_test_instances(std::list<SnapSet*>& o);
 
   SnapContext get_ssc_as_of(snapid_t as_of) const {
     SnapContext out;
@@ -5564,6 +5564,7 @@ struct watch_info_t {
   void encode(ceph::buffer::list& bl, uint64_t features) const;
   void decode(ceph::buffer::list::const_iterator& bl);
   void dump(ceph::Formatter *f) const;
+  std::string fmt_print() const;
   static void generate_test_instances(std::list<watch_info_t*>& o);
 };
 WRITE_CLASS_ENCODER_FEATURES(watch_info_t)
@@ -5574,8 +5575,7 @@ static inline bool operator==(const watch_info_t& l, const watch_info_t& r) {
 }
 
 static inline std::ostream& operator<<(std::ostream& out, const watch_info_t& w) {
-  return out << "watch(cookie " << w.cookie << " " << w.timeout_seconds << "s"
-    << " " << w.addr << ")";
+  return out << w.fmt_print();
 }
 
 struct notify_info_t {
index c10877cf3aab6903bcde181a62c70b3a88a4c384..ed0e48ae082a968c5798f1e884525e19fe777bbd 100644 (file)
@@ -329,6 +329,5 @@ struct fmt::formatter<ScrubMap> {
 };
 
 #if FMT_VERSION >= 90000
-template <> struct fmt::formatter<watch_info_t> : fmt::ostream_formatter {};
 template <bool TrackChanges> struct fmt::formatter<pg_missing_set<TrackChanges>> : fmt::ostream_formatter {};
 #endif