summaryrefslogtreecommitdiffstats
path: root/fs/ceph/buffer.c
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2009-12-07 12:17:17 -0800
committerSage Weil <sage@newdream.net>2009-12-07 12:17:17 -0800
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 847c5da9a0d..2576bd452cb 100644
--- a/fs/ceph/buffer.c
+++ b/fs/ceph/buffer.c
@@ -2,23 +2,38 @@
#include "ceph_debug.h"
#include "buffer.h"
-struct ceph_buffer *ceph_buffer_new(gfp_t gfp)
+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 = kmalloc(len, gfp | __GFP_NOWARN);
+ if (b->vec.iov_base) {
+ b->is_vmalloc = false;
+ } else {
+ b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
+ if (!b->vec.iov_base) {
+ kfree(b);
+ return NULL;
+ }
+ b->is_vmalloc = true;
+ }
+
kref_init(&b->kref);
- b->vec.iov_base = NULL;
- b->vec.iov_len = 0;
- b->alloc_len = 0;
+ b->alloc_len = len;
+ b->vec.iov_len = len;
+ dout("buffer_new %p\n", b);
return b;
}
void ceph_buffer_release(struct kref *kref)
{
struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
+
+ dout("buffer_release %p\n", b);
if (b->vec.iov_base) {
if (b->is_vmalloc)
vfree(b->vec.iov_base);