mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-24 04:34:08 +08:00
a421ef3030
Support for GFP_NO{FS,IO} and __GFP_NOFAIL has been implemented by previous patches so we can allow the support for kvmalloc. This will allow some external users to simplify or completely remove their helpers. GFP_NOWAIT semantic hasn't been supported so far but it hasn't been explicitly documented so let's add a note about that. ceph_kvmalloc is the first helper to be dropped and changed to kvmalloc. Link: https://lkml.kernel.org/r/20211122153233.9924-5-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Christoph Hellwig <hch@lst.de> Cc: Dave Chinner <david@fromorbit.com> Cc: Ilya Dryomov <idryomov@gmail.com> Cc: Jeff Layton <jlayton@kernel.org> Cc: Neil Brown <neilb@suse.de> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/ceph/ceph_debug.h>
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ceph/buffer.h>
|
|
#include <linux/ceph/decode.h>
|
|
#include <linux/ceph/libceph.h> /* for kvmalloc */
|
|
|
|
struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
|
|
{
|
|
struct ceph_buffer *b;
|
|
|
|
b = kmalloc(sizeof(*b), gfp);
|
|
if (!b)
|
|
return NULL;
|
|
|
|
b->vec.iov_base = kvmalloc(len, gfp);
|
|
if (!b->vec.iov_base) {
|
|
kfree(b);
|
|
return NULL;
|
|
}
|
|
|
|
kref_init(&b->kref);
|
|
b->alloc_len = len;
|
|
b->vec.iov_len = len;
|
|
dout("buffer_new %p\n", b);
|
|
return b;
|
|
}
|
|
EXPORT_SYMBOL(ceph_buffer_new);
|
|
|
|
void ceph_buffer_release(struct kref *kref)
|
|
{
|
|
struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
|
|
|
|
dout("buffer_release %p\n", b);
|
|
kvfree(b->vec.iov_base);
|
|
kfree(b);
|
|
}
|
|
EXPORT_SYMBOL(ceph_buffer_release);
|
|
|
|
int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end)
|
|
{
|
|
size_t len;
|
|
|
|
ceph_decode_need(p, end, sizeof(u32), bad);
|
|
len = ceph_decode_32(p);
|
|
dout("decode_buffer len %d\n", (int)len);
|
|
ceph_decode_need(p, end, len, bad);
|
|
*b = ceph_buffer_new(len, GFP_NOFS);
|
|
if (!*b)
|
|
return -ENOMEM;
|
|
ceph_decode_copy(p, (*b)->vec.iov_base, len);
|
|
return 0;
|
|
bad:
|
|
return -EINVAL;
|
|
}
|