Skip to content

Commit aca420b

Browse files
committed
libceph: fix leak of osd structs during shutdown
We want to remove all OSDs, not just those on the idle LRU. Signed-off-by: Sage Weil <[email protected]>
1 parent 259a187 commit aca420b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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)