]> git.pld-linux.org Git - packages/autofs.git/blame - autofs-5.0.2-negative-timeout-update.patch
- 5.0.3 with few official patches. ldap fixes needed
[packages/autofs.git] / autofs-5.0.2-negative-timeout-update.patch
CommitLineData
3d551623
PG
1diff --git a/CHANGELOG b/CHANGELOG
2index 74d39fd..2c815e7 100644
3--- a/CHANGELOG
4+++ b/CHANGELOG
5@@ -42,6 +42,7 @@
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.
10
11 18/06/2007 autofs-5.0.2
12 -----------------------
13diff --git a/daemon/automount.c b/daemon/automount.c
14index 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;
22+
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[])
44 foreground = 0;
45
46 opterr = 0;
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) {
49 switch (opt) {
50 case 'h':
51 usage();
52@@ -1871,6 +1876,10 @@ int main(int argc, char *argv[])
53 global_random_selection = 1;
54 break;
55
56+ case 'n':
57+ global_negative_timeout = getnumopt(optarg, opt);
58+ break;
59+
60 case 'O':
61 if (!have_global_options) {
62 global_options = strdup(optarg);
63diff --git a/include/automount.h b/include/automount.h
64index 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 */
75diff --git a/include/defaults.h b/include/defaults.h
76index e296478..6e4f52a 100644
77--- a/include/defaults.h
78+++ b/include/defaults.h
79@@ -22,9 +22,10 @@
80
81 #define DEFAULT_MASTER_MAP_NAME "auto.master"
82
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
90
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);
101diff --git a/lib/defaults.c b/lib/defaults.c
102index f494103..8149549 100644
103--- a/lib/defaults.c
104+++ b/lib/defaults.c
105@@ -28,6 +28,7 @@
106 #define ENV_NAME_MASTER_MAP "MASTER_MAP_NAME"
107
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"
112
113@@ -308,6 +309,7 @@ unsigned int defaults_read_config(unsigned int to_syslog)
114
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;
123 }
124
125+unsigned int defaults_get_negative_timeout(void)
126+{
127+ long n_timeout;
128+
129+ n_timeout = get_env_number(ENV_NAME_NEGATIVE_TIMEOUT);
130+ if (n_timeout <= 0)
131+ n_timeout = DEFAULT_NEGATIVE_TIMEOUT;
132+
133+ return (unsigned int) n_timeout;
134+}
135+
136 unsigned int defaults_get_browse_mode(void)
137 {
138 int res;
139diff --git a/lib/master.c b/lib/master.c
140index 2188bca..c001d20 100644
141--- a/lib/master.c
142+++ b/lib/master.c
143@@ -30,6 +30,8 @@
144 /* The root of the map entry tree */
145 struct master *master_list = NULL;
146
147+extern long global_negative_timeout;
148+
149 /* Attribute to create detached thread */
150 extern pthread_attr_t thread_attr;
151
152@@ -68,6 +70,14 @@ int master_add_autofs_point(struct master_mapent *entry,
153 ap->exp_thread = 0;
154 ap->readmap_thread = 0;
155 ap->exp_timeout = timeout;
156+ /*
157+ * Program command line option overrides config.
158+ * We can't use 0 negative timeout so use default.
159+ */
160+ if (global_negative_timeout <= 0)
161+ ap->negative_timeout = defaults_get_negative_timeout();
162+ else
163+ ap->negative_timeout = global_negative_timeout;
164 ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
165 ap->ghost = ghost;
166
167diff --git a/lib/master_parse.y b/lib/master_parse.y
168index a767f9e..b450122 100644
169--- a/lib/master_parse.y
170+++ b/lib/master_parse.y
171@@ -55,6 +55,7 @@ static char *path;
172 static char *type;
173 static char *format;
174 static long timeout;
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 *, ...);
180
181 %token COMMENT
182 %token MAP
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
187 %type <strtype> map
188 %type <strtype> options
189@@ -542,6 +544,7 @@ option: daemon_option
190 ;
191
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)
198 verbose = 0;
199 debug = 0;
200 timeout = -1;
201+ negative_timeout = 0;
202 ghost = defaults_get_browse_mode();
203 random_selection = global_random_selection;
204 tmp_argv = NULL;
205@@ -793,6 +797,8 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
206 }
207 }
208 entry->ap->random_selection = random_selection;
209+ if (negative_timeout)
210+ entry->ap->negative_timeout = negative_timeout;
211
212 /*
213 source = master_find_map_source(entry, type, format,
214diff --git a/lib/master_tok.l b/lib/master_tok.l
215index 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))?(
219
220
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})
223
224 %%
225
226@@ -321,6 +322,8 @@ OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS})
227
228 {OPTTOUT}/{NUMBER} { return(OPT_TIMEOUT); }
229
230+ {OPTNTOUT}/{NUMBER} { return(OPT_NTIMEOUT); }
231+
232 {NUMBER} {
233 master_lval.longtype = atol(master_text);
234 return(NUMBER);
235diff --git a/man/auto.master.5.in b/man/auto.master.5.in
236index 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
242 command line.
243+.TP
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
249 .P
250 The default value of several general settings may be changed in the
251@@ -164,6 +169,11 @@ They are:
252 .B TIMEOUT
253 sets the default mount timeout (program default 600).
254 .TP
255+.B NEGATIVE_TIMEOUT
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
258+setting.
259+.TP
260 .B BROWSE_MODE
261 Maps are browsable by default (program default "yes").
262 .TP
263diff --git a/man/automount.8 b/man/automount.8
264index 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.
270 .TP
271+.I "\-n <seconds>, \-\-negative\-timeout <seconds>"
272+Set the default timeout for caching failed key lookups. The default is 60 seconds.
273+.TP
274 .I "\-v, \-\-verbose"
275 Enables logging of general status and progress messages for all
276 autofs managed mounts.
277diff --git a/modules/lookup_file.c b/modules/lookup_file.c
278index 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;
287 }
288 cache_unlock(mc);
289 }
290diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
291index 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 *
295
296 cache_readlock(mc);
297 me = cache_lookup_distinct(mc, name);
298- if (!me) {
299+ if (me && me->status >= time(NULL)) {
300+ cache_unlock(mc);
301+ return NSS_STATUS_NOTFOUND;
302+ } else if (!me) {
303 cache_unlock(mc);
304 /*
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);
309
310- if (!ret)
311- return NSS_STATUS_SUCCESS;
312-
313- return NSS_STATUS_TRYAGAIN;
314+ if (ret) {
315+ time_t now = time(NULL);
316+ int rv = CHE_OK;
317+
318+ cache_writelock(mc);
319+ me = cache_lookup_distinct(mc, name);
320+ if (!me)
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;
325+ }
326+ cache_unlock(mc);
327+ return NSS_STATUS_TRYAGAIN;
328+ }
329+ return NSS_STATUS_SUCCESS;
330 }
331 done:
332 /*
333@@ -267,8 +282,21 @@ done:
334 mapent, ctxt->parse->context);
335 free(mapent);
336
337- if (ret)
338+ if (ret) {
339+ time_t now = time(NULL);
340+ int rv = CHE_OK;
341+
342+ cache_writelock(mc);
343+ me = cache_lookup_distinct(mc, name);
344+ if (!me)
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;
349+ }
350+ cache_unlock(mc);
351 return NSS_STATUS_TRYAGAIN;
352+ }
353
354 return NSS_STATUS_SUCCESS;
355 }
356diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
357index 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;
366 }
367 cache_unlock(mc);
368 }
369diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
370index 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;
379 }
380 cache_unlock(mc);
381 }
382diff --git a/modules/lookup_program.c b/modules/lookup_program.c
383index 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 */
388 cache_readlock(mc);
389 me = cache_lookup_distinct(mc, name);
390- if (!me) {
391+ if (me && me->status >= time(NULL)) {
392+ cache_unlock(mc);
393+ return NSS_STATUS_NOTFOUND;
394+ } else if (!me) {
395 cache_unlock(mc);
396 /*
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 *
399 }
400 } else {
401 cache_unlock(mc);
402+
403 /* Otherwise we found a valid offset so try mount it */
404 debug(ap->logopt, MODPREFIX "%s -> %s", name, me->mapent);
405
406- master_source_current_wait(ap->entry);
407- ap->entry->current = source;
408-
409- ret = ctxt->parse->parse_mount(ap, name, name_len,
410- me->mapent, ctxt->parse->context);
411- goto out_free;
412+ /*
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.
418+ */
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);
425+ goto out_free;
426+ } else {
427+ if (me->multi) {
428+ warn(ap->logopt, MODPREFIX
429+ "unexpected lookup for active multi-mount"
430+ " key %s, returning fail", name);
431+ return NSS_STATUS_UNAVAIL;
432+ }
433+ cache_delete(mc, name);
434+ }
435 }
436
437 mapent = (char *) malloc(MAPENT_MAX_LEN + 1);
438@@ -356,8 +377,21 @@ out_free:
439 if (mapent)
440 free(mapent);
441
442- if (ret)
443+ if (ret) {
444+ time_t now = time(NULL);
445+ int rv = CHE_OK;
446+
447+ cache_writelock(mc);
448+ me = cache_lookup_distinct(mc, name);
449+ if (!me)
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;
454+ }
455+ cache_unlock(mc);
456 return NSS_STATUS_UNAVAIL;
457+ }
458
459 return NSS_STATUS_SUCCESS;
460 }
461diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c
462index 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;
471 }
472 cache_unlock(mc);
473 }
474diff --git a/redhat/autofs.sysconfig.in b/redhat/autofs.sysconfig.in
475index f01ee5f..636763a 100644
476--- a/redhat/autofs.sysconfig.in
477+++ b/redhat/autofs.sysconfig.in
478@@ -9,6 +9,11 @@
479 #
480 TIMEOUT=300
481 #
482+# NEGATIVE_TIMEOUT - set the default negative timeout for
483+# failed mount attempts (default 60).
484+#
485+#NEGATIVE_TIMEOUT=60
486+#
487 # BROWSE_MODE - maps are browsable by default.
488 #
489 BROWSE_MODE="no"
490diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in
491index 028341c..086ba4f 100644
492--- a/samples/autofs.conf.default.in
493+++ b/samples/autofs.conf.default.in
494@@ -9,6 +9,11 @@
495 #
496 TIMEOUT=300
497 #
498+# NEGATIVE_TIMEOUT - set the default negative timeout for
499+# failed mount attempts (default 60).
500+#
501+#NEGATIVE_TIMEOUT=60
502+#
503 # BROWSE_MODE - maps are browsable by default.
504 #
505 BROWSE_MODE="no"
This page took 2.633649 seconds and 4 git commands to generate.