changeset 21437:624e8530581c

11004 Several door servers don't properly handle exiting threads 11198 Allow adjustment of max_threads for idmapd Reviewed by: Gordon Ross <gordon.ross@nexenta.com> Reviewed by: Evan Layton <evan.layton@nexenta.com> Approved by: Garrett D'Amore <garrett@damore.org>
author Matt Barden <matt.barden@nexenta.com>
date Wed, 05 Dec 2018 16:59:06 -0500
parents ecacac58c70f
children 90c979f55037
files usr/src/cmd/idmap/idmapd/idmap.xml usr/src/cmd/idmap/idmapd/idmap_config.c usr/src/cmd/idmap/idmapd/idmap_config.h usr/src/cmd/idmap/idmapd/idmapd.c usr/src/cmd/idmap/idmapd/init.c usr/src/cmd/ldapcachemgr/cachemgr.c usr/src/cmd/nscd/nscd_frontend.c
diffstat 7 files changed, 58 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/idmap/idmapd/idmap.xml	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/idmap/idmapd/idmap.xml	Wed Dec 05 16:59:06 2018 -0500
@@ -2,7 +2,7 @@
 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
 <!--
  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.
 
  CDDL HEADER START
 
@@ -41,12 +41,12 @@
 	<single_instance />
 
 	<dependency
-		name='rpcbind' 
-		grouping='require_all' 
-		restart_on='restart' 
-		type='service'> 
-		<service_fmri value='svc:/network/rpc/bind' /> 
-	</dependency> 
+		name='rpcbind'
+		grouping='require_all'
+		restart_on='restart'
+		type='service'>
+		<service_fmri value='svc:/network/rpc/bind' />
+	</dependency>
 
 	<dependency name='filesystem-minimal'
 		grouping='require_all'
@@ -94,6 +94,10 @@
 			type='count'
 			value='0' />
 		<propval
+			name='max_threads'
+			type='count'
+			value='40' />
+		<propval
 			name='value_authorization'
 			type='astring'
 			value='solaris.smf.value.idmap' />
--- a/usr/src/cmd/idmap/idmapd/idmap_config.c	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/idmap/idmapd/idmap_config.c	Wed Dec 05 16:59:06 2018 -0500
@@ -20,7 +20,7 @@
  */
 /*
  * 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.
  */
 
 
@@ -45,6 +45,7 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <note.h>
+#include <limits.h>
 #include "idmapd.h"
 #include "addisc.h"
 
@@ -77,6 +78,11 @@
  */
 #define	MIN_REDISCOVERY_INTERVAL	60
 
+/*
+ * Max number of concurrent door calls
+ */
+#define	MAX_THREADS_DEFAULT	40
+
 enum event_type {
 	EVENT_NOTHING,	/* Woke up for no good reason */
 	EVENT_TIMEOUT,	/* Timeout expired */
@@ -1601,6 +1607,15 @@
 	if (rc != 0)
 		(*errors)++;
 
+	rc = get_val_int(handles, "max_threads",
+	    &pgcfg->max_threads, SCF_TYPE_COUNT);
+	if (rc != 0)
+		(*errors)++;
+	if (pgcfg->max_threads == 0)
+		pgcfg->max_threads = MAX_THREADS_DEFAULT;
+	if (pgcfg->max_threads > UINT_MAX)
+		pgcfg->max_threads = UINT_MAX;
+
 	rc = get_val_int(handles, "id_cache_timeout",
 	    &pgcfg->id_cache_timeout, SCF_TYPE_COUNT);
 	if (rc != 0)
@@ -2198,6 +2213,9 @@
 	changed += update_uint64(&live_pgcfg->list_size_limit,
 	    &new_pgcfg.list_size_limit, "list_size_limit");
 
+	changed += update_uint64(&live_pgcfg->max_threads,
+	    &new_pgcfg.max_threads, "max_threads");
+
 	changed += update_uint64(&live_pgcfg->id_cache_timeout,
 	    &new_pgcfg.id_cache_timeout, "id_cache_timeout");
 
--- a/usr/src/cmd/idmap/idmapd/idmap_config.h	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/idmap/idmapd/idmap_config.h	Wed Dec 05 16:59:06 2018 -0500
@@ -20,7 +20,7 @@
  */
 /*
  * 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.
  */
 
 #ifndef _IDMAP_CONFIG_H
@@ -75,6 +75,7 @@
 
 typedef struct idmap_pg_config {
 	uint64_t	list_size_limit;
+	uint64_t	max_threads;
 	uint64_t	id_cache_timeout;
 	uint64_t	name_cache_timeout;
 	uint64_t	rediscovery_interval;
@@ -125,7 +126,7 @@
 } idmap_cfg_t;
 
 
-extern void 		idmap_cfg_unload(idmap_pg_config_t *);
+extern void		idmap_cfg_unload(idmap_pg_config_t *);
 extern int		idmap_cfg_load(idmap_cfg_t *, int);
 extern idmap_cfg_t	*idmap_cfg_init(void);
 extern int		idmap_cfg_fini(idmap_cfg_t *);
--- a/usr/src/cmd/idmap/idmapd/idmapd.c	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/idmap/idmapd/idmapd.c	Wed Dec 05 16:59:06 2018 -0500
@@ -20,7 +20,7 @@
  */
 /*
  * 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.
  */
 
 
@@ -84,13 +84,14 @@
  * 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
@@ -136,6 +137,8 @@
 {
 	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",
@@ -379,6 +382,13 @@
 		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) {
@@ -521,7 +531,8 @@
 
 /* printflike */
 void
-idmapdlog(int pri, const char *format, ...) {
+idmapdlog(int pri, const char *format, ...)
+{
 	static time_t prev_ts;
 	va_list args;
 	char cbuf[CBUFSIZ];
--- a/usr/src/cmd/idmap/idmapd/init.c	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/idmap/idmapd/init.c	Wed Dec 05 16:59:06 2018 -0500
@@ -20,7 +20,7 @@
  */
 /*
  * 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.
  */
 
 /*
@@ -357,6 +357,7 @@
 	pgcfg = &_idmapdstate.cfg->pgcfg;
 
 	idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit);
+	idmapdlog(LOG_DEBUG, "max_threads=%llu", pgcfg->max_threads);
 	idmapdlog(LOG_DEBUG, "default_domain=%s",
 	    CHECK_NULL(pgcfg->default_domain));
 	idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name));
--- a/usr/src/cmd/ldapcachemgr/cachemgr.c	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/ldapcachemgr/cachemgr.c	Wed Dec 05 16:59:06 2018 -0500
@@ -21,6 +21,7 @@
 /*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2019 Nexenta Systems, Inc.
  */
 
 /*
@@ -225,13 +226,13 @@
 static void *
 server_tsd_bind(void *arg)
 {
-	static void	*value = 0;
+	static void *value = "NON-NULL TSD";
 
 	/*
 	 * disable cancellation to prevent hangs when server
 	 * threads disappear
 	 */
-
+	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
 	(void) thr_setspecific(server_key, value);
 	(void) door_return(NULL, 0, NULL, 0);
 
@@ -268,6 +269,7 @@
 	(void) mutex_lock(&create_lock);
 	num_servers--;
 	(void) mutex_unlock(&create_lock);
+	(void) thr_setspecific(server_key, NULL);
 }
 
 static void		client_killserver();
@@ -1198,7 +1200,7 @@
 static void
 detachfromtty(char *pgm)
 {
-	int 	status;
+	int	status;
 	pid_t	pid, wret;
 
 	(void) close(0);
--- a/usr/src/cmd/nscd/nscd_frontend.c	Tue Oct 30 17:39:32 2018 +0300
+++ b/usr/src/cmd/nscd/nscd_frontend.c	Wed Dec 05 16:59:06 2018 -0500
@@ -23,6 +23,7 @@
  * Use is subject to license terms.
  * Copyright 2012 Milan Jurik. All rights reserved.
  * Copyright 2018 Joyent, Inc.
+ * Copyright 2019 Nexenta Systems, Inc.
  */
 
 #include <stdlib.h>
@@ -88,7 +89,7 @@
 static void *
 server_tsd_bind(void *arg)
 {
-	static void *value = 0;
+	static void *value = "NON-NULL TSD";
 
 	(void) thr_setname(thr_self(), "server_tsd_bind");
 
@@ -129,6 +130,7 @@
 	(void) mutex_lock(&create_lock);
 	num_servers--;
 	(void) mutex_unlock(&create_lock);
+	(void) thr_setspecific(server_key, NULL);
 }
 
 /*