]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: add entity_addrvec_t
authorZhao Junwang <zhjwpku@gmail.com>
Thu, 19 May 2016 13:02:21 +0000 (09:02 -0400)
committerSage Weil <sage@redhat.com>
Tue, 18 Oct 2016 20:40:11 +0000 (16:40 -0400)
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
src/msg/msg_types.cc
src/msg/msg_types.h
src/test/encoding/types.h

index 6a9ffa285d102715444f7f5e352d5e3a7f9f7dd7..309b19a4ff7c7275fde068176a34e4e0bd3d3fe9 100644 (file)
@@ -211,3 +211,94 @@ ostream& operator<<(ostream& out, const sockaddr *sa)
     return out << '[' << buf << "]:" << serv;
   return out << buf << ':' << serv;
 }
+
+// entity_addrvec_t
+
+void entity_addrvec_t::encode(bufferlist& bl, uint64_t features) const
+{
+  if ((features & CEPH_FEATURE_MSG_ADDR2) == 0) {
+    // encode a single legacy entity_addr_t for unfeatured peers
+    if (v.size() > 0) {
+      for (vector<entity_addr_t>::const_iterator p = v.begin();
+           p != v.end(); ++p) {
+        if ((*p).type == (*p).TYPE_LEGACY) {
+         ::encode(*p, bl, 0);
+         return;
+       }
+      }
+      ::encode(v[0], bl, 0);
+    } else {
+      ::encode(entity_addr_t(), bl, 0);
+    }
+    return;
+  }
+  ::encode((__u8)2, bl);
+  ::encode(v, bl, features);
+}
+
+void entity_addrvec_t::decode(bufferlist::iterator& bl)
+{
+  __u8 marker;
+  ::decode(marker, bl);
+  if (marker == 0) {
+    // legacy!
+    ::decode(marker, bl);
+    __u16 rest;
+    ::decode(rest, bl);
+    entity_addr_t addr;
+    addr.type = addr.TYPE_LEGACY;
+    ::decode(addr.nonce, bl);
+    sockaddr_storage ss;
+#if defined(__linux__) || defined(DARWIN) || defined(__FreeBSD__)
+    ::decode(ss, bl);
+#else
+    ceph_sockaddr_storage wireaddr;
+    ::memset(&wireaddr, '\0', sizeof(wireaddr));
+    ::decode(wireaddr, bl);
+    unsigned copysize = MIN(sizeof(wireaddr), sizeof(ss));
+    ::memcpy(&ss, &wireaddr, copysize);
+#endif
+    addr.set_sockaddr((sockaddr*)&ss);
+    v.clear();
+    v.push_back(addr);
+    return;
+  }
+  if (marker == 1) {
+    entity_addr_t addr;
+    DECODE_START(1, bl);
+    ::decode(addr.type, bl);
+    ::decode(addr.nonce, bl);
+    __u32 elen;
+    ::decode(elen, bl);
+    if (elen) {
+      bl.copy(elen, (char*)addr.get_sockaddr());
+    }
+    DECODE_FINISH(bl);
+    v.clear();
+    v.push_back(addr);
+    return;
+  }
+  if (marker > 2)
+    throw buffer::malformed_input("entity_addrvec_marker > 2");
+  ::decode(v, bl);
+}
+
+void entity_addrvec_t::dump(Formatter *f) const
+{
+  f->open_array_section("addrvec");
+  for (vector<entity_addr_t>::const_iterator p = v.begin();
+       p != v.end(); ++p) {
+    f->dump_object("addr", *p);
+  }
+  f->close_section();
+}
+
+void entity_addrvec_t::generate_test_instances(list<entity_addrvec_t*>& ls)
+{
+  ls.push_back(new entity_addrvec_t());
+  ls.push_back(new entity_addrvec_t());
+  ls.back()->v.push_back(entity_addr_t());
+  ls.push_back(new entity_addrvec_t());
+  ls.back()->v.push_back(entity_addr_t());
+  ls.back()->v.push_back(entity_addr_t());
+}
index c36fc978bf1e7924ef491ab193421f15af1f793a..c8ac06253abc854e4fdc954a0a605d1c52c7043f 100644 (file)
@@ -479,6 +479,18 @@ namespace std {
   };
 } // namespace std
 
+struct entity_addrvec_t {
+  vector<entity_addr_t> v;
+
+  unsigned size() const { return v.size(); }
+  bool empty() const { return v.empty(); }
+
+  void encode(bufferlist& bl, uint64_t features) const;
+  void decode(bufferlist::iterator& bl);
+  void dump(Formatter *f) const;
+  static void generate_test_instances(list<entity_addrvec_t*>& ls);
+};
+WRITE_CLASS_ENCODER_FEATURES(entity_addrvec_t);
 
 /*
  * a particular entity instance
index a28f210b9ac6ea8698d91f802207c6e47a27b2fe..c56ce71313e09ce8dcfc8887f852ac9f5fa3c925 100644 (file)
@@ -35,6 +35,7 @@ TYPE(SloppyCRCMap)
 #include "msg/msg_types.h"
 TYPE(entity_name_t)
 TYPE_FEATUREFUL(entity_addr_t)
+TYPE_FEATUREFUL(entity_addrvec_t)
 TYPE_FEATUREFUL(entity_inst_t)
 
 #include "osd/OSDMap.h"