Skip to content

Commit

Permalink
ceph: cancel delayed work instead of flushing on mdsc teardown
Browse files Browse the repository at this point in the history
[ Upstream commit b4002173b7989588b6feaefc42edaf011b596782 ]

The first thing metric_delayed_work does is check mdsc->stopping,
and then return immediately if it's set. That's good since we would
have already torn down the metric structures at this point, otherwise,
but there is no locking around mdsc->stopping.

It's possible that the ceph_metric_destroy call could race with the
delayed_work, in which case we could end up with the delayed_work
accessing destroyed percpu variables.

At this point in the mdsc teardown, the "stopping" flag has already been
set, so there's no benefit to flushing the work. Move the work
cancellation in ceph_metric_destroy ahead of the percpu variable
destruction, and eliminate the flush_delayed_work call in
ceph_mdsc_destroy.

Fixes: 18f473b ("ceph: periodically send perf metrics to MDSes")
Signed-off-by: Jeff Layton <[email protected]>
Reviewed-by: Xiubo Li <[email protected]>
Signed-off-by: Ilya Dryomov <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
jtlayton authored and gregkh committed Sep 26, 2021
1 parent 8193ad3 commit e418ce8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion fs/ceph/mds_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4859,7 +4859,6 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)

ceph_metric_destroy(&mdsc->metric);

flush_delayed_work(&mdsc->metric.delayed_work);
fsc->mdsc = NULL;
kfree(mdsc);
dout("mdsc_destroy %p done\n", mdsc);
Expand Down
4 changes: 2 additions & 2 deletions fs/ceph/metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ void ceph_metric_destroy(struct ceph_client_metric *m)
if (!m)
return;

cancel_delayed_work_sync(&m->delayed_work);

percpu_counter_destroy(&m->total_inodes);
percpu_counter_destroy(&m->opened_inodes);
percpu_counter_destroy(&m->i_caps_mis);
percpu_counter_destroy(&m->i_caps_hit);
percpu_counter_destroy(&m->d_lease_mis);
percpu_counter_destroy(&m->d_lease_hit);

cancel_delayed_work_sync(&m->delayed_work);

ceph_put_mds_session(m->session);
}

Expand Down

0 comments on commit e418ce8

Please sign in to comment.