Ian Kent 310093
autofs-5.0.3 - mount thread create condition handling fix
Ian Kent 310093
Ian Kent 310093
From: Ian Kent <raven@themaw.net>
Ian Kent 310093
Ian Kent 310093
Make the mount thread creation condition mutex specific to the
Ian Kent 310093
thread being created.
Ian Kent 310093
---
Ian Kent 310093
Ian Kent 310093
 CHANGELOG         |    1 +
Ian Kent 310093
 daemon/direct.c   |   31 +++++++++++++++++++++++--------
Ian Kent 310093
 daemon/indirect.c |   31 +++++++++++++++++++++++--------
Ian Kent 310093
 3 files changed, 47 insertions(+), 16 deletions(-)
Ian Kent 310093
Ian Kent 310093
Ian Kent 310093
diff --git a/CHANGELOG b/CHANGELOG
Ian Kent 310093
index 995daea..f7aa839 100644
Ian Kent 310093
--- a/CHANGELOG
Ian Kent 310093
+++ b/CHANGELOG
Ian Kent 310093
@@ -18,6 +18,7 @@
Ian Kent 310093
 - update nsswitch parser to ignore nsswitch sources that aren't supported.
Ian Kent 310093
 - check for map key in (possible) alternate map sources when doing lookup.
Ian Kent 310093
 - eliminate redundant DNS name lookups.
Ian Kent 310093
+- additional fix incorrect pthreads condition handling for mount requests.
Ian Kent 310093
  
Ian Kent 310093
 14/01/2008 autofs-5.0.3
Ian Kent 310093
 -----------------------
Ian Kent 310093
diff --git a/daemon/direct.c b/daemon/direct.c
Ian Kent 310093
index 86c817c..768fbf9 100644
Ian Kent 310093
--- a/daemon/direct.c
Ian Kent 310093
+++ b/daemon/direct.c
Ian Kent 310093
@@ -50,7 +50,6 @@ pthread_key_t key_mnt_direct_params;
Ian Kent 310093
 pthread_key_t key_mnt_offset_params;
Ian Kent 310093
 pthread_once_t key_mnt_params_once = PTHREAD_ONCE_INIT;
Ian Kent 310093
 
Ian Kent 310093
-static pthread_mutex_t ma_mutex = PTHREAD_MUTEX_INITIALIZER;
Ian Kent 310093
 static pthread_mutex_t ea_mutex = PTHREAD_MUTEX_INITIALIZER;
Ian Kent 310093
 
Ian Kent 310093
 static void key_mnt_params_destroy(void *arg)
Ian Kent 310093
@@ -1218,9 +1217,18 @@ static void mount_send_fail(void *arg)
Ian Kent 310093
 	close(mt->ioctlfd);
Ian Kent 310093
 }
Ian Kent 310093
 
Ian Kent 310093
+static void pending_mutex_destroy(void *arg)
Ian Kent 310093
+{
Ian Kent 310093
+	struct pending_args *mt = (struct pending_args *) arg;
Ian Kent 310093
+	int status = pthread_mutex_destroy(&mt->mutex);
Ian Kent 310093
+	if (status)
Ian Kent 310093
+		fatal(status);
Ian Kent 310093
+}
Ian Kent 310093
+
Ian Kent 310093
 static void mount_mutex_unlock(void *arg)
Ian Kent 310093
 {
Ian Kent 310093
-	int status = pthread_mutex_unlock(&ma_mutex);
Ian Kent 310093
+	struct pending_args *mt = (struct pending_args *) arg;
Ian Kent 310093
+	int status = pthread_mutex_unlock(&mt->mutex);
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 }
Ian Kent 310093
@@ -1243,7 +1251,7 @@ static void *do_mount_direct(void *arg)
Ian Kent 310093
 
Ian Kent 310093
 	args = (struct pending_args *) arg;
Ian Kent 310093
 
Ian Kent 310093
-	status = pthread_mutex_lock(&ma_mutex);
Ian Kent 310093
+	status = pthread_mutex_lock(&args->mutex);
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
@@ -1256,7 +1264,7 @@ static void *do_mount_direct(void *arg)
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
-	mount_mutex_unlock(NULL);
Ian Kent 310093
+	mount_mutex_unlock(args);
Ian Kent 310093
 
Ian Kent 310093
 	pthread_cleanup_push(mount_send_fail, &mt;;
Ian Kent 310093
 
Ian Kent 310093
@@ -1533,7 +1541,11 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
-	status = pthread_mutex_lock(&ma_mutex);
Ian Kent 310093
+	status = pthread_mutex_init(&mt->mutex, NULL);
Ian Kent 310093
+	if (status)
Ian Kent 310093
+		fatal(status);
Ian Kent 310093
+
Ian Kent 310093
+	status = pthread_mutex_lock(&mt->mutex);
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
@@ -1553,8 +1565,9 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 310093
 		send_fail(ap->logopt, ioctlfd, pkt->wait_queue_token);
Ian Kent 310093
 		close(ioctlfd);
Ian Kent 310093
 		cache_unlock(mc);
Ian Kent 310093
-		mount_mutex_unlock(NULL);
Ian Kent 310093
+		mount_mutex_unlock(mt);
Ian Kent 310093
 		pending_cond_destroy(mt);
Ian Kent 310093
+		pending_mutex_destroy(mt);
Ian Kent 310093
 		free_pending_args(mt);
Ian Kent 310093
 		pthread_setcancelstate(state, NULL);
Ian Kent 310093
 		return 1;
Ian Kent 310093
@@ -1562,13 +1575,14 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 310093
 
Ian Kent 310093
 	cache_unlock(mc);
Ian Kent 310093
 	pthread_cleanup_push(free_pending_args, mt);
Ian Kent 310093
+	pthread_cleanup_push(pending_mutex_destroy, mt);
Ian Kent 310093
 	pthread_cleanup_push(pending_cond_destroy, mt);
Ian Kent 310093
-	pthread_cleanup_push(mount_mutex_unlock, NULL);
Ian Kent 310093
+	pthread_cleanup_push(mount_mutex_unlock, mt);
Ian Kent 310093
 	pthread_setcancelstate(state, NULL);
Ian Kent 310093
 
Ian Kent 310093
 	mt->signaled = 0;
Ian Kent 310093
 	while (!mt->signaled) {
Ian Kent 310093
-		status = pthread_cond_wait(&mt->cond, &ma_mutex);
Ian Kent 310093
+		status = pthread_cond_wait(&mt->cond, &mt->mutex);
Ian Kent 310093
 		if (status)
Ian Kent 310093
 			fatal(status);
Ian Kent 310093
 	}
Ian Kent 310093
@@ -1576,6 +1590,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 310093
 	pthread_cleanup_pop(1);
Ian Kent 310093
 	pthread_cleanup_pop(1);
Ian Kent 310093
 	pthread_cleanup_pop(1);
Ian Kent 310093
+	pthread_cleanup_pop(1);
Ian Kent 310093
 
Ian Kent 310093
 	return 0;
Ian Kent 310093
 }
Ian Kent 310093
diff --git a/daemon/indirect.c b/daemon/indirect.c
Ian Kent 310093
index 11865b3..9f22ec9 100644
Ian Kent 310093
--- a/daemon/indirect.c
Ian Kent 310093
+++ b/daemon/indirect.c
Ian Kent 310093
@@ -40,7 +40,6 @@
Ian Kent 310093
 
Ian Kent 310093
 extern pthread_attr_t thread_attr;
Ian Kent 310093
 
Ian Kent 310093
-static pthread_mutex_t ma_mutex = PTHREAD_MUTEX_INITIALIZER;
Ian Kent 310093
 static pthread_mutex_t ea_mutex = PTHREAD_MUTEX_INITIALIZER;
Ian Kent 310093
 
Ian Kent 310093
 static int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
Ian Kent 310093
@@ -651,9 +650,18 @@ static void mount_send_fail(void *arg)
Ian Kent 310093
 	send_fail(mt->ap->logopt, mt->ap->ioctlfd, mt->wait_queue_token);
Ian Kent 310093
 }
Ian Kent 310093
 
Ian Kent 310093
+static void pending_mutex_destroy(void *arg)
Ian Kent 310093
+{
Ian Kent 310093
+	struct pending_args *mt = (struct pending_args *) arg;
Ian Kent 310093
+	int status = pthread_mutex_destroy(&mt->mutex);
Ian Kent 310093
+	if (status)
Ian Kent 310093
+		fatal(status);
Ian Kent 310093
+}
Ian Kent 310093
+
Ian Kent 310093
 static void mount_mutex_unlock(void *arg)
Ian Kent 310093
 {
Ian Kent 310093
-	int status = pthread_mutex_unlock(&ma_mutex);
Ian Kent 310093
+	struct pending_args *mt = (struct pending_args *) arg;
Ian Kent 310093
+	int status = pthread_mutex_unlock(&mt->mutex);
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 }
Ian Kent 310093
@@ -676,7 +684,7 @@ static void *do_mount_indirect(void *arg)
Ian Kent 310093
 
Ian Kent 310093
 	args = (struct pending_args *) arg;
Ian Kent 310093
 
Ian Kent 310093
-	status = pthread_mutex_lock(&ma_mutex);
Ian Kent 310093
+	status = pthread_mutex_lock(&args->mutex);
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
@@ -689,7 +697,7 @@ static void *do_mount_indirect(void *arg)
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
-	mount_mutex_unlock(NULL);
Ian Kent 310093
+	mount_mutex_unlock(args);
Ian Kent 310093
 
Ian Kent 310093
 	pthread_cleanup_push(mount_send_fail, &mt;;
Ian Kent 310093
 
Ian Kent 310093
@@ -884,7 +892,11 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
-	status = pthread_mutex_lock(&ma_mutex);
Ian Kent 310093
+	status = pthread_mutex_init(&mt->mutex, NULL);
Ian Kent 310093
+	if (status)
Ian Kent 310093
+		fatal(status);
Ian Kent 310093
+
Ian Kent 310093
+	status = pthread_mutex_lock(&mt->mutex);
Ian Kent 310093
 	if (status)
Ian Kent 310093
 		fatal(status);
Ian Kent 310093
 
Ian Kent 310093
@@ -901,21 +913,23 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
Ian Kent 310093
 	if (status) {
Ian Kent 310093
 		error(ap->logopt, "expire thread create failed");
Ian Kent 310093
 		send_fail(ap->logopt, ap->ioctlfd, pkt->wait_queue_token);
Ian Kent 310093
-		mount_mutex_unlock(NULL);
Ian Kent 310093
+		mount_mutex_unlock(mt);
Ian Kent 310093
 		pending_cond_destroy(mt);
Ian Kent 310093
+		pending_mutex_destroy(mt);
Ian Kent 310093
 		free_pending_args(mt);
Ian Kent 310093
 		pthread_setcancelstate(state, NULL);
Ian Kent 310093
 		return 1;
Ian Kent 310093
 	}
Ian Kent 310093
 
Ian Kent 310093
 	pthread_cleanup_push(free_pending_args, mt);
Ian Kent 310093
+	pthread_cleanup_push(pending_mutex_destroy, mt);
Ian Kent 310093
 	pthread_cleanup_push(pending_cond_destroy, mt);
Ian Kent 310093
-	pthread_cleanup_push(mount_mutex_unlock, NULL);
Ian Kent 310093
+	pthread_cleanup_push(mount_mutex_unlock, mt);
Ian Kent 310093
 	pthread_setcancelstate(state, NULL);
Ian Kent 310093
 
Ian Kent 310093
 	mt->signaled = 0;
Ian Kent 310093
 	while (!mt->signaled) {
Ian Kent 310093
-		status = pthread_cond_wait(&mt->cond, &ma_mutex);
Ian Kent 310093
+		status = pthread_cond_wait(&mt->cond, &mt->mutex);
Ian Kent 310093
 		if (status)
Ian Kent 310093
 			fatal(status);
Ian Kent 310093
 	}
Ian Kent 310093
@@ -923,6 +937,7 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
Ian Kent 310093
 	pthread_cleanup_pop(1);
Ian Kent 310093
 	pthread_cleanup_pop(1);
Ian Kent 310093
 	pthread_cleanup_pop(1);
Ian Kent 310093
+	pthread_cleanup_pop(1);
Ian Kent 310093
 
Ian Kent 310093
 	return 0;
Ian Kent 310093
 }