[PATCH 26/34] autofs-5.1.2 - factor out set_thread_mount_request_log_id()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Factor out setting the thread mount request log id.

Signed-off-by: Ian Kent <raven@xxxxxxxxxx>
---
 CHANGELOG           |    1 +
 daemon/automount.c  |   24 +++++++++++++++++++++++-
 daemon/direct.c     |   17 +----------------
 daemon/indirect.c   |   17 +----------------
 include/automount.h |    3 ++-
 5 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index eed9697..7add032 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -52,6 +52,7 @@ xx/xx/2016 autofs-5.1.3
 - add the mount requestor's pid to pending_args.
 - create thread-local ID for mount attempts.
 - log functions to prefix messages with attempt_id if available.
+- factor out set_thread_mount_request_log_id().
 
 15/06/2016 autofs-5.1.2
 =======================
diff --git a/daemon/automount.c b/daemon/automount.c
index 2b23dec..203d21f 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -100,7 +100,7 @@ static int umount_all(struct autofs_point *ap, int force);
 extern struct master *master_list;
 
 /* simple string hash based on public domain sdbm library */
-unsigned long sdbm_hash(const char *str, unsigned long seed)
+static unsigned long sdbm_hash(const char *str, unsigned long seed)
 {
 	unsigned long hash = seed;
 	char c;
@@ -110,6 +110,28 @@ unsigned long sdbm_hash(const char *str, unsigned long seed)
 	return hash;
 }
 
+void set_thread_mount_request_log_id(struct pending_args *mt)
+{
+	char attempt_id_comp[20];
+	unsigned long *attempt_id;
+	int status;
+
+	attempt_id = pthread_getspecific(key_thread_attempt_id);
+	if (attempt_id == NULL) {
+		attempt_id = (unsigned long *) calloc(1, sizeof(unsigned long));
+		if (attempt_id  == NULL)
+			fatal(ENOMEM);
+		snprintf(attempt_id_comp, 20, "%ld", mt->wait_queue_token);
+		*attempt_id = sdbm_hash(attempt_id_comp, 0);
+		snprintf(attempt_id_comp, 20, "%u", mt->pid);
+		*attempt_id = sdbm_hash(attempt_id_comp, *attempt_id);
+		*attempt_id = sdbm_hash(mt->name, *attempt_id);
+		status = pthread_setspecific(key_thread_attempt_id, attempt_id);
+		if (status != 0)
+			fatal(status);
+	}
+}
+
 static int is_remote_fstype(unsigned int fs_type)
 {
 	int ret = 0;
diff --git a/daemon/direct.c b/daemon/direct.c
index 6f1329b..b682346 100644
--- a/daemon/direct.c
+++ b/daemon/direct.c
@@ -1210,8 +1210,6 @@ static void *do_mount_direct(void *arg)
 	struct autofs_point *ap;
 	struct stat st;
 	int status, state;
-	char attempt_id_comp[20];
-	unsigned long *attempt_id;
 
 	args = (struct pending_args *) arg;
 
@@ -1221,20 +1219,7 @@ static void *do_mount_direct(void *arg)
 
 	ap = mt.ap;
 
-	attempt_id = pthread_getspecific(key_thread_attempt_id);
-	if (attempt_id == NULL) {
-		attempt_id = (unsigned long *) calloc(1, sizeof(unsigned long));
-		if (attempt_id == NULL)
-			fatal(ENOMEM);
-		snprintf(attempt_id_comp, 20, "%ld", mt.wait_queue_token);
-		*attempt_id = sdbm_hash(attempt_id_comp, 0);
-		snprintf(attempt_id_comp, 20, "%u", mt.pid);
-		*attempt_id = sdbm_hash(attempt_id_comp, *attempt_id);
-		*attempt_id = sdbm_hash(mt.name, *attempt_id);
-		status = pthread_setspecific(key_thread_attempt_id, attempt_id);
-		if (status != 0)
-			fatal(status);
-	}
+	set_thread_mount_request_log_id(&mt);
 
 	args->signaled = 1;
 	status = pthread_cond_signal(&args->cond);
diff --git a/daemon/indirect.c b/daemon/indirect.c
index 3ed47e8..00b2622 100644
--- a/daemon/indirect.c
+++ b/daemon/indirect.c
@@ -726,8 +726,6 @@ static void *do_mount_indirect(void *arg)
 	char buf[PATH_MAX + 1];
 	struct stat st;
 	int len, status, state;
-	char attempt_id_comp[20];
-	unsigned long *attempt_id;
 
 	args = (struct pending_args *) arg;
 
@@ -737,20 +735,7 @@ static void *do_mount_indirect(void *arg)
 
 	ap = mt.ap;
 
-	attempt_id = pthread_getspecific(key_thread_attempt_id);
-	if (attempt_id == NULL) {
-		attempt_id = (unsigned long *) calloc(1, sizeof(unsigned long));
-		if (attempt_id  == NULL)
-			fatal(ENOMEM);
-		snprintf(attempt_id_comp, 20, "%ld", mt.wait_queue_token);
-		*attempt_id = sdbm_hash(attempt_id_comp, 0);
-		snprintf(attempt_id_comp, 20, "%u", mt.pid);
-		*attempt_id = sdbm_hash(attempt_id_comp, *attempt_id);
-		*attempt_id = sdbm_hash(mt.name, *attempt_id);
-		status = pthread_setspecific(key_thread_attempt_id, attempt_id);
-		if (status != 0)
-			fatal(status);
-	}
+	set_thread_mount_request_log_id(&mt);
 
 	args->signaled = 1;
 	status = pthread_cond_signal(&args->cond);
diff --git a/include/automount.h b/include/automount.h
index 1800c21..eb4fcc4 100644
--- a/include/automount.h
+++ b/include/automount.h
@@ -245,7 +245,8 @@ const char **copy_argv(int argc, const char **argv);
 int compare_argv(int argc1, const char **argv1, int argc2, const char **argv2);
 int free_argv(int argc, const char **argv);
 
-unsigned long sdbm_hash(const char *str, unsigned long seed);
+struct pending_args;
+void set_thread_mount_request_log_id(struct pending_args *mt);
 
 void dump_core(void);
 int aquire_lock(void);

--
To unsubscribe from this list: send the line "unsubscribe autofs" in



[Index of Archives]     [Linux Filesystem Development]     [Linux Ext4]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux