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

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