summaryrefslogtreecommitdiffstats
path: root/fs/ceph/decode.h
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2009-10-14 09:59:09 -0700
committerSage Weil <sage@newdream.net>2009-10-14 09:59:09 -0700
commitc89136ea4253c73e89e97f5138bb22d97ad9f564 (patch)
treeba8080adfaa6f5b84eadd4d65eff70840f9dfe22 /fs/ceph/decode.h
parent535bbb530764b1b2b3b732837f0e61e1baae7109 (diff)
ceph: convert encode/decode macros to inlines
This avoids the fugly pass by reference and makes the code a bit easier to read. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/decode.h')
-rw-r--r--fs/ceph/decode.h129
1 files changed, 67 insertions, 62 deletions
diff --git a/fs/ceph/decode.h b/fs/ceph/decode.h
index fc2769df062..91179fb2cc3 100644
--- a/fs/ceph/decode.h
+++ b/fs/ceph/decode.h
@@ -3,12 +3,44 @@
#include <asm/unaligned.h>
+#include "types.h"
+
/*
* in all cases,
* void **p pointer to position pointer
* void *end pointer to end of buffer (last byte + 1)
*/
+static inline u64 ceph_decode_64(void **p)
+{
+ u64 v = get_unaligned_le64(*p);
+ *p += sizeof(u64);
+ return v;
+}
+static inline u32 ceph_decode_32(void **p)
+{
+ u32 v = get_unaligned_le32(*p);
+ *p += sizeof(u32);
+ return v;
+}
+static inline u16 ceph_decode_16(void **p)
+{
+ u16 v = get_unaligned_le16(*p);
+ *p += sizeof(u16);
+ return v;
+}
+static inline u8 ceph_decode_8(void **p)
+{
+ u8 v = *(u8 *)*p;
+ (*p)++;
+ return v;
+}
+static inline void ceph_decode_copy(void **p, void *pv, size_t n)
+{
+ memcpy(pv, *p, n);
+ *p += n;
+}
+
/*
* bounds check input.
*/
@@ -18,48 +50,20 @@
goto bad; \
} while (0)
-#define ceph_decode_64(p, v) \
- do { \
- v = get_unaligned_le64(*(p)); \
- *(p) += sizeof(u64); \
- } while (0)
-#define ceph_decode_32(p, v) \
- do { \
- v = get_unaligned_le32(*(p)); \
- *(p) += sizeof(u32); \
- } while (0)
-#define ceph_decode_16(p, v) \
- do { \
- v = get_unaligned_le16(*(p)); \
- *(p) += sizeof(u16); \
- } while (0)
-#define ceph_decode_8(p, v) \
- do { \
- v = *(u8 *)*(p); \
- (*p)++; \
- } while (0)
-
-#define ceph_decode_copy(p, pv, n) \
- do { \
- memcpy(pv, *(p), n); \
- *(p) += n; \
- } while (0)
-
-/* bounds check too */
#define ceph_decode_64_safe(p, end, v, bad) \
do { \
ceph_decode_need(p, end, sizeof(u64), bad); \
- ceph_decode_64(p, v); \
+ v = ceph_decode_64(p); \
} while (0)
#define ceph_decode_32_safe(p, end, v, bad) \
do { \
ceph_decode_need(p, end, sizeof(u32), bad); \
- ceph_decode_32(p, v); \
+ v = ceph_decode_32(p); \
} while (0)
#define ceph_decode_16_safe(p, end, v, bad) \
do { \
ceph_decode_need(p, end, sizeof(u16), bad); \
- ceph_decode_16(p, v); \
+ v = ceph_decode_16(p); \
} while (0)
#define ceph_decode_copy_safe(p, end, pv, n, bad) \
@@ -71,41 +75,42 @@
/*
* struct ceph_timespec <-> struct timespec
*/
-#define ceph_decode_timespec(ts, tv) \
- do { \
- (ts)->tv_sec = le32_to_cpu((tv)->tv_sec); \
- (ts)->tv_nsec = le32_to_cpu((tv)->tv_nsec); \
- } while (0)
-#define ceph_encode_timespec(tv, ts) \
- do { \
- (tv)->tv_sec = cpu_to_le32((ts)->tv_sec); \
- (tv)->tv_nsec = cpu_to_le32((ts)->tv_nsec); \
- } while (0)
-
+static inline void ceph_decode_timespec(struct timespec *ts,
+ struct ceph_timespec *tv)
+{
+ ts->tv_sec = le32_to_cpu(tv->tv_sec);
+ ts->tv_nsec = le32_to_cpu(tv->tv_nsec);
+}
+static inline void ceph_encode_timespec(struct ceph_timespec *tv,
+ struct timespec *ts)
+{
+ tv->tv_sec = cpu_to_le32(ts->tv_sec);
+ tv->tv_nsec = cpu_to_le32(ts->tv_nsec);
+}
/*
* encoders
*/
-#define ceph_encode_64(p, v) \
- do { \
- put_unaligned_le64(v, (__le64 *)*(p)); \
- *(p) += sizeof(u64); \
- } while (0)
-#define ceph_encode_32(p, v) \
- do { \
- put_unaligned_le32(v, (__le32 *)*(p)); \
- *(p) += sizeof(u32); \
- } while (0)
-#define ceph_encode_16(p, v) \
- do { \
- put_unaligned_le16(v), (__le16 *)*(p)); \
- *(p) += sizeof(u16); \
- } while (0)
-#define ceph_encode_8(p, v) \
- do { \
- *(u8 *)*(p) = v; \
- (*(p))++; \
- } while (0)
+static inline void ceph_encode_64(void **p, u64 v)
+{
+ put_unaligned_le64(v, (__le64 *)*p);
+ *p += sizeof(u64);
+}
+static inline void ceph_encode_32(void **p, u32 v)
+{
+ put_unaligned_le32(v, (__le32 *)*p);
+ *p += sizeof(u32);
+}
+static inline void ceph_encode_16(void **p, u16 v)
+{
+ put_unaligned_le16(v, (__le16 *)*p);
+ *p += sizeof(u16);
+}
+static inline void ceph_encode_8(void **p, u8 v)
+{
+ *(u8 *)*p = v;
+ (*p)++;
+}
/*
* filepath, string encoders