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

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