Blame view
net/ceph/msgpool.c
1.93 KB
3d14c5d2b
|
1 |
#include <linux/ceph/ceph_debug.h> |
8fc91fd85
|
2 3 4 5 6 |
#include <linux/err.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/vmalloc.h> |
3d14c5d2b
|
7 |
#include <linux/ceph/msgpool.h> |
8fc91fd85
|
8 |
|
5185352c1
|
9 |
static void *msgpool_alloc(gfp_t gfp_mask, void *arg) |
d52f847a8
|
10 11 |
{ struct ceph_msgpool *pool = arg; |
5185352c1
|
12 |
struct ceph_msg *msg; |
8fc91fd85
|
13 |
|
5185352c1
|
14 15 16 17 18 19 20 21 22 23 |
msg = ceph_msg_new(0, pool->front_len, gfp_mask); if (!msg) { dout("msgpool_alloc %s failed ", pool->name); } else { dout("msgpool_alloc %s %p ", pool->name, msg); msg->pool = pool; } return msg; |
d52f847a8
|
24 |
} |
8fc91fd85
|
25 |
|
5185352c1
|
26 |
static void msgpool_free(void *element, void *arg) |
8fc91fd85
|
27 |
{ |
5185352c1
|
28 29 30 31 32 33 34 |
struct ceph_msgpool *pool = arg; struct ceph_msg *msg = element; dout("msgpool_release %s %p ", pool->name, msg); msg->pool = NULL; ceph_msg_put(msg); |
8fc91fd85
|
35 36 37 |
} int ceph_msgpool_init(struct ceph_msgpool *pool, |
4f48280ee
|
38 |
int front_len, int size, bool blocking, const char *name) |
8fc91fd85
|
39 |
{ |
5185352c1
|
40 41 |
dout("msgpool %s init ", name); |
8fc91fd85
|
42 |
pool->front_len = front_len; |
5185352c1
|
43 |
pool->pool = mempool_create(size, msgpool_alloc, msgpool_free, pool); |
d52f847a8
|
44 45 |
if (!pool->pool) return -ENOMEM; |
4f48280ee
|
46 |
pool->name = name; |
d52f847a8
|
47 |
return 0; |
8fc91fd85
|
48 49 50 51 |
} void ceph_msgpool_destroy(struct ceph_msgpool *pool) { |
5185352c1
|
52 53 |
dout("msgpool %s destroy ", pool->name); |
d52f847a8
|
54 |
mempool_destroy(pool->pool); |
8fc91fd85
|
55 |
} |
d52f847a8
|
56 57 |
struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool, int front_len) |
8fc91fd85
|
58 |
{ |
5185352c1
|
59 |
struct ceph_msg *msg; |
d52f847a8
|
60 |
if (front_len > pool->front_len) { |
5185352c1
|
61 62 |
dout("msgpool_get %s need front %d, pool size is %d ", |
4f48280ee
|
63 |
pool->name, front_len, pool->front_len); |
8f3bc053c
|
64 65 66 |
WARN_ON(1); /* try to alloc a fresh message */ |
34d23762d
|
67 |
return ceph_msg_new(0, front_len, GFP_NOFS); |
8f3bc053c
|
68 |
} |
5185352c1
|
69 70 71 72 |
msg = mempool_alloc(pool->pool, GFP_NOFS); dout("msgpool_get %s %p ", pool->name, msg); return msg; |
8fc91fd85
|
73 74 75 76 |
} void ceph_msgpool_put(struct ceph_msgpool *pool, struct ceph_msg *msg) { |
5185352c1
|
77 78 |
dout("msgpool_put %s %p ", pool->name, msg); |
d52f847a8
|
79 80 81 |
/* reset msg front_len; user may have changed it */ msg->front.iov_len = pool->front_len; msg->hdr.front_len = cpu_to_le32(pool->front_len); |
3ca02ef96
|
82 |
|
d52f847a8
|
83 |
kref_init(&msg->kref); /* retake single ref */ |
5185352c1
|
84 |
mempool_free(msg, pool->pool); |
8fc91fd85
|
85 |
} |