From 2c26282d7643e1b47c0aca164c45200a1d6a41b1 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Mon, 7 Aug 2023 11:52:12 -0500 Subject: [PATCH] osd: formatters for watch_info_t ...and entity_addr_t Signed-off-by: Ronen Friedman --- src/msg/msg_types.cc | 15 +++++++++++++++ src/msg/msg_types.h | 6 ++---- src/osd/osd_types.cc | 7 +++++++ src/osd/osd_types.h | 8 ++++---- src/osd/osd_types_fmt.h | 1 - 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/msg/msg_types.cc b/src/msg/msg_types.cc index d4114b06e59..8d94c955527 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -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 }; diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 8420ff83e1a..b39120cc08d 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -18,7 +18,7 @@ #include #include -#include +#include "common/fmt_common.h" #if FMT_VERSION >= 90000 #include #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& 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 : 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; } diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 1f78e767e8f..664d8a28740 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -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& o) { o.push_back(new watch_info_t); diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index b258eeb944e..16955ef5ef4 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -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& o); + static void generate_test_instances(std::list& 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& 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 { diff --git a/src/osd/osd_types_fmt.h b/src/osd/osd_types_fmt.h index c10877cf3aa..ed0e48ae082 100644 --- a/src/osd/osd_types_fmt.h +++ b/src/osd/osd_types_fmt.h @@ -329,6 +329,5 @@ struct fmt::formatter { }; #if FMT_VERSION >= 90000 -template <> struct fmt::formatter : fmt::ostream_formatter {}; template struct fmt::formatter> : fmt::ostream_formatter {}; #endif