From 657c28a3a9876ea49cdc92c08ed151e6836db6d1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 May 2008 15:02:15 -0700 Subject: [PATCH] pg encoding cleanup --- src/include/object.h | 18 +++++++ src/include/pobject.h | 15 +++++- src/messages/MOSDPGLog.h | 20 ++++--- src/osd/PG.h | 113 ++++++++++++++++++++++++++++++--------- src/osd/osd_types.h | 11 ++++ 5 files changed, 141 insertions(+), 36 deletions(-) diff --git a/src/include/object.h b/src/include/object.h index 9a508ed35ec65..30fe131d99534 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -26,6 +26,8 @@ using namespace __gnu_cxx; #include "hash.h" +#include "encoding.h" + typedef uint32_t objectrev_t; struct object_t { @@ -52,7 +54,23 @@ struct object_t { oid.rev = rev; return oid; } + void encode(bufferlist &bl) const { + ::encode(ino, bl); + ::encode(bno, bl); + ::encode(rev, bl); + } + void decode(bufferlist::iterator &bl) { + __u64 i; + __u32 b, r; + ::decode(i, bl); + ::decode(b, bl); + ::decode(r, bl); + ino = i; + bno = b; + rev = r; + } } __attribute__ ((packed)); +WRITE_CLASS_ENCODERS(object_t) inline bool operator==(const object_t l, const object_t r) { return memcmp(&l, &r, sizeof(l)) == 0; diff --git a/src/include/pobject.h b/src/include/pobject.h index c3c6487ccd4e7..4c2ae08bb8bc5 100644 --- a/src/include/pobject.h +++ b/src/include/pobject.h @@ -28,9 +28,22 @@ struct pobject_t { uint32_t rank; // rank/stripe id (e.g. for parity encoding) object_t oid; // logical object pobject_t() : volume(0), rank(0) {} - //pobject_t(object_t o) : volume(0), rank(0), oid(o) {} // this should go away eventually pobject_t(uint16_t v, uint16_t r, object_t o) : volume(v), rank(r), oid(o) {} + void encode(bufferlist &bl) const { + ::encode(volume, bl); + ::encode(rank, bl); + ::encode(oid, bl); + } + void decode(bufferlist::iterator &bl) { + __u32 v, r; + ::decode(v, bl); + ::decode(r, bl); + volume = v; + rank = r; + oid.decode(bl); + } } __attribute__ ((packed)); +WRITE_CLASS_ENCODERS(pobject_t) inline ostream& operator<<(ostream& out, const pobject_t o) { return out << o.volume << '/' << o.rank << '/' << o.oid; diff --git a/src/messages/MOSDPGLog.h b/src/messages/MOSDPGLog.h index aa6efebf227c8..7bcc69269d440 100644 --- a/src/messages/MOSDPGLog.h +++ b/src/messages/MOSDPGLog.h @@ -40,19 +40,17 @@ public: } void encode_payload() { - payload.append((char*)&epoch, sizeof(epoch)); - payload.append((char*)&info, sizeof(info)); - log._encode(payload); - missing._encode(payload); + ::encode(epoch, payload); + ::encode(info, payload); + ::encode(log, payload); + ::encode(missing, payload); } void decode_payload() { - int off = 0; - payload.copy(off, sizeof(epoch), (char*)&epoch); - off += sizeof(epoch); - payload.copy(off, sizeof(info), (char*)&info); - off += sizeof(info); - log._decode(payload, off); - missing._decode(payload, off); + bufferlist::iterator p = payload.begin(); + ::decode(epoch, p); + ::decode(info, p); + ::decode(log, p); + ::decode(missing, p); } }; diff --git a/src/osd/PG.h b/src/osd/PG.h index 0c0ad6574b4d4..0e7e77d2c992b 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -74,7 +74,17 @@ public: epoch_t same_primary_since; // same primary at least back through this epoch. epoch_t same_acker_since; // same acker at least back through this epoch. History() : same_since(0), same_primary_since(0), same_acker_since(0) {} - } __attribute__ ((packed)) history; + void encode(bufferlist &bl) const { + ::encode(same_since, bl); + ::encode(same_primary_since, bl); + ::encode(same_acker_since, bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(same_since, bl); + ::decode(same_primary_since, bl); + ::decode(same_acker_since, bl); + } + } history; Info(pg_t p=0) : pgid(p), log_backlog(false), @@ -84,8 +94,31 @@ public: bool is_uptodate() const { return last_update == last_complete; } bool is_empty() const { return last_update.version == 0; } bool dne() const { return epoch_created == 0; } - } __attribute__ ((packed)); - + + void encode(bufferlist &bl) const { + ::encode(pgid, bl); + ::encode(last_update, bl); + ::encode(last_complete, bl); + ::encode(log_bottom, bl); + ::encode(log_backlog, bl); + ::encode(epoch_created, bl); + ::encode(last_epoch_started, bl); + history.encode(bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(pgid, bl); + ::decode(last_update, bl); + ::decode(last_complete, bl); + ::decode(log_bottom, bl); + ::decode(log_backlog, bl); + ::decode(epoch_created, bl); + ::decode(last_epoch_started, bl); + history.decode(bl); + } + }; + WRITE_CLASS_ENCODERS(Info::History) + WRITE_CLASS_ENCODERS(Info) + /** * Query - used to ask a peer for information about a pg. @@ -108,8 +141,22 @@ public: type(t), history(h) { assert(t != LOG); } Query(int t, eversion_t s, eversion_t f, Info::History& h) : type(t), split(s), floor(f), history(h) { assert(t == LOG); } + + void encode(bufferlist &bl) const { + ::encode(type, bl); + ::encode(split, bl); + ::encode(floor, bl); + history.encode(bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(type, bl); + ::decode(split, bl); + ::decode(floor, bl); + history.decode(bl); + } }; - + WRITE_CLASS_ENCODERS(Query) + /* * Missing - summary of missing objects. @@ -165,13 +212,13 @@ public: missing.erase(oid); } - void _encode(bufferlist& blist) { - ::_encode(missing, blist); - ::_encode(loc, blist); + void encode(bufferlist &bl) const { + ::encode(missing, bl); + ::encode(loc, bl); } - void _decode(bufferlist& blist, int& off) { - ::_decode(missing, blist, off); - ::_decode(loc, blist, off); + void decode(bufferlist::iterator &bl) { + ::decode(missing, bl); + ::decode(loc, bl); for (map::iterator it = missing.begin(); it != missing.end(); @@ -179,6 +226,7 @@ public: rmissing[it->second] = it->first; } }; + WRITE_CLASS_ENCODERS(Missing) /* @@ -232,7 +280,21 @@ public: bool is_clone() const { return op == CLONE; } bool is_modify() const { return op == MODIFY; } bool is_update() const { return is_clone() || is_modify(); } + + void encode(bufferlist &bl) const { + ::encode(op, bl); + ::encode(oid, bl); + ::encode(version, bl); + ::encode(reqid, bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(op, bl); + ::decode(oid, bl); + ::decode(version, bl); + ::decode(reqid, bl); + } }; + WRITE_CLASS_ENCODERS(Entry) list log; // the actual log. @@ -248,21 +310,17 @@ public: return top.version == 0 && top.epoch == 0; } - void _encode(bufferlist& blist) const { - blist.append((char*)&top, sizeof(top)); - blist.append((char*)&bottom, sizeof(bottom)); - blist.append((char*)&backlog, sizeof(backlog)); - ::_encode(log, blist); + void encode(bufferlist& bl) const { + ::encode(top, bl); + ::encode(bottom, bl); + ::encode(backlog, bl); + ::encode(log, bl); } - void _decode(bufferlist& blist, int& off) { - blist.copy(off, sizeof(top), (char*)&top); - off += sizeof(top); - blist.copy(off, sizeof(bottom), (char*)&bottom); - off += sizeof(bottom); - blist.copy(off, sizeof(backlog), (char*)&backlog); - off += sizeof(backlog); - - ::_decode(log, blist, off); + void decode(bufferlist::iterator &bl) { + ::decode(top, bl); + ::decode(bottom, bl); + ::decode(backlog, bl); + ::decode(log, bl); } void copy_after(const Log &other, eversion_t v); @@ -270,6 +328,7 @@ public: void copy_non_backlog(const Log &other); ostream& print(ostream& out) const; }; + WRITE_CLASS_ENCODERS(Log) /** * IndexLog - adds in-memory index of the log, by oid. @@ -639,6 +698,12 @@ public: virtual void on_change() = 0; }; +WRITE_CLASS_ENCODERS(PG::Info::History) +WRITE_CLASS_ENCODERS(PG::Info) +WRITE_CLASS_ENCODERS(PG::Query) +WRITE_CLASS_ENCODERS(PG::Missing) +WRITE_CLASS_ENCODERS(PG::Log::Entry) +WRITE_CLASS_ENCODERS(PG::Log) inline ostream& operator<<(ostream& out, const PG::Info::History& h) diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index f26847c6037bf..ee3a5f28636bb 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -28,7 +28,18 @@ struct osd_reqid_t { int32_t inc; // incarnation osd_reqid_t() : tid(0), inc(0) {} osd_reqid_t(const entity_name_t& a, int i, tid_t t) : name(a), tid(t), inc(i) {} + void encode(bufferlist &bl) const { + ::encode(name, bl); + ::encode(tid, bl); + ::encode(inc, bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(name, bl); + ::decode(tid, bl); + ::decode(inc, bl); + } }; +WRITE_CLASS_ENCODERS(osd_reqid_t) inline ostream& operator<<(ostream& out, const osd_reqid_t& r) { return out << r.name << "." << r.inc << ":" << r.tid; -- 2.39.5