osd: formatters for watch_info_t

...and entity_addr_t

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
This commit is contained in:
Ronen Friedman 2023-08-07 11:52:12 -05:00
parent 6590e56b42
commit 2c26282d76
5 changed files with 28 additions and 9 deletions

View 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 };

View 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; }

View 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);

View 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 {

View 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