Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 255

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

diff -up autofs-5.0.1/redhat/autofs.sysconfig.in.negative-timeout-update autofs-5.0.1/redhat/autofs.sysconfig.in
--- autofs-5.0.1/redhat/autofs.sysconfig.in.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/redhat/autofs.sysconfig.in	2007-11-12 17:17:08.000000000 +0900
@@ -9,6 +9,11 @@
 #
 TIMEOUT=300
 #
+# NEGATIVE_TIMEOUT - set the default negative timeout for
+# 		     failed mount attempts (default 60).
+#
+#NEGATIVE_TIMEOUT=60
+#
 # BROWSE_MODE - maps are browsable by default.
 #
 BROWSE_MODE="no"
diff -up autofs-5.0.1/include/automount.h.negative-timeout-update autofs-5.0.1/include/automount.h
--- autofs-5.0.1/include/automount.h.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/include/automount.h	2007-11-12 17:16:58.000000000 +0900
@@ -442,6 +442,7 @@ struct autofs_point {
 	unsigned int type;		/* Type of map direct or indirect */
 	time_t exp_timeout;		/* Timeout for expiring mounts */
 	time_t exp_runfreq;		/* Frequency for polling for timeouts */
+	time_t negative_timeout;	/* timeout in secs for failed mounts */
 	unsigned ghost;			/* Enable/disable gohsted directories */
 	unsigned logopt;		/* Per map logging */
 	pthread_t exp_thread;		/* Thread that is expiring */
diff -up autofs-5.0.1/include/defaults.h.negative-timeout-update autofs-5.0.1/include/defaults.h
--- autofs-5.0.1/include/defaults.h.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/include/defaults.h	2007-11-12 17:16:58.000000000 +0900
@@ -22,9 +22,10 @@
 
 #define DEFAULT_MASTER_MAP_NAME	"auto.master"
 
-#define DEFAULT_TIMEOUT		600
-#define DEFAULT_BROWSE_MODE	1
-#define DEFAULT_LOGGING		0
+#define DEFAULT_TIMEOUT			600
+#define DEFAULT_NEGATIVE_TIMEOUT	60
+#define DEFAULT_BROWSE_MODE		1
+#define DEFAULT_LOGGING			0
 
 #define DEFAULT_LDAP_TIMEOUT		-1
 #define DEFAULT_LDAP_NETWORK_TIMEOUT	8
@@ -45,6 +46,7 @@ unsigned int defaults_read_config(unsign
 const char *defaults_get_master_map(void);
 int defaults_master_set(void);
 unsigned int defaults_get_timeout(void);
+unsigned int defaults_get_negative_timeout(void);
 unsigned int defaults_get_browse_mode(void);
 unsigned int defaults_get_logging(void);
 const char *defaults_get_ldap_server(void);
diff -up autofs-5.0.1/modules/lookup_ldap.c.negative-timeout-update autofs-5.0.1/modules/lookup_ldap.c
--- autofs-5.0.1/modules/lookup_ldap.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/modules/lookup_ldap.c	2007-11-12 17:17:08.000000000 +0900
@@ -2125,7 +2125,7 @@ int lookup_mount(struct autofs_point *ap
 				rv = cache_update(mc, source, key, NULL, now);
 			if (rv != CHE_FAIL) {
 				me = cache_lookup_distinct(mc, key);
-				me->status = now + NEGATIVE_TIMEOUT;
+				me->status = now + ap->negative_timeout;
 			}
 			cache_unlock(mc);
 		}
diff -up autofs-5.0.1/modules/lookup_hosts.c.negative-timeout-update autofs-5.0.1/modules/lookup_hosts.c
--- autofs-5.0.1/modules/lookup_hosts.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/modules/lookup_hosts.c	2007-11-12 17:20:29.000000000 +0900
@@ -132,7 +132,10 @@ int lookup_mount(struct autofs_point *ap
 
 	cache_readlock(mc);
 	me = cache_lookup_distinct(mc, name);
-	if (!me) {
+	if (me && me->status >= time(NULL)) {
+		cache_unlock(mc);
+		return NSS_STATUS_NOTFOUND;
+	} else if (!me) {
 		cache_unlock(mc);
 		/*
 		 * We haven't read the list of hosts into the
@@ -185,10 +188,22 @@ int lookup_mount(struct autofs_point *ap
 		ret = ctxt->parse->parse_mount(ap, name, name_len,
 				 mapent, ctxt->parse->context);
 
-		if (!ret)
-			return NSS_STATUS_SUCCESS;
-
-		debug(ap->logopt, MODPREFIX "mount failed - update exports list");
+		if (ret) {
+			time_t now = time(NULL);
+			int rv = CHE_OK;
+
+			cache_writelock(mc);
+			me = cache_lookup_distinct(mc, name);
+			if (!me)
+				rv = cache_update(mc, source, name, NULL, now);
+			if (rv != CHE_FAIL) {
+				me = cache_lookup_distinct(mc, name);
+				me->status = now + ap->negative_timeout;
+			}
+			cache_unlock(mc);
+			return NSS_STATUS_TRYAGAIN;
+		}
+		return NSS_STATUS_SUCCESS;
 	}
 done:
 	/*
@@ -260,8 +275,21 @@ done:
 				 mapent, ctxt->parse->context);
 	free(mapent);
 
-	if (ret)
+	if (ret) {
+		time_t now = time(NULL);
+		int rv = CHE_OK;
+
+		cache_writelock(mc);
+		me = cache_lookup_distinct(mc, name);
+		if (!me)
+			rv = cache_update(mc, source, name, NULL, now);
+		if (rv != CHE_FAIL) {
+			me = cache_lookup_distinct(mc, name);
+			me->status = now + ap->negative_timeout;
+		}
+		cache_unlock(mc);
 		return NSS_STATUS_TRYAGAIN;
+	}
 
 	return NSS_STATUS_SUCCESS;
 }
diff -up autofs-5.0.1/modules/lookup_file.c.negative-timeout-update autofs-5.0.1/modules/lookup_file.c
--- autofs-5.0.1/modules/lookup_file.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/modules/lookup_file.c	2007-11-12 17:17:08.000000000 +0900
@@ -1130,7 +1130,7 @@ int lookup_mount(struct autofs_point *ap
 				rv = cache_update(mc, source, key, NULL, now);
 			if (rv != CHE_FAIL) {
 				me = cache_lookup_distinct(mc, key);
-				me->status = now + NEGATIVE_TIMEOUT;
+				me->status = now + ap->negative_timeout;
 			}
 			cache_unlock(mc);
 		}
diff -up autofs-5.0.1/modules/lookup_program.c.negative-timeout-update autofs-5.0.1/modules/lookup_program.c
--- autofs-5.0.1/modules/lookup_program.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/modules/lookup_program.c	2007-11-12 17:17:08.000000000 +0900
@@ -134,7 +134,10 @@ int lookup_mount(struct autofs_point *ap
 	/* Catch installed direct offset triggers */
 	cache_readlock(mc);
 	me = cache_lookup_distinct(mc, name);
-	if (!me) {
+	if (me && me->status >= time(NULL)) {
+		cache_unlock(mc);
+		return NSS_STATUS_NOTFOUND;
+	} else if (!me) {
 		cache_unlock(mc);
 		/*
 		 * If there's a '/' in the name and the offset is not in
@@ -147,15 +150,33 @@ int lookup_mount(struct autofs_point *ap
 		}
 	} else {
 		cache_unlock(mc);
+
 		/* Otherwise we found a valid offset so try mount it */
 		debug(ap->logopt, MODPREFIX "%s -> %s", name, me->mapent);
 
-		master_source_current_wait(ap->entry);
-		ap->entry->current = source;
-
-		ret = ctxt->parse->parse_mount(ap, name, name_len,
-				      me->mapent, ctxt->parse->context);
-		goto out_free;
+		/*
+		 * If this is a request for an offset mount (whose entry
+		 * must be present in the cache to be valid) or the entry
+		 * is newer than the negative timeout value then just
+		 * try and mount it. Otherwise try and remove it and
+		 * proceed with the program map lookup.
+		 */
+		if (strchr(name, '/') ||
+		    me->age + ap->negative_timeout > time(NULL)) {
+			master_source_current_wait(ap->entry);
+			ap->entry->current = source;
+			ret = ctxt->parse->parse_mount(ap, name,
+				 name_len, me->mapent, ctxt->parse->context);
+			goto out_free;
+		} else {
+			if (me->multi) {
+				warn(ap->logopt, MODPREFIX
+				     "unexpected lookup for active multi-mount"
+				     " key %s, returning fail", name);
+				return NSS_STATUS_UNAVAIL;
+			}
+			cache_delete(mc, name);
+		}
 	}
 
 	mapent = (char *) malloc(MAPENT_MAX_LEN + 1);
@@ -352,8 +373,21 @@ out_free:
 	if (mapent)
 		free(mapent);
 
-	if (ret)
+	if (ret) {
+		time_t now = time(NULL);
+		int rv = CHE_OK;
+
+		cache_writelock(mc);
+		me = cache_lookup_distinct(mc, name);
+		if (!me)
+			rv = cache_update(mc, source, name, NULL, now);
+		if (rv != CHE_FAIL) {
+			me = cache_lookup_distinct(mc, name);
+			me->status = now + ap->negative_timeout;
+		}
+		cache_unlock(mc);
 		return NSS_STATUS_UNAVAIL;
+	}
 
 	return NSS_STATUS_SUCCESS;
 }
diff -up autofs-5.0.1/modules/lookup_yp.c.negative-timeout-update autofs-5.0.1/modules/lookup_yp.c
--- autofs-5.0.1/modules/lookup_yp.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/modules/lookup_yp.c	2007-11-12 17:17:08.000000000 +0900
@@ -639,7 +639,7 @@ int lookup_mount(struct autofs_point *ap
 				rv = cache_update(mc, source, key, NULL, now);
 			if (rv != CHE_FAIL) {
 				me = cache_lookup_distinct(mc, key);
-				me->status = now + NEGATIVE_TIMEOUT;
+				me->status = now + ap->negative_timeout;
 			}
 			cache_unlock(mc);
 		}
diff -up autofs-5.0.1/modules/lookup_nisplus.c.negative-timeout-update autofs-5.0.1/modules/lookup_nisplus.c
--- autofs-5.0.1/modules/lookup_nisplus.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/modules/lookup_nisplus.c	2007-11-12 17:17:08.000000000 +0900
@@ -547,7 +547,7 @@ int lookup_mount(struct autofs_point *ap
 				rv = cache_update(mc, source, key, NULL, now);
 			if (rv != CHE_FAIL) {
 				me = cache_lookup_distinct(mc, key);
-				me->status = time(NULL) + NEGATIVE_TIMEOUT;
+				me->status = time(NULL) + ap->negative_timeout;
 			}
 			cache_unlock(mc);
 		}
diff -up autofs-5.0.1/samples/autofs.conf.default.in.negative-timeout-update autofs-5.0.1/samples/autofs.conf.default.in
--- autofs-5.0.1/samples/autofs.conf.default.in.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/samples/autofs.conf.default.in	2007-11-12 17:17:08.000000000 +0900
@@ -9,6 +9,11 @@
 #
 TIMEOUT=300
 #
+# NEGATIVE_TIMEOUT - set the default negative timeout for
+# 		     failed mount attempts (default 60).
+#
+#NEGATIVE_TIMEOUT=60
+#
 # BROWSE_MODE - maps are browsable by default.
 #
 BROWSE_MODE="no"
diff -up autofs-5.0.1/daemon/automount.c.negative-timeout-update autofs-5.0.1/daemon/automount.c
--- autofs-5.0.1/daemon/automount.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/daemon/automount.c	2007-11-12 17:16:58.000000000 +0900
@@ -57,6 +57,8 @@ const char *global_options;		/* Global o
 static char *pid_file = NULL;		/* File in which to keep pid */
 unsigned int global_random_selection;	/* use random policy when selecting
 					 * which multi-mount host to mount */
+long global_negative_timeout = -1;
+
 static int start_pipefd[2];
 static int st_stat = 0;
 static int *pst_stat = &st_stat;
@@ -1648,6 +1650,8 @@ static void usage(void)
 		"	-f --foreground do not fork into background\n"
 		"	-r --random-multimount-selection\n"
 		"			use ramdom replicated server selection\n"
+		"	-n --negative-timeout n\n"
+		"			set the timeout for failed key lookups.\n"
 		"	-O --global-options\n"
 		"			specify global mount options\n"
 		"	-l --set-log-priority priority path [path,...]\n"
@@ -1787,6 +1791,7 @@ int main(int argc, char *argv[])
 		{"define", 1, 0, 'D'},
 		{"foreground", 0, 0, 'f'},
 		{"random-multimount-selection", 0, 0, 'r'},
+		{"negative-timeout", 1, 0, 'n'},
 		{"global-options", 1, 0, 'O'},
 		{"version", 0, 0, 'V'},
 		{"set-log-priority", 1, 0, 'l'},
@@ -1809,7 +1814,7 @@ int main(int argc, char *argv[])
 	foreground = 0;
 
 	opterr = 0;
-	while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:", long_options, NULL)) != EOF) {
+	while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:", long_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage();
@@ -1847,6 +1852,10 @@ int main(int argc, char *argv[])
 			global_random_selection = 1;
 			break;
 
+		case 'n':
+			global_negative_timeout = getnumopt(optarg, opt);
+			break;
+
 		case 'O':
 			if (!have_global_options) {
 				global_options = strdup(optarg);
diff -up autofs-5.0.1/lib/master_tok.l.negative-timeout-update autofs-5.0.1/lib/master_tok.l
--- autofs-5.0.1/lib/master_tok.l.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/lib/master_tok.l	2007-11-12 17:16:58.000000000 +0900
@@ -120,6 +120,7 @@ MTYPE		((file|program|yp|nis|nisplus|lda
 
 
 OPTTOUT		(-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS})
+OPTNTOUT	(-n{OPTWS}|-n{OPTWS}={OPTWS}|--negative-timeout{OPTWS}|--negative-timeout{OPTWS}={OPTWS})
 
 %%
 
@@ -325,6 +326,8 @@ OPTTOUT		(-t{OPTWS}|-t{OPTWS}={OPTWS}|--
 
 	-D{OPTWS}
 
+	{OPTNTOUT}/{NUMBER} { return(OPT_NTIMEOUT); }
+
 	{NUMBER} {
 		master_lval.longtype = atol(master_text);
 		return(NUMBER);
diff -up autofs-5.0.1/lib/defaults.c.negative-timeout-update autofs-5.0.1/lib/defaults.c
--- autofs-5.0.1/lib/defaults.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/lib/defaults.c	2007-11-12 17:16:58.000000000 +0900
@@ -28,6 +28,7 @@
 #define ENV_NAME_MASTER_MAP		"MASTER_MAP_NAME"
 
 #define ENV_NAME_TIMEOUT		"TIMEOUT"
+#define ENV_NAME_NEGATIVE_TIMEOUT	"NEGATIVE_TIMEOUT"
 #define ENV_NAME_BROWSE_MODE		"BROWSE_MODE"
 #define ENV_NAME_LOGGING		"LOGGING"
 
@@ -308,6 +309,7 @@ unsigned int defaults_read_config(unsign
 
 		if (check_set_config_value(key, ENV_NAME_MASTER_MAP, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_TIMEOUT, value, to_syslog) ||
+		    check_set_config_value(key, ENV_NAME_NEGATIVE_TIMEOUT, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_BROWSE_MODE, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_LOGGING, value, to_syslog) ||
 		    check_set_config_value(key, ENV_LDAP_TIMEOUT, value, to_syslog) ||
@@ -370,6 +372,17 @@ unsigned int defaults_get_timeout(void)
 	return (unsigned int) timeout;
 }
 
+unsigned int defaults_get_negative_timeout(void)
+{
+	long n_timeout;
+
+	n_timeout = get_env_number(ENV_NAME_NEGATIVE_TIMEOUT);
+	if (n_timeout <= 0)
+		n_timeout = DEFAULT_NEGATIVE_TIMEOUT;
+
+	return (unsigned int) n_timeout;
+}
+
 unsigned int defaults_get_browse_mode(void)
 {
 	int res;
diff -up autofs-5.0.1/lib/master_parse.y.negative-timeout-update autofs-5.0.1/lib/master_parse.y
--- autofs-5.0.1/lib/master_parse.y.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/lib/master_parse.y	2007-11-12 17:16:58.000000000 +0900
@@ -57,6 +57,7 @@ static char *path;
 static char *type;
 static char *format;
 static long timeout;
+static long negative_timeout;
 static unsigned ghost;
 extern unsigned global_random_selection;
 static unsigned random_selection;
@@ -97,7 +98,8 @@ static int master_fprintf(FILE *, char *
 
 %token COMMENT
 %token MAP
-%token OPT_TIMEOUT OPT_NOGHOST OPT_GHOST OPT_VERBOSE OPT_DEBUG OPT_RANDOM
+%token OPT_TIMEOUT OPT_NTIMEOUT OPT_NOGHOST OPT_GHOST OPT_VERBOSE
+%token OPT_DEBUG OPT_RANDOM
 %token COLON COMMA NL DDASH
 %type <strtype> map
 %type <strtype> options
@@ -544,6 +546,7 @@ option: daemon_option
 	;
 
 daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; }
+	| OPT_NTIMEOUT NUMBER { negative_timeout = $2; }
 	| OPT_NOGHOST	{ ghost = 0; }
 	| OPT_GHOST	{ ghost = 1; }
 	| OPT_VERBOSE	{ verbose = 1; }
@@ -605,6 +608,7 @@ static void local_init_vars(void)
 	verbose = 0;
 	debug = 0;
 	timeout = -1;
+	negative_timeout = 0;
 	ghost = defaults_get_browse_mode();
 	random_selection = global_random_selection;
 	tmp_argv = NULL;
@@ -795,6 +799,8 @@ int master_parse_entry(const char *buffe
 		}
 	}
 	entry->ap->random_selection = random_selection;
+	if (negative_timeout)
+		entry->ap->negative_timeout = negative_timeout;
 
 /*
 	source = master_find_map_source(entry, type, format,
diff -up autofs-5.0.1/lib/master.c.negative-timeout-update autofs-5.0.1/lib/master.c
--- autofs-5.0.1/lib/master.c.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/lib/master.c	2007-11-12 17:16:58.000000000 +0900
@@ -30,6 +30,8 @@
 /* The root of the map entry tree */
 struct master *master_list = NULL;
 
+extern long global_negative_timeout;
+
 /* Attribute to create detached thread */
 extern pthread_attr_t thread_attr;
 
@@ -68,6 +70,14 @@ int master_add_autofs_point(struct maste
 	ap->exp_thread = 0;
 	ap->readmap_thread = 0;
 	ap->exp_timeout = timeout;
+	/*
+	 * Program command line option overrides config.
+	 * We can't use 0 negative timeout so use default.
+	 */
+	if (global_negative_timeout <= 0)
+		ap->negative_timeout = defaults_get_negative_timeout();
+	else
+		ap->negative_timeout = global_negative_timeout;
 	ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
 	ap->ghost = ghost;
 
diff -up autofs-5.0.1/man/auto.master.5.in.negative-timeout-update autofs-5.0.1/man/auto.master.5.in
--- autofs-5.0.1/man/auto.master.5.in.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/man/auto.master.5.in	2007-11-12 17:16:58.000000000 +0900
@@ -153,6 +153,11 @@ Enables the use of ramdom selection when
 list of replicated servers. This option is applied to this mount
 only, overriding the global setting that may be specified on the
 command line.
+.TP
+.I "\-n, \-\-negative\-timeout <seconds>"
+Set the timeout for caching failed key lookups. This option can be
+used to override the global default given either on the command line
+or in the configuration.
 .SH GENERAL SYSTEM DEFAULTS CONFIGURATION
 .P
 The default value of several general settings may be changed in the
@@ -165,6 +170,11 @@ They are:
 .B TIMEOUT
 sets the default mount timeout (program default 600).
 .TP
+.B NEGATIVE_TIMEOUT
+Set the default timeout for caching failed key lookups (program default
+60). If the equivalent command line option is given it will override this
+setting.
+.TP
 .B BROWSE_MODE
 Maps are browsable by default (program default "yes").
 .TP
diff -up autofs-5.0.1/man/automount.8.in.negative-timeout-update autofs-5.0.1/man/automount.8.in
--- autofs-5.0.1/man/automount.8.in.negative-timeout-update	2007-11-12 17:14:40.000000000 +0900
+++ autofs-5.0.1/man/automount.8.in	2007-11-12 17:17:08.000000000 +0900
@@ -36,6 +36,9 @@ Set the global minimum timeout, in secon
 are unmounted. The default is 10 minutes. Setting the timeout
 to zero disables umounts completely.
 .TP
+.I "\-n <seconds>, \-\-negative\-timeout <seconds>"
+Set the default timeout for caching failed key lookups. The default is 60 seconds.
+.TP
 .I "\-v, \-\-verbose"
 Enables logging of general status and progress messages for all
 autofs managed mounts.