]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
enconding: add legacy decoder for 32 bit versions
authorYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 8 Mar 2012 00:28:01 +0000 (16:28 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 8 Mar 2012 00:28:01 +0000 (16:28 -0800)
In these cases if the version is smaller than the compat ver
we skip 3 bytes.

Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
src/include/encoding.h

index 79a28c77a4420e308434820a06f6c3f81670947e..fa1cebeec48732e08a4f1be0b7b265bad27eec4f 100644 (file)
@@ -709,21 +709,7 @@ inline void decode(std::deque<T>& ls, bufferlist::iterator& p)
   unsigned struct_end = bl.get_off() + struct_len;                     \
   do {
 
-/**
- * start a decoding block with legacy support for older encoding schemes
- *
- * The old encoding schemes has a __u8 struct_v only, or lacked either
- * the compat version or length.  Skip those fields conditionally.
- *
- * Most of the time, v, compatv, and lenv will all match the version
- * where the structure was switched over to the new macros.
- *
- * @param v current version of the encoding that the code supports/encodes
- * @param compatv oldest version that includes a __u8 compat version field
- * @param lenv oldest version that includes a __u32 length wrapper
- * @param bl bufferlist::iterator containing the encoded data
- */
-#define DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, bl)           \
+#define __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, skip_v, bl) \
   __u8 struct_v;                                                       \
   ::decode(struct_v, bl);                                              \
   if (struct_v >= compatv) {                                           \
@@ -731,6 +717,10 @@ inline void decode(std::deque<T>& ls, bufferlist::iterator& p)
     ::decode(struct_compat, bl);                                       \
     if (v < struct_compat)                                             \
       throw buffer::malformed_input(DECODE_ERR_VERSION(__PRETTY_FUNCTION__, v)); \
+  } else if (skip_v) {                                                 \
+    if ((int)bl.get_remaining() < skip_v)                              \
+      throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
+    bl.advance(skip_v);                                                        \
   }                                                                    \
   unsigned struct_end = 0;                                             \
   if (struct_v >= lenv) {                                              \
@@ -742,6 +732,43 @@ inline void decode(std::deque<T>& ls, bufferlist::iterator& p)
   }                                                                    \
   do {
 
+/**
+ * start a decoding block with legacy support for older encoding schemes
+ *
+ * The old encoding schemes has a __u8 struct_v only, or lacked either
+ * the compat version or length.  Skip those fields conditionally.
+ *
+ * Most of the time, v, compatv, and lenv will all match the version
+ * where the structure was switched over to the new macros.
+ *
+ * @param v current version of the encoding that the code supports/encodes
+ * @param compatv oldest version that includes a __u8 compat version field
+ * @param lenv oldest version that includes a __u32 length wrapper
+ * @param bl bufferlist::iterator containing the encoded data
+ */
+#define DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, bl)           \
+  __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, 0, bl)
+
+/**
+ * start a decoding block with legacy support for older encoding schemes
+ *
+ * This version of the macro assumes the legacy encoding had a 32 bit
+ * version
+ *
+ * The old encoding schemes has a __u8 struct_v only, or lacked either
+ * the compat version or length.  Skip those fields conditionally.
+ *
+ * Most of the time, v, compatv, and lenv will all match the version
+ * where the structure was switched over to the new macros.
+ *
+ * @param v current version of the encoding that the code supports/encodes
+ * @param compatv oldest version that includes a __u8 compat version field
+ * @param lenv oldest version that includes a __u32 length wrapper
+ * @param bl bufferlist::iterator containing the encoded data
+ */
+#define DECODE_START_LEGACY_COMPAT_LEN_32(v, compatv, lenv, bl)                \
+  __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, 3, bl)
+
 /**
  * finish decode block
  *