]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/MgrClient: guard send_pgstats() with lock 23791/head
authorKefu Chai <kchai@redhat.com>
Thu, 15 Mar 2018 05:30:34 +0000 (13:30 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 29 Aug 2018 02:35:58 +0000 (10:35 +0800)
ms_handle_reset() races with send_pgstats(), and the latter could
reference a session with a null connection. so we need to guard
send_pgstats() with a lock.

Fixes: http://tracker.ceph.com/issues/23370
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit b17ff3c54b38c37f715a8cd165eba2c6b79f8d70)

src/mgr/MgrClient.cc
src/mgr/MgrClient.h

index c06d94039bf39cf43c327a2aebf4ef4980d9ede2..38f0c313c15db56d2115182c8175cac79ba59e2a 100644 (file)
@@ -216,17 +216,20 @@ bool MgrClient::ms_handle_refused(Connection *con)
   return false;
 }
 
-void MgrClient::send_stats()
+void MgrClient::_send_stats()
 {
-  send_report();
-  send_pgstats();
+  _send_report();
+  _send_pgstats();
   if (stats_period != 0) {
-    report_callback = new FunctionContext([this](int){send_stats();});
-    timer.add_event_after(stats_period, report_callback);
+    report_callback = timer.add_event_after(
+      stats_period,
+      new FunctionContext([this](int) {
+         _send_stats();
+       }));
   }
 }
 
-void MgrClient::send_report()
+void MgrClient::_send_report()
 {
   assert(lock.is_locked_by_me());
   assert(session);
@@ -329,6 +332,12 @@ void MgrClient::send_report()
 }
 
 void MgrClient::send_pgstats()
+{
+  Mutex::Locker l(lock);
+  _send_pgstats();
+}
+
+void MgrClient::_send_pgstats()
 {
   if (pgstats_cb && session) {
     session->con->send_message(pgstats_cb());
@@ -357,7 +366,7 @@ bool MgrClient::handle_mgr_configure(MMgrConfigure *m)
   bool starting = (stats_period == 0) && (m->stats_period != 0);
   stats_period = m->stats_period;
   if (starting) {
-    send_stats();
+    _send_stats();
   }
 
   m->put();
index a3afe701ebe2c25797096515ad7d9e927c6aff1c..ef1dd058b4221808dd189b19fd79842f105318c4 100644 (file)
@@ -121,8 +121,9 @@ public:
   void update_osd_health(std::vector<OSDHealthMetric>&& metrics);
 
 private:
-  void send_stats();
-  void send_report();
+  void _send_stats();
+  void _send_pgstats();
+  void _send_report();
 };
 
 #endif