]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buncha encoding
authorSage Weil <sage@newdream.net>
Wed, 30 Apr 2008 21:04:38 +0000 (14:04 -0700)
committerSage Weil <sage@newdream.net>
Wed, 30 Apr 2008 21:04:38 +0000 (14:04 -0700)
15 files changed:
src/include/encodable.h
src/include/encoding.h
src/include/frag.h
src/include/types.h
src/include/utime.h
src/mds/SessionMap.h
src/mds/SimpleLock.h
src/mds/mdstypes.h
src/messages/MMonGetMap.h
src/mon/OSDMonitor.cc
src/mon/PGMonitor.cc
src/osd/OSD.cc
src/osd/OSDMap.h
src/osd/osd_types.h
src/osdc/Objecter.cc

index 321361866ec9bf15a57acd6187e9161cc7a771fd..ca19fcd538aa7268b04216f2c93c1982044e77a8 100644 (file)
@@ -15,6 +15,8 @@
 #ifndef __ENCODABLE_H
 #define __ENCODABLE_H
 
+//#warning "deprecated"
+
 #include "buffer.h"
 
 #include <set>
index 62c7a9482366c27195f0cbbb2eb282db46cf8fbd..743310af62d2852d94a23a61421d0c8829109a7d 100644 (file)
@@ -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)
 
 
 
index 667cc60265ad2f4c2b7445bfaabc1c59077c990b..5392ea12c296834e8111ba2e34c57a393ba95bdf 100644 (file)
@@ -20,7 +20,6 @@
 #include <list>
 #include <iostream>
 #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) {
index 94b9599e539a154ebde744cc6d2de0cee2e0458e..8aabfc0be00e5464c2067ef7d7a42d08909d21c4 100644 (file)
@@ -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;
 }
index 6b377c109d9b032bd177ca354152e2f442db23d9..074e5bf1982998b449714f1073a72aad6590f85b 100644 (file)
@@ -102,7 +102,7 @@ public:
     return (double)sec() + ((double)usec() / 1000000.0L);
   }
 };
-ENCODABLE_CLASS(utime_t)
+WRITE_CLASS_ENCODERS(utime_t)
 
 
 // arithmetic operators
index 78241ada3807834288e454c4255245556e88139f..5a2ef9f4313e8e7e9d6a087378d0d0983af09560 100644 (file)
@@ -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);
   }
 };
 
index 5734b20793897423fb2be29b0ed40d17e9eb91f5..cebd98e8df557bd7d7a4764d41781de0e6699d01 100644 (file)
@@ -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);
   }
 
   
index b57dce2184a738d35a44df45059d52a732259450..3befb32f20a9f4c81e737714628d60b6649b45b8 100644 (file)
@@ -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);
   }
 };
 
index 5e28cac8d8c445526828dfd5f0da495ca97b7988..f87b1e7218374f05d90cb2cb0443383858db77b3 100644 (file)
@@ -18,7 +18,6 @@
 #include "msg/Message.h"
 
 #include "include/types.h"
-#include "include/encodable.h"
 
 class MMonGetMap : public Message {
  public:
index 71c439453dee903c0bcb61e200c6e5a12b666576..fbfd9776058bcb2678ba345ada4ec62f87d7bbd6 100644 (file)
@@ -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.
index b604d6df5809cb26b005240b13a89c4195590bf6..e7942c1d1b3c30be960123d8b045fc006b664a98 100644 (file)
@@ -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<int32_t,uint32_t>::iterator p = inc.new_offload.begin();
         p != inc.new_offload.end();
         p++)
index ae4d326e19d38eb4232e98f0854e1b7478bce68a..70f24db93175eb15311d5ab95d11974458bd3287 100644 (file)
@@ -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;
 }
 
index 73ac7827da8196f158d24f183e5300af8c773bec..56555ac3aa2ab9196ada54bd5165bbd8c3d76965 100644 (file)
@@ -94,44 +94,51 @@ public:
     list<pg_t> 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);
   }
index 7c253d651d8c6ac3839fd55fa0de2a483fabc79d..8ead0e50a8ddd6670b1c10fc15eb7f704abcef2f 100644 (file)
@@ -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()) 
index 61af45b69bc0d1ebbfd0ac7fdd028b8315dc8f43..3d2eb9974dec94373fa5388e56910e5c0580d938 100644 (file)
@@ -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