Print this page
NEX-19665 Several door servers don't properly handle exiting threads
Review by: Gordon Ross <gordon.ross@nexenta.com>
Review by: Evan Layton <evan.layton@nexenta.com>
NEX-2225 Unable to join NexentaStor to 2008 AD
NEX-1638 Updated DC Locator
 Includes work by: matt.barden@nexenta.com, kevin.crowe@nexenta.com

@@ -18,11 +18,11 @@
  *
  * CDDL HEADER END
  */
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  */
 
 
 /*
  * main() of idmapd(1M)

@@ -82,17 +82,18 @@
 
 /*
  * Server door thread start routine.
  *
  * Set a TSD value to the door thread. This enables the destructor to
- * be called when this thread exits.
+ * be called when this thread exits. Note that we need a non-NULL
+ * value for this or the TSD destructor is not called.
  */
 /*ARGSUSED*/
 static void *
 idmapd_door_thread_start(void *arg)
 {
-        static void *value = 0;
+        static void *value = "NON-NULL TSD";
 
         /*
          * Disable cancellation to avoid memory leaks from not running
          * the thread cleanup code.
          */

@@ -134,10 +135,12 @@
 static void
 idmapd_door_thread_cleanup(void *arg)
 {
         int num;
 
+        /* set TSD to NULL so we don't loop infinitely */
+        (void) pthread_setspecific(create_threads_key, NULL);
         num = atomic_dec_32_nv(&num_threads);
         idmapdlog(LOG_DEBUG,
             "exiting thread ID %d - %d threads currently active",
             pthread_self(), num);
 }

@@ -377,10 +380,17 @@
         if ((error = init_mapping_system()) < 0) {
                 idmapdlog(LOG_ERR, "unable to initialize mapping system");
                 exit(error < -2 ? SMF_EXIT_ERR_CONFIG : 1);
         }
 
+        /*
+         * This means max_threads can't be updated without restarting idmap.
+         */
+        RDLOCK_CONFIG();
+        max_threads = _idmapdstate.cfg->pgcfg.max_threads;
+        UNLOCK_CONFIG();
+
         (void) door_server_create(idmapd_door_thread_create);
         if ((error = pthread_key_create(&create_threads_key,
             idmapd_door_thread_cleanup)) != 0) {
                 idmapdlog(LOG_ERR, "unable to create threads key (%s)",
                     strerror(error));