Blame SOURCES/autofs-5.1.6-simplify-sss-source-stale-check.patch

d702dc
autofs-5.1.6 - simplify sss source stale check
d702dc
d702dc
From: Ian Kent <raven@themaw.net>
d702dc
d702dc
Now that there's a positive timeout on valid map cache entries
d702dc
simplifying the map stale checks should be able to be done, and
d702dc
eventually this will be much simpler in a lot of places.
d702dc
d702dc
Start with the key lookup in the sss lookup module since that's
d702dc
needed to prevent recently retrieved map keys from being pruned
d702dc
immediately after being used since the existing check wasn't
d702dc
working and was questionable anyway (and likely hadn't for worked
d702dc
some time).
d702dc
d702dc
Signed-off-by: Ian Kent <raven@themaw.net>
d702dc
---
d702dc
 CHANGELOG            |    1 +
d702dc
 modules/lookup_sss.c |   47 ++++++++++-------------------------------------
d702dc
 2 files changed, 11 insertions(+), 37 deletions(-)
d702dc
d702dc
diff --git a/CHANGELOG b/CHANGELOG
d702dc
index 34b160e..e9c7a59 100644
d702dc
--- a/CHANGELOG
d702dc
+++ b/CHANGELOG
d702dc
@@ -110,6 +110,7 @@ xx/xx/2018 autofs-5.1.5
d702dc
 - improve sss getautomntbyname() error handling.
d702dc
 - use a valid timeout in lookup_prune_one_cache().
d702dc
 - dont prune offset map entries.
d702dc
+- simplify sss source stale check.
d702dc
 
d702dc
 19/12/2017 autofs-5.1.4
d702dc
 - fix spec file url.
d702dc
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
d702dc
index 70efc11..69be765 100644
d702dc
--- a/modules/lookup_sss.c
d702dc
+++ b/modules/lookup_sss.c
d702dc
@@ -869,7 +869,7 @@ static int lookup_one(struct autofs_point *ap,
d702dc
 	time_t age = monotonic_time(NULL);
d702dc
 	char *value = NULL;
d702dc
 	char *s_key;
d702dc
-	int ret;
d702dc
+	int err, ret;
d702dc
 
d702dc
 	source = ap->entry->current;
d702dc
 	ap->entry->current = NULL;
d702dc
@@ -901,8 +901,11 @@ static int lookup_one(struct autofs_point *ap,
d702dc
 		goto wild;
d702dc
 	}
d702dc
 	cache_writelock(mc);
d702dc
-	ret = cache_update(mc, source, s_key, value, age);
d702dc
+	err = cache_update(mc, source, s_key, value, age);
d702dc
 	cache_unlock(mc);
d702dc
+	/* Entry in map but not in cache, map is stale */
d702dc
+	if (err & CHE_UPDATED)
d702dc
+		source->stale = 1;
d702dc
 	endautomntent(ap->logopt, ctxt, &sss_ctxt);
d702dc
 	free(s_key);
d702dc
 	free(value);
d702dc
@@ -952,12 +955,12 @@ wild:
d702dc
 	}
d702dc
 
d702dc
 	cache_writelock(mc);
d702dc
-	/* Wildcard not in map but now is */
d702dc
-	we = cache_lookup_distinct(mc, "*");
d702dc
-	if (!we)
d702dc
-		source->stale = 1;
d702dc
-	ret = cache_update(mc, source, "*", value, age);
d702dc
+	/* Wildcard in map but not in cache, update it */
d702dc
+	err = cache_update(mc, source, "*", value, age);
d702dc
 	cache_unlock(mc);
d702dc
+	/* Wildcard in map but not in cache, map is stale */
d702dc
+	if (err & CHE_UPDATED)
d702dc
+		source->stale = 1;
d702dc
 
d702dc
 	endautomntent(ap->logopt, ctxt, &sss_ctxt);
d702dc
         free(value);
d702dc
@@ -971,9 +974,6 @@ static int check_map_indirect(struct autofs_point *ap,
d702dc
 {
d702dc
 	struct map_source *source;
d702dc
 	struct mapent_cache *mc;
d702dc
-	struct mapent *me;
d702dc
-	time_t now = monotonic_time(NULL);
d702dc
-	time_t t_last_read;
d702dc
 	int ret, cur_state;
d702dc
 
d702dc
 	source = ap->entry->current;
d702dc
@@ -1009,33 +1009,6 @@ static int check_map_indirect(struct autofs_point *ap,
d702dc
 	}
d702dc
 	pthread_setcancelstate(cur_state, NULL);
d702dc
 
d702dc
-	/*
d702dc
-	 * Check for map change and update as needed for
d702dc
-	 * following cache lookup.
d702dc
-	 */
d702dc
-	cache_readlock(mc);
d702dc
-	t_last_read = ap->exp_runfreq + 1;
d702dc
-	me = cache_lookup_first(mc);
d702dc
-	while (me) {
d702dc
-		if (me->source == source) {
d702dc
-			t_last_read = now - me->age;
d702dc
-			break;
d702dc
-		}
d702dc
-		me = cache_lookup_next(mc, me);
d702dc
-	}
d702dc
-	cache_unlock(mc);
d702dc
-
d702dc
-	if (t_last_read > ap->exp_runfreq && ret & CHE_UPDATED)
d702dc
-		source->stale = 1;
d702dc
-
d702dc
-	cache_readlock(mc);
d702dc
-	me = cache_lookup_distinct(mc, "*");
d702dc
-	if (ret == CHE_MISSING && (!me || me->source != source)) {
d702dc
-		cache_unlock(mc);
d702dc
-		return NSS_STATUS_NOTFOUND;
d702dc
-	}
d702dc
-	cache_unlock(mc);
d702dc
-
d702dc
 	return NSS_STATUS_SUCCESS;
d702dc
 }
d702dc