aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph/buffer.c
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2009-12-07 15:17:17 -0500
committerSage Weil <sage@newdream.net>2009-12-07 15:17:17 -0500
commitb6c1d5b81ea0841ae9d3ce2cda319ab986b081cf (patch)
treec7ddbaa1acdaec0704dfb0c1c539ddaf6e8c7506 /fs/ceph/buffer.c
parentdd26d857a7bf1b5b734a23180c19eac3e46db944 (diff)
ceph: simplify ceph_buffer interface
We never allocate the ceph_buffer and buffer separtely, so use a single constructor. Disallow put on NULL buffer; make the caller check. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/buffer.c')
-rw-r--r--fs/ceph/buffer.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/fs/ceph/buffer.c b/fs/ceph/buffer.c
index 847c5da9a0db..2576bd452cb8 100644
--- a/fs/ceph/buffer.c
+++ b/fs/ceph/buffer.c
@@ -2,23 +2,38 @@
2#include "ceph_debug.h" 2#include "ceph_debug.h"
3#include "buffer.h" 3#include "buffer.h"
4 4
5struct ceph_buffer *ceph_buffer_new(gfp_t gfp) 5struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
6{ 6{
7 struct ceph_buffer *b; 7 struct ceph_buffer *b;
8 8
9 b = kmalloc(sizeof(*b), gfp); 9 b = kmalloc(sizeof(*b), gfp);
10 if (!b) 10 if (!b)
11 return NULL; 11 return NULL;
12
13 b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN);
14 if (b->vec.iov_base) {
15 b->is_vmalloc = false;
16 } else {
17 b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
18 if (!b->vec.iov_base) {
19 kfree(b);
20 return NULL;
21 }
22 b->is_vmalloc = true;
23 }
24
12 kref_init(&b->kref); 25 kref_init(&b->kref);
13 b->vec.iov_base = NULL; 26 b->alloc_len = len;
14 b->vec.iov_len = 0; 27 b->vec.iov_len = len;
15 b->alloc_len = 0; 28 dout("buffer_new %p\n", b);
16 return b; 29 return b;
17} 30}
18 31
19void ceph_buffer_release(struct kref *kref) 32void ceph_buffer_release(struct kref *kref)
20{ 33{
21 struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref); 34 struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
35
36 dout("buffer_release %p\n", b);
22 if (b->vec.iov_base) { 37 if (b->vec.iov_base) {
23 if (b->is_vmalloc) 38 if (b->is_vmalloc)
24 vfree(b->vec.iov_base); 39 vfree(b->vec.iov_base);