|
|
cd8711 |
autofs-5.1.8 - serialise lookup module open and reinit
|
|
|
cd8711 |
|
|
|
cd8711 |
From: Ian Kent <raven@themaw.net>
|
|
|
cd8711 |
|
|
|
cd8711 |
Add a map source lock to serialise map setting and use of module
|
|
|
cd8711 |
structure fields such as the context.
|
|
|
cd8711 |
|
|
|
cd8711 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
cd8711 |
---
|
|
|
cd8711 |
CHANGELOG | 1 +
|
|
|
cd8711 |
daemon/lookup.c | 35 +++++++++++++++++++++--------------
|
|
|
cd8711 |
daemon/master.c | 43 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
cd8711 |
include/master.h | 5 +++++
|
|
|
cd8711 |
modules/parse_amd.c | 26 +++++++++++++++-----------
|
|
|
cd8711 |
5 files changed, 85 insertions(+), 25 deletions(-)
|
|
|
cd8711 |
|
|
|
cd8711 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
cd8711 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
cd8711 |
@@ -97,6 +97,7 @@
|
|
|
cd8711 |
- dont use initgroups() at spawn.
|
|
|
cd8711 |
- fix invalid tsv access.
|
|
|
cd8711 |
- fix parse module instance mutex naming.
|
|
|
cd8711 |
+- serialise lookup module open and reinit.
|
|
|
cd8711 |
|
|
|
cd8711 |
xx/xx/2018 autofs-5.1.5
|
|
|
cd8711 |
- fix flag file permission.
|
|
|
cd8711 |
--- autofs-5.1.4.orig/daemon/lookup.c
|
|
|
cd8711 |
+++ autofs-5.1.4/daemon/lookup.c
|
|
|
cd8711 |
@@ -318,28 +318,27 @@ static int do_read_map(struct autofs_poi
|
|
|
cd8711 |
struct lookup_mod *lookup;
|
|
|
cd8711 |
int status;
|
|
|
cd8711 |
|
|
|
cd8711 |
- lookup = NULL;
|
|
|
cd8711 |
- master_source_writelock(ap->entry);
|
|
|
cd8711 |
+ pthread_cleanup_push(map_module_lock_cleanup, map);
|
|
|
cd8711 |
+ map_module_writelock(map);
|
|
|
cd8711 |
if (!map->lookup) {
|
|
|
cd8711 |
status = open_lookup(map->type, "", map->format,
|
|
|
cd8711 |
map->argc, map->argv, &lookup);
|
|
|
cd8711 |
- if (status != NSS_STATUS_SUCCESS) {
|
|
|
cd8711 |
- master_source_unlock(ap->entry);
|
|
|
cd8711 |
+ if (status == NSS_STATUS_SUCCESS)
|
|
|
cd8711 |
+ map->lookup = lookup;
|
|
|
cd8711 |
+ else
|
|
|
cd8711 |
debug(ap->logopt,
|
|
|
cd8711 |
"lookup module %s open failed", map->type);
|
|
|
cd8711 |
- return status;
|
|
|
cd8711 |
- }
|
|
|
cd8711 |
- map->lookup = lookup;
|
|
|
cd8711 |
} else {
|
|
|
cd8711 |
- lookup = map->lookup;
|
|
|
cd8711 |
- status = lookup->lookup_reinit(map->format,
|
|
|
cd8711 |
- map->argc, map->argv,
|
|
|
cd8711 |
- &lookup->context);
|
|
|
cd8711 |
+ status = map->lookup->lookup_reinit(map->format,
|
|
|
cd8711 |
+ map->argc, map->argv,
|
|
|
cd8711 |
+ &map->lookup->context);
|
|
|
cd8711 |
if (status)
|
|
|
cd8711 |
warn(ap->logopt,
|
|
|
cd8711 |
"lookup module %s reinit failed", map->type);
|
|
|
cd8711 |
}
|
|
|
cd8711 |
- master_source_unlock(ap->entry);
|
|
|
cd8711 |
+ pthread_cleanup_pop(1);
|
|
|
cd8711 |
+ if (status != NSS_STATUS_SUCCESS)
|
|
|
cd8711 |
+ return status;
|
|
|
cd8711 |
|
|
|
cd8711 |
if (!map->stale)
|
|
|
cd8711 |
return NSS_STATUS_SUCCESS;
|
|
|
cd8711 |
@@ -347,7 +346,11 @@ static int do_read_map(struct autofs_poi
|
|
|
cd8711 |
master_source_current_wait(ap->entry);
|
|
|
cd8711 |
ap->entry->current = map;
|
|
|
cd8711 |
|
|
|
cd8711 |
+ pthread_cleanup_push(map_module_lock_cleanup, map);
|
|
|
cd8711 |
+ map_module_readlock(map);
|
|
|
cd8711 |
+ lookup = map->lookup;
|
|
|
cd8711 |
status = lookup->lookup_read_map(ap, age, lookup->context);
|
|
|
cd8711 |
+ pthread_cleanup_pop(1);
|
|
|
cd8711 |
|
|
|
cd8711 |
if (status != NSS_STATUS_SUCCESS)
|
|
|
cd8711 |
map->stale = 0;
|
|
|
cd8711 |
@@ -812,23 +815,27 @@ int do_lookup_mount(struct autofs_point
|
|
|
cd8711 |
struct lookup_mod *lookup;
|
|
|
cd8711 |
int status;
|
|
|
cd8711 |
|
|
|
cd8711 |
+ map_module_writelock(map);
|
|
|
cd8711 |
if (!map->lookup) {
|
|
|
cd8711 |
status = open_lookup(map->type, "",
|
|
|
cd8711 |
map->format, map->argc, map->argv, &lookup);
|
|
|
cd8711 |
if (status != NSS_STATUS_SUCCESS) {
|
|
|
cd8711 |
+ map_module_unlock(map);
|
|
|
cd8711 |
debug(ap->logopt,
|
|
|
cd8711 |
"lookup module %s open failed", map->type);
|
|
|
cd8711 |
return status;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
map->lookup = lookup;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
-
|
|
|
cd8711 |
- lookup = map->lookup;
|
|
|
cd8711 |
+ map_module_unlock(map);
|
|
|
cd8711 |
|
|
|
cd8711 |
master_source_current_wait(ap->entry);
|
|
|
cd8711 |
ap->entry->current = map;
|
|
|
cd8711 |
|
|
|
cd8711 |
+ map_module_readlock(map);
|
|
|
cd8711 |
+ lookup = map->lookup;
|
|
|
cd8711 |
status = lookup->lookup_mount(ap, name, name_len, lookup->context);
|
|
|
cd8711 |
+ map_module_unlock(map);
|
|
|
cd8711 |
|
|
|
cd8711 |
return status;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
--- autofs-5.1.4.orig/daemon/master.c
|
|
|
cd8711 |
+++ autofs-5.1.4/daemon/master.c
|
|
|
cd8711 |
@@ -65,6 +65,34 @@ void master_mutex_lock_cleanup(void *arg
|
|
|
cd8711 |
return;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
|
|
|
cd8711 |
+void map_module_writelock(struct map_source *map)
|
|
|
cd8711 |
+{
|
|
|
cd8711 |
+ int status = pthread_rwlock_wrlock(&map->module_lock);
|
|
|
cd8711 |
+ if (status)
|
|
|
cd8711 |
+ fatal(status);
|
|
|
cd8711 |
+}
|
|
|
cd8711 |
+
|
|
|
cd8711 |
+void map_module_readlock(struct map_source *map)
|
|
|
cd8711 |
+{
|
|
|
cd8711 |
+ int status = pthread_rwlock_rdlock(&map->module_lock);
|
|
|
cd8711 |
+ if (status)
|
|
|
cd8711 |
+ fatal(status);
|
|
|
cd8711 |
+}
|
|
|
cd8711 |
+
|
|
|
cd8711 |
+void map_module_unlock(struct map_source *map)
|
|
|
cd8711 |
+{
|
|
|
cd8711 |
+ int status = pthread_rwlock_unlock(&map->module_lock);
|
|
|
cd8711 |
+ if (status)
|
|
|
cd8711 |
+ fatal(status);
|
|
|
cd8711 |
+}
|
|
|
cd8711 |
+
|
|
|
cd8711 |
+void map_module_lock_cleanup(void *arg)
|
|
|
cd8711 |
+{
|
|
|
cd8711 |
+ struct map_source *map = (struct map_source *) arg;
|
|
|
cd8711 |
+
|
|
|
cd8711 |
+ map_module_unlock(map);
|
|
|
cd8711 |
+}
|
|
|
cd8711 |
+
|
|
|
cd8711 |
int master_add_autofs_point(struct master_mapent *entry, unsigned logopt,
|
|
|
cd8711 |
unsigned nobind, unsigned ghost, int submount)
|
|
|
cd8711 |
{
|
|
|
cd8711 |
@@ -155,6 +183,7 @@ master_add_map_source(struct master_mape
|
|
|
cd8711 |
struct map_source *source;
|
|
|
cd8711 |
char *ntype, *nformat;
|
|
|
cd8711 |
const char **tmpargv;
|
|
|
cd8711 |
+ int status;
|
|
|
cd8711 |
|
|
|
cd8711 |
source = malloc(sizeof(struct map_source));
|
|
|
cd8711 |
if (!source)
|
|
|
cd8711 |
@@ -241,6 +270,10 @@ master_add_map_source(struct master_mape
|
|
|
cd8711 |
|
|
|
cd8711 |
master_source_unlock(entry);
|
|
|
cd8711 |
|
|
|
cd8711 |
+ status = pthread_rwlock_init(&source->module_lock, NULL);
|
|
|
cd8711 |
+ if (status)
|
|
|
cd8711 |
+ fatal(status);
|
|
|
cd8711 |
+
|
|
|
cd8711 |
return source;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
|
|
|
cd8711 |
@@ -330,6 +363,8 @@ master_get_map_source(struct master_mape
|
|
|
cd8711 |
|
|
|
cd8711 |
static void __master_free_map_source(struct map_source *source, unsigned int free_cache)
|
|
|
cd8711 |
{
|
|
|
cd8711 |
+ int status;
|
|
|
cd8711 |
+
|
|
|
cd8711 |
/* instance map sources are not ref counted */
|
|
|
cd8711 |
if (source->ref && --source->ref)
|
|
|
cd8711 |
return;
|
|
|
cd8711 |
@@ -365,6 +400,10 @@ static void __master_free_map_source(str
|
|
|
cd8711 |
}
|
|
|
cd8711 |
}
|
|
|
cd8711 |
|
|
|
cd8711 |
+ status = pthread_rwlock_destroy(&source->module_lock);
|
|
|
cd8711 |
+ if (status)
|
|
|
cd8711 |
+ fatal(status);
|
|
|
cd8711 |
+
|
|
|
cd8711 |
free(source);
|
|
|
cd8711 |
|
|
|
cd8711 |
return;
|
|
|
cd8711 |
@@ -496,6 +535,10 @@ master_add_source_instance(struct map_so
|
|
|
cd8711 |
if (status)
|
|
|
cd8711 |
fatal(status);
|
|
|
cd8711 |
|
|
|
cd8711 |
+ status = pthread_rwlock_init(&new->module_lock, NULL);
|
|
|
cd8711 |
+ if (status)
|
|
|
cd8711 |
+ fatal(status);
|
|
|
cd8711 |
+
|
|
|
cd8711 |
return new;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
|
|
|
cd8711 |
--- autofs-5.1.4.orig/include/master.h
|
|
|
cd8711 |
+++ autofs-5.1.4/include/master.h
|
|
|
cd8711 |
@@ -35,6 +35,7 @@ struct map_source {
|
|
|
cd8711 |
unsigned int stale;
|
|
|
cd8711 |
unsigned int recurse;
|
|
|
cd8711 |
unsigned int depth;
|
|
|
cd8711 |
+ pthread_rwlock_t module_lock;
|
|
|
cd8711 |
struct lookup_mod *lookup;
|
|
|
cd8711 |
int argc;
|
|
|
cd8711 |
const char **argv;
|
|
|
cd8711 |
@@ -126,5 +127,9 @@ int __master_list_empty(struct master *)
|
|
|
cd8711 |
int master_list_empty(struct master *);
|
|
|
cd8711 |
int master_done(struct master *);
|
|
|
cd8711 |
int master_kill(struct master *);
|
|
|
cd8711 |
+void map_module_writelock(struct map_source *map);
|
|
|
cd8711 |
+void map_module_readlock(struct map_source *map);
|
|
|
cd8711 |
+void map_module_unlock(struct map_source *map);
|
|
|
cd8711 |
+void map_module_lock_cleanup(void *arg);
|
|
|
cd8711 |
|
|
|
cd8711 |
#endif
|
|
|
cd8711 |
--- autofs-5.1.4.orig/modules/parse_amd.c
|
|
|
cd8711 |
+++ autofs-5.1.4/modules/parse_amd.c
|
|
|
cd8711 |
@@ -1358,14 +1358,6 @@ static int do_host_mount(struct autofs_p
|
|
|
cd8711 |
argc = 1;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
|
|
|
cd8711 |
- parse_instance_mutex_lock();
|
|
|
cd8711 |
- status = open_lookup("hosts", MODPREFIX, NULL, argc, pargv, &lookup);
|
|
|
cd8711 |
- if (status != NSS_STATUS_SUCCESS) {
|
|
|
cd8711 |
- debug(ap->logopt, "open lookup module hosts failed");
|
|
|
cd8711 |
- parse_instance_mutex_unlock();
|
|
|
cd8711 |
- goto out;
|
|
|
cd8711 |
- }
|
|
|
cd8711 |
-
|
|
|
cd8711 |
instance = master_find_source_instance(source,
|
|
|
cd8711 |
"hosts", "sun", argc, pargv);
|
|
|
cd8711 |
if (!instance) {
|
|
|
cd8711 |
@@ -1374,13 +1366,22 @@ static int do_host_mount(struct autofs_p
|
|
|
cd8711 |
if (!instance) {
|
|
|
cd8711 |
error(ap->logopt, MODPREFIX
|
|
|
cd8711 |
"failed to create source instance for hosts map");
|
|
|
cd8711 |
- parse_instance_mutex_unlock();
|
|
|
cd8711 |
close_lookup(lookup);
|
|
|
cd8711 |
goto out;
|
|
|
cd8711 |
}
|
|
|
cd8711 |
}
|
|
|
cd8711 |
- instance->lookup = lookup;
|
|
|
cd8711 |
- parse_instance_mutex_unlock();
|
|
|
cd8711 |
+
|
|
|
cd8711 |
+ map_module_writelock(instance);
|
|
|
cd8711 |
+ if (!instance->lookup) {
|
|
|
cd8711 |
+ status = open_lookup("hosts", MODPREFIX, NULL, argc, pargv, &lookup);
|
|
|
cd8711 |
+ if (status != NSS_STATUS_SUCCESS) {
|
|
|
cd8711 |
+ map_module_unlock(instance);
|
|
|
cd8711 |
+ debug(ap->logopt, "open lookup module hosts failed");
|
|
|
cd8711 |
+ goto out;
|
|
|
cd8711 |
+ }
|
|
|
cd8711 |
+ instance->lookup = lookup;
|
|
|
cd8711 |
+ }
|
|
|
cd8711 |
+ map_module_unlock(instance);
|
|
|
cd8711 |
|
|
|
cd8711 |
cache_writelock(source->mc);
|
|
|
cd8711 |
me = cache_lookup_distinct(source->mc, name);
|
|
|
cd8711 |
@@ -1391,8 +1392,11 @@ static int do_host_mount(struct autofs_p
|
|
|
cd8711 |
master_source_current_wait(ap->entry);
|
|
|
cd8711 |
ap->entry->current = source;
|
|
|
cd8711 |
|
|
|
cd8711 |
+ map_module_readlock(instance);
|
|
|
cd8711 |
+ lookup = instance->lookup;
|
|
|
cd8711 |
ret = lookup->lookup_mount(ap, entry->rhost,
|
|
|
cd8711 |
strlen(entry->rhost), lookup->context);
|
|
|
cd8711 |
+ map_module_unlock(instance);
|
|
|
cd8711 |
|
|
|
cd8711 |
if (!strcmp(name, entry->rhost))
|
|
|
cd8711 |
goto out;
|