On Fri, 2009-01-16 at 10:43 +0900, Ian Kent wrote: > > > > > > I'm tending toward reading the map during the lookup so the map is up to > > > date when we look for the key in the cache. > > Or maybe not. > > If we take advantage of the existing code to mark the map as stale and > handle the re-read and we accept the overhead of scanning the file map > while waiting for the update something like this could be all that's > needed.
So here is a slightly updated patch. autofs-5.0.4 - always read file maps From: Ian Kent <ra...@themaw.net> --- daemon/lookup.c | 9 ++++++--- modules/lookup_file.c | 26 ++++++++++++++------------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/daemon/lookup.c b/daemon/lookup.c index 741d846..e034348 100644 --- a/daemon/lookup.c +++ b/daemon/lookup.c @@ -283,10 +283,13 @@ static int do_read_map(struct autofs_point *ap, struct map_source *map, time_t a * for the fail cases to function correctly and to cache the * lookup handle. * - * We always need to whole map for direct mounts in order to - * mount the triggers. + * We always need to read the whole map for direct mounts in + * order to mount the triggers. We also want to read the whole + * map if it's a file map to avoid potentially lengthy linear + * file scanning. */ - if (!(ap->flags & MOUNT_FLAG_GHOST) && ap->type != LKP_DIRECT) + if (strcmp(map->type, "file") && + !(ap->flags & MOUNT_FLAG_GHOST) && ap->type != LKP_DIRECT) return NSS_STATUS_SUCCESS; if (!map->stale) diff --git a/modules/lookup_file.c b/modules/lookup_file.c index 95b9f6f..6f426a5 100644 --- a/modules/lookup_file.c +++ b/modules/lookup_file.c @@ -93,7 +93,6 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co argv[0]); return 1; } - ctxt->mtime = st.st_mtime; if (!mapfmt) @@ -951,9 +950,6 @@ static int check_map_indirect(struct autofs_point *ap, if (ret == CHE_FAIL) return NSS_STATUS_NOTFOUND; - if (ret & CHE_UPDATED) - source->stale = 1; - pthread_cleanup_push(cache_lock_cleanup, mc); cache_writelock(mc); exists = cache_lookup_distinct(mc, key); @@ -963,7 +959,6 @@ static int check_map_indirect(struct autofs_point *ap, free(exists->mapent); exists->mapent = NULL; exists->status = 0; - source->stale = 1; } } pthread_cleanup_pop(1); @@ -985,14 +980,8 @@ static int check_map_indirect(struct autofs_point *ap, we = cache_lookup_distinct(mc, "*"); if (we) { /* Wildcard entry existed and is now gone */ - if (we->source == source && (wild & CHE_MISSING)) { + if (we->source == source && (wild & CHE_MISSING)) cache_delete(mc, "*"); - source->stale = 1; - } - } else { - /* Wildcard not in map but now is */ - if (wild & (CHE_OK | CHE_UPDATED)) - source->stale = 1; } pthread_cleanup_pop(1); @@ -1064,7 +1053,19 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void * if (ap->type == LKP_INDIRECT && *key != '/') { char *lkp_key; + /* + * We can skip the map lookup and cache update altogether + * if we know the map hasn't been modified since it was + * last read. If it has then we can mark the map stale + * so a re-read is triggered following the lookup. + */ cache_readlock(mc); + me = cache_lookup_first(mc); + if (me && ctxt->mtime <= me->age) + goto do_cache_lookup; + else + source->stale = 1; + me = cache_lookup_distinct(mc, key); if (me && me->multi) lkp_key = strdup(me->multi->key); @@ -1088,6 +1089,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void * } cache_readlock(mc); +do_cache_lookup: me = cache_lookup(mc, key); /* Stale mapent => check for entry in alternate source or wildcard */ if (me && !me->mapent) { _______________________________________________ autofs mailing list autofs@linux.kernel.org http://linux.kernel.org/mailman/listinfo/autofs