From: Sage Weil Date: Wed, 30 Apr 2008 21:04:38 +0000 (-0700) Subject: buncha encoding X-Git-Tag: v0.3~239^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b10b5d2e4a861ba13fedc3236e6d1c1120669529;p=ceph.git buncha encoding --- diff --git a/src/include/encodable.h b/src/include/encodable.h index 321361866ec9b..ca19fcd538aa7 100644 --- a/src/include/encodable.h +++ b/src/include/encodable.h @@ -15,6 +15,8 @@ #ifndef __ENCODABLE_H #define __ENCODABLE_H +//#warning "deprecated" + #include "buffer.h" #include diff --git a/src/include/encoding.h b/src/include/encoding.h index 62c7a9482366c..743310af62d28 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -20,7 +20,7 @@ #include "buffer.h" -#define ENCODABLE_CLASS(cl) \ +#define WRITE_CLASS_ENCODERS(cl) \ inline void encode(const cl &c, bufferlist &bl) { c.encode(bl); } \ inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); } @@ -47,13 +47,13 @@ inline void decode_raw(T& t, bufferlist::iterator &p) // __u32, __s64, etc. #define WRITE_ENCODER(type, etype) \ inline void encode(__##type v, bufferlist& bl) { \ - __##etype e = cpu_to_##etype(v); \ + __##etype e = init_##etype(v); \ encode_raw(e, bl); \ } \ inline void decode(__##type &v, bufferlist::iterator& p) { \ __##etype e; \ decode_raw(e, p); \ - v = etype##_to_cpu(e); \ + v = e; \ } WRITE_ENCODER(u64, le64) @@ -67,6 +67,9 @@ WRITE_ENCODER(s16, le16) WRITE_RAW_ENCODER(__u8) WRITE_RAW_ENCODER(__s8) WRITE_RAW_ENCODER(bool) +WRITE_RAW_ENCODER(__le64) +WRITE_RAW_ENCODER(__le32) +WRITE_RAW_ENCODER(__le16) diff --git a/src/include/frag.h b/src/include/frag.h index 667cc60265ad2..5392ea12c2968 100644 --- a/src/include/frag.h +++ b/src/include/frag.h @@ -20,7 +20,6 @@ #include #include #include "buffer.h" -#include "encodable.h" /* * @@ -74,9 +73,9 @@ class frag_t { * 8 upper bits = "bits" * 24 lower bits = "value" */ + public: _frag_t _enc; - public: frag_t() : _enc(0) { } frag_t(unsigned v, unsigned b) : _enc((b << 24) + (v & (0xffffffffULL >> (32-b)))) { } @@ -157,6 +156,14 @@ inline std::ostream& operator<<(std::ostream& out, frag_t hb) return out << std::hex << hb.value() << std::dec << "/" << hb.bits(); } +inline void encode(frag_t f, bufferlist& bl) { encode_raw(f._enc, bl); } +inline void decode(frag_t &f, bufferlist::iterator& p) { + __u32 v; + decode_raw(v, p); + f._enc = v; +} + + /** * fragtree_t -- partition an entire namespace into one or more frag_t's. @@ -459,13 +466,13 @@ public: // encoding void _encode(bufferlist& bl) const { - ::_encode(_splits, bl); + ::encode(_splits, bl); } void _decode(bufferlist& bl, int& off) { ::_decode(_splits, bl, off); } void _decode(bufferlist::iterator& p) { - ::_decode_simple(_splits, p); + ::decode(_splits, p); } void print(std::ostream& out) { diff --git a/src/include/types.h b/src/include/types.h index 94b9599e539a1..8aabfc0be00e5 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -108,6 +108,11 @@ struct ltstr +#include "encoding.h" + +WRITE_RAW_ENCODER(ceph_fsid); + + // ---------------------- // some basic types @@ -135,6 +140,9 @@ struct inodeno_t { operator _inodeno_t() const { return val; } }; +inline void encode(inodeno_t i, bufferlist &bl) { encode(i.val, bl); } +inline void decode(inodeno_t &i, bufferlist::iterator &p) { decode(i.val, p); } + inline ostream& operator<<(ostream& out, inodeno_t ino) { return out << hex << ino.val << dec; } diff --git a/src/include/utime.h b/src/include/utime.h index 6b377c109d9b0..074e5bf198299 100644 --- a/src/include/utime.h +++ b/src/include/utime.h @@ -102,7 +102,7 @@ public: return (double)sec() + ((double)usec() / 1000000.0L); } }; -ENCODABLE_CLASS(utime_t) +WRITE_CLASS_ENCODERS(utime_t) // arithmetic operators diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index 78241ada38078..5a2ef9f4313e8 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -117,14 +117,14 @@ public: cap_push_seq(0) { } void _encode(bufferlist& bl) const { - ::_encode_simple(inst, bl); - ::_encode_simple(cap_push_seq, bl); - ::_encode_simple(completed_requests, bl); + ::encode(inst, bl); + ::encode(cap_push_seq, bl); + ::encode(completed_requests, bl); } void _decode(bufferlist::iterator& p) { - ::_decode_simple(inst, p); - ::_decode_simple(cap_push_seq, p); - ::_decode_simple(completed_requests, p); + ::decode(inst, p); + ::decode(cap_push_seq, p); + ::decode(completed_requests, p); } }; diff --git a/src/mds/SimpleLock.h b/src/mds/SimpleLock.h index 5734b20793897..cebd98e8df557 100644 --- a/src/mds/SimpleLock.h +++ b/src/mds/SimpleLock.h @@ -225,12 +225,12 @@ public: // encode/decode void _encode(bufferlist& bl) { - ::_encode_simple(state, bl); - ::_encode_simple(gather_set, bl); + ::encode(state, bl); + ::encode(gather_set, bl); } void _decode(bufferlist::iterator& p) { - ::_decode_simple(state, p); - ::_decode_simple(gather_set, p); + ::decode(state, p); + ::decode(gather_set, p); } diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index b57dce2184a73..3befb32f20a9f 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -114,6 +114,16 @@ struct dirfrag_t { dirfrag_t(inodeno_t i, frag_t f) : ino(i), frag(f), _pad(0) { } }; +inline void encode(const dirfrag_t &f, bufferlist& bl) { + encode(f.ino, bl); + encode(f.frag, bl); +} +inline void decode(dirfrag_t &f, bufferlist::iterator& p) { + decode(f.ino, p); + decode(f.frag, p); +} + + inline ostream& operator<<(ostream& out, const dirfrag_t df) { out << df.ino; if (!df.frag.is_root()) out << "." << df.frag; @@ -377,9 +387,9 @@ public: MDSCacheObjectInfo() : ino(0) {} void _encode(bufferlist& bl) const { - ::_encode(ino, bl); - ::_encode(dirfrag, bl); - ::_encode(dname, bl); + ::encode(ino, bl); + ::encode(dirfrag, bl); + ::encode(dname, bl); } void _decode(bufferlist& bl, int& off) { ::_decode(ino, bl, off); @@ -387,9 +397,9 @@ public: ::_decode(dname, bl, off); } void _decode(bufferlist::iterator& p) { - ::_decode_simple(ino, p); - ::_decode_simple(dirfrag, p); - ::_decode_simple(dname, p); + ::decode(ino, p); + ::decode(dirfrag, p); + ::decode(dname, p); } }; diff --git a/src/messages/MMonGetMap.h b/src/messages/MMonGetMap.h index 5e28cac8d8c44..f87b1e7218374 100644 --- a/src/messages/MMonGetMap.h +++ b/src/messages/MMonGetMap.h @@ -18,7 +18,6 @@ #include "msg/Message.h" #include "include/types.h" -#include "include/encodable.h" class MMonGetMap : public Message { public: diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 71c439453dee9..fbfd9776058bc 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -155,9 +155,7 @@ bool OSDMonitor::update_from_paxos() assert(success); dout(7) << "update_from_paxos applying incremental " << osdmap.epoch+1 << dendl; - OSDMap::Incremental inc; - int off = 0; - inc.decode(bl, off); + OSDMap::Incremental inc(bl); osdmap.apply_incremental(inc); // write out the full map, too. diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index b604d6df5809c..e7942c1d1b3c3 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -338,9 +338,7 @@ void PGMonitor::check_osd_map(epoch_t epoch) bufferlist bl; mon->store->get_bl_sn(bl, "osdmap", e); assert(bl.length()); - OSDMap::Incremental inc; - int off = 0; - inc.decode(bl, off); + OSDMap::Incremental inc(bl); for (map::iterator p = inc.new_offload.begin(); p != inc.new_offload.end(); p++) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index ae4d326e19d38..70f24db93175e 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1339,10 +1339,7 @@ void OSD::handle_osd_map(MOSDMap *m) get_inc_map_bl(cur+1, bl); } - OSDMap::Incremental inc; - int off = 0; - inc.decode(bl, off); - + OSDMap::Incremental inc(bl); osdmap->apply_incremental(inc); // archive the full map @@ -1712,8 +1709,8 @@ bool OSD::get_inc_map(epoch_t e, OSDMap::Incremental &inc) bufferlist bl; if (!get_inc_map_bl(e, bl)) return false; - int off = 0; - inc.decode(bl, off); + bufferlist::iterator p = bl.begin(); + inc.decode(p); return true; } diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 73ac7827da819..56555ac3aa2ab 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -94,44 +94,51 @@ public: list old_pg_swap_primary; void encode(bufferlist& bl) { - ::_encode(fsid, bl); - ::_encode(epoch, bl); - ctime._encode(bl); - ::_encode(fullmap, bl); - ::_encode(crush, bl); - ::_encode(new_max_osd, bl); - ::_encode(new_pg_num, bl); - ::_encode(new_pgp_num, bl); - ::_encode(new_lpg_num, bl); - ::_encode(new_lpgp_num, bl); - ::_encode(new_up, bl); - ::_encode(new_down, bl); - ::_encode(new_offload, bl); - ::_encode(new_pg_swap_primary, bl); - ::_encode(old_pg_swap_primary, bl); + ::encode(fsid, bl); + ::encode(epoch, bl); + ::encode(ctime, bl); + ::encode(fullmap, bl); + ::encode(crush, bl); + ::encode(new_max_osd, bl); + ::encode(new_pg_num, bl); + ::encode(new_pgp_num, bl); + ::encode(new_lpg_num, bl); + ::encode(new_lpgp_num, bl); + ::encode(new_up, bl); + ::encode(new_down, bl); + ::encode(new_offload, bl); + ::encode(new_pg_swap_primary, bl); + ::encode(old_pg_swap_primary, bl); } - void decode(bufferlist& bl, int& off) { - ::_decode(fsid, bl, off); - ::_decode(epoch, bl, off); - ctime._decode(bl, off); - ::_decode(fullmap, bl, off); - ::_decode(crush, bl, off); - ::_decode(new_max_osd, bl, off); - ::_decode(new_pg_num, bl, off); - ::_decode(new_pgp_num, bl, off); - ::_decode(new_lpg_num, bl, off); - ::_decode(new_lpgp_num, bl, off); - ::_decode(new_up, bl, off); - ::_decode(new_down, bl, off); - ::_decode(new_offload, bl, off); - ::_decode(new_pg_swap_primary, bl, off); - ::_decode(old_pg_swap_primary, bl, off); + void decode(bufferlist::iterator &p) { + ::decode(fsid, p); + ::decode(epoch, p); + ::decode(ctime, p); + ::decode(fullmap, p); + ::decode(crush, p); + ::decode(new_max_osd, p); + ::decode(new_pg_num, p); + ::decode(new_pgp_num, p); + ::decode(new_lpg_num, p); + ::decode(new_lpgp_num, p); + ::decode(new_up, p); + ::decode(new_down, p); + ::decode(new_offload, p); + ::decode(new_pg_swap_primary, p); + ::decode(old_pg_swap_primary, p); } Incremental(epoch_t e=0) : epoch(e), new_max_osd(-1), new_pg_num(0), new_pgp_num(0), new_lpg_num(0), new_lpgp_num(0) { fsid.major = fsid.minor = 0; } + Incremental(bufferlist &bl) { + bufferlist::iterator p = bl.begin(); + decode(p); + } + Incremental(bufferlist::iterator &p) { + decode(p); + } }; private: @@ -390,46 +397,46 @@ private: // serialize, unserialize void encode(bufferlist& blist) { - ::_encode(fsid, blist); - ::_encode(epoch, blist); - ::_encode(ctime, blist); - ::_encode(mtime, blist); - ::_encode(pg_num, blist); - ::_encode(pgp_num, blist); - ::_encode(lpg_num, blist); - ::_encode(lpgp_num, blist); - ::_encode(last_pg_change, blist); + ::encode(fsid, blist); + ::encode(epoch, blist); + ::encode(ctime, blist); + ::encode(mtime, blist); + ::encode(pg_num, blist); + ::encode(pgp_num, blist); + ::encode(lpg_num, blist); + ::encode(lpgp_num, blist); + ::encode(last_pg_change, blist); - ::_encode(max_osd, blist); - ::_encode(osd_state, blist); - ::_encode(osd_addr, blist); - ::_encode(pg_swap_primary, blist); + ::encode(max_osd, blist); + ::encode(osd_state, blist); + ::encode(osd_addr, blist); + ::encode(pg_swap_primary, blist); bufferlist cbl; crush._encode(cbl); - ::_encode(cbl, blist); + ::encode(cbl, blist); } void decode(bufferlist& blist) { - int off = 0; - ::_decode(fsid, blist, off); - ::_decode(epoch, blist, off); - ::_decode(ctime, blist, off); - ::_decode(mtime, blist, off); - ::_decode(pg_num, blist, off); - ::_decode(pgp_num, blist, off); - ::_decode(lpg_num, blist, off); - ::_decode(lpgp_num, blist, off); + bufferlist::iterator p = blist.begin(); + ::decode(fsid, p); + ::decode(epoch, p); + ::decode(ctime, p); + ::decode(mtime, p); + ::decode(pg_num, p); + ::decode(pgp_num, p); + ::decode(lpg_num, p); + ::decode(lpgp_num, p); calc_pg_masks(); - ::_decode(last_pg_change, blist, off); + ::decode(last_pg_change, p); - ::_decode(max_osd, blist, off); - ::_decode(osd_state, blist, off); - ::_decode(osd_addr, blist, off); - ::_decode(pg_swap_primary, blist, off); + ::decode(max_osd, p); + ::decode(osd_state, p); + ::decode(osd_addr, p); + ::decode(pg_swap_primary, p); bufferlist cbl; - ::_decode(cbl, blist, off); + ::decode(cbl, p); bufferlist::iterator cblp = cbl.begin(); crush._decode(cblp); } diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 7c253d651d8c6..8ead0e50a8ddd 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -107,13 +107,6 @@ public: int pool() { return u.pg.pool; } int preferred() { return u.pg.preferred; } // hack: avoid negative. - /* - pg_t operator=(uint64_t v) { u.val = v; return *this; } - pg_t operator&=(uint64_t v) { u.val &= v; return *this; } - pg_t operator+=(pg_t o) { u.val += o.val; return *this; } - pg_t operator-=(pg_t o) { u.val -= o.val; return *this; } - pg_t operator++() { ++u.val; return *this; } - */ operator uint64_t() const { return u.pg64; } pobject_t to_pobject() const { @@ -123,6 +116,14 @@ public: } } __attribute__ ((packed)); +inline void encode(pg_t pgid, bufferlist& bl) { encode_raw(pgid.u.pg64, bl); } +inline void decode(pg_t &pgid, bufferlist::iterator& p) { + __u64 v; + decode_raw(v, p); + pgid.u.pg64 = v; +} + + inline ostream& operator<<(ostream& out, pg_t pg) { if (pg.is_rep()) diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 61af45b69bc0d..3d2eb9974dec9 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -94,9 +94,7 @@ void Objecter::handle_osd_map(MOSDMap *m) e++) { if (m->incremental_maps.count(e)) { dout(3) << "handle_osd_map decoding incremental epoch " << e << dendl; - OSDMap::Incremental inc; - int off = 0; - inc.decode(m->incremental_maps[e], off); + OSDMap::Incremental inc(m->incremental_maps[e]); osdmap->apply_incremental(inc); // notify messenger