2 #include "ceph_debug.h"
4 #include <linux/slab.h>
9 struct ceph_buffer
*ceph_buffer_new(size_t len
, gfp_t gfp
)
11 struct ceph_buffer
*b
;
13 b
= kmalloc(sizeof(*b
), gfp
);
17 b
->vec
.iov_base
= kmalloc(len
, gfp
| __GFP_NOWARN
);
18 if (b
->vec
.iov_base
) {
19 b
->is_vmalloc
= false;
21 b
->vec
.iov_base
= __vmalloc(len
, gfp
, PAGE_KERNEL
);
22 if (!b
->vec
.iov_base
) {
32 dout("buffer_new %p\n", b
);
36 void ceph_buffer_release(struct kref
*kref
)
38 struct ceph_buffer
*b
= container_of(kref
, struct ceph_buffer
, kref
);
40 dout("buffer_release %p\n", b
);
41 if (b
->vec
.iov_base
) {
43 vfree(b
->vec
.iov_base
);
45 kfree(b
->vec
.iov_base
);
50 int ceph_buffer_alloc(struct ceph_buffer
*b
, int len
, gfp_t gfp
)
52 b
->vec
.iov_base
= kmalloc(len
, gfp
| __GFP_NOWARN
);
53 if (b
->vec
.iov_base
) {
54 b
->is_vmalloc
= false;
56 b
->vec
.iov_base
= __vmalloc(len
, gfp
, PAGE_KERNEL
);
66 int ceph_decode_buffer(struct ceph_buffer
**b
, void **p
, void *end
)
70 ceph_decode_need(p
, end
, sizeof(u32
), bad
);
71 len
= ceph_decode_32(p
);
72 dout("decode_buffer len %d\n", (int)len
);
73 ceph_decode_need(p
, end
, len
, bad
);
74 *b
= ceph_buffer_new(len
, GFP_NOFS
);
77 ceph_decode_copy(p
, (*b
)->vec
.iov_base
, len
);