Skip to content

Commit 5185352

Browse files
committed
libceph: fix msgpool
There were several problems here: 1- we weren't tagging allocations with the pool, so they were never returned to the pool. 2- msgpool_put didn't add back to the mempool, even it were called. 3- msgpool_release didn't clear the pool pointer, so it would have looped had raspberrypi#1 not been broken. These may or may not have been responsible for raspberrypi#1136 or raspberrypi#1381 (BUG due to non-empty mempool on umount). I can't seem to trigger the crash now using the method I was using before. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent d79698d commit 5185352

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

‎net/ceph/msgpool.c‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,37 @@
77

88
#include <linux/ceph/msgpool.h>
99

10-
static void *alloc_fn(gfp_t gfp_mask, void *arg)
10+
static void *msgpool_alloc(gfp_t gfp_mask, void *arg)
1111
{
1212
struct ceph_msgpool *pool = arg;
13-
void *p;
13+
struct ceph_msg *msg;
1414

15-
p = ceph_msg_new(0, pool->front_len, gfp_mask);
16-
if (!p)
17-
pr_err("msgpool %s alloc failed\n", pool->name);
18-
return p;
15+
msg = ceph_msg_new(0, pool->front_len, gfp_mask);
16+
if (!msg) {
17+
dout("msgpool_alloc %s failed\n", pool->name);
18+
} else {
19+
dout("msgpool_alloc %s %p\n", pool->name, msg);
20+
msg->pool = pool;
21+
}
22+
return msg;
1923
}
2024

21-
static void free_fn(void *element, void *arg)
25+
static void msgpool_free(void *element, void *arg)
2226
{
23-
ceph_msg_put(element);
27+
struct ceph_msgpool *pool = arg;
28+
struct ceph_msg *msg = element;
29+
30+
dout("msgpool_release %s %p\n", pool->name, msg);
31+
msg->pool = NULL;
32+
ceph_msg_put(msg);
2433
}
2534

2635
int ceph_msgpool_init(struct ceph_msgpool *pool,
2736
int front_len, int size, bool blocking, const char *name)
2837
{
38+
dout("msgpool %s init\n", name);
2939
pool->front_len = front_len;
30-
pool->pool = mempool_create(size, alloc_fn, free_fn, pool);
40+
pool->pool = mempool_create(size, msgpool_alloc, msgpool_free, pool);
3141
if (!pool->pool)
3242
return -ENOMEM;
3343
pool->name = name;
@@ -36,29 +46,37 @@ int ceph_msgpool_init(struct ceph_msgpool *pool,
3646

3747
void ceph_msgpool_destroy(struct ceph_msgpool *pool)
3848
{
49+
dout("msgpool %s destroy\n", pool->name);
3950
mempool_destroy(pool->pool);
4051
}
4152

4253
struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool,
4354
int front_len)
4455
{
56+
struct ceph_msg *msg;
57+
4558
if (front_len > pool->front_len) {
46-
pr_err("msgpool_get pool %s need front %d, pool size is %d\n",
59+
dout("msgpool_get %s need front %d, pool size is %d\n",
4760
pool->name, front_len, pool->front_len);
4861
WARN_ON(1);
4962

5063
/* try to alloc a fresh message */
5164
return ceph_msg_new(0, front_len, GFP_NOFS);
5265
}
5366

54-
return mempool_alloc(pool->pool, GFP_NOFS);
67+
msg = mempool_alloc(pool->pool, GFP_NOFS);
68+
dout("msgpool_get %s %p\n", pool->name, msg);
69+
return msg;
5570
}
5671

5772
void ceph_msgpool_put(struct ceph_msgpool *pool, struct ceph_msg *msg)
5873
{
74+
dout("msgpool_put %s %p\n", pool->name, msg);
75+
5976
/* reset msg front_len; user may have changed it */
6077
msg->front.iov_len = pool->front_len;
6178
msg->hdr.front_len = cpu_to_le32(pool->front_len);
6279

6380
kref_init(&msg->kref); /* retake single ref */
81+
mempool_free(msg, pool->pool);
6482
}

0 commit comments

Comments
 (0)