]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/ceph_context: count crypto/shutdown cycles
authorSage Weil <sage@redhat.com>
Thu, 4 Jan 2018 20:55:30 +0000 (14:55 -0600)
committerSage Weil <sage@redhat.com>
Tue, 6 Mar 2018 20:44:48 +0000 (14:44 -0600)
We need to allow crypto to be set up and torn down before a fork.  Count
the init/shutdown cycles to make that safe.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/ceph_context.cc
src/common/ceph_context.h

index 8d5f770486aeb5fafd44b8c56958ef89dd3c6f4e..582788da4c4e453611747cad2b5450c524c72606 100644 (file)
@@ -531,7 +531,7 @@ CephContext::CephContext(uint32_t module_type_,
     _set_gid(0),
     _set_uid_string(),
     _set_gid_string(),
-    _crypto_inited(false),
+    _crypto_inited(0),
     _service_thread(NULL),
     _log_obs(NULL),
     _admin_socket(NULL),
@@ -657,8 +657,11 @@ CephContext::~CephContext()
   
   delete _crypto_none;
   delete _crypto_aes;
-  if (_crypto_inited)
-    ceph::crypto::shutdown(g_code_env == CODE_ENVIRONMENT_LIBRARY);
+  if (_crypto_inited > 0) {
+    assert(_crypto_inited == 1);  // or else someone explicitly did
+                                 // init but not shutdown
+    shutdown_crypto();
+  }
 }
 
 void CephContext::put() {
@@ -673,9 +676,15 @@ void CephContext::put() {
 
 void CephContext::init_crypto()
 {
-  if (!_crypto_inited) {
+  if (_crypto_inited++ == 0) {
     ceph::crypto::init(this);
-    _crypto_inited = true;
+  }
+}
+
+void CephContext::shutdown_crypto()
+{
+  if (--_crypto_inited == 0) {
+    ceph::crypto::shutdown(g_code_env == CODE_ENVIRONMENT_LIBRARY);
   }
 }
 
index 55c59eca22e0568cfc6ef266cc6d58da6cf23d08..94179c133d1d529c09a7b1a11c4de93c9b35fcf0 100644 (file)
@@ -88,6 +88,9 @@ public:
   /* init ceph::crypto */
   void init_crypto();
 
+  /// shutdown crypto (should match init_crypto calls)
+  void shutdown_crypto();
+
   /* Start the Ceph Context's service thread */
   void start_service_thread();
 
@@ -233,7 +236,7 @@ private:
   std::string _set_uid_string;
   std::string _set_gid_string;
 
-  bool _crypto_inited;
+  int _crypto_inited;
 
   /* libcommon service thread.
    * SIGHUP wakes this thread, which then reopens logfiles */