@@ -104,8 +104,11 @@ static inline bool ceph_has_room(void **p, void *end, size_t n)
* beyond the "end" pointer provided (-ERANGE)
* - memory could not be allocated for the result (-ENOMEM)
*/
-static inline char *ceph_extract_encoded_string(void **p, void *end,
- size_t *lenp, gfp_t gfp)
+typedef void * (mem_alloc_t)(size_t size, gfp_t flags);
+extern void *ceph_kvmalloc(size_t size, gfp_t flags);
+static inline char *extract_encoded_string(void **p, void *end,
+ mem_alloc_t alloc_fn,
+ size_t *lenp, gfp_t gfp)
{
u32 len;
void *sp = *p;
@@ -115,7 +118,7 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
if (!ceph_has_room(&sp, end, len))
goto bad;
- buf = kmalloc(len + 1, gfp);
+ buf = alloc_fn(len + 1, gfp);
if (!buf)
return ERR_PTR(-ENOMEM);
@@ -133,6 +136,18 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
return ERR_PTR(-ERANGE);
}
+static inline char *ceph_extract_encoded_string(void **p, void *end,
+ size_t *lenp, gfp_t gfp)
+{
+ return extract_encoded_string(p, end, kmalloc, lenp, gfp);
+}
+
+static inline char *ceph_extract_encoded_string_kvmalloc(void **p, void *end,
+ size_t *lenp, gfp_t gfp)
+{
+ return extract_encoded_string(p, end, ceph_kvmalloc, lenp, gfp);
+}
+
/*
* skip helpers
*/
When we are going to extract the encoded string, there would be a large string encoded. Especially in the journaling case, if we use the default journal object size, 16M, there could be a 16M string encoded in this object. Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn> --- include/linux/ceph/decode.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)