ceph: cancel delayed work instead of flushing on mdsc teardown
authorJeff Layton <jlayton@kernel.org>
Tue, 27 Jul 2021 19:47:12 +0000 (15:47 -0400)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 2 Sep 2021 20:49:17 +0000 (22:49 +0200)
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: 18f473b384a6 ("ceph: periodically send perf metrics to MDSes")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/mds_client.c
fs/ceph/metric.c

index d98a3eda0d4c4917fdb74d4e9c568873d26ae197..85934091e0242fc4d5fd8e6d26093515d310f035 100644 (file)
@@ -4954,7 +4954,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);
index 5ac151eb0d498d0d612cfb3a860890de4f19f59f..04d5df29bbbfb30bbfe06253e3438df1dd0b10eb 100644 (file)
@@ -302,6 +302,8 @@ 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);
@@ -309,8 +311,6 @@ void ceph_metric_destroy(struct ceph_client_metric *m)
        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);
 }