2 #include "ceph_debug.h"
6 struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
10 b = kmalloc(sizeof(*b), gfp);
14 b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN);
15 if (b->vec.iov_base) {
16 b->is_vmalloc = false;
18 b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
19 if (!b->vec.iov_base) {
29 dout("buffer_new %p\n", b);
33 void ceph_buffer_release(struct kref *kref)
35 struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
37 dout("buffer_release %p\n", b);
38 if (b->vec.iov_base) {
40 vfree(b->vec.iov_base);
42 kfree(b->vec.iov_base);
47 int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp)
49 b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN);
50 if (b->vec.iov_base) {
51 b->is_vmalloc = false;
53 b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
63 int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end)
67 ceph_decode_need(p, end, sizeof(u32), bad);
68 len = ceph_decode_32(p);
69 dout("decode_buffer len %d\n", (int)len);
70 ceph_decode_need(p, end, len, bad);
71 *b = ceph_buffer_new(len, GFP_NOFS);
74 ceph_decode_copy(p, (*b)->vec.iov_base, len);