|
|
23b4c9 |
autofs-5.1.2 - create thread-local ID for mount attempts
|
|
|
23b4c9 |
|
|
|
23b4c9 |
From: Lars R. Damerow <lars@pixar.com>
|
|
|
23b4c9 |
|
|
|
23b4c9 |
This patch creates key_thread_attempt_id as a pthread key and populates it
|
|
|
23b4c9 |
in each new thread serving a mount attempt. This ID can be used in output logs
|
|
|
23b4c9 |
as an easy string to grep for, allowing admins to quickly see a mount attempt's
|
|
|
23b4c9 |
log entries without the messages from other attempts interleaved.
|
|
|
23b4c9 |
|
|
|
23b4c9 |
The contents of the ID are intended to be opaque, but to get a chance at
|
|
|
23b4c9 |
a unique value for each mount attempt, this patch does a very simple hash
|
|
|
23b4c9 |
computation of the thread's wait_queue_token, the pid of the requesting
|
|
|
23b4c9 |
process, and the key for the mount. The hash is based on the public domain
|
|
|
23b4c9 |
sdbm library.
|
|
|
23b4c9 |
|
|
|
23b4c9 |
Signed-off-by: Lars R. Damerow <lars@pixar.com>
|
|
|
23b4c9 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
23b4c9 |
---
|
|
|
23b4c9 |
CHANGELOG | 1 +
|
|
|
23b4c9 |
daemon/automount.c | 24 ++++++++++++++++++++++++
|
|
|
23b4c9 |
daemon/direct.c | 17 +++++++++++++++++
|
|
|
23b4c9 |
daemon/indirect.c | 17 +++++++++++++++++
|
|
|
23b4c9 |
include/automount.h | 6 ++++++
|
|
|
23b4c9 |
5 files changed, 65 insertions(+)
|
|
|
23b4c9 |
|
|
|
23b4c9 |
--- autofs-5.0.7.orig/CHANGELOG
|
|
|
23b4c9 |
+++ autofs-5.0.7/CHANGELOG
|
|
|
23b4c9 |
@@ -236,6 +236,7 @@
|
|
|
23b4c9 |
- fix bogus check in expire_cleanup().
|
|
|
23b4c9 |
- delay submount exit for amd submounts.
|
|
|
23b4c9 |
- add the mount requestor's pid to pending_args.
|
|
|
23b4c9 |
+- create thread-local ID for mount attempts.
|
|
|
23b4c9 |
|
|
|
23b4c9 |
25/07/2012 autofs-5.0.7
|
|
|
23b4c9 |
=======================
|
|
|
23b4c9 |
--- autofs-5.0.7.orig/daemon/automount.c
|
|
|
23b4c9 |
+++ autofs-5.0.7/daemon/automount.c
|
|
|
23b4c9 |
@@ -89,6 +89,7 @@ struct startup_cond suc = {
|
|
|
23b4c9 |
PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0};
|
|
|
23b4c9 |
|
|
|
23b4c9 |
pthread_key_t key_thread_stdenv_vars;
|
|
|
23b4c9 |
+pthread_key_t key_thread_attempt_id = (pthread_key_t) 0L;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
#define MAX_OPEN_FILES 10240
|
|
|
23b4c9 |
|
|
|
23b4c9 |
@@ -98,6 +99,17 @@ static int umount_all(struct autofs_poin
|
|
|
23b4c9 |
|
|
|
23b4c9 |
extern struct master *master_list;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
+/* simple string hash based on public domain sdbm library */
|
|
|
23b4c9 |
+unsigned long sdbm_hash(const char *str, unsigned long seed)
|
|
|
23b4c9 |
+{
|
|
|
23b4c9 |
+ unsigned long hash = seed;
|
|
|
23b4c9 |
+ char c;
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
+ while ((c = *str++))
|
|
|
23b4c9 |
+ hash = c + (hash << 6) + (hash << 16) - hash;
|
|
|
23b4c9 |
+ return hash;
|
|
|
23b4c9 |
+}
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
static int do_mkdir(const char *parent, const char *path, mode_t mode)
|
|
|
23b4c9 |
{
|
|
|
23b4c9 |
int status;
|
|
|
23b4c9 |
@@ -2441,6 +2453,18 @@ int main(int argc, char *argv[])
|
|
|
23b4c9 |
program);
|
|
|
23b4c9 |
master_kill(master_list);
|
|
|
23b4c9 |
res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
|
|
|
23b4c9 |
+ close(start_pipefd[1]);
|
|
|
23b4c9 |
+ release_flag_file();
|
|
|
23b4c9 |
+ macro_free_global_table();
|
|
|
23b4c9 |
+ exit(1);
|
|
|
23b4c9 |
+ }
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
+ status = pthread_key_create(&key_thread_attempt_id, free);
|
|
|
23b4c9 |
+ if (status) {
|
|
|
23b4c9 |
+ logerr("%s: failed to create thread data key for attempt ID!",
|
|
|
23b4c9 |
+ program);
|
|
|
23b4c9 |
+ master_kill(master_list);
|
|
|
23b4c9 |
+ res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
|
|
|
23b4c9 |
close(start_pipefd[1]);
|
|
|
23b4c9 |
release_flag_file();
|
|
|
23b4c9 |
macro_free_global_table();
|
|
|
23b4c9 |
--- autofs-5.0.7.orig/daemon/direct.c
|
|
|
23b4c9 |
+++ autofs-5.0.7/daemon/direct.c
|
|
|
23b4c9 |
@@ -1210,6 +1210,8 @@ static void *do_mount_direct(void *arg)
|
|
|
23b4c9 |
struct autofs_point *ap;
|
|
|
23b4c9 |
struct stat st;
|
|
|
23b4c9 |
int status, state;
|
|
|
23b4c9 |
+ char attempt_id_comp[20];
|
|
|
23b4c9 |
+ unsigned long *attempt_id;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
args = (struct pending_args *) arg;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
@@ -1219,6 +1221,21 @@ static void *do_mount_direct(void *arg)
|
|
|
23b4c9 |
|
|
|
23b4c9 |
ap = mt.ap;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
+ attempt_id = pthread_getspecific(key_thread_attempt_id);
|
|
|
23b4c9 |
+ if (attempt_id == NULL) {
|
|
|
23b4c9 |
+ attempt_id = (unsigned long *) calloc(1, sizeof(unsigned long));
|
|
|
23b4c9 |
+ if (attempt_id == NULL)
|
|
|
23b4c9 |
+ fatal(ENOMEM);
|
|
|
23b4c9 |
+ snprintf(attempt_id_comp, 20, "%ld", mt.wait_queue_token);
|
|
|
23b4c9 |
+ *attempt_id = sdbm_hash(attempt_id_comp, 0);
|
|
|
23b4c9 |
+ snprintf(attempt_id_comp, 20, "%u", mt.pid);
|
|
|
23b4c9 |
+ *attempt_id = sdbm_hash(attempt_id_comp, *attempt_id);
|
|
|
23b4c9 |
+ *attempt_id = sdbm_hash(mt.name, *attempt_id);
|
|
|
23b4c9 |
+ status = pthread_setspecific(key_thread_attempt_id, attempt_id);
|
|
|
23b4c9 |
+ if (status != 0)
|
|
|
23b4c9 |
+ fatal(status);
|
|
|
23b4c9 |
+ }
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
args->signaled = 1;
|
|
|
23b4c9 |
status = pthread_cond_signal(&args->cond);
|
|
|
23b4c9 |
if (status)
|
|
|
23b4c9 |
--- autofs-5.0.7.orig/daemon/indirect.c
|
|
|
23b4c9 |
+++ autofs-5.0.7/daemon/indirect.c
|
|
|
23b4c9 |
@@ -726,6 +726,8 @@ static void *do_mount_indirect(void *arg
|
|
|
23b4c9 |
char buf[PATH_MAX + 1];
|
|
|
23b4c9 |
struct stat st;
|
|
|
23b4c9 |
int len, status, state;
|
|
|
23b4c9 |
+ char attempt_id_comp[20];
|
|
|
23b4c9 |
+ unsigned long *attempt_id;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
args = (struct pending_args *) arg;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
@@ -735,6 +737,21 @@ static void *do_mount_indirect(void *arg
|
|
|
23b4c9 |
|
|
|
23b4c9 |
ap = mt.ap;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
+ attempt_id = pthread_getspecific(key_thread_attempt_id);
|
|
|
23b4c9 |
+ if (attempt_id == NULL) {
|
|
|
23b4c9 |
+ attempt_id = (unsigned long *) calloc(1, sizeof(unsigned long));
|
|
|
23b4c9 |
+ if (attempt_id == NULL)
|
|
|
23b4c9 |
+ fatal(ENOMEM);
|
|
|
23b4c9 |
+ snprintf(attempt_id_comp, 20, "%ld", mt.wait_queue_token);
|
|
|
23b4c9 |
+ *attempt_id = sdbm_hash(attempt_id_comp, 0);
|
|
|
23b4c9 |
+ snprintf(attempt_id_comp, 20, "%u", mt.pid);
|
|
|
23b4c9 |
+ *attempt_id = sdbm_hash(attempt_id_comp, *attempt_id);
|
|
|
23b4c9 |
+ *attempt_id = sdbm_hash(mt.name, *attempt_id);
|
|
|
23b4c9 |
+ status = pthread_setspecific(key_thread_attempt_id, attempt_id);
|
|
|
23b4c9 |
+ if (status != 0)
|
|
|
23b4c9 |
+ fatal(status);
|
|
|
23b4c9 |
+ }
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
args->signaled = 1;
|
|
|
23b4c9 |
status = pthread_cond_signal(&args->cond);
|
|
|
23b4c9 |
if (status)
|
|
|
23b4c9 |
--- autofs-5.0.7.orig/include/automount.h
|
|
|
23b4c9 |
+++ autofs-5.0.7/include/automount.h
|
|
|
23b4c9 |
@@ -76,6 +76,8 @@ int load_autofs4_module(void);
|
|
|
23b4c9 |
#define SMB_SUPER_MAGIC 0x0000517BL
|
|
|
23b4c9 |
#define CIFS_MAGIC_NUMBER 0xFF534D42L
|
|
|
23b4c9 |
|
|
|
23b4c9 |
+#define ATTEMPT_ID_SIZE 24
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
/* This sould be enough for at least 20 host aliases */
|
|
|
23b4c9 |
#define HOST_ENT_BUF_SIZE 2048
|
|
|
23b4c9 |
|
|
|
23b4c9 |
@@ -241,6 +243,8 @@ const char **copy_argv(int argc, const c
|
|
|
23b4c9 |
int compare_argv(int argc1, const char **argv1, int argc2, const char **argv2);
|
|
|
23b4c9 |
int free_argv(int argc, const char **argv);
|
|
|
23b4c9 |
|
|
|
23b4c9 |
+unsigned long sdbm_hash(const char *str, unsigned long seed);
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
void dump_core(void);
|
|
|
23b4c9 |
int aquire_lock(void);
|
|
|
23b4c9 |
void release_lock(void);
|
|
|
23b4c9 |
@@ -480,6 +484,8 @@ struct thread_stdenv_vars {
|
|
|
23b4c9 |
|
|
|
23b4c9 |
extern pthread_key_t key_thread_stdenv_vars;
|
|
|
23b4c9 |
|
|
|
23b4c9 |
+extern pthread_key_t key_thread_attempt_id;
|
|
|
23b4c9 |
+
|
|
|
23b4c9 |
struct kernel_mod_version {
|
|
|
23b4c9 |
unsigned int major;
|
|
|
23b4c9 |
unsigned int minor;
|