Skip to content

Commit 0d20fbb

Browse files
committed
Merge branch 'for-linus' of git://ceph.newdream.net/git/ceph-client
* 'for-linus' of git://ceph.newdream.net/git/ceph-client: libceph: fix leak of osd structs during shutdown ceph: fix memory leak ceph: fix encoding of ino only (not relative) paths libceph: fix msgpool
2 parents 0ec26fd + aca420b commit 0d20fbb

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

fs/ceph/mds_client.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ static int set_request_path_attr(struct inode *rinode, struct dentry *rdentry,
15951595
r = build_dentry_path(rdentry, ppath, pathlen, ino, freepath);
15961596
dout(" dentry %p %llx/%.*s\n", rdentry, *ino, *pathlen,
15971597
*ppath);
1598-
} else if (rpath) {
1598+
} else if (rpath || rino) {
15991599
*ino = rino;
16001600
*ppath = rpath;
16011601
*pathlen = strlen(rpath);

fs/ceph/super.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ static struct dentry *ceph_mount(struct file_system_type *fs_type,
813813
fsc = create_fs_client(fsopt, opt);
814814
if (IS_ERR(fsc)) {
815815
res = ERR_CAST(fsc);
816-
kfree(fsopt);
817-
kfree(opt);
816+
destroy_mount_options(fsopt);
817+
ceph_destroy_options(opt);
818818
goto out_final;
819819
}
820820

net/ceph/msgpool.c

+29-11
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
}

net/ceph/osd_client.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,18 @@ static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
685685
put_osd(osd);
686686
}
687687

688+
static void remove_all_osds(struct ceph_osd_client *osdc)
689+
{
690+
dout("__remove_old_osds %p\n", osdc);
691+
mutex_lock(&osdc->request_mutex);
692+
while (!RB_EMPTY_ROOT(&osdc->osds)) {
693+
struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
694+
struct ceph_osd, o_node);
695+
__remove_osd(osdc, osd);
696+
}
697+
mutex_unlock(&osdc->request_mutex);
698+
}
699+
688700
static void __move_osd_to_lru(struct ceph_osd_client *osdc,
689701
struct ceph_osd *osd)
690702
{
@@ -701,14 +713,14 @@ static void __remove_osd_from_lru(struct ceph_osd *osd)
701713
list_del_init(&osd->o_osd_lru);
702714
}
703715

704-
static void remove_old_osds(struct ceph_osd_client *osdc, int remove_all)
716+
static void remove_old_osds(struct ceph_osd_client *osdc)
705717
{
706718
struct ceph_osd *osd, *nosd;
707719

708720
dout("__remove_old_osds %p\n", osdc);
709721
mutex_lock(&osdc->request_mutex);
710722
list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
711-
if (!remove_all && time_before(jiffies, osd->lru_ttl))
723+
if (time_before(jiffies, osd->lru_ttl))
712724
break;
713725
__remove_osd(osdc, osd);
714726
}
@@ -751,6 +763,7 @@ static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
751763
struct rb_node *parent = NULL;
752764
struct ceph_osd *osd = NULL;
753765

766+
dout("__insert_osd %p osd%d\n", new, new->o_osd);
754767
while (*p) {
755768
parent = *p;
756769
osd = rb_entry(parent, struct ceph_osd, o_node);
@@ -1144,7 +1157,7 @@ static void handle_osds_timeout(struct work_struct *work)
11441157

11451158
dout("osds timeout\n");
11461159
down_read(&osdc->map_sem);
1147-
remove_old_osds(osdc, 0);
1160+
remove_old_osds(osdc);
11481161
up_read(&osdc->map_sem);
11491162

11501163
schedule_delayed_work(&osdc->osds_timeout_work,
@@ -1862,8 +1875,7 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
18621875
ceph_osdmap_destroy(osdc->osdmap);
18631876
osdc->osdmap = NULL;
18641877
}
1865-
remove_old_osds(osdc, 1);
1866-
WARN_ON(!RB_EMPTY_ROOT(&osdc->osds));
1878+
remove_all_osds(osdc);
18671879
mempool_destroy(osdc->req_mempool);
18681880
ceph_msgpool_destroy(&osdc->msgpool_op);
18691881
ceph_msgpool_destroy(&osdc->msgpool_op_reply);

0 commit comments

Comments
 (0)