Root/
1 | |
2 | #include "ceph_debug.h" |
3 | |
4 | #include <linux/slab.h> |
5 | |
6 | #include "buffer.h" |
7 | #include "decode.h" |
8 | |
9 | struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp) |
10 | { |
11 | struct ceph_buffer *b; |
12 | |
13 | b = kmalloc(sizeof(*b), gfp); |
14 | if (!b) |
15 | return NULL; |
16 | |
17 | b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN); |
18 | if (b->vec.iov_base) { |
19 | b->is_vmalloc = false; |
20 | } else { |
21 | b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL); |
22 | if (!b->vec.iov_base) { |
23 | kfree(b); |
24 | return NULL; |
25 | } |
26 | b->is_vmalloc = true; |
27 | } |
28 | |
29 | kref_init(&b->kref); |
30 | b->alloc_len = len; |
31 | b->vec.iov_len = len; |
32 | dout("buffer_new %p\n", b); |
33 | return b; |
34 | } |
35 | |
36 | void ceph_buffer_release(struct kref *kref) |
37 | { |
38 | struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref); |
39 | |
40 | dout("buffer_release %p\n", b); |
41 | if (b->vec.iov_base) { |
42 | if (b->is_vmalloc) |
43 | vfree(b->vec.iov_base); |
44 | else |
45 | kfree(b->vec.iov_base); |
46 | } |
47 | kfree(b); |
48 | } |
49 | |
50 | int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp) |
51 | { |
52 | b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN); |
53 | if (b->vec.iov_base) { |
54 | b->is_vmalloc = false; |
55 | } else { |
56 | b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL); |
57 | b->is_vmalloc = true; |
58 | } |
59 | if (!b->vec.iov_base) |
60 | return -ENOMEM; |
61 | b->alloc_len = len; |
62 | b->vec.iov_len = len; |
63 | return 0; |
64 | } |
65 | |
66 | int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end) |
67 | { |
68 | size_t len; |
69 | |
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); |
75 | if (!*b) |
76 | return -ENOMEM; |
77 | ceph_decode_copy(p, (*b)->vec.iov_base, len); |
78 | return 0; |
79 | bad: |
80 | return -EINVAL; |
81 | } |
82 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9