Skip to content

Commit

Permalink
msg/msg_types: optionally accept features when encoding entity_{addr,…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
liewegas authored and zhjwpku committed May 9, 2016
1 parent 35f1077 commit 2dddc32
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/include/encoding.h
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions src/msg/msg_types.cc
Expand Up @@ -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") << addr;
}

void entity_inst_t::dump(Formatter *f) const
{
f->dump_object("name", name);
f->dump_object("addr", addr);
}

This comment has been minimized.

Copy link
@liewegas

liewegas May 10, 2016

Author

👍

void entity_name_t::generate_test_instances(list<entity_name_t*>& o)
{
o.push_back(new entity_name_t(entity_name_t::MON()));
Expand All @@ -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 = new entity_name_t(entity_name_t::MON());
entity_addr_t *addr = new entity_addr_t();

This comment has been minimized.

Copy link
@liewegas

liewegas May 10, 2016

Author

these two shouldn't be pointers

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));
Expand Down Expand Up @@ -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 };
Expand Down
13 changes: 8 additions & 5 deletions src/msg/msg_types.h
Expand Up @@ -358,7 +358,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);
#if defined(__linux__) || defined(DARWIN) || defined(__FreeBSD__)
Expand Down Expand Up @@ -390,7 +390,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)
{
Expand Down Expand Up @@ -432,16 +432,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) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/encoding/types.h
Expand Up @@ -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)
Expand Down

0 comments on commit 2dddc32

Please sign in to comment.