msg/msg_types: optionally accept features when encoding entity_{addr,inst}_t

We will eventually require features, but it will take many patches to get
all callers to pass them in.  While we're doing that, behave both with
and without features.

v2:
  Add entity_inst_t::dump() & entity_inst_t::generate_test_instances()

Signed-off-by: Sage Weil <sage@redhat.com>
Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
This commit is contained in:
Sage Weil 2016-05-05 10:35:12 -04:00
parent bc300f3e1a
commit 5290133107
4 changed files with 30 additions and 9 deletions

View File

@ -160,6 +160,11 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
#define WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(cl) \
inline void encode(const cl &c, bufferlist &bl, uint64_t features = 0) { \
ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
// string
inline void encode(const std::string& s, bufferlist& bl, uint64_t features=0)

View File

@ -14,13 +14,18 @@ void entity_name_t::dump(Formatter *f) const
f->dump_unsigned("num", num());
}
void entity_addr_t::dump(Formatter *f) const
{
f->dump_unsigned("nonce", nonce);
f->dump_stream("addr") << get_sockaddr();
}
void entity_inst_t::dump(Formatter *f) const
{
f->dump_object("name", name);
f->dump_object("addr", addr);
}
void entity_name_t::generate_test_instances(list<entity_name_t*>& o)
{
o.push_back(new entity_name_t(entity_name_t::MON()));
@ -46,6 +51,15 @@ void entity_addr_t::generate_test_instances(list<entity_addr_t*>& o)
o.push_back(b);
}
void entity_inst_t::generate_test_instances(list<entity_inst_t*>& o)
{
o.push_back(new entity_inst_t());
entity_name_t name;
entity_addr_t addr;
entity_inst_t *a = new entity_inst_t(name, addr);
o.push_back(a);
}
bool entity_addr_t::parse(const char *s, const char **end)
{
memset(this, 0, sizeof(*this));
@ -130,8 +144,6 @@ bool entity_addr_t::parse(const char *s, const char **end)
return true;
}
ostream& operator<<(ostream& out, const sockaddr_storage &ss)
{
char buf[NI_MAXHOST] = { 0 };

View File

@ -365,7 +365,7 @@ struct entity_addr_t {
// broader study
void encode(bufferlist& bl) const {
void encode(bufferlist& bl, uint64_t features = 0) const {
::encode(type, bl);
::encode(nonce, bl);
sockaddr_storage ss = get_sockaddr_storage();
@ -400,7 +400,7 @@ struct entity_addr_t {
static void generate_test_instances(list<entity_addr_t*>& o);
};
WRITE_CLASS_ENCODER(entity_addr_t)
WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(entity_addr_t)
inline ostream& operator<<(ostream& out, const entity_addr_t &addr)
{
@ -442,16 +442,19 @@ struct entity_inst_t {
return i;
}
void encode(bufferlist& bl) const {
void encode(bufferlist& bl, uint64_t features = 0) const {
::encode(name, bl);
::encode(addr, bl);
::encode(addr, bl, features);
}
void decode(bufferlist::iterator& bl) {
::decode(name, bl);
::decode(addr, bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<entity_inst_t*>& o);
};
WRITE_CLASS_ENCODER(entity_inst_t)
WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(entity_inst_t)
inline bool operator==(const entity_inst_t& a, const entity_inst_t& b) {

View File

@ -34,7 +34,8 @@ TYPE(SloppyCRCMap)
#include "msg/msg_types.h"
TYPE(entity_name_t)
TYPE(entity_addr_t)
TYPE_FEATUREFUL(entity_addr_t)
TYPE_FEATUREFUL(entity_inst_t)
#include "osd/OSDMap.h"
TYPE(osd_info_t)