]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: eversion_t encoding optimization
authorXinze Chi <xinze@xsky.com>
Mon, 14 Dec 2015 16:29:15 +0000 (00:29 +0800)
committerXinze Chi <xinze@xsky.com>
Mon, 14 Dec 2015 16:29:15 +0000 (00:29 +0800)
There is no padding between version and epoch, no matter 32-bit
or 64-bit machine.

Signed-off-by: Xinze Chi <xinze@xsky.com>
src/osd/osd_types.h

index cb712188b7625f0ae9d7012e3618feb69198abd5..c8c9a422278c287fd5cc5d4f475e0599df67a9f5 100644 (file)
@@ -673,6 +673,10 @@ inline ostream& operator<<(ostream& out, const ceph_object_layout &ol)
 
 
 // compound rados version type
+/* WARNING: If add member in eversion_t, please make sure the encode/decode function
+ * work well. For little-endian machine, we should make sure there is no padding
+ * in 32-bit machine and 64-bit machine.
+ */
 class eversion_t {
 public:
   version_t version;
@@ -705,12 +709,20 @@ public:
   string get_key_name() const;
 
   void encode(bufferlist &bl) const {
+#if defined(CEPH_LITTLE_ENDIAN)
+    bl.append((char *)this, sizeof(version_t) + sizeof(epoch_t));
+#else
     ::encode(version, bl);
     ::encode(epoch, bl);
+#endif
   }
   void decode(bufferlist::iterator &bl) {
+#if defined(CEPH_LITTLE_ENDIAN)
+    bl.copy(sizeof(version_t) + sizeof(epoch_t), (char *)this);
+#else
     ::decode(version, bl);
     ::decode(epoch, bl);
+#endif
   }
   void decode(bufferlist& bl) {
     bufferlist::iterator p = bl.begin();