diff options
author | Sage Weil <sage@newdream.net> | 2009-10-14 12:59:09 -0400 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2009-10-14 12:59:09 -0400 |
commit | c89136ea4253c73e89e97f5138bb22d97ad9f564 (patch) | |
tree | ba8080adfaa6f5b84eadd4d65eff70840f9dfe22 /fs | |
parent | 535bbb530764b1b2b3b732837f0e61e1baae7109 (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')
-rw-r--r-- | fs/ceph/decode.h | 129 | ||||
-rw-r--r-- | fs/ceph/mds_client.c | 20 | ||||
-rw-r--r-- | fs/ceph/mdsmap.c | 38 | ||||
-rw-r--r-- | fs/ceph/mon_client.c | 4 | ||||
-rw-r--r-- | fs/ceph/osd_client.c | 8 | ||||
-rw-r--r-- | fs/ceph/osdmap.c | 70 |
6 files changed, 137 insertions, 132 deletions
diff --git a/fs/ceph/decode.h b/fs/ceph/decode.h index fc2769df062d..91179fb2cc3f 100644 --- a/fs/ceph/decode.h +++ b/fs/ceph/decode.h | |||
@@ -3,12 +3,44 @@ | |||
3 | 3 | ||
4 | #include <asm/unaligned.h> | 4 | #include <asm/unaligned.h> |
5 | 5 | ||
6 | #include "types.h" | ||
7 | |||
6 | /* | 8 | /* |
7 | * in all cases, | 9 | * in all cases, |
8 | * void **p pointer to position pointer | 10 | * void **p pointer to position pointer |
9 | * void *end pointer to end of buffer (last byte + 1) | 11 | * void *end pointer to end of buffer (last byte + 1) |
10 | */ | 12 | */ |
11 | 13 | ||
14 | static inline u64 ceph_decode_64(void **p) | ||
15 | { | ||
16 | u64 v = get_unaligned_le64(*p); | ||
17 | *p += sizeof(u64); | ||
18 | return v; | ||
19 | } | ||
20 | static inline u32 ceph_decode_32(void **p) | ||
21 | { | ||
22 | u32 v = get_unaligned_le32(*p); | ||
23 | *p += sizeof(u32); | ||
24 | return v; | ||
25 | } | ||
26 | static inline u16 ceph_decode_16(void **p) | ||
27 | { | ||
28 | u16 v = get_unaligned_le16(*p); | ||
29 | *p += sizeof(u16); | ||
30 | return v; | ||
31 | } | ||
32 | static inline u8 ceph_decode_8(void **p) | ||
33 | { | ||
34 | u8 v = *(u8 *)*p; | ||
35 | (*p)++; | ||
36 | return v; | ||
37 | } | ||
38 | static inline void ceph_decode_copy(void **p, void *pv, size_t n) | ||
39 | { | ||
40 | memcpy(pv, *p, n); | ||
41 | *p += n; | ||
42 | } | ||
43 | |||
12 | /* | 44 | /* |
13 | * bounds check input. | 45 | * bounds check input. |
14 | */ | 46 | */ |
@@ -18,48 +50,20 @@ | |||
18 | goto bad; \ | 50 | goto bad; \ |
19 | } while (0) | 51 | } while (0) |
20 | 52 | ||
21 | #define ceph_decode_64(p, v) \ | ||
22 | do { \ | ||
23 | v = get_unaligned_le64(*(p)); \ | ||
24 | *(p) += sizeof(u64); \ | ||
25 | } while (0) | ||
26 | #define ceph_decode_32(p, v) \ | ||
27 | do { \ | ||
28 | v = get_unaligned_le32(*(p)); \ | ||
29 | *(p) += sizeof(u32); \ | ||
30 | } while (0) | ||
31 | #define ceph_decode_16(p, v) \ | ||
32 | do { \ | ||
33 | v = get_unaligned_le16(*(p)); \ | ||
34 | *(p) += sizeof(u16); \ | ||
35 | } while (0) | ||
36 | #define ceph_decode_8(p, v) \ | ||
37 | do { \ | ||
38 | v = *(u8 *)*(p); \ | ||
39 | (*p)++; \ | ||
40 | } while (0) | ||
41 | |||
42 | #define ceph_decode_copy(p, pv, n) \ | ||
43 | do { \ | ||
44 | memcpy(pv, *(p), n); \ | ||
45 | *(p) += n; \ | ||
46 | } while (0) | ||
47 | |||
48 | /* bounds check too */ | ||
49 | #define ceph_decode_64_safe(p, end, v, bad) \ | 53 | #define ceph_decode_64_safe(p, end, v, bad) \ |
50 | do { \ | 54 | do { \ |
51 | ceph_decode_need(p, end, sizeof(u64), bad); \ | 55 | ceph_decode_need(p, end, sizeof(u64), bad); \ |
52 | ceph_decode_64(p, v); \ | 56 | v = ceph_decode_64(p); \ |
53 | } while (0) | 57 | } while (0) |
54 | #define ceph_decode_32_safe(p, end, v, bad) \ | 58 | #define ceph_decode_32_safe(p, end, v, bad) \ |
55 | do { \ | 59 | do { \ |
56 | ceph_decode_need(p, end, sizeof(u32), bad); \ | 60 | ceph_decode_need(p, end, sizeof(u32), bad); \ |
57 | ceph_decode_32(p, v); \ | 61 | v = ceph_decode_32(p); \ |
58 | } while (0) | 62 | } while (0) |
59 | #define ceph_decode_16_safe(p, end, v, bad) \ | 63 | #define ceph_decode_16_safe(p, end, v, bad) \ |
60 | do { \ | 64 | do { \ |
61 | ceph_decode_need(p, end, sizeof(u16), bad); \ | 65 | ceph_decode_need(p, end, sizeof(u16), bad); \ |
62 | ceph_decode_16(p, v); \ | 66 | v = ceph_decode_16(p); \ |
63 | } while (0) | 67 | } while (0) |
64 | 68 | ||
65 | #define ceph_decode_copy_safe(p, end, pv, n, bad) \ | 69 | #define ceph_decode_copy_safe(p, end, pv, n, bad) \ |
@@ -71,41 +75,42 @@ | |||
71 | /* | 75 | /* |
72 | * struct ceph_timespec <-> struct timespec | 76 | * struct ceph_timespec <-> struct timespec |
73 | */ | 77 | */ |
74 | #define ceph_decode_timespec(ts, tv) \ | 78 | static inline void ceph_decode_timespec(struct timespec *ts, |
75 | do { \ | 79 | struct ceph_timespec *tv) |
76 | (ts)->tv_sec = le32_to_cpu((tv)->tv_sec); \ | 80 | { |
77 | (ts)->tv_nsec = le32_to_cpu((tv)->tv_nsec); \ | 81 | ts->tv_sec = le32_to_cpu(tv->tv_sec); |
78 | } while (0) | 82 | ts->tv_nsec = le32_to_cpu(tv->tv_nsec); |
79 | #define ceph_encode_timespec(tv, ts) \ | 83 | } |
80 | do { \ | 84 | static inline void ceph_encode_timespec(struct ceph_timespec *tv, |
81 | (tv)->tv_sec = cpu_to_le32((ts)->tv_sec); \ | 85 | struct timespec *ts) |
82 | (tv)->tv_nsec = cpu_to_le32((ts)->tv_nsec); \ | 86 | { |
83 | } while (0) | 87 | tv->tv_sec = cpu_to_le32(ts->tv_sec); |
84 | 88 | tv->tv_nsec = cpu_to_le32(ts->tv_nsec); | |
89 | } | ||
85 | 90 | ||
86 | /* | 91 | /* |
87 | * encoders | 92 | * encoders |
88 | */ | 93 | */ |
89 | #define ceph_encode_64(p, v) \ | 94 | static inline void ceph_encode_64(void **p, u64 v) |
90 | do { \ | 95 | { |
91 | put_unaligned_le64(v, (__le64 *)*(p)); \ | 96 | put_unaligned_le64(v, (__le64 *)*p); |
92 | *(p) += sizeof(u64); \ | 97 | *p += sizeof(u64); |
93 | } while (0) | 98 | } |
94 | #define ceph_encode_32(p, v) \ | 99 | static inline void ceph_encode_32(void **p, u32 v) |
95 | do { \ | 100 | { |
96 | put_unaligned_le32(v, (__le32 *)*(p)); \ | 101 | put_unaligned_le32(v, (__le32 *)*p); |
97 | *(p) += sizeof(u32); \ | 102 | *p += sizeof(u32); |
98 | } while (0) | 103 | } |
99 | #define ceph_encode_16(p, v) \ | 104 | static inline void ceph_encode_16(void **p, u16 v) |
100 | do { \ | 105 | { |
101 | put_unaligned_le16(v), (__le16 *)*(p)); \ | 106 | put_unaligned_le16(v, (__le16 *)*p); |
102 | *(p) += sizeof(u16); \ | 107 | *p += sizeof(u16); |
103 | } while (0) | 108 | } |
104 | #define ceph_encode_8(p, v) \ | 109 | static inline void ceph_encode_8(void **p, u8 v) |
105 | do { \ | 110 | { |
106 | *(u8 *)*(p) = v; \ | 111 | *(u8 *)*p = v; |
107 | (*(p))++; \ | 112 | (*p)++; |
108 | } while (0) | 113 | } |
109 | 114 | ||
110 | /* | 115 | /* |
111 | * filepath, string encoders | 116 | * filepath, string encoders |
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index de8ba4a242ca..2b19da31a8b3 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c | |||
@@ -136,9 +136,9 @@ static int parse_reply_info_dir(void **p, void *end, | |||
136 | goto bad; | 136 | goto bad; |
137 | 137 | ||
138 | ceph_decode_need(p, end, sizeof(num) + 2, bad); | 138 | ceph_decode_need(p, end, sizeof(num) + 2, bad); |
139 | ceph_decode_32(p, num); | 139 | num = ceph_decode_32(p); |
140 | ceph_decode_8(p, info->dir_end); | 140 | info->dir_end = ceph_decode_8(p); |
141 | ceph_decode_8(p, info->dir_complete); | 141 | info->dir_complete = ceph_decode_8(p); |
142 | if (num == 0) | 142 | if (num == 0) |
143 | goto done; | 143 | goto done; |
144 | 144 | ||
@@ -160,7 +160,7 @@ static int parse_reply_info_dir(void **p, void *end, | |||
160 | while (num) { | 160 | while (num) { |
161 | /* dentry */ | 161 | /* dentry */ |
162 | ceph_decode_need(p, end, sizeof(u32)*2, bad); | 162 | ceph_decode_need(p, end, sizeof(u32)*2, bad); |
163 | ceph_decode_32(p, info->dir_dname_len[i]); | 163 | info->dir_dname_len[i] = ceph_decode_32(p); |
164 | ceph_decode_need(p, end, info->dir_dname_len[i], bad); | 164 | ceph_decode_need(p, end, info->dir_dname_len[i], bad); |
165 | info->dir_dname[i] = *p; | 165 | info->dir_dname[i] = *p; |
166 | *p += info->dir_dname_len[i]; | 166 | *p += info->dir_dname_len[i]; |
@@ -1791,10 +1791,10 @@ static void handle_forward(struct ceph_mds_client *mdsc, struct ceph_msg *msg) | |||
1791 | from_mds = le64_to_cpu(msg->hdr.src.name.num); | 1791 | from_mds = le64_to_cpu(msg->hdr.src.name.num); |
1792 | 1792 | ||
1793 | ceph_decode_need(&p, end, sizeof(u64)+2*sizeof(u32), bad); | 1793 | ceph_decode_need(&p, end, sizeof(u64)+2*sizeof(u32), bad); |
1794 | ceph_decode_64(&p, tid); | 1794 | tid = ceph_decode_64(&p); |
1795 | ceph_decode_32(&p, next_mds); | 1795 | next_mds = ceph_decode_32(&p); |
1796 | ceph_decode_32(&p, fwd_seq); | 1796 | fwd_seq = ceph_decode_32(&p); |
1797 | ceph_decode_8(&p, must_resend); | 1797 | must_resend = ceph_decode_8(&p); |
1798 | 1798 | ||
1799 | WARN_ON(must_resend); /* shouldn't happen. */ | 1799 | WARN_ON(must_resend); /* shouldn't happen. */ |
1800 | 1800 | ||
@@ -2783,8 +2783,8 @@ void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, struct ceph_msg *msg) | |||
2783 | pr_err("got mdsmap with wrong fsid\n"); | 2783 | pr_err("got mdsmap with wrong fsid\n"); |
2784 | return; | 2784 | return; |
2785 | } | 2785 | } |
2786 | ceph_decode_32(&p, epoch); | 2786 | epoch = ceph_decode_32(&p); |
2787 | ceph_decode_32(&p, maplen); | 2787 | maplen = ceph_decode_32(&p); |
2788 | dout("handle_map epoch %u len %d\n", epoch, (int)maplen); | 2788 | dout("handle_map epoch %u len %d\n", epoch, (int)maplen); |
2789 | 2789 | ||
2790 | /* do we need it? */ | 2790 | /* do we need it? */ |
diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c index 09180d8fafe4..80daea064470 100644 --- a/fs/ceph/mdsmap.c +++ b/fs/ceph/mdsmap.c | |||
@@ -60,21 +60,21 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) | |||
60 | ceph_decode_16_safe(p, end, version, bad); | 60 | ceph_decode_16_safe(p, end, version, bad); |
61 | 61 | ||
62 | ceph_decode_need(p, end, 8*sizeof(u32) + sizeof(u64), bad); | 62 | ceph_decode_need(p, end, 8*sizeof(u32) + sizeof(u64), bad); |
63 | ceph_decode_32(p, m->m_epoch); | 63 | m->m_epoch = ceph_decode_32(p); |
64 | ceph_decode_32(p, m->m_client_epoch); | 64 | m->m_client_epoch = ceph_decode_32(p); |
65 | ceph_decode_32(p, m->m_last_failure); | 65 | m->m_last_failure = ceph_decode_32(p); |
66 | ceph_decode_32(p, m->m_root); | 66 | m->m_root = ceph_decode_32(p); |
67 | ceph_decode_32(p, m->m_session_timeout); | 67 | m->m_session_timeout = ceph_decode_32(p); |
68 | ceph_decode_32(p, m->m_session_autoclose); | 68 | m->m_session_autoclose = ceph_decode_32(p); |
69 | ceph_decode_64(p, m->m_max_file_size); | 69 | m->m_max_file_size = ceph_decode_64(p); |
70 | ceph_decode_32(p, m->m_max_mds); | 70 | m->m_max_mds = ceph_decode_32(p); |
71 | 71 | ||
72 | m->m_info = kcalloc(m->m_max_mds, sizeof(*m->m_info), GFP_NOFS); | 72 | m->m_info = kcalloc(m->m_max_mds, sizeof(*m->m_info), GFP_NOFS); |
73 | if (m->m_info == NULL) | 73 | if (m->m_info == NULL) |
74 | goto badmem; | 74 | goto badmem; |
75 | 75 | ||
76 | /* pick out active nodes from mds_info (state > 0) */ | 76 | /* pick out active nodes from mds_info (state > 0) */ |
77 | ceph_decode_32(p, n); | 77 | n = ceph_decode_32(p); |
78 | for (i = 0; i < n; i++) { | 78 | for (i = 0; i < n; i++) { |
79 | u32 namelen; | 79 | u32 namelen; |
80 | s32 mds, inc, state; | 80 | s32 mds, inc, state; |
@@ -86,18 +86,18 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) | |||
86 | 86 | ||
87 | ceph_decode_need(p, end, sizeof(addr) + 1 + sizeof(u32), bad); | 87 | ceph_decode_need(p, end, sizeof(addr) + 1 + sizeof(u32), bad); |
88 | ceph_decode_copy(p, &addr, sizeof(addr)); | 88 | ceph_decode_copy(p, &addr, sizeof(addr)); |
89 | ceph_decode_8(p, infoversion); | 89 | infoversion = ceph_decode_8(p); |
90 | ceph_decode_32(p, namelen); /* skip mds name */ | 90 | namelen = ceph_decode_32(p); /* skip mds name */ |
91 | *p += namelen; | 91 | *p += namelen; |
92 | 92 | ||
93 | ceph_decode_need(p, end, | 93 | ceph_decode_need(p, end, |
94 | 4*sizeof(u32) + sizeof(u64) + | 94 | 4*sizeof(u32) + sizeof(u64) + |
95 | sizeof(addr) + sizeof(struct ceph_timespec), | 95 | sizeof(addr) + sizeof(struct ceph_timespec), |
96 | bad); | 96 | bad); |
97 | ceph_decode_32(p, mds); | 97 | mds = ceph_decode_32(p); |
98 | ceph_decode_32(p, inc); | 98 | inc = ceph_decode_32(p); |
99 | ceph_decode_32(p, state); | 99 | state = ceph_decode_32(p); |
100 | ceph_decode_64(p, state_seq); | 100 | state_seq = ceph_decode_64(p); |
101 | *p += sizeof(addr); | 101 | *p += sizeof(addr); |
102 | *p += sizeof(struct ceph_timespec); | 102 | *p += sizeof(struct ceph_timespec); |
103 | *p += sizeof(u32); | 103 | *p += sizeof(u32); |
@@ -123,8 +123,8 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) | |||
123 | kcalloc(num_export_targets, sizeof(u32), | 123 | kcalloc(num_export_targets, sizeof(u32), |
124 | GFP_NOFS); | 124 | GFP_NOFS); |
125 | for (j = 0; j < num_export_targets; j++) | 125 | for (j = 0; j < num_export_targets; j++) |
126 | ceph_decode_32(&pexport_targets, | 126 | m->m_info[mds].export_targets[j] = |
127 | m->m_info[mds].export_targets[j]); | 127 | ceph_decode_32(&pexport_targets); |
128 | } else { | 128 | } else { |
129 | m->m_info[mds].export_targets = NULL; | 129 | m->m_info[mds].export_targets = NULL; |
130 | } | 130 | } |
@@ -139,8 +139,8 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) | |||
139 | goto badmem; | 139 | goto badmem; |
140 | ceph_decode_need(p, end, sizeof(u32)*(n+1), bad); | 140 | ceph_decode_need(p, end, sizeof(u32)*(n+1), bad); |
141 | for (i = 0; i < n; i++) | 141 | for (i = 0; i < n; i++) |
142 | ceph_decode_32(p, m->m_data_pg_pools[i]); | 142 | m->m_data_pg_pools[i] = ceph_decode_32(p); |
143 | ceph_decode_32(p, m->m_cas_pg_pool); | 143 | m->m_cas_pg_pool = ceph_decode_32(p); |
144 | 144 | ||
145 | /* ok, we don't care about the rest. */ | 145 | /* ok, we don't care about the rest. */ |
146 | dout("mdsmap_decode success epoch %u\n", m->m_epoch); | 146 | dout("mdsmap_decode success epoch %u\n", m->m_epoch); |
diff --git a/fs/ceph/mon_client.c b/fs/ceph/mon_client.c index d6c8e783467e..bea2be9077e4 100644 --- a/fs/ceph/mon_client.c +++ b/fs/ceph/mon_client.c | |||
@@ -45,9 +45,9 @@ struct ceph_monmap *ceph_monmap_decode(void *p, void *end) | |||
45 | 45 | ||
46 | ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad); | 46 | ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad); |
47 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); | 47 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
48 | ceph_decode_32(&p, epoch); | 48 | epoch = ceph_decode_32(&p); |
49 | 49 | ||
50 | ceph_decode_32(&p, num_mon); | 50 | num_mon = ceph_decode_32(&p); |
51 | ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad); | 51 | ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad); |
52 | 52 | ||
53 | if (num_mon >= CEPH_MAX_MON) | 53 | if (num_mon >= CEPH_MAX_MON) |
diff --git a/fs/ceph/osd_client.c b/fs/ceph/osd_client.c index 8e33928647f4..bbd9a5d23712 100644 --- a/fs/ceph/osd_client.c +++ b/fs/ceph/osd_client.c | |||
@@ -894,8 +894,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) | |||
894 | dout(" %d inc maps\n", nr_maps); | 894 | dout(" %d inc maps\n", nr_maps); |
895 | while (nr_maps > 0) { | 895 | while (nr_maps > 0) { |
896 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); | 896 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
897 | ceph_decode_32(&p, epoch); | 897 | epoch = ceph_decode_32(&p); |
898 | ceph_decode_32(&p, maplen); | 898 | maplen = ceph_decode_32(&p); |
899 | ceph_decode_need(&p, end, maplen, bad); | 899 | ceph_decode_need(&p, end, maplen, bad); |
900 | next = p + maplen; | 900 | next = p + maplen; |
901 | if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) { | 901 | if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) { |
@@ -927,8 +927,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) | |||
927 | dout(" %d full maps\n", nr_maps); | 927 | dout(" %d full maps\n", nr_maps); |
928 | while (nr_maps) { | 928 | while (nr_maps) { |
929 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); | 929 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
930 | ceph_decode_32(&p, epoch); | 930 | epoch = ceph_decode_32(&p); |
931 | ceph_decode_32(&p, maplen); | 931 | maplen = ceph_decode_32(&p); |
932 | ceph_decode_need(&p, end, maplen, bad); | 932 | ceph_decode_need(&p, end, maplen, bad); |
933 | if (nr_maps > 1) { | 933 | if (nr_maps > 1) { |
934 | dout("skipping non-latest full map %u len %d\n", | 934 | dout("skipping non-latest full map %u len %d\n", |
diff --git a/fs/ceph/osdmap.c b/fs/ceph/osdmap.c index 342e5f80996b..6f0aeff4185a 100644 --- a/fs/ceph/osdmap.c +++ b/fs/ceph/osdmap.c | |||
@@ -67,7 +67,7 @@ static int crush_decode_uniform_bucket(void **p, void *end, | |||
67 | { | 67 | { |
68 | dout("crush_decode_uniform_bucket %p to %p\n", *p, end); | 68 | dout("crush_decode_uniform_bucket %p to %p\n", *p, end); |
69 | ceph_decode_need(p, end, (1+b->h.size) * sizeof(u32), bad); | 69 | ceph_decode_need(p, end, (1+b->h.size) * sizeof(u32), bad); |
70 | ceph_decode_32(p, b->item_weight); | 70 | b->item_weight = ceph_decode_32(p); |
71 | return 0; | 71 | return 0; |
72 | bad: | 72 | bad: |
73 | return -EINVAL; | 73 | return -EINVAL; |
@@ -86,8 +86,8 @@ static int crush_decode_list_bucket(void **p, void *end, | |||
86 | return -ENOMEM; | 86 | return -ENOMEM; |
87 | ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); | 87 | ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); |
88 | for (j = 0; j < b->h.size; j++) { | 88 | for (j = 0; j < b->h.size; j++) { |
89 | ceph_decode_32(p, b->item_weights[j]); | 89 | b->item_weights[j] = ceph_decode_32(p); |
90 | ceph_decode_32(p, b->sum_weights[j]); | 90 | b->sum_weights[j] = ceph_decode_32(p); |
91 | } | 91 | } |
92 | return 0; | 92 | return 0; |
93 | bad: | 93 | bad: |
@@ -105,7 +105,7 @@ static int crush_decode_tree_bucket(void **p, void *end, | |||
105 | return -ENOMEM; | 105 | return -ENOMEM; |
106 | ceph_decode_need(p, end, b->num_nodes * sizeof(u32), bad); | 106 | ceph_decode_need(p, end, b->num_nodes * sizeof(u32), bad); |
107 | for (j = 0; j < b->num_nodes; j++) | 107 | for (j = 0; j < b->num_nodes; j++) |
108 | ceph_decode_32(p, b->node_weights[j]); | 108 | b->node_weights[j] = ceph_decode_32(p); |
109 | return 0; | 109 | return 0; |
110 | bad: | 110 | bad: |
111 | return -EINVAL; | 111 | return -EINVAL; |
@@ -124,8 +124,8 @@ static int crush_decode_straw_bucket(void **p, void *end, | |||
124 | return -ENOMEM; | 124 | return -ENOMEM; |
125 | ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); | 125 | ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad); |
126 | for (j = 0; j < b->h.size; j++) { | 126 | for (j = 0; j < b->h.size; j++) { |
127 | ceph_decode_32(p, b->item_weights[j]); | 127 | b->item_weights[j] = ceph_decode_32(p); |
128 | ceph_decode_32(p, b->straws[j]); | 128 | b->straws[j] = ceph_decode_32(p); |
129 | } | 129 | } |
130 | return 0; | 130 | return 0; |
131 | bad: | 131 | bad: |
@@ -148,15 +148,15 @@ static struct crush_map *crush_decode(void *pbyval, void *end) | |||
148 | return ERR_PTR(-ENOMEM); | 148 | return ERR_PTR(-ENOMEM); |
149 | 149 | ||
150 | ceph_decode_need(p, end, 4*sizeof(u32), bad); | 150 | ceph_decode_need(p, end, 4*sizeof(u32), bad); |
151 | ceph_decode_32(p, magic); | 151 | magic = ceph_decode_32(p); |
152 | if (magic != CRUSH_MAGIC) { | 152 | if (magic != CRUSH_MAGIC) { |
153 | pr_err("crush_decode magic %x != current %x\n", | 153 | pr_err("crush_decode magic %x != current %x\n", |
154 | (unsigned)magic, (unsigned)CRUSH_MAGIC); | 154 | (unsigned)magic, (unsigned)CRUSH_MAGIC); |
155 | goto bad; | 155 | goto bad; |
156 | } | 156 | } |
157 | ceph_decode_32(p, c->max_buckets); | 157 | c->max_buckets = ceph_decode_32(p); |
158 | ceph_decode_32(p, c->max_rules); | 158 | c->max_rules = ceph_decode_32(p); |
159 | ceph_decode_32(p, c->max_devices); | 159 | c->max_devices = ceph_decode_32(p); |
160 | 160 | ||
161 | c->device_parents = kcalloc(c->max_devices, sizeof(u32), GFP_NOFS); | 161 | c->device_parents = kcalloc(c->max_devices, sizeof(u32), GFP_NOFS); |
162 | if (c->device_parents == NULL) | 162 | if (c->device_parents == NULL) |
@@ -208,11 +208,11 @@ static struct crush_map *crush_decode(void *pbyval, void *end) | |||
208 | goto badmem; | 208 | goto badmem; |
209 | 209 | ||
210 | ceph_decode_need(p, end, 4*sizeof(u32), bad); | 210 | ceph_decode_need(p, end, 4*sizeof(u32), bad); |
211 | ceph_decode_32(p, b->id); | 211 | b->id = ceph_decode_32(p); |
212 | ceph_decode_16(p, b->type); | 212 | b->type = ceph_decode_16(p); |
213 | ceph_decode_16(p, b->alg); | 213 | b->alg = ceph_decode_16(p); |
214 | ceph_decode_32(p, b->weight); | 214 | b->weight = ceph_decode_32(p); |
215 | ceph_decode_32(p, b->size); | 215 | b->size = ceph_decode_32(p); |
216 | 216 | ||
217 | dout("crush_decode bucket size %d off %x %p to %p\n", | 217 | dout("crush_decode bucket size %d off %x %p to %p\n", |
218 | b->size, (int)(*p-start), *p, end); | 218 | b->size, (int)(*p-start), *p, end); |
@@ -227,7 +227,7 @@ static struct crush_map *crush_decode(void *pbyval, void *end) | |||
227 | 227 | ||
228 | ceph_decode_need(p, end, b->size*sizeof(u32), bad); | 228 | ceph_decode_need(p, end, b->size*sizeof(u32), bad); |
229 | for (j = 0; j < b->size; j++) | 229 | for (j = 0; j < b->size; j++) |
230 | ceph_decode_32(p, b->items[j]); | 230 | b->items[j] = ceph_decode_32(p); |
231 | 231 | ||
232 | switch (b->alg) { | 232 | switch (b->alg) { |
233 | case CRUSH_BUCKET_UNIFORM: | 233 | case CRUSH_BUCKET_UNIFORM: |
@@ -290,9 +290,9 @@ static struct crush_map *crush_decode(void *pbyval, void *end) | |||
290 | ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */ | 290 | ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */ |
291 | ceph_decode_need(p, end, r->len*3*sizeof(u32), bad); | 291 | ceph_decode_need(p, end, r->len*3*sizeof(u32), bad); |
292 | for (j = 0; j < r->len; j++) { | 292 | for (j = 0; j < r->len; j++) { |
293 | ceph_decode_32(p, r->steps[j].op); | 293 | r->steps[j].op = ceph_decode_32(p); |
294 | ceph_decode_32(p, r->steps[j].arg1); | 294 | r->steps[j].arg1 = ceph_decode_32(p); |
295 | ceph_decode_32(p, r->steps[j].arg2); | 295 | r->steps[j].arg2 = ceph_decode_32(p); |
296 | } | 296 | } |
297 | } | 297 | } |
298 | 298 | ||
@@ -411,11 +411,11 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) | |||
411 | 411 | ||
412 | ceph_decode_need(p, end, 2*sizeof(u64)+6*sizeof(u32), bad); | 412 | ceph_decode_need(p, end, 2*sizeof(u64)+6*sizeof(u32), bad); |
413 | ceph_decode_copy(p, &map->fsid, sizeof(map->fsid)); | 413 | ceph_decode_copy(p, &map->fsid, sizeof(map->fsid)); |
414 | ceph_decode_32(p, map->epoch); | 414 | map->epoch = ceph_decode_32(p); |
415 | ceph_decode_copy(p, &map->created, sizeof(map->created)); | 415 | ceph_decode_copy(p, &map->created, sizeof(map->created)); |
416 | ceph_decode_copy(p, &map->modified, sizeof(map->modified)); | 416 | ceph_decode_copy(p, &map->modified, sizeof(map->modified)); |
417 | 417 | ||
418 | ceph_decode_32(p, map->num_pools); | 418 | map->num_pools = ceph_decode_32(p); |
419 | map->pg_pool = kcalloc(map->num_pools, sizeof(*map->pg_pool), | 419 | map->pg_pool = kcalloc(map->num_pools, sizeof(*map->pg_pool), |
420 | GFP_NOFS); | 420 | GFP_NOFS); |
421 | if (!map->pg_pool) { | 421 | if (!map->pg_pool) { |
@@ -425,7 +425,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) | |||
425 | ceph_decode_32_safe(p, end, max, bad); | 425 | ceph_decode_32_safe(p, end, max, bad); |
426 | while (max--) { | 426 | while (max--) { |
427 | ceph_decode_need(p, end, 4+sizeof(map->pg_pool->v), bad); | 427 | ceph_decode_need(p, end, 4+sizeof(map->pg_pool->v), bad); |
428 | ceph_decode_32(p, i); | 428 | i = ceph_decode_32(p); |
429 | if (i >= map->num_pools) | 429 | if (i >= map->num_pools) |
430 | goto bad; | 430 | goto bad; |
431 | ceph_decode_copy(p, &map->pg_pool[i].v, | 431 | ceph_decode_copy(p, &map->pg_pool[i].v, |
@@ -438,7 +438,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) | |||
438 | 438 | ||
439 | ceph_decode_32_safe(p, end, map->flags, bad); | 439 | ceph_decode_32_safe(p, end, map->flags, bad); |
440 | 440 | ||
441 | ceph_decode_32(p, max); | 441 | max = ceph_decode_32(p); |
442 | 442 | ||
443 | /* (re)alloc osd arrays */ | 443 | /* (re)alloc osd arrays */ |
444 | err = osdmap_set_max_osd(map, max); | 444 | err = osdmap_set_max_osd(map, max); |
@@ -456,7 +456,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) | |||
456 | 456 | ||
457 | *p += 4; /* skip length field (should match max) */ | 457 | *p += 4; /* skip length field (should match max) */ |
458 | for (i = 0; i < map->max_osd; i++) | 458 | for (i = 0; i < map->max_osd; i++) |
459 | ceph_decode_32(p, map->osd_weight[i]); | 459 | map->osd_weight[i] = ceph_decode_32(p); |
460 | 460 | ||
461 | *p += 4; /* skip length field (should match max) */ | 461 | *p += 4; /* skip length field (should match max) */ |
462 | ceph_decode_copy(p, map->osd_addr, map->max_osd*sizeof(*map->osd_addr)); | 462 | ceph_decode_copy(p, map->osd_addr, map->max_osd*sizeof(*map->osd_addr)); |
@@ -469,8 +469,8 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) | |||
469 | struct ceph_pg_mapping *pg; | 469 | struct ceph_pg_mapping *pg; |
470 | 470 | ||
471 | ceph_decode_need(p, end, sizeof(u32) + sizeof(u64), bad); | 471 | ceph_decode_need(p, end, sizeof(u32) + sizeof(u64), bad); |
472 | ceph_decode_64(p, pgid); | 472 | pgid = ceph_decode_64(p); |
473 | ceph_decode_32(p, n); | 473 | n = ceph_decode_32(p); |
474 | ceph_decode_need(p, end, n * sizeof(u32), bad); | 474 | ceph_decode_need(p, end, n * sizeof(u32), bad); |
475 | pg = kmalloc(sizeof(*pg) + n*sizeof(u32), GFP_NOFS); | 475 | pg = kmalloc(sizeof(*pg) + n*sizeof(u32), GFP_NOFS); |
476 | if (!pg) { | 476 | if (!pg) { |
@@ -480,7 +480,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end) | |||
480 | pg->pgid = pgid; | 480 | pg->pgid = pgid; |
481 | pg->len = n; | 481 | pg->len = n; |
482 | for (j = 0; j < n; j++) | 482 | for (j = 0; j < n; j++) |
483 | ceph_decode_32(p, pg->osds[j]); | 483 | pg->osds[j] = ceph_decode_32(p); |
484 | 484 | ||
485 | err = __insert_pg_mapping(pg, &map->pg_temp); | 485 | err = __insert_pg_mapping(pg, &map->pg_temp); |
486 | if (err) | 486 | if (err) |
@@ -537,10 +537,10 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, | |||
537 | ceph_decode_need(p, end, sizeof(fsid)+sizeof(modified)+2*sizeof(u32), | 537 | ceph_decode_need(p, end, sizeof(fsid)+sizeof(modified)+2*sizeof(u32), |
538 | bad); | 538 | bad); |
539 | ceph_decode_copy(p, &fsid, sizeof(fsid)); | 539 | ceph_decode_copy(p, &fsid, sizeof(fsid)); |
540 | ceph_decode_32(p, epoch); | 540 | epoch = ceph_decode_32(p); |
541 | BUG_ON(epoch != map->epoch+1); | 541 | BUG_ON(epoch != map->epoch+1); |
542 | ceph_decode_copy(p, &modified, sizeof(modified)); | 542 | ceph_decode_copy(p, &modified, sizeof(modified)); |
543 | ceph_decode_32(p, new_flags); | 543 | new_flags = ceph_decode_32(p); |
544 | 544 | ||
545 | /* full map? */ | 545 | /* full map? */ |
546 | ceph_decode_32_safe(p, end, len, bad); | 546 | ceph_decode_32_safe(p, end, len, bad); |
@@ -568,7 +568,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, | |||
568 | ceph_decode_need(p, end, 5*sizeof(u32), bad); | 568 | ceph_decode_need(p, end, 5*sizeof(u32), bad); |
569 | 569 | ||
570 | /* new max? */ | 570 | /* new max? */ |
571 | ceph_decode_32(p, max); | 571 | max = ceph_decode_32(p); |
572 | if (max >= 0) { | 572 | if (max >= 0) { |
573 | err = osdmap_set_max_osd(map, max); | 573 | err = osdmap_set_max_osd(map, max); |
574 | if (err < 0) | 574 | if (err < 0) |
@@ -641,8 +641,8 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, | |||
641 | while (len--) { | 641 | while (len--) { |
642 | u32 osd, off; | 642 | u32 osd, off; |
643 | ceph_decode_need(p, end, sizeof(u32)*2, bad); | 643 | ceph_decode_need(p, end, sizeof(u32)*2, bad); |
644 | ceph_decode_32(p, osd); | 644 | osd = ceph_decode_32(p); |
645 | ceph_decode_32(p, off); | 645 | off = ceph_decode_32(p); |
646 | pr_info("osd%d weight 0x%x %s\n", osd, off, | 646 | pr_info("osd%d weight 0x%x %s\n", osd, off, |
647 | off == CEPH_OSD_IN ? "(in)" : | 647 | off == CEPH_OSD_IN ? "(in)" : |
648 | (off == CEPH_OSD_OUT ? "(out)" : "")); | 648 | (off == CEPH_OSD_OUT ? "(out)" : "")); |
@@ -659,8 +659,8 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, | |||
659 | u64 pgid; | 659 | u64 pgid; |
660 | u32 pglen; | 660 | u32 pglen; |
661 | ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad); | 661 | ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad); |
662 | ceph_decode_64(p, pgid); | 662 | pgid = ceph_decode_64(p); |
663 | ceph_decode_32(p, pglen); | 663 | pglen = ceph_decode_32(p); |
664 | 664 | ||
665 | /* remove any? */ | 665 | /* remove any? */ |
666 | while (rbp && rb_entry(rbp, struct ceph_pg_mapping, | 666 | while (rbp && rb_entry(rbp, struct ceph_pg_mapping, |
@@ -683,7 +683,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, | |||
683 | pg->pgid = pgid; | 683 | pg->pgid = pgid; |
684 | pg->len = pglen; | 684 | pg->len = pglen; |
685 | for (j = 0; j < len; j++) | 685 | for (j = 0; j < len; j++) |
686 | ceph_decode_32(p, pg->osds[j]); | 686 | pg->osds[j] = ceph_decode_32(p); |
687 | err = __insert_pg_mapping(pg, &map->pg_temp); | 687 | err = __insert_pg_mapping(pg, &map->pg_temp); |
688 | if (err) | 688 | if (err) |
689 | goto bad; | 689 | goto bad; |