From: Adam C. Emerson Date: Tue, 26 Dec 2017 06:45:26 +0000 (-0500) Subject: msg: Use unqualified encode/decode X-Git-Tag: v13.0.2~540^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7ea02d327d446122b35bbec0908a5a22c324277a;p=ceph.git msg: Use unqualified encode/decode This is a portion of Part 1 of the namespace project: using ADL properly in encode and decode so we can use namespaces easily in Ceph. Signed-off-by: Adam C. Emerson --- diff --git a/src/msg/Message.cc b/src/msg/Message.cc index 8cc5b8e1fc34..11ad14ae28c7 100644 --- a/src/msg/Message.cc +++ b/src/msg/Message.cc @@ -227,7 +227,7 @@ void Message::encode(uint64_t features, int crcflags) #ifdef ENCODE_DUMP bufferlist bl; - ::encode(get_header(), bl); + encode(get_header(), bl); // dump the old footer format ceph_msg_footer_old old_footer; @@ -235,11 +235,11 @@ void Message::encode(uint64_t features, int crcflags) old_footer.middle_crc = footer.middle_crc; old_footer.data_crc = footer.data_crc; old_footer.flags = footer.flags; - ::encode(old_footer, bl); + encode(old_footer, bl); - ::encode(get_payload(), bl); - ::encode(get_middle(), bl); - ::encode(get_data(), bl); + encode(get_payload(), bl); + encode(get_middle(), bl); + encode(get_data(), bl); // this is almost an exponential backoff, except because we count // bits we tend to sample things we encode later, which should be @@ -857,18 +857,19 @@ Message *decode_message(CephContext *cct, int crcflags, void Message::encode_trace(bufferlist &bl, uint64_t features) const { + using ceph::encode; auto p = trace.get_info(); static const blkin_trace_info empty = { 0, 0, 0 }; if (!p) { p = ∅ } - ::encode(*p, bl); + encode(*p, bl); } void Message::decode_trace(bufferlist::iterator &p, bool create) { blkin_trace_info info = {}; - ::decode(info, p); + decode(info, p); #ifdef WITH_BLKIN if (!connection) @@ -904,7 +905,7 @@ void encode_message(Message *msg, uint64_t features, bufferlist& payload) ceph_msg_footer_old old_footer; ceph_msg_footer footer; msg->encode(features, MSG_CRC_ALL); - ::encode(msg->get_header(), payload); + encode(msg->get_header(), payload); // Here's where we switch to the old footer format. PLR @@ -913,11 +914,11 @@ void encode_message(Message *msg, uint64_t features, bufferlist& payload) old_footer.middle_crc = footer.middle_crc; old_footer.data_crc = footer.data_crc; old_footer.flags = footer.flags; - ::encode(old_footer, payload); + encode(old_footer, payload); - ::encode(msg->get_payload(), payload); - ::encode(msg->get_middle(), payload); - ::encode(msg->get_data(), payload); + encode(msg->get_payload(), payload); + encode(msg->get_middle(), payload); + encode(msg->get_data(), payload); } // See above for somewhat bogus use of the old message footer. We switch to the current footer @@ -931,16 +932,15 @@ Message *decode_message(CephContext *cct, int crcflags, bufferlist::iterator& p) ceph_msg_footer_old fo; ceph_msg_footer f; bufferlist fr, mi, da; - ::decode(h, p); - ::decode(fo, p); + decode(h, p); + decode(fo, p); f.front_crc = fo.front_crc; f.middle_crc = fo.middle_crc; f.data_crc = fo.data_crc; f.flags = fo.flags; f.sig = 0; - ::decode(fr, p); - ::decode(mi, p); - ::decode(da, p); + decode(fr, p); + decode(mi, p); + decode(da, p); return decode_message(cct, crcflags, h, f, fr, mi, da, nullptr); } - diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index 43277182056d..b2d0c74dcf9c 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -948,8 +948,8 @@ ssize_t AsyncConnection::_process_connection() bl.append(state_buffer+banner_len, sizeof(ceph_entity_addr)*2); bufferlist::iterator p = bl.begin(); try { - ::decode(paddr, p); - ::decode(peer_addr_for_me, p); + decode(paddr, p); + decode(peer_addr_for_me, p); } catch (const buffer::error& e) { lderr(async_msgr->cct) << __func__ << " decode peer addr failed " << dendl; goto fail; @@ -989,7 +989,7 @@ ssize_t AsyncConnection::_process_connection() return 0; } - ::encode(async_msgr->get_myaddr(), myaddrbl, 0); // legacy + encode(async_msgr->get_myaddr(), myaddrbl, 0); // legacy r = try_send(myaddrbl); if (r == 0) { state = STATE_CONNECTING_SEND_CONNECT_MSG; @@ -1206,9 +1206,9 @@ ssize_t AsyncConnection::_process_connection() bl.append(CEPH_BANNER, strlen(CEPH_BANNER)); - ::encode(async_msgr->get_myaddr(), bl, 0); // legacy + encode(async_msgr->get_myaddr(), bl, 0); // legacy port = async_msgr->get_myaddr().get_port(); - ::encode(socket_addr, bl, 0); // legacy + encode(socket_addr, bl, 0); // legacy ldout(async_msgr->cct, 1) << __func__ << " sd=" << cs.fd() << " " << socket_addr << dendl; r = try_send(bl); @@ -1249,7 +1249,7 @@ ssize_t AsyncConnection::_process_connection() addr_bl.append(state_buffer+strlen(CEPH_BANNER), sizeof(ceph_entity_addr)); try { bufferlist::iterator ti = addr_bl.begin(); - ::decode(peer_addr, ti); + decode(peer_addr, ti); } catch (const buffer::error& e) { lderr(async_msgr->cct) << __func__ << " decode peer_addr failed " << dendl; goto fail; diff --git a/src/msg/msg_types.cc b/src/msg/msg_types.cc index d1a53b03420e..da0eb0f31861 100644 --- a/src/msg/msg_types.cc +++ b/src/msg/msg_types.cc @@ -222,30 +222,32 @@ ostream& operator<<(ostream& out, const sockaddr *sa) void entity_addrvec_t::encode(bufferlist& bl, uint64_t features) const { + using ceph::encode; if ((features & CEPH_FEATURE_MSG_ADDR2) == 0) { // encode a single legacy entity_addr_t for unfeatured peers if (v.size() > 0) { for (vector::const_iterator p = v.begin(); p != v.end(); ++p) { if ((*p).type == entity_addr_t::TYPE_LEGACY) { - ::encode(*p, bl, 0); + encode(*p, bl, 0); return; } } - ::encode(v[0], bl, 0); + encode(v[0], bl, 0); } else { - ::encode(entity_addr_t(), bl, 0); + encode(entity_addr_t(), bl, 0); } return; } - ::encode((__u8)2, bl); - ::encode(v, bl, features); + encode((__u8)2, bl); + encode(v, bl, features); } void entity_addrvec_t::decode(bufferlist::iterator& bl) { + using ceph::decode; __u8 marker; - ::decode(marker, bl); + decode(marker, bl); if (marker == 0) { // legacy! entity_addr_t addr; @@ -257,10 +259,10 @@ void entity_addrvec_t::decode(bufferlist::iterator& bl) if (marker == 1) { entity_addr_t addr; DECODE_START(1, bl); - ::decode(addr.type, bl); - ::decode(addr.nonce, bl); + decode(addr.type, bl); + decode(addr.nonce, bl); __u32 elen; - ::decode(elen, bl); + decode(elen, bl); if (elen) { bl.copy(elen, (char*)addr.get_sockaddr()); } @@ -271,7 +273,7 @@ void entity_addrvec_t::decode(bufferlist::iterator& bl) } if (marker > 2) throw buffer::malformed_input("entity_addrvec_marker > 2"); - ::decode(v, bl); + decode(v, bl); } void entity_addrvec_t::dump(Formatter *f) const diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 46929fafc5c3..66ca945a56c4 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -189,12 +189,12 @@ static inline void encode(const sockaddr_storage& a, bufferlist& bl) { const auto copy_size = std::min((unsigned char*)(&a + 1) - src, (unsigned char*)(&ss + 1) - dst); ::memcpy(dst, src, copy_size); - ::encode(ss, bl); + encode(ss, bl); #else ceph_sockaddr_storage ss{}; ::memset(&ss, '\0', sizeof(ss)); ::memcpy(&wireaddr, &ss, std::min(sizeof(ss), sizeof(a))); - ::encode(ss, bl); + encode(ss, bl); #endif } static inline void decode(sockaddr_storage& a, bufferlist::iterator& bl) { @@ -203,7 +203,7 @@ static inline void decode(sockaddr_storage& a, bufferlist::iterator& bl) { a.ss_family = ntohs(a.ss_family); #elif defined(__FreeBSD__) || defined(__APPLE__) ceph_sockaddr_storage ss{}; - ::decode(ss, bl); + decode(ss, bl); auto src = (unsigned char const *)&ss; auto dst = (unsigned char *)&a; a.ss_len = 0; @@ -216,7 +216,7 @@ static inline void decode(sockaddr_storage& a, bufferlist::iterator& bl) { ::memcpy(dst, src, copy_size); #else ceph_sockaddr_storage ss{}; - ::decode(ss, bl); + decode(ss, bl); ::memcpy(&a, &ss, std::min(sizeof(ss), sizeof(a))); #endif } @@ -416,14 +416,15 @@ struct entity_addr_t { void decode_legacy_addr_after_marker(bufferlist::iterator& bl) { + using ceph::decode; __u8 marker; __u16 rest; - ::decode(marker, bl); - ::decode(rest, bl); + decode(marker, bl); + decode(rest, bl); type = TYPE_LEGACY; - ::decode(nonce, bl); + decode(nonce, bl); sockaddr_storage ss; - ::decode(ss, bl); + decode(ss, bl); set_sockaddr((sockaddr*)&ss); } @@ -432,23 +433,24 @@ struct entity_addr_t { // broader study void encode(bufferlist& bl, uint64_t features) const { + using ceph::encode; if ((features & CEPH_FEATURE_MSG_ADDR2) == 0) { - ::encode((__u32)0, bl); - ::encode(nonce, bl); + encode((__u32)0, bl); + encode(nonce, bl); sockaddr_storage ss = get_sockaddr_storage(); - ::encode(ss, bl); + encode(ss, bl); return; } - ::encode((__u8)1, bl); + encode((__u8)1, bl); ENCODE_START(1, 1, bl); - ::encode(type, bl); - ::encode(nonce, bl); + encode(type, bl); + encode(nonce, bl); __u32 elen = get_sockaddr_len(); - ::encode(elen, bl); + encode(elen, bl); if (elen) { #if (__FreeBSD__) || defined(__APPLE__) __le16 ss_family = u.sa.sa_family; - ::encode(ss_family, bl); + encode(ss_family, bl); bl.append(u.sa.sa_data, elen - sizeof(u.sa.sa_len) - sizeof(u.sa.sa_family)); #else @@ -458,8 +460,9 @@ struct entity_addr_t { ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { + using ceph::decode; __u8 marker; - ::decode(marker, bl); + decode(marker, bl); if (marker == 0) { decode_legacy_addr_after_marker(bl); return; @@ -467,10 +470,10 @@ struct entity_addr_t { if (marker != 1) throw buffer::malformed_input("entity_addr_t marker != 1"); DECODE_START(1, bl); - ::decode(type, bl); - ::decode(nonce, bl); + decode(type, bl); + decode(nonce, bl); __u32 elen; - ::decode(elen, bl); + decode(elen, bl); if (elen) { #if defined(__FreeBSD__) || defined(__APPLE__) u.sa.sa_len = 0; @@ -478,7 +481,7 @@ struct entity_addr_t { if (elen < sizeof(ss_family)) { throw buffer::malformed_input("elen smaller than family len"); } - ::decode(ss_family, bl); + decode(ss_family, bl); u.sa.sa_family = ss_family; elen -= sizeof(ss_family); if (elen > get_sockaddr_len() - sizeof(u.sa.sa_family)) { @@ -556,12 +559,14 @@ struct entity_inst_t { } void encode(bufferlist& bl, uint64_t features) const { - ::encode(name, bl); - ::encode(addr, bl, features); + using ceph::encode; + encode(name, bl); + encode(addr, bl, features); } void decode(bufferlist::iterator& bl) { - ::decode(name, bl); - ::decode(addr, bl); + using ceph::decode; + decode(name, bl); + decode(addr, bl); } void dump(Formatter *f) const; diff --git a/src/msg/simple/Pipe.cc b/src/msg/simple/Pipe.cc index c28c0cf5e135..a5dd7e7998aa 100644 --- a/src/msg/simple/Pipe.cc +++ b/src/msg/simple/Pipe.cc @@ -363,7 +363,7 @@ int Pipe::accept() } // and my addr - ::encode(msgr->my_inst.addr, addrs, 0); // legacy + encode(msgr->my_inst.addr, addrs, 0); // legacy port = msgr->my_inst.addr.get_port(); @@ -376,7 +376,7 @@ int Pipe::accept() goto fail_unlocked; } socket_addr.set_sockaddr((sockaddr*)&ss); - ::encode(socket_addr, addrs, 0); // legacy + encode(socket_addr, addrs, 0); // legacy r = tcp_write(addrs.c_str(), addrs.length()); if (r < 0) { @@ -406,7 +406,7 @@ int Pipe::accept() } try { bufferlist::iterator ti = addrbl.begin(); - ::decode(peer_addr, ti); + decode(peer_addr, ti); } catch (const buffer::error& e) { ldout(msgr->cct,2) << __func__ << " decode peer_addr failed: " << e.what() << dendl; @@ -1072,8 +1072,8 @@ int Pipe::connect() } try { bufferlist::iterator p = addrbl.begin(); - ::decode(paddr, p); - ::decode(peer_addr_for_me, p); + decode(paddr, p); + decode(peer_addr_for_me, p); } catch (buffer::error& e) { ldout(msgr->cct,2) << "connect couldn't decode peer addrs: " << e.what() @@ -1100,7 +1100,7 @@ int Pipe::connect() msgr->learned_addr(peer_addr_for_me); - ::encode(msgr->my_inst.addr, myaddrbl, 0); // legacy + encode(msgr->my_inst.addr, myaddrbl, 0); // legacy memset(&msg, 0, sizeof(msg)); msgvec[0].iov_base = myaddrbl.c_str(); diff --git a/src/msg/xio/XioMsg.h b/src/msg/xio/XioMsg.h index f85950ebc402..b21e1835c36a 100644 --- a/src/msg/xio/XioMsg.h +++ b/src/msg/xio/XioMsg.h @@ -40,7 +40,7 @@ public: { bl.append(p); buffer::list::iterator bl_iter = bl.begin(); - ::decode(msg_cnt, bl_iter); + decode(msg_cnt, bl_iter); } }; @@ -74,31 +74,33 @@ public: const buffer::list& get_bl() { encode(bl); return bl; }; inline void encode_hdr(ceph::buffer::list& bl) const { - ::encode(tag, bl); - ::encode(msg_cnt, bl); - ::encode(peer_type, bl); - ::encode(addr, bl, features); - ::encode(hdr->seq, bl); - ::encode(hdr->tid, bl); - ::encode(hdr->type, bl); - ::encode(hdr->priority, bl); - ::encode(hdr->version, bl); - ::encode(hdr->front_len, bl); - ::encode(hdr->middle_len, bl); - ::encode(hdr->data_len, bl); - ::encode(hdr->data_off, bl); - ::encode(hdr->src.type, bl); - ::encode(hdr->src.num, bl); - ::encode(hdr->compat_version, bl); - ::encode(hdr->crc, bl); + using ceph::encode; + encode(tag, bl); + encode(msg_cnt, bl); + encode(peer_type, bl); + encode(addr, bl, features); + encode(hdr->seq, bl); + encode(hdr->tid, bl); + encode(hdr->type, bl); + encode(hdr->priority, bl); + encode(hdr->version, bl); + encode(hdr->front_len, bl); + encode(hdr->middle_len, bl); + encode(hdr->data_len, bl); + encode(hdr->data_off, bl); + encode(hdr->src.type, bl); + encode(hdr->src.num, bl); + encode(hdr->compat_version, bl); + encode(hdr->crc, bl); } inline void encode_ftr(buffer::list& bl) const { - ::encode(ftr->front_crc, bl); - ::encode(ftr->middle_crc, bl); - ::encode(ftr->data_crc, bl); - ::encode(ftr->sig, bl); - ::encode(ftr->flags, bl); + using ceph::encode; + encode(ftr->front_crc, bl); + encode(ftr->middle_crc, bl); + encode(ftr->data_crc, bl); + encode(ftr->sig, bl); + encode(ftr->flags, bl); } inline void encode(buffer::list& bl) const { @@ -107,31 +109,33 @@ public: } inline void decode_hdr(buffer::list::iterator& bl) { - ::decode(tag, bl); - ::decode(msg_cnt, bl); - ::decode(peer_type, bl); - ::decode(addr, bl); - ::decode(hdr->seq, bl); - ::decode(hdr->tid, bl); - ::decode(hdr->type, bl); - ::decode(hdr->priority, bl); - ::decode(hdr->version, bl); - ::decode(hdr->front_len, bl); - ::decode(hdr->middle_len, bl); - ::decode(hdr->data_len, bl); - ::decode(hdr->data_off, bl); - ::decode(hdr->src.type, bl); - ::decode(hdr->src.num, bl); - ::decode(hdr->compat_version, bl); - ::decode(hdr->crc, bl); + using ceph::decode; + decode(tag, bl); + decode(msg_cnt, bl); + decode(peer_type, bl); + decode(addr, bl); + decode(hdr->seq, bl); + decode(hdr->tid, bl); + decode(hdr->type, bl); + decode(hdr->priority, bl); + decode(hdr->version, bl); + decode(hdr->front_len, bl); + decode(hdr->middle_len, bl); + decode(hdr->data_len, bl); + decode(hdr->data_off, bl); + decode(hdr->src.type, bl); + decode(hdr->src.num, bl); + decode(hdr->compat_version, bl); + decode(hdr->crc, bl); } inline void decode_ftr(buffer::list::iterator& bl) { - ::decode(ftr->front_crc, bl); - ::decode(ftr->middle_crc, bl); - ::decode(ftr->data_crc, bl); - ::decode(ftr->sig, bl); - ::decode(ftr->flags, bl); + using ceph::decode; + decode(ftr->front_crc, bl); + decode(ftr->middle_crc, bl); + decode(ftr->data_crc, bl); + decode(ftr->sig, bl); + decode(ftr->flags, bl); } inline void decode(buffer::list::iterator& bl) {