File autofs-5.1.0-make-negative-cache-update-consistent-for-all-lookup-modules.patch of Package autofs.3485

autofs-5.1.0 - make negative cache update consistent for all lookup modules

From: Ian Kent <ikent@redhat.com>

Use common function for negative cache update everywhere to ensure consistency.
---
 CHANGELOG                |    1 +
 modules/lookup_hosts.c   |   14 +-------------
 modules/lookup_nisplus.c |   13 +------------
 modules/lookup_program.c |   14 +-------------
 4 files changed, 4 insertions(+), 38 deletions(-)

Index: autofs-5.0.9/modules/lookup_hosts.c
===================================================================
--- autofs-5.0.9.orig/modules/lookup_hosts.c
+++ autofs-5.0.9/modules/lookup_hosts.c
@@ -148,22 +148,10 @@ static int do_parse_mount(struct autofs_
 	ret = ctxt->parse->parse_mount(ap, name, name_len,
 				 mapent, ctxt->parse->context);
 	if (ret) {
-		time_t now = time(NULL);
 		struct mapent_cache *mc = source->mc;
-		struct mapent *me;
-		int rv = CHE_OK;
 
 		cache_writelock(mc);
-		me = cache_lookup_distinct(mc, name);
-		if (me)
-			rv = cache_push_mapent(me, NULL);
-		else
-			rv = cache_update(mc, source, name, NULL, now);
-		if (rv != CHE_FAIL) {
-			me = cache_lookup_distinct(mc, name);
-			if (me)
-				me->status = now + ap->negative_timeout;
-		}
+		cache_update_negative(mc, source, name, ap->negative_timeout);
 		cache_unlock(mc);
 		return NSS_STATUS_TRYAGAIN;
 	}
Index: autofs-5.0.9/modules/lookup_nisplus.c
===================================================================
--- autofs-5.0.9.orig/modules/lookup_nisplus.c
+++ autofs-5.0.9/modules/lookup_nisplus.c
@@ -594,24 +594,13 @@ int lookup_mount(struct autofs_point *ap
 	ret = ctxt->parse->parse_mount(ap, key, key_len,
 				       mapent, ctxt->parse->context);
 	if (ret) {
-		time_t now = time(NULL);
-		int rv = CHE_OK;
-
 		free(mapent);
 
 		/* Don't update negative cache when re-connecting */
 		if (ap->flags & MOUNT_FLAG_REMOUNT)
 			return NSS_STATUS_TRYAGAIN;
 		cache_writelock(mc);
-		me = cache_lookup_distinct(mc, key);
-		if (me)
-			rv = cache_push_mapent(me, NULL);
-		else
-			rv = cache_update(mc, source, key, NULL, now);
-		if (rv != CHE_FAIL) {
-			me = cache_lookup_distinct(mc, key);
-			me->status = time(NULL) + ap->negative_timeout;
-		}
+		cache_update_negative(mc, source, key, ap->negative_timeout);
 		cache_unlock(mc);
 		return NSS_STATUS_TRYAGAIN;
 	}
Index: autofs-5.0.9/modules/lookup_program.c
===================================================================
--- autofs-5.0.9.orig/modules/lookup_program.c
+++ autofs-5.0.9/modules/lookup_program.c
@@ -448,20 +448,8 @@ out_free:
 		free(mapent);
 
 	if (ret) {
-		time_t now = time(NULL);
-		int rv = CHE_OK;
-
 		cache_writelock(mc);
-		me = cache_lookup_distinct(mc, name);
-		if (me)
-			rv = cache_push_mapent(me, NULL);
-		else
-			rv = cache_update(mc, source, name, NULL, now);
-		if (rv != CHE_FAIL) {
-			me = cache_lookup_distinct(mc, name);
-			if (me)
-				me->status = now + ap->negative_timeout;
-		}
+		cache_update_negative(mc, source, name, ap->negative_timeout);
 		cache_unlock(mc);
 		return NSS_STATUS_TRYAGAIN;
 	}