mirror of
https://github.com/torvalds/linux.git
synced 2024-11-02 10:11:36 +00:00
libceph: ceph_decode_skip_* helpers
Some of these won't be as efficient as they could be (e.g. ceph_decode_skip_set(... 32 ...) could advance by len * sizeof(u32) once instead of advancing by sizeof(u32) len times), but that's fine and not worth a bunch of extra macro code. Replace skip_name_map() with ceph_decode_skip_map as an example. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
parent
ab75144be0
commit
278b1d709c
@ -132,6 +132,66 @@ bad:
|
|||||||
return ERR_PTR(-ERANGE);
|
return ERR_PTR(-ERANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* skip helpers
|
||||||
|
*/
|
||||||
|
#define ceph_decode_skip_n(p, end, n, bad) \
|
||||||
|
do { \
|
||||||
|
ceph_decode_need(p, end, n, bad); \
|
||||||
|
*p += n; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_64(p, end, bad) \
|
||||||
|
ceph_decode_skip_n(p, end, sizeof(u64), bad)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_32(p, end, bad) \
|
||||||
|
ceph_decode_skip_n(p, end, sizeof(u32), bad)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_16(p, end, bad) \
|
||||||
|
ceph_decode_skip_n(p, end, sizeof(u16), bad)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_8(p, end, bad) \
|
||||||
|
ceph_decode_skip_n(p, end, sizeof(u8), bad)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_string(p, end, bad) \
|
||||||
|
do { \
|
||||||
|
u32 len; \
|
||||||
|
\
|
||||||
|
ceph_decode_32_safe(p, end, len, bad); \
|
||||||
|
ceph_decode_skip_n(p, end, len, bad); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_set(p, end, type, bad) \
|
||||||
|
do { \
|
||||||
|
u32 len; \
|
||||||
|
\
|
||||||
|
ceph_decode_32_safe(p, end, len, bad); \
|
||||||
|
while (len--) \
|
||||||
|
ceph_decode_skip_##type(p, end, bad); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_map(p, end, ktype, vtype, bad) \
|
||||||
|
do { \
|
||||||
|
u32 len; \
|
||||||
|
\
|
||||||
|
ceph_decode_32_safe(p, end, len, bad); \
|
||||||
|
while (len--) { \
|
||||||
|
ceph_decode_skip_##ktype(p, end, bad); \
|
||||||
|
ceph_decode_skip_##vtype(p, end, bad); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ceph_decode_skip_map_of_map(p, end, ktype1, ktype2, vtype2, bad) \
|
||||||
|
do { \
|
||||||
|
u32 len; \
|
||||||
|
\
|
||||||
|
ceph_decode_32_safe(p, end, len, bad); \
|
||||||
|
while (len--) { \
|
||||||
|
ceph_decode_skip_##ktype1(p, end, bad); \
|
||||||
|
ceph_decode_skip_map(p, end, ktype2, vtype2, bad); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* struct ceph_timespec <-> struct timespec
|
* struct ceph_timespec <-> struct timespec
|
||||||
*/
|
*/
|
||||||
|
@ -138,21 +138,6 @@ bad:
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int skip_name_map(void **p, void *end)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
ceph_decode_32_safe(p, end, len ,bad);
|
|
||||||
while (len--) {
|
|
||||||
int strlen;
|
|
||||||
*p += sizeof(u32);
|
|
||||||
ceph_decode_32_safe(p, end, strlen, bad);
|
|
||||||
*p += strlen;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
bad:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void crush_finalize(struct crush_map *c)
|
static void crush_finalize(struct crush_map *c)
|
||||||
{
|
{
|
||||||
__s32 b;
|
__s32 b;
|
||||||
@ -187,7 +172,6 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
|
|||||||
void **p = &pbyval;
|
void **p = &pbyval;
|
||||||
void *start = pbyval;
|
void *start = pbyval;
|
||||||
u32 magic;
|
u32 magic;
|
||||||
u32 num_name_maps;
|
|
||||||
|
|
||||||
dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p));
|
dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p));
|
||||||
|
|
||||||
@ -353,12 +337,9 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignore trailing name maps. */
|
ceph_decode_skip_map(p, end, 32, string, bad); /* type_map */
|
||||||
for (num_name_maps = 0; num_name_maps < 3; num_name_maps++) {
|
ceph_decode_skip_map(p, end, 32, string, bad); /* name_map */
|
||||||
err = skip_name_map(p, end);
|
ceph_decode_skip_map(p, end, 32, string, bad); /* rule_name_map */
|
||||||
if (err < 0)
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* tunables */
|
/* tunables */
|
||||||
ceph_decode_need(p, end, 3*sizeof(u32), done);
|
ceph_decode_need(p, end, 3*sizeof(u32), done);
|
||||||
|
Loading…
Reference in New Issue
Block a user