]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: do shutdown using finisher so we can do it in the right order 14835/head
authorKefu Chai <kchai@redhat.com>
Thu, 27 Apr 2017 12:37:35 +0000 (20:37 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 27 Apr 2017 14:16:41 +0000 (22:16 +0800)
otherwise we can shutdown a PyModules while it still being init'ed

Fixes: http://tracker.ceph.com/issues/19743
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/Mgr.cc
src/mgr/PyModules.cc

index 6be7216b2e4046fbcbdeaa1e5643537ce28318de..e2466b37f03909e97f0c873d92826e5f51547d5f 100644 (file)
@@ -343,12 +343,13 @@ void Mgr::shutdown()
   // give up the lock for us.
   Mutex::Locker l(lock);
 
-  // First stop the server so that we're not taking any more incoming requests
-  server.shutdown();
-
-  // after the messenger is stopped, signal modules to shutdown via finisher
-  py_modules.shutdown();
-
+  finisher.queue(new FunctionContext([&](int) {
+    // First stop the server so that we're not taking any more incoming
+    // requests
+    server.shutdown();
+    // after the messenger is stopped, signal modules to shutdown via finisher
+    py_modules.shutdown();
+  }));
   // Then stop the finisher to ensure its enqueued contexts aren't going
   // to touch references to the things we're about to tear down
   finisher.wait_for_empty();
index 45078262b65093e79ce55909954b593d721d25c1..420807efb32eb39c91d8fa49b29f3992a8acccc6 100644 (file)
@@ -458,22 +458,15 @@ void PyModules::start()
 void PyModules::shutdown()
 {
   Mutex::Locker locker(lock);
+  assert(global_handle);
 
   // Signal modules to drop out of serve() and/or tear down resources
-  C_SaferCond shutdown_called;
-  C_GatherBuilder gather(g_ceph_context);
   for (auto &i : modules) {
     auto module = i.second.get();
-    auto shutdown_cb = gather.new_sub();
-    finisher.queue(new FunctionContext([module, shutdown_cb](int r){
-      module->shutdown();
-      shutdown_cb->complete(0);
-    }));
-  }
-
-  if (gather.has_subs()) {
-    gather.set_finisher(&shutdown_called);
-    gather.activate();
+    const auto& name = i.first;
+    dout(10) << "waiting for module " << name << " to shutdown" << dendl;
+    module->shutdown();
+    dout(10) << "module " << name << " shutdown" << dendl;
   }
 
   // For modules implementing serve(), finish the threads where we
@@ -485,17 +478,13 @@ void PyModules::shutdown()
   }
   serve_threads.clear();
 
-  // Wait for the module's shutdown() to complete before
-  // we proceed to destroy the module.
-  if (!modules.empty()) {
-    dout(4) << "waiting for module shutdown calls" << dendl;
-    shutdown_called.wait();
-  }
-
   modules.clear();
 
   PyGILState_Ensure();
   Py_Finalize();
+
+  // nobody needs me anymore.
+  global_handle = nullptr;
 }
 
 void PyModules::notify_all(const std::string &notify_type,