]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pg encoding cleanup
authorSage Weil <sage@newdream.net>
Thu, 8 May 2008 22:02:15 +0000 (15:02 -0700)
committerSage Weil <sage@newdream.net>
Thu, 8 May 2008 22:02:15 +0000 (15:02 -0700)
src/include/object.h
src/include/pobject.h
src/messages/MOSDPGLog.h
src/osd/PG.h
src/osd/osd_types.h

index 9a508ed35ec659ad47021212dce693041215b8c7..30fe131d99534cf05a741ce7fd6fd100440a6c4c 100644 (file)
@@ -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;
index c3c6487ccd4e7ff5f5de67eacfe2be1f6d175516..4c2ae08bb8bc56234d6c37598ddc28f2cc0373ef 100644 (file)
@@ -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;
index aa6efebf227c8fc6fcb382ce5ea36353c5f86ad9..7bcc69269d44038500656a0dcde49cd605538736 100644 (file)
@@ -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);
   }
 };
 
index 0c0ad6574b4d40aebfdd6bf8dca6a5de90f628ae..0e7e77d2c992bbefbd9870ae4cede31f2ef3ae35 100644 (file)
@@ -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<object_t,eversion_t>::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<Entry> 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) 
index f26847c6037bff3468557d5b160ed6f65af98389..ee3a5f28636bb34671e2e16c5915c00c282e1251 100644 (file)
@@ -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;