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

121 lines
3.4 KiB
Diff
Raw Normal View History

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