From 0d4ea9f746936d508bbfd4d51aadeafa29d11b33 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Wed, 20 Nov 2013 17:04:26 -0800 Subject: [PATCH] encoding: allow users to specify a different compatv after encoding This way we can set the compatv preferentially depending on whether we've actually encoded new information or not. Signed-off-by: Greg Farnum --- src/include/encoding.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/include/encoding.h b/src/include/encoding.h index fedc8b31299..2bd996ca461 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -708,6 +708,8 @@ inline void decode(std::deque& ls, bufferlist::iterator& p) __u8 struct_v = v, struct_compat = compat; \ ::encode(struct_v, bl); \ ::encode(struct_compat, bl); \ + buffer::list::iterator struct_compat_it = bl.end(); \ + struct_compat_it.advance(-1); \ ceph_le32 struct_len; \ struct_len = 0; \ ::encode(struct_len, bl); \ @@ -719,11 +721,18 @@ inline void decode(std::deque& ls, bufferlist::iterator& p) * finish encoding block * * @param bl bufferlist we were encoding to + * @param new_struct_compat struct-compat value to use */ -#define ENCODE_FINISH(bl) \ +#define ENCODE_FINISH_NEW_COMPAT(bl, new_struct_compat) \ } while (false); \ struct_len = bl.length() - struct_len_it.get_off() - sizeof(struct_len); \ - struct_len_it.copy_in(4, (char *)&struct_len); + struct_len_it.copy_in(4, (char *)&struct_len); \ + if (new_struct_compat) { \ + struct_compat = new_struct_compat; \ + struct_compat_it.copy_in(1, (char *)&struct_compat); \ + } + +#define ENCODE_FINISH(bl) ENCODE_FINISH_NEW_COMPAT(bl, 0) #define DECODE_ERR_VERSION(func, v) \ "" #func " unknown encoding version > " #v