From 3561eb380af61a36f590646c8cfd78bf627d7c71 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 18 Jun 2016 12:45:11 -0400 Subject: [PATCH] msg/msg_types: prefix addr with type; - for none Previously entityt_addr_t() rendered as ":/0". Now it is "-". Signed-off-by: Sage Weil --- src/msg/msg_types.cc | 25 +++++++++++++++++++ src/msg/msg_types.h | 15 +++++++---- src/test/common/dns_resolve.cc | 2 +- .../librados_test_stub/TestWatchNotify.cc | 2 +- src/test/test_addrs.cc | 8 ++++++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/msg/msg_types.cc b/src/msg/msg_types.cc index fb8ec5efea4..f8e6a562fe4 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -65,6 +65,17 @@ bool entity_addr_t::parse(const char *s, const char **end) memset(this, 0, sizeof(*this)); const char *start = s; + + int newtype = TYPE_DEFAULT; + if (strncmp("legacy:", s, 7) == 0) { + start += 7; + newtype = TYPE_LEGACY; + } else if (*s == '-') { + *this = entity_addr_t(); + *end = s + 1; + return true; + } + bool brackets = false; if (*start == '[') { start++; @@ -140,10 +151,24 @@ bool entity_addr_t::parse(const char *s, const char **end) if (end) *end = p; + type = newtype; + //cout << *this << std::endl; return true; } +ostream& operator<<(ostream& out, const entity_addr_t &addr) +{ + if (addr.type == entity_addr_t::TYPE_NONE) { + return out << "-"; + } + if (addr.type != entity_addr_t::TYPE_DEFAULT) { + out << entity_addr_t::get_type_name(addr.type) << ":"; + } + out << addr.get_sockaddr() << '/' << addr.nonce; + return out; +} + ostream& operator<<(ostream& out, const sockaddr_storage &ss) { char buf[NI_MAXHOST] = { 0 }; diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index fa83dfbd295..a0bc924039d 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -207,8 +207,16 @@ WRITE_CLASS_ENCODER(ceph_sockaddr_storage) struct entity_addr_t { typedef enum { TYPE_NONE = 0, - TYPE_LEGACY = 1, + TYPE_LEGACY = 1, ///< legacy msgr1 protocol (ceph jewel and older) } type_t; + static const type_t TYPE_DEFAULT = TYPE_LEGACY; + static const char *get_type_name(int t) { + switch (t) { + case TYPE_NONE: return "none"; + case TYPE_LEGACY: return "legacy"; + default: return "???"; + } + }; __u32 type; __u32 nonce; @@ -446,10 +454,7 @@ struct entity_addr_t { }; WRITE_CLASS_ENCODER_FEATURES(entity_addr_t) -inline ostream& operator<<(ostream& out, const entity_addr_t &addr) -{ - return out << addr.get_sockaddr() << '/' << addr.nonce; -} +ostream& operator<<(ostream& out, const entity_addr_t &addr); 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/test/common/dns_resolve.cc b/src/test/common/dns_resolve.cc index d3e0677b8dc..3cf5586e00f 100644 --- a/src/test/common/dns_resolve.cc +++ b/src/test/common/dns_resolve.cc @@ -84,7 +84,7 @@ TEST_F(DNSResolverTest, resolve_ip_addr_fail) { ASSERT_EQ(ret, -1); std::ostringstream os; os << addr; - ASSERT_EQ(os.str(), ":/0"); + ASSERT_EQ(os.str(), "-"); } diff --git a/src/test/librados_test_stub/TestWatchNotify.cc b/src/test/librados_test_stub/TestWatchNotify.cc index 2aacd486152..6e749a7b92c 100644 --- a/src/test/librados_test_stub/TestWatchNotify.cc +++ b/src/test/librados_test_stub/TestWatchNotify.cc @@ -49,7 +49,7 @@ int TestWatchNotify::list_watchers(const std::string& o, watcher->watch_handles.begin(); it != watcher->watch_handles.end(); ++it) { obj_watch_t obj; - strcpy(obj.addr, ":/0"); + strcpy(obj.addr, "-"); obj.watcher_id = static_cast(it->second.gid); obj.cookie = it->second.handle; obj.timeout_seconds = 30; diff --git a/src/test/test_addrs.cc b/src/test/test_addrs.cc index 8cb3d4d7ab9..d8251221ec9 100644 --- a/src/test/test_addrs.cc +++ b/src/test/test_addrs.cc @@ -36,6 +36,14 @@ const char *addr_checks[][3] = { { "::", "[::]:0/0", "" }, { "::zz", "[::]:0/0", "zz" }, { ":: 12:34", "[::]:0/0", " 12:34" }, + { "-", "-", "" }, + { "-asdf", "-", "asdf" }, + { "legacy:1.2.3.4", "1.2.3.4:0/0", "" }, + { "legacy:1.2.3.4:12", "1.2.3.4:12/0", "" }, + { "legacy:1.2.3.4:12/34", "1.2.3.4:12/34", "" }, + { "msgr2:1.2.3.4", "msgr2:1.2.3.4:0/0", "" }, + { "msgr2:1.2.3.4:12", "msgr2:1.2.3.4:12/0", "" }, + { "msgr2:1.2.3.4:12/34", "msgr2:1.2.3.4:12/34", "" }, { NULL, NULL, NULL }, };