Blame SOURCES/autofs-5.0.8-add-negative-cache-lookup-to-hesiod-lookup.patch

306fa1
autofs-5.0.8 - add negative cache lookup to hesiod lookup
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Warning, this is completely untested.
306fa1
306fa1
I don't have a hesiod test environment so I can't test this at all.
306fa1
If we do in fact have hesiod users then I'll need to work with them
306fa1
to fix any reported problems.
306fa1
---
306fa1
 CHANGELOG               |    1 +
306fa1
 modules/lookup_hesiod.c |   39 ++++++++++++++++++++++++++++++++++++++-
306fa1
 2 files changed, 39 insertions(+), 1 deletion(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -91,6 +91,7 @@
306fa1
 - fix bad mkdir permission on create.
306fa1
 - fix macro_addvar() and move init to main thread.
306fa1
 - change walk_tree() to take ap.
306fa1
+- add negative cache lookup to hesiod lookup.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/modules/lookup_hesiod.c
306fa1
+++ autofs-5.0.7/modules/lookup_hesiod.c
306fa1
@@ -99,10 +99,11 @@ int lookup_read_map(struct autofs_point
306fa1
  */
306fa1
 int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *context)
306fa1
 {
306fa1
+	struct lookup_context *ctxt = (struct lookup_context *) context;
306fa1
 	struct map_source *source;
306fa1
 	struct mapent_cache *mc;
306fa1
+	struct mapent *me;
306fa1
 	char **hes_result;
306fa1
-	struct lookup_context *ctxt = (struct lookup_context *) context;
306fa1
 	int status, rv;
306fa1
 	char **record, *best_record = NULL, *p;
306fa1
 	int priority, lowest_priority = INT_MAX;	
306fa1
@@ -117,6 +118,32 @@ int lookup_mount(struct autofs_point *ap
306fa1
 	      MODPREFIX "looking up root=\"%s\", name=\"%s\"",
306fa1
 	      ap->path, name);
306fa1
 
306fa1
+	/* Check if we recorded a mount fail for this key anywhere */
306fa1
+	me = lookup_source_mapent(ap, name, LKP_DISTINCT);
306fa1
+	if (me) {
306fa1
+		if (me->status >= time(NULL)) {
306fa1
+			cache_unlock(me->mc);
306fa1
+			return NSS_STATUS_NOTFOUND;
306fa1
+		} else {
306fa1
+			struct mapent_cache *smc = me->mc;
306fa1
+			struct mapent *sme;
306fa1
+
306fa1
+			if (me->mapent)
306fa1
+				cache_unlock(smc);
306fa1
+			else {
306fa1
+				cache_unlock(smc);
306fa1
+				cache_writelock(smc);
306fa1
+				sme = cache_lookup_distinct(smc, name);
306fa1
+				/* Negative timeout expired for non-existent entry. */
306fa1
+				if (sme && !sme->mapent) {
306fa1
+					if (cache_pop_mapent(sme) == CHE_FAIL)
306fa1
+						cache_delete(smc, name);
306fa1
+				}
306fa1
+				cache_unlock(smc);
306fa1
+			}
306fa1
+		}
306fa1
+	}
306fa1
+
306fa1
 	chdir("/");		/* If this is not here the filesystem stays
306fa1
 				   busy, for some reason... */
306fa1
 
306fa1
@@ -171,6 +198,16 @@ int lookup_mount(struct autofs_point *ap
306fa1
 	if (status)
306fa1
 		fatal(status);
306fa1
 
306fa1
+	if (rv) {
306fa1
+		/* Don't update negative cache when re-connecting */
306fa1
+		if (ap->flags & MOUNT_FLAG_REMOUNT)
306fa1
+			return NSS_STATUS_TRYAGAIN;
306fa1
+		cache_writelock(mc);
306fa1
+		cache_update_negative(mc, source, name, ap->negative_timeout);
306fa1
+		cache_unlock(mc);
306fa1
+		return NSS_STATUS_TRYAGAIN;
306fa1
+	}
306fa1
+
306fa1
 	/*
306fa1
 	 * Unavailable due to error such as module load fail 
306fa1
 	 * or out of memory, etc.