1 diff --git a/CHANGELOG b/CHANGELOG
2 index 74d39fd..2c815e7 100644
6 - handle MTAB_NOTUPDATED status return from mount.
7 - when default master map, auto.master, is used also check for auto_master.
8 - fix schema selection in LDAP schema discovery.
9 +- update negative mount timeout handling.
11 18/06/2007 autofs-5.0.2
12 -----------------------
13 diff --git a/daemon/automount.c b/daemon/automount.c
14 index a12b6da..7becad5 100644
15 --- a/daemon/automount.c
16 +++ b/daemon/automount.c
17 @@ -58,6 +58,8 @@ const char *global_options; /* Global option, from command line */
18 static char *pid_file = NULL; /* File in which to keep pid */
19 unsigned int global_random_selection; /* use random policy when selecting
20 * which multi-mount host to mount */
21 +long global_negative_timeout = -1;
23 static int start_pipefd[2];
24 static int st_stat = 0;
25 static int *pst_stat = &st_stat;
26 @@ -1671,6 +1673,8 @@ static void usage(void)
27 " -f --foreground do not fork into background\n"
28 " -r --random-multimount-selection\n"
29 " use ramdom replicated server selection\n"
30 + " -n --negative-timeout n\n"
31 + " set the timeout for failed key lookups.\n"
32 " -O --global-options\n"
33 " specify global mount options\n"
34 " -l --set-log-priority priority path [path,...]\n"
35 @@ -1810,6 +1814,7 @@ int main(int argc, char *argv[])
36 {"define", 1, 0, 'D'},
37 {"foreground", 0, 0, 'f'},
38 {"random-multimount-selection", 0, 0, 'r'},
39 + {"negative-timeout", 1, 0, 'n'},
40 {"global-options", 1, 0, 'O'},
41 {"version", 0, 0, 'V'},
42 {"set-log-priority", 1, 0, 'l'},
43 @@ -1833,7 +1838,7 @@ int main(int argc, char *argv[])
47 - while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:", long_options, NULL)) != EOF) {
48 + while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:", long_options, NULL)) != EOF) {
52 @@ -1871,6 +1876,10 @@ int main(int argc, char *argv[])
53 global_random_selection = 1;
57 + global_negative_timeout = getnumopt(optarg, opt);
61 if (!have_global_options) {
62 global_options = strdup(optarg);
63 diff --git a/include/automount.h b/include/automount.h
64 index b0d1a9c..4887da6 100644
65 --- a/include/automount.h
66 +++ b/include/automount.h
67 @@ -442,6 +442,7 @@ struct autofs_point {
68 unsigned int type; /* Type of map direct or indirect */
69 time_t exp_timeout; /* Timeout for expiring mounts */
70 time_t exp_runfreq; /* Frequency for polling for timeouts */
71 + time_t negative_timeout; /* timeout in secs for failed mounts */
72 unsigned ghost; /* Enable/disable gohsted directories */
73 unsigned logopt; /* Per map logging */
74 pthread_t exp_thread; /* Thread that is expiring */
75 diff --git a/include/defaults.h b/include/defaults.h
76 index e296478..6e4f52a 100644
77 --- a/include/defaults.h
78 +++ b/include/defaults.h
81 #define DEFAULT_MASTER_MAP_NAME "auto.master"
83 -#define DEFAULT_TIMEOUT 600
84 -#define DEFAULT_BROWSE_MODE 1
85 -#define DEFAULT_LOGGING 0
86 +#define DEFAULT_TIMEOUT 600
87 +#define DEFAULT_NEGATIVE_TIMEOUT 60
88 +#define DEFAULT_BROWSE_MODE 1
89 +#define DEFAULT_LOGGING 0
91 #define DEFAULT_LDAP_TIMEOUT -1
92 #define DEFAULT_LDAP_NETWORK_TIMEOUT 8
93 @@ -45,6 +46,7 @@ unsigned int defaults_read_config(unsigned int);
94 const char *defaults_get_master_map(void);
95 int defaults_master_set(void);
96 unsigned int defaults_get_timeout(void);
97 +unsigned int defaults_get_negative_timeout(void);
98 unsigned int defaults_get_browse_mode(void);
99 unsigned int defaults_get_logging(void);
100 const char *defaults_get_ldap_server(void);
101 diff --git a/lib/defaults.c b/lib/defaults.c
102 index f494103..8149549 100644
106 #define ENV_NAME_MASTER_MAP "MASTER_MAP_NAME"
108 #define ENV_NAME_TIMEOUT "TIMEOUT"
109 +#define ENV_NAME_NEGATIVE_TIMEOUT "NEGATIVE_TIMEOUT"
110 #define ENV_NAME_BROWSE_MODE "BROWSE_MODE"
111 #define ENV_NAME_LOGGING "LOGGING"
113 @@ -308,6 +309,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
115 if (check_set_config_value(key, ENV_NAME_MASTER_MAP, value, to_syslog) ||
116 check_set_config_value(key, ENV_NAME_TIMEOUT, value, to_syslog) ||
117 + check_set_config_value(key, ENV_NAME_NEGATIVE_TIMEOUT, value, to_syslog) ||
118 check_set_config_value(key, ENV_NAME_BROWSE_MODE, value, to_syslog) ||
119 check_set_config_value(key, ENV_NAME_LOGGING, value, to_syslog) ||
120 check_set_config_value(key, ENV_LDAP_TIMEOUT, value, to_syslog) ||
121 @@ -370,6 +372,17 @@ unsigned int defaults_get_timeout(void)
122 return (unsigned int) timeout;
125 +unsigned int defaults_get_negative_timeout(void)
129 + n_timeout = get_env_number(ENV_NAME_NEGATIVE_TIMEOUT);
130 + if (n_timeout <= 0)
131 + n_timeout = DEFAULT_NEGATIVE_TIMEOUT;
133 + return (unsigned int) n_timeout;
136 unsigned int defaults_get_browse_mode(void)
139 diff --git a/lib/master.c b/lib/master.c
140 index 2188bca..c001d20 100644
144 /* The root of the map entry tree */
145 struct master *master_list = NULL;
147 +extern long global_negative_timeout;
149 /* Attribute to create detached thread */
150 extern pthread_attr_t thread_attr;
152 @@ -68,6 +70,14 @@ int master_add_autofs_point(struct master_mapent *entry,
154 ap->readmap_thread = 0;
155 ap->exp_timeout = timeout;
157 + * Program command line option overrides config.
158 + * We can't use 0 negative timeout so use default.
160 + if (global_negative_timeout <= 0)
161 + ap->negative_timeout = defaults_get_negative_timeout();
163 + ap->negative_timeout = global_negative_timeout;
164 ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
167 diff --git a/lib/master_parse.y b/lib/master_parse.y
168 index a767f9e..b450122 100644
169 --- a/lib/master_parse.y
170 +++ b/lib/master_parse.y
171 @@ -55,6 +55,7 @@ static char *path;
175 +static long negative_timeout;
176 static unsigned ghost;
177 extern unsigned global_random_selection;
178 static unsigned random_selection;
179 @@ -95,7 +96,8 @@ static int master_fprintf(FILE *, char *, ...);
183 -%token OPT_TIMEOUT OPT_NOGHOST OPT_GHOST OPT_VERBOSE OPT_DEBUG OPT_RANDOM
184 +%token OPT_TIMEOUT OPT_NTIMEOUT OPT_NOGHOST OPT_GHOST OPT_VERBOSE
185 +%token OPT_DEBUG OPT_RANDOM
186 %token COLON COMMA NL DDASH
188 %type <strtype> options
189 @@ -542,6 +544,7 @@ option: daemon_option
192 daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; }
193 + | OPT_NTIMEOUT NUMBER { negative_timeout = $2; }
194 | OPT_NOGHOST { ghost = 0; }
195 | OPT_GHOST { ghost = 1; }
196 | OPT_VERBOSE { verbose = 1; }
197 @@ -603,6 +606,7 @@ static void local_init_vars(void)
201 + negative_timeout = 0;
202 ghost = defaults_get_browse_mode();
203 random_selection = global_random_selection;
205 @@ -793,6 +797,8 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
208 entry->ap->random_selection = random_selection;
209 + if (negative_timeout)
210 + entry->ap->negative_timeout = negative_timeout;
213 source = master_find_map_source(entry, type, format,
214 diff --git a/lib/master_tok.l b/lib/master_tok.l
215 index 36aa785..d908047 100644
216 --- a/lib/master_tok.l
217 +++ b/lib/master_tok.l
218 @@ -118,6 +118,7 @@ MTYPE ((file|program|yp|nis|nisplus|ldap|ldaps|hesiod|userdir)(,(sun|hesiod))?(
221 OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS})
222 +OPTNTOUT (-n{OPTWS}|-n{OPTWS}={OPTWS}|--negative-timeout{OPTWS}|--negative-timeout{OPTWS}={OPTWS})
226 @@ -321,6 +322,8 @@ OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS})
228 {OPTTOUT}/{NUMBER} { return(OPT_TIMEOUT); }
230 + {OPTNTOUT}/{NUMBER} { return(OPT_NTIMEOUT); }
233 master_lval.longtype = atol(master_text);
235 diff --git a/man/auto.master.5.in b/man/auto.master.5.in
236 index 68447e0..d488960 100644
237 --- a/man/auto.master.5.in
238 +++ b/man/auto.master.5.in
239 @@ -152,6 +152,11 @@ Enables the use of ramdom selection when choosing a host from a
240 list of replicated servers. This option is applied to this mount
241 only, overriding the global setting that may be specified on the
244 +.I "\-n, \-\-negative\-timeout <seconds>"
245 +Set the timeout for caching failed key lookups. This option can be
246 +used to override the global default given either on the command line
247 +or in the configuration.
248 .SH GENERAL SYSTEM DEFAULTS CONFIGURATION
250 The default value of several general settings may be changed in the
251 @@ -164,6 +169,11 @@ They are:
253 sets the default mount timeout (program default 600).
256 +Set the default timeout for caching failed key lookups (program default
257 +60). If the equivalent command line option is given it will override this
261 Maps are browsable by default (program default "yes").
263 diff --git a/man/automount.8 b/man/automount.8
264 index 5cd63c7..59ad50e 100644
265 --- a/man/automount.8
266 +++ b/man/automount.8
267 @@ -34,6 +34,9 @@ Set the global minimum timeout, in seconds, until directories
268 are unmounted. The default is 10 minutes. Setting the timeout
269 to zero disables umounts completely.
271 +.I "\-n <seconds>, \-\-negative\-timeout <seconds>"
272 +Set the default timeout for caching failed key lookups. The default is 60 seconds.
274 .I "\-v, \-\-verbose"
275 Enables logging of general status and progress messages for all
276 autofs managed mounts.
277 diff --git a/modules/lookup_file.c b/modules/lookup_file.c
278 index c093415..1007de4 100644
279 --- a/modules/lookup_file.c
280 +++ b/modules/lookup_file.c
281 @@ -1126,7 +1126,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
282 rv = cache_update(mc, source, key, NULL, now);
283 if (rv != CHE_FAIL) {
284 me = cache_lookup_distinct(mc, key);
285 - me->status = now + NEGATIVE_TIMEOUT;
286 + me->status = now + ap->negative_timeout;
290 diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
291 index d746e42..1ef420e 100644
292 --- a/modules/lookup_hosts.c
293 +++ b/modules/lookup_hosts.c
294 @@ -138,7 +138,10 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
297 me = cache_lookup_distinct(mc, name);
299 + if (me && me->status >= time(NULL)) {
301 + return NSS_STATUS_NOTFOUND;
305 * We haven't read the list of hosts into the
306 @@ -192,10 +195,22 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
307 ret = ctxt->parse->parse_mount(ap, name, name_len,
308 mapent, ctxt->parse->context);
311 - return NSS_STATUS_SUCCESS;
313 - return NSS_STATUS_TRYAGAIN;
315 + time_t now = time(NULL);
318 + cache_writelock(mc);
319 + me = cache_lookup_distinct(mc, name);
321 + rv = cache_update(mc, source, name, NULL, now);
322 + if (rv != CHE_FAIL) {
323 + me = cache_lookup_distinct(mc, name);
324 + me->status = now + ap->negative_timeout;
327 + return NSS_STATUS_TRYAGAIN;
329 + return NSS_STATUS_SUCCESS;
333 @@ -267,8 +282,21 @@ done:
334 mapent, ctxt->parse->context);
339 + time_t now = time(NULL);
342 + cache_writelock(mc);
343 + me = cache_lookup_distinct(mc, name);
345 + rv = cache_update(mc, source, name, NULL, now);
346 + if (rv != CHE_FAIL) {
347 + me = cache_lookup_distinct(mc, name);
348 + me->status = now + ap->negative_timeout;
351 return NSS_STATUS_TRYAGAIN;
354 return NSS_STATUS_SUCCESS;
356 diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
357 index 8719af9..4dea3b2 100644
358 --- a/modules/lookup_ldap.c
359 +++ b/modules/lookup_ldap.c
360 @@ -2125,7 +2125,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
361 rv = cache_update(mc, source, key, NULL, now);
362 if (rv != CHE_FAIL) {
363 me = cache_lookup_distinct(mc, key);
364 - me->status = now + NEGATIVE_TIMEOUT;
365 + me->status = now + ap->negative_timeout;
369 diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
370 index bcdaeeb..e948c14 100644
371 --- a/modules/lookup_nisplus.c
372 +++ b/modules/lookup_nisplus.c
373 @@ -547,7 +547,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
374 rv = cache_update(mc, source, key, NULL, now);
375 if (rv != CHE_FAIL) {
376 me = cache_lookup_distinct(mc, key);
377 - me->status = time(NULL) + NEGATIVE_TIMEOUT;
378 + me->status = time(NULL) + ap->negative_timeout;
382 diff --git a/modules/lookup_program.c b/modules/lookup_program.c
383 index e28168e..7c266d6 100644
384 --- a/modules/lookup_program.c
385 +++ b/modules/lookup_program.c
386 @@ -134,7 +134,10 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
387 /* Catch installed direct offset triggers */
389 me = cache_lookup_distinct(mc, name);
391 + if (me && me->status >= time(NULL)) {
393 + return NSS_STATUS_NOTFOUND;
397 * If there's a '/' in the name and the offset is not in
398 @@ -147,15 +150,33 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
403 /* Otherwise we found a valid offset so try mount it */
404 debug(ap->logopt, MODPREFIX "%s -> %s", name, me->mapent);
406 - master_source_current_wait(ap->entry);
407 - ap->entry->current = source;
409 - ret = ctxt->parse->parse_mount(ap, name, name_len,
410 - me->mapent, ctxt->parse->context);
413 + * If this is a request for an offset mount (whose entry
414 + * must be present in the cache to be valid) or the entry
415 + * is newer than the negative timeout value then just
416 + * try and mount it. Otherwise try and remove it and
417 + * proceed with the program map lookup.
419 + if (strchr(name, '/') ||
420 + me->age + ap->negative_timeout > time(NULL)) {
421 + master_source_current_wait(ap->entry);
422 + ap->entry->current = source;
423 + ret = ctxt->parse->parse_mount(ap, name,
424 + name_len, me->mapent, ctxt->parse->context);
428 + warn(ap->logopt, MODPREFIX
429 + "unexpected lookup for active multi-mount"
430 + " key %s, returning fail", name);
431 + return NSS_STATUS_UNAVAIL;
433 + cache_delete(mc, name);
437 mapent = (char *) malloc(MAPENT_MAX_LEN + 1);
438 @@ -356,8 +377,21 @@ out_free:
444 + time_t now = time(NULL);
447 + cache_writelock(mc);
448 + me = cache_lookup_distinct(mc, name);
450 + rv = cache_update(mc, source, name, NULL, now);
451 + if (rv != CHE_FAIL) {
452 + me = cache_lookup_distinct(mc, name);
453 + me->status = now + ap->negative_timeout;
456 return NSS_STATUS_UNAVAIL;
459 return NSS_STATUS_SUCCESS;
461 diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
462 index 7ba6940..6c20145 100644
463 --- a/modules/lookup_yp.c
464 +++ b/modules/lookup_yp.c
465 @@ -639,7 +639,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
466 rv = cache_update(mc, source, key, NULL, now);
467 if (rv != CHE_FAIL) {
468 me = cache_lookup_distinct(mc, key);
469 - me->status = now + NEGATIVE_TIMEOUT;
470 + me->status = now + ap->negative_timeout;
474 diff --git a/redhat/autofs.sysconfig.in b/redhat/autofs.sysconfig.in
475 index f01ee5f..636763a 100644
476 --- a/redhat/autofs.sysconfig.in
477 +++ b/redhat/autofs.sysconfig.in
482 +# NEGATIVE_TIMEOUT - set the default negative timeout for
483 +# failed mount attempts (default 60).
485 +#NEGATIVE_TIMEOUT=60
487 # BROWSE_MODE - maps are browsable by default.
490 diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in
491 index 028341c..086ba4f 100644
492 --- a/samples/autofs.conf.default.in
493 +++ b/samples/autofs.conf.default.in
498 +# NEGATIVE_TIMEOUT - set the default negative timeout for
499 +# failed mount attempts (default 60).
501 +#NEGATIVE_TIMEOUT=60
503 # BROWSE_MODE - maps are browsable by default.