Skip to content

Commit

Permalink
messages: Use unqualified encode/decode
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
adamemerson committed Jan 10, 2018
1 parent c7582b7 commit f45e480
Show file tree
Hide file tree
Showing 139 changed files with 1,689 additions and 1,499 deletions.
23 changes: 16 additions & 7 deletions src/common/mClockCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <cstdint>
#include "include/encoding.h"
#include "dmclock/src/dmclock_recs.h"

// the following is done to unclobber _ASSERT_H so it returns to the
Expand All @@ -22,20 +24,27 @@


namespace ceph {
namespace dmc = crimson::dmclock;
namespace dmc = ::crimson::dmclock;
}

WRITE_RAW_ENCODER(dmc::ReqParams)
namespace crimson {
namespace dmclock {

inline void encode(const dmc::PhaseType &phase, bufferlist& bl,
WRITE_RAW_ENCODER(ReqParams)

inline void encode(const PhaseType &phase, bufferlist& bl,
uint64_t features=0)
{
encode(static_cast<uint8_t>(phase), bl);
using ceph::encode;
encode(static_cast<std::uint8_t>(phase), bl);
}

inline void decode(dmc::PhaseType &phase, bufferlist::iterator& p)
inline void decode(PhaseType &phase, bufferlist::iterator& p)
{
uint8_t int_phase;
decode((uint8_t&)int_phase, p);
using ceph::decode;
std::uint8_t int_phase;
decode((std::uint8_t&)int_phase, p);
phase = static_cast<dmc::PhaseType>(int_phase);
}
}
}
14 changes: 8 additions & 6 deletions src/messages/MAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ struct MAuth : public PaxosServiceMessage {
}

void decode_payload() override {
using ceph::encode;
bufferlist::iterator p = payload.begin();
paxos_decode(p);
::decode(protocol, p);
::decode(auth_payload, p);
decode(protocol, p);
decode(auth_payload, p);
if (!p.end())
::decode(monmap_epoch, p);
decode(monmap_epoch, p);
else
monmap_epoch = 0;
}
void encode_payload(uint64_t features) override {
using ceph::encode;
paxos_encode();
::encode(protocol, payload);
::encode(auth_payload, payload);
::encode(monmap_epoch, payload);
encode(protocol, payload);
encode(auth_payload, payload);
encode(monmap_epoch, payload);
}
bufferlist& get_auth_payload() { return auth_payload; }
};
Expand Down
21 changes: 11 additions & 10 deletions src/messages/MAuthReply.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ struct MAuthReply : public Message {

void decode_payload() override {
bufferlist::iterator p = payload.begin();
::decode(protocol, p);
::decode(result, p);
::decode(global_id, p);
::decode(result_bl, p);
::decode(result_msg, p);
decode(protocol, p);
decode(result, p);
decode(global_id, p);
decode(result_bl, p);
decode(result_msg, p);
}
void encode_payload(uint64_t features) override {
::encode(protocol, payload);
::encode(result, payload);
::encode(global_id, payload);
::encode(result_bl, payload);
::encode(result_msg, payload);
using ceph::encode;
encode(protocol, payload);
encode(result, payload);
encode(global_id, payload);
encode(result_bl, payload);
encode(result_msg, payload);
}
};

Expand Down
31 changes: 16 additions & 15 deletions src/messages/MBackfillReserve.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,33 @@ class MBackfillReserve : public Message {

void decode_payload() override {
bufferlist::iterator p = payload.begin();
::decode(pgid.pgid, p);
::decode(query_epoch, p);
::decode(type, p);
::decode(priority, p);
::decode(pgid.shard, p);
decode(pgid.pgid, p);
decode(query_epoch, p);
decode(type, p);
decode(priority, p);
decode(pgid.shard, p);
}

void encode_payload(uint64_t features) override {
using ceph::encode;
if (!HAVE_FEATURE(features, RECOVERY_RESERVATION_2)) {
header.version = 3;
header.compat_version = 3;
::encode(pgid.pgid, payload);
::encode(query_epoch, payload);
::encode((type == RELEASE || type == TOOFULL || type == REVOKE) ?
encode(pgid.pgid, payload);
encode(query_epoch, payload);
encode((type == RELEASE || type == TOOFULL || type == REVOKE) ?
REJECT : type, payload);
::encode(priority, payload);
::encode(pgid.shard, payload);
encode(priority, payload);
encode(pgid.shard, payload);
return;
}
header.version = HEAD_VERSION;
header.compat_version = COMPAT_VERSION;
::encode(pgid.pgid, payload);
::encode(query_epoch, payload);
::encode(type, payload);
::encode(priority, payload);
::encode(pgid.shard, payload);
encode(pgid.pgid, payload);
encode(query_epoch, payload);
encode(type, payload);
encode(priority, payload);
encode(pgid.shard, payload);
}
};

Expand Down
24 changes: 14 additions & 10 deletions src/messages/MCacheExpire.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ class MCacheExpire : public Message {
}

void encode(bufferlist &bl) const {
::encode(inodes, bl);
::encode(dirs, bl);
::encode(dentries, bl);
using ceph::encode;
encode(inodes, bl);
encode(dirs, bl);
encode(dentries, bl);
}
void decode(bufferlist::iterator &bl) {
::decode(inodes, bl);
::decode(dirs, bl);
::decode(dentries, bl);
using ceph::decode;
decode(inodes, bl);
decode(dirs, bl);
decode(dentries, bl);
}
};
WRITE_CLASS_ENCODER(realm)
Expand Down Expand Up @@ -88,14 +90,16 @@ class MCacheExpire : public Message {
}

void decode_payload() override {
using ceph::decode;
bufferlist::iterator p = payload.begin();
::decode(from, p);
::decode(realms, p);
decode(from, p);
decode(realms, p);
}

void encode_payload(uint64_t features) override {
::encode(from, payload);
::encode(realms, payload);
using ceph::encode;
encode(from, payload);
encode(realms, payload);
}
};

Expand Down
13 changes: 7 additions & 6 deletions src/messages/MClientCapRelease.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ class MClientCapRelease : public Message {

void decode_payload() override {
bufferlist::iterator p = payload.begin();
::decode(head, p);
::decode_nohead(head.num, caps, p);
decode(head, p);
decode_nohead(head.num, caps, p);
if (header.version >= 2) {
::decode(osd_epoch_barrier, p);
decode(osd_epoch_barrier, p);
}
}
void encode_payload(uint64_t features) override {
using ceph::encode;
head.num = caps.size();
::encode(head, payload);
::encode_nohead(caps, payload);
::encode(osd_epoch_barrier, payload);
encode(head, payload);
encode_nohead(caps, payload);
encode(osd_epoch_barrier, payload);
}
};

Expand Down
65 changes: 33 additions & 32 deletions src/messages/MClientCaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ class MClientCaps : public Message {

void decode_payload() override {
bufferlist::iterator p = payload.begin();
::decode(head, p);
decode(head, p);
ceph_mds_caps_body_legacy body;
::decode(body, p);
decode(body, p);
if (head.op == CEPH_CAP_OP_EXPORT) {
peer = body.peer;
} else {
Expand All @@ -239,55 +239,56 @@ class MClientCaps : public Message {
layout.from_legacy(body.layout);
time_warp_seq = body.time_warp_seq;
}
::decode_nohead(head.snap_trace_len, snapbl, p);
decode_nohead(head.snap_trace_len, snapbl, p);

assert(middle.length() == head.xattr_len);
if (head.xattr_len)
xattrbl = middle;

// conditionally decode flock metadata
if (header.version >= 2)
::decode(flockbl, p);
decode(flockbl, p);

if (header.version >= 3) {
if (head.op == CEPH_CAP_OP_IMPORT)
::decode(peer, p);
decode(peer, p);
}

if (header.version >= 4) {
::decode(inline_version, p);
::decode(inline_data, p);
decode(inline_version, p);
decode(inline_data, p);
} else {
inline_version = CEPH_INLINE_NONE;
}

if (header.version >= 5) {
::decode(osd_epoch_barrier, p);
decode(osd_epoch_barrier, p);
}
if (header.version >= 6) {
::decode(oldest_flush_tid, p);
decode(oldest_flush_tid, p);
}
if (header.version >= 7) {
::decode(caller_uid, p);
::decode(caller_gid, p);
decode(caller_uid, p);
decode(caller_gid, p);
}
if (header.version >= 8) {
::decode(layout.pool_ns, p);
decode(layout.pool_ns, p);
}
if (header.version >= 9) {
::decode(btime, p);
::decode(change_attr, p);
decode(btime, p);
decode(change_attr, p);
}
if (header.version >= 10) {
::decode(flags, p);
decode(flags, p);
}
}
void encode_payload(uint64_t features) override {
using ceph::encode;
header.version = HEAD_VERSION;
head.snap_trace_len = snapbl.length();
head.xattr_len = xattrbl.length();

::encode(head, payload);
encode(head, payload);
ceph_mds_caps_body_legacy body;
if (head.op == CEPH_CAP_OP_EXPORT) {
memset(&body, 0, sizeof(body));
Expand All @@ -303,44 +304,44 @@ class MClientCaps : public Message {
layout.to_legacy(&body.layout);
body.time_warp_seq = time_warp_seq;
}
::encode(body, payload);
::encode_nohead(snapbl, payload);
encode(body, payload);
encode_nohead(snapbl, payload);

middle = xattrbl;

// conditionally include flock metadata
if (features & CEPH_FEATURE_FLOCK) {
::encode(flockbl, payload);
encode(flockbl, payload);
} else {
header.version = 1;
return;
}

if (features & CEPH_FEATURE_EXPORT_PEER) {
if (head.op == CEPH_CAP_OP_IMPORT)
::encode(peer, payload);
encode(peer, payload);
} else {
header.version = 2;
return;
}

if (features & CEPH_FEATURE_MDS_INLINE_DATA) {
::encode(inline_version, payload);
::encode(inline_data, payload);
encode(inline_version, payload);
encode(inline_data, payload);
} else {
::encode(inline_version, payload);
::encode(bufferlist(), payload);
encode(inline_version, payload);
encode(bufferlist(), payload);
}

::encode(osd_epoch_barrier, payload);
::encode(oldest_flush_tid, payload);
::encode(caller_uid, payload);
::encode(caller_gid, payload);
encode(osd_epoch_barrier, payload);
encode(oldest_flush_tid, payload);
encode(caller_uid, payload);
encode(caller_gid, payload);

::encode(layout.pool_ns, payload);
::encode(btime, payload);
::encode(change_attr, payload);
::encode(flags, payload);
encode(layout.pool_ns, payload);
encode(btime, payload);
encode(change_attr, payload);
encode(flags, payload);
}
};

Expand Down
9 changes: 5 additions & 4 deletions src/messages/MClientLease.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ struct MClientLease : public Message {

void decode_payload() override {
bufferlist::iterator p = payload.begin();
::decode(h, p);
::decode(dname, p);
decode(h, p);
decode(dname, p);
}
void encode_payload(uint64_t features) override {
::encode(h, payload);
::encode(dname, payload);
using ceph::encode;
encode(h, payload);
encode(dname, payload);
}

};
Expand Down
Loading

0 comments on commit f45e480

Please sign in to comment.