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

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