libmultipath: dict.c: rename duplicate set_no_path_retry()
[multipath-tools/.git] / libmultipath / dict.c
1 /*
2  * Based on Alexandre Cassen template for keepalived
3  * Copyright (c) 2004, 2005, 2006  Christophe Varoqui
4  * Copyright (c) 2005 Benjamin Marzinski, Redhat
5  * Copyright (c) 2005 Kiyoshi Ueda, NEC
6  */
7 #include <sys/types.h>
8 #include <pwd.h>
9 #include <string.h>
10 #include "checkers.h"
11 #include "vector.h"
12 #include "hwtable.h"
13 #include "structs.h"
14 #include "parser.h"
15 #include "config.h"
16 #include "debug.h"
17 #include "memory.h"
18 #include "pgpolicies.h"
19 #include "blacklist.h"
20 #include "defaults.h"
21 #include "prio.h"
22 #include "util.h"
23 #include <errno.h>
24 #include <inttypes.h>
25 #include <libudev.h>
26 #include <mpath_persist.h>
27 #include "mpath_cmd.h"
28 #include "dict.h"
29
30 static int
31 set_int(vector strvec, void *ptr)
32 {
33         int *int_ptr = (int *)ptr;
34         char *buff, *eptr;
35         long res;
36         int rc;
37
38         buff = set_value(strvec);
39         if (!buff)
40                 return 1;
41
42         res = strtol(buff, &eptr, 10);
43         if (eptr > buff)
44                 while (isspace(*eptr))
45                         eptr++;
46         if (*buff == '\0' || *eptr != '\0' || res > INT_MAX || res < INT_MIN) {
47                 condlog(1, "%s: invalid value for %s: \"%s\"",
48                         __func__, (char*)VECTOR_SLOT(strvec, 0), buff);
49                 rc = 1;
50         } else {
51                 rc = 0;
52                 *int_ptr = res;
53         }
54
55         FREE(buff);
56         return rc;
57 }
58
59 static int
60 set_uint(vector strvec, void *ptr)
61 {
62         unsigned int *uint_ptr = (unsigned int *)ptr;
63         char *buff, *eptr;
64         long res;
65         int rc;
66
67         buff = set_value(strvec);
68         if (!buff)
69                 return 1;
70
71         res = strtol(buff, &eptr, 10);
72         if (eptr > buff)
73                 while (isspace(*eptr))
74                         eptr++;
75         if (*buff == '\0' || *eptr != '\0' || res < 0 || res > UINT_MAX) {
76                 condlog(1, "%s: invalid value for %s: \"%s\"",
77                         __func__, (char*)VECTOR_SLOT(strvec, 0), buff);
78                 rc = 1;
79         } else {
80                 rc = 0;
81                 *uint_ptr = res;
82         }
83
84         FREE(buff);
85         return rc;
86 }
87
88 static int
89 set_str(vector strvec, void *ptr)
90 {
91         char **str_ptr = (char **)ptr;
92
93         if (*str_ptr)
94                 FREE(*str_ptr);
95         *str_ptr = set_value(strvec);
96
97         if (!*str_ptr)
98                 return 1;
99
100         return 0;
101 }
102
103 static int
104 set_yes_no(vector strvec, void *ptr)
105 {
106         char * buff;
107         int *int_ptr = (int *)ptr;
108
109         buff = set_value(strvec);
110         if (!buff)
111                 return 1;
112
113         if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
114                 *int_ptr = YN_YES;
115         else
116                 *int_ptr = YN_NO;
117
118         FREE(buff);
119         return 0;
120 }
121
122 static int
123 set_yes_no_undef(vector strvec, void *ptr)
124 {
125         char * buff;
126         int *int_ptr = (int *)ptr;
127
128         buff = set_value(strvec);
129         if (!buff)
130                 return 1;
131
132         if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
133                 *int_ptr = YNU_NO;
134         else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
135                 *int_ptr = YNU_YES;
136         else
137                 *int_ptr = YNU_UNDEF;
138
139         FREE(buff);
140         return 0;
141 }
142
143 static int
144 print_int (char *buff, int len, long v)
145 {
146         return snprintf(buff, len, "%li", v);
147 }
148
149 static int
150 print_nonzero (char *buff, int len, long v)
151 {
152         if (!v)
153                 return 0;
154         return snprintf(buff, len, "%li", v);
155 }
156
157 static int
158 print_str (char *buff, int len, const char *ptr)
159 {
160         char *p;
161         char *last;
162         const char *q;
163
164         if (!ptr || len <= 0)
165                 return 0;
166
167         q = strchr(ptr, '"');
168         if (q == NULL)
169                 return snprintf(buff, len, "\"%s\"", ptr);
170
171         last = buff + len - 1;
172         p = buff;
173         if (p >= last)
174                 goto out;
175         *p++ = '"';
176         if (p >= last)
177                 goto out;
178         for (; q; q = strchr(ptr, '"')) {
179                 if (q + 1 - ptr < last - p)
180                         p = mempcpy(p, ptr, q + 1 - ptr);
181                 else {
182                         p = mempcpy(p, ptr, last - p);
183                         goto out;
184                 }
185                 *p++ = '"';
186                 if (p >= last)
187                         goto out;
188                 ptr = q + 1;
189         }
190         p += strlcpy(p, ptr, last - p);
191         if (p >= last)
192                 goto out;
193         *p++ = '"';
194         *p = '\0';
195         return p - buff;
196 out:
197         *p = '\0';
198         return len;
199 }
200
201 static int
202 print_ignored (char *buff, int len)
203 {
204         return snprintf(buff, len, "ignored");
205 }
206
207 static int
208 print_yes_no (char *buff, int len, long v)
209 {
210         return snprintf(buff, len, "\"%s\"",
211                         (v == YN_NO)? "no" : "yes");
212 }
213
214 static int
215 print_yes_no_undef (char *buff, int len, long v)
216 {
217         if (!v)
218                 return 0;
219         return snprintf(buff, len, "\"%s\"",
220                         (v == YNU_NO)? "no" : "yes");
221 }
222
223 #define declare_def_handler(option, function)                           \
224 static int                                                              \
225 def_ ## option ## _handler (struct config *conf, vector strvec)         \
226 {                                                                       \
227         return function (strvec, &conf->option);                        \
228 }
229
230 #define declare_def_snprint(option, function)                           \
231 static int                                                              \
232 snprint_def_ ## option (struct config *conf, char * buff, int len,      \
233                         const void * data)                              \
234 {                                                                       \
235         return function (buff, len, conf->option);                      \
236 }
237
238 #define declare_def_snprint_defint(option, function, value)             \
239 static int                                                              \
240 snprint_def_ ## option (struct config *conf, char * buff, int len,      \
241                         const void * data)                              \
242 {                                                                       \
243         int i = value;                                                  \
244         if (!conf->option)                                              \
245                 return function (buff, len, i);                         \
246         return function (buff, len, conf->option);                      \
247 }
248
249 #define declare_def_snprint_defstr(option, function, value)             \
250 static int                                                              \
251 snprint_def_ ## option (struct config *conf, char * buff, int len,      \
252                         const void * data)                              \
253 {                                                                       \
254         static const char *s = value;                                   \
255         if (!conf->option)                                              \
256                 return function (buff, len, s);                         \
257         return function (buff, len, conf->option);                      \
258 }
259
260 #define declare_hw_handler(option, function)                            \
261 static int                                                              \
262 hw_ ## option ## _handler (struct config *conf, vector strvec)          \
263 {                                                                       \
264         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);         \
265         if (!hwe)                                                       \
266                 return 1;                                               \
267         return function (strvec, &hwe->option);                         \
268 }
269
270 #define declare_hw_snprint(option, function)                            \
271 static int                                                              \
272 snprint_hw_ ## option (struct config *conf, char * buff, int len,       \
273                        const void * data)                               \
274 {                                                                       \
275         const struct hwentry * hwe = (const struct hwentry *)data;      \
276         return function (buff, len, hwe->option);                       \
277 }
278
279 #define declare_ovr_handler(option, function)                           \
280 static int                                                              \
281 ovr_ ## option ## _handler (struct config *conf, vector strvec)         \
282 {                                                                       \
283         if (!conf->overrides)                                           \
284                 return 1;                                               \
285         return function (strvec, &conf->overrides->option);             \
286 }
287
288 #define declare_ovr_snprint(option, function)                           \
289 static int                                                              \
290 snprint_ovr_ ## option (struct config *conf, char * buff, int len,      \
291                         const void * data)                              \
292 {                                                                       \
293         return function (buff, len, conf->overrides->option);           \
294 }
295
296 #define declare_mp_handler(option, function)                            \
297 static int                                                              \
298 mp_ ## option ## _handler (struct config *conf, vector strvec)          \
299 {                                                                       \
300         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);         \
301         if (!mpe)                                                       \
302                 return 1;                                               \
303         return function (strvec, &mpe->option);                         \
304 }
305
306 #define declare_mp_snprint(option, function)                            \
307 static int                                                              \
308 snprint_mp_ ## option (struct config *conf, char * buff, int len,       \
309                        const void * data)                               \
310 {                                                                       \
311         const struct mpentry * mpe = (const struct mpentry *)data;      \
312         return function (buff, len, mpe->option);                       \
313 }
314
315 static int checkint_handler(struct config *conf, vector strvec)
316 {
317         int rc = set_uint(strvec, &conf->checkint);
318
319         if (rc)
320                 return rc;
321         if (conf->checkint == CHECKINT_UNDEF)
322                 conf->checkint--;
323         return 0;
324 }
325
326 declare_def_snprint(checkint, print_int)
327
328 declare_def_handler(max_checkint, set_uint)
329 declare_def_snprint(max_checkint, print_int)
330
331 declare_def_handler(verbosity, set_int)
332 declare_def_snprint(verbosity, print_int)
333
334 declare_def_handler(reassign_maps, set_yes_no)
335 declare_def_snprint(reassign_maps, print_yes_no)
336
337 declare_def_handler(multipath_dir, set_str)
338 declare_def_snprint(multipath_dir, print_str)
339
340 static int def_partition_delim_handler(struct config *conf, vector strvec)
341 {
342         int rc = set_str(strvec, &conf->partition_delim);
343
344         if (rc != 0)
345                 return rc;
346
347         if (!strcmp(conf->partition_delim, UNSET_PARTITION_DELIM)) {
348                 FREE(conf->partition_delim);
349                 conf->partition_delim = NULL;
350         }
351         return 0;
352 }
353
354 static int snprint_def_partition_delim(struct config *conf, char *buff,
355                                        int len, const void *data)
356 {
357         if (default_partition_delim == NULL || conf->partition_delim != NULL)
358                 return print_str(buff, len, conf->partition_delim);
359         else
360                 return print_str(buff, len, UNSET_PARTITION_DELIM);
361 }
362
363 static const char * const find_multipaths_optvals[] = {
364         [FIND_MULTIPATHS_OFF] = "off",
365         [FIND_MULTIPATHS_ON] = "on",
366         [FIND_MULTIPATHS_STRICT] = "strict",
367         [FIND_MULTIPATHS_GREEDY] = "greedy",
368         [FIND_MULTIPATHS_SMART] = "smart",
369 };
370
371 static int
372 def_find_multipaths_handler(struct config *conf, vector strvec)
373 {
374         char *buff;
375         int i;
376
377         if (set_yes_no_undef(strvec, &conf->find_multipaths) == 0 &&
378             conf->find_multipaths != FIND_MULTIPATHS_UNDEF)
379                 return 0;
380
381         buff = set_value(strvec);
382         if (!buff)
383                 return 1;
384
385         for (i = FIND_MULTIPATHS_OFF; i < __FIND_MULTIPATHS_LAST; i++) {
386                 if (find_multipaths_optvals[i] != NULL &&
387                     !strcmp(buff, find_multipaths_optvals[i])) {
388                         conf->find_multipaths = i;
389                         break;
390                 }
391         }
392
393         if (conf->find_multipaths == YNU_UNDEF) {
394                 condlog(0, "illegal value for find_multipaths: %s", buff);
395                 conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
396         }
397
398         FREE(buff);
399         return 0;
400 }
401
402 static int
403 snprint_def_find_multipaths(struct config *conf, char *buff, int len,
404                             const void *data)
405 {
406         return print_str(buff, len,
407                          find_multipaths_optvals[conf->find_multipaths]);
408 }
409
410 declare_def_handler(selector, set_str)
411 declare_def_snprint_defstr(selector, print_str, DEFAULT_SELECTOR)
412 declare_hw_handler(selector, set_str)
413 declare_hw_snprint(selector, print_str)
414 declare_ovr_handler(selector, set_str)
415 declare_ovr_snprint(selector, print_str)
416 declare_mp_handler(selector, set_str)
417 declare_mp_snprint(selector, print_str)
418
419 static int snprint_uid_attrs(struct config *conf, char *buff, int len,
420                              const void *dummy)
421 {
422         char *p = buff;
423         int n, j;
424         const char *att;
425
426         vector_foreach_slot(&conf->uid_attrs, att, j) {
427                 n = snprintf(p, len, "%s%s", j == 0 ? "" : " ", att);
428                 if (n >= len)
429                         return (p - buff) + n;
430                 p += n;
431                 len -= n;
432         }
433         return p - buff;
434 }
435
436 static int uid_attrs_handler(struct config *conf, vector strvec)
437 {
438         char *val;
439
440         vector_reset(&conf->uid_attrs);
441         val = set_value(strvec);
442         if (!val)
443                 return 1;
444         if (parse_uid_attrs(val, conf))
445                 condlog(1, "error parsing uid_attrs: \"%s\"", val);
446         condlog(3, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
447         FREE(val);
448         return 0;
449 }
450
451 declare_def_handler(uid_attribute, set_str)
452 declare_def_snprint_defstr(uid_attribute, print_str, DEFAULT_UID_ATTRIBUTE)
453 declare_ovr_handler(uid_attribute, set_str)
454 declare_ovr_snprint(uid_attribute, print_str)
455 declare_hw_handler(uid_attribute, set_str)
456 declare_hw_snprint(uid_attribute, print_str)
457
458 declare_def_handler(getuid, set_str)
459 declare_def_snprint(getuid, print_str)
460 declare_ovr_handler(getuid, set_str)
461 declare_ovr_snprint(getuid, print_str)
462 declare_hw_handler(getuid, set_str)
463 declare_hw_snprint(getuid, print_str)
464
465 declare_def_handler(prio_name, set_str)
466 declare_def_snprint_defstr(prio_name, print_str, DEFAULT_PRIO)
467 declare_ovr_handler(prio_name, set_str)
468 declare_ovr_snprint(prio_name, print_str)
469 declare_hw_handler(prio_name, set_str)
470 declare_hw_snprint(prio_name, print_str)
471 declare_mp_handler(prio_name, set_str)
472 declare_mp_snprint(prio_name, print_str)
473
474 declare_def_handler(alias_prefix, set_str)
475 declare_def_snprint_defstr(alias_prefix, print_str, DEFAULT_ALIAS_PREFIX)
476 declare_ovr_handler(alias_prefix, set_str)
477 declare_ovr_snprint(alias_prefix, print_str)
478 declare_hw_handler(alias_prefix, set_str)
479 declare_hw_snprint(alias_prefix, print_str)
480
481 declare_def_handler(prio_args, set_str)
482 declare_def_snprint_defstr(prio_args, print_str, DEFAULT_PRIO_ARGS)
483 declare_ovr_handler(prio_args, set_str)
484 declare_ovr_snprint(prio_args, print_str)
485 declare_hw_handler(prio_args, set_str)
486 declare_hw_snprint(prio_args, print_str)
487 declare_mp_handler(prio_args, set_str)
488 declare_mp_snprint(prio_args, print_str)
489
490 declare_def_handler(features, set_str)
491 declare_def_snprint_defstr(features, print_str, DEFAULT_FEATURES)
492 declare_ovr_handler(features, set_str)
493 declare_ovr_snprint(features, print_str)
494 declare_hw_handler(features, set_str)
495 declare_hw_snprint(features, print_str)
496 declare_mp_handler(features, set_str)
497 declare_mp_snprint(features, print_str)
498
499 declare_def_handler(checker_name, set_str)
500 declare_def_snprint_defstr(checker_name, print_str, DEFAULT_CHECKER)
501 declare_ovr_handler(checker_name, set_str)
502 declare_ovr_snprint(checker_name, print_str)
503 declare_hw_handler(checker_name, set_str)
504 declare_hw_snprint(checker_name, print_str)
505
506 declare_def_handler(minio, set_int)
507 declare_def_snprint_defint(minio, print_int, DEFAULT_MINIO)
508 declare_ovr_handler(minio, set_int)
509 declare_ovr_snprint(minio, print_nonzero)
510 declare_hw_handler(minio, set_int)
511 declare_hw_snprint(minio, print_nonzero)
512 declare_mp_handler(minio, set_int)
513 declare_mp_snprint(minio, print_nonzero)
514
515 declare_def_handler(minio_rq, set_int)
516 declare_def_snprint_defint(minio_rq, print_int, DEFAULT_MINIO_RQ)
517 declare_ovr_handler(minio_rq, set_int)
518 declare_ovr_snprint(minio_rq, print_nonzero)
519 declare_hw_handler(minio_rq, set_int)
520 declare_hw_snprint(minio_rq, print_nonzero)
521 declare_mp_handler(minio_rq, set_int)
522 declare_mp_snprint(minio_rq, print_nonzero)
523
524 declare_def_handler(queue_without_daemon, set_yes_no)
525 static int
526 snprint_def_queue_without_daemon (struct config *conf,
527                                   char * buff, int len, const void * data)
528 {
529         switch (conf->queue_without_daemon) {
530         case QUE_NO_DAEMON_OFF:
531                 return snprintf(buff, len, "\"no\"");
532         case QUE_NO_DAEMON_ON:
533                 return snprintf(buff, len, "\"yes\"");
534         case QUE_NO_DAEMON_FORCE:
535                 return snprintf(buff, len, "\"forced\"");
536         }
537         return 0;
538 }
539
540 declare_def_handler(checker_timeout, set_int)
541 declare_def_snprint(checker_timeout, print_nonzero)
542
543 declare_def_handler(flush_on_last_del, set_yes_no_undef)
544 declare_def_snprint_defint(flush_on_last_del, print_yes_no_undef, DEFAULT_FLUSH)
545 declare_ovr_handler(flush_on_last_del, set_yes_no_undef)
546 declare_ovr_snprint(flush_on_last_del, print_yes_no_undef)
547 declare_hw_handler(flush_on_last_del, set_yes_no_undef)
548 declare_hw_snprint(flush_on_last_del, print_yes_no_undef)
549 declare_mp_handler(flush_on_last_del, set_yes_no_undef)
550 declare_mp_snprint(flush_on_last_del, print_yes_no_undef)
551
552 declare_def_handler(user_friendly_names, set_yes_no_undef)
553 declare_def_snprint_defint(user_friendly_names, print_yes_no_undef,
554                            DEFAULT_USER_FRIENDLY_NAMES)
555 declare_ovr_handler(user_friendly_names, set_yes_no_undef)
556 declare_ovr_snprint(user_friendly_names, print_yes_no_undef)
557 declare_hw_handler(user_friendly_names, set_yes_no_undef)
558 declare_hw_snprint(user_friendly_names, print_yes_no_undef)
559 declare_mp_handler(user_friendly_names, set_yes_no_undef)
560 declare_mp_snprint(user_friendly_names, print_yes_no_undef)
561
562 declare_def_handler(bindings_file, set_str)
563 declare_def_snprint(bindings_file, print_str)
564
565 declare_def_handler(wwids_file, set_str)
566 declare_def_snprint(wwids_file, print_str)
567
568 declare_def_handler(prkeys_file, set_str)
569 declare_def_snprint(prkeys_file, print_str)
570
571 declare_def_handler(retain_hwhandler, set_yes_no_undef)
572 declare_def_snprint_defint(retain_hwhandler, print_yes_no_undef,
573                            DEFAULT_RETAIN_HWHANDLER)
574 declare_ovr_handler(retain_hwhandler, set_yes_no_undef)
575 declare_ovr_snprint(retain_hwhandler, print_yes_no_undef)
576 declare_hw_handler(retain_hwhandler, set_yes_no_undef)
577 declare_hw_snprint(retain_hwhandler, print_yes_no_undef)
578
579 declare_def_handler(detect_prio, set_yes_no_undef)
580 declare_def_snprint_defint(detect_prio, print_yes_no_undef,
581                            DEFAULT_DETECT_PRIO)
582 declare_ovr_handler(detect_prio, set_yes_no_undef)
583 declare_ovr_snprint(detect_prio, print_yes_no_undef)
584 declare_hw_handler(detect_prio, set_yes_no_undef)
585 declare_hw_snprint(detect_prio, print_yes_no_undef)
586
587 declare_def_handler(detect_checker, set_yes_no_undef)
588 declare_def_snprint_defint(detect_checker, print_yes_no_undef,
589                            DEFAULT_DETECT_CHECKER)
590 declare_ovr_handler(detect_checker, set_yes_no_undef)
591 declare_ovr_snprint(detect_checker, print_yes_no_undef)
592 declare_hw_handler(detect_checker, set_yes_no_undef)
593 declare_hw_snprint(detect_checker, print_yes_no_undef)
594
595 declare_def_handler(force_sync, set_yes_no)
596 declare_def_snprint(force_sync, print_yes_no)
597
598 declare_def_handler(deferred_remove, set_yes_no_undef)
599 declare_def_snprint_defint(deferred_remove, print_yes_no_undef,
600                            DEFAULT_DEFERRED_REMOVE)
601 declare_ovr_handler(deferred_remove, set_yes_no_undef)
602 declare_ovr_snprint(deferred_remove, print_yes_no_undef)
603 declare_hw_handler(deferred_remove, set_yes_no_undef)
604 declare_hw_snprint(deferred_remove, print_yes_no_undef)
605 declare_mp_handler(deferred_remove, set_yes_no_undef)
606 declare_mp_snprint(deferred_remove, print_yes_no_undef)
607
608 declare_def_handler(retrigger_tries, set_int)
609 declare_def_snprint(retrigger_tries, print_int)
610
611 declare_def_handler(retrigger_delay, set_int)
612 declare_def_snprint(retrigger_delay, print_int)
613
614 declare_def_handler(uev_wait_timeout, set_int)
615 declare_def_snprint(uev_wait_timeout, print_int)
616
617 declare_def_handler(strict_timing, set_yes_no)
618 declare_def_snprint(strict_timing, print_yes_no)
619
620 declare_def_handler(skip_kpartx, set_yes_no_undef)
621 declare_def_snprint_defint(skip_kpartx, print_yes_no_undef,
622                            DEFAULT_SKIP_KPARTX)
623 declare_ovr_handler(skip_kpartx, set_yes_no_undef)
624 declare_ovr_snprint(skip_kpartx, print_yes_no_undef)
625 declare_hw_handler(skip_kpartx, set_yes_no_undef)
626 declare_hw_snprint(skip_kpartx, print_yes_no_undef)
627 declare_mp_handler(skip_kpartx, set_yes_no_undef)
628 declare_mp_snprint(skip_kpartx, print_yes_no_undef)
629 static int def_disable_changed_wwids_handler(struct config *conf, vector strvec)
630 {
631         return 0;
632 }
633 static int snprint_def_disable_changed_wwids(struct config *conf, char *buff,
634                                              int len, const void *data)
635 {
636         return print_ignored(buff, len);
637 }
638
639 declare_def_handler(remove_retries, set_int)
640 declare_def_snprint(remove_retries, print_int)
641
642 declare_def_handler(max_sectors_kb, set_int)
643 declare_def_snprint(max_sectors_kb, print_nonzero)
644 declare_ovr_handler(max_sectors_kb, set_int)
645 declare_ovr_snprint(max_sectors_kb, print_nonzero)
646 declare_hw_handler(max_sectors_kb, set_int)
647 declare_hw_snprint(max_sectors_kb, print_nonzero)
648 declare_mp_handler(max_sectors_kb, set_int)
649 declare_mp_snprint(max_sectors_kb, print_nonzero)
650
651 declare_def_handler(find_multipaths_timeout, set_int)
652 declare_def_snprint_defint(find_multipaths_timeout, print_int,
653                            DEFAULT_FIND_MULTIPATHS_TIMEOUT)
654
655 declare_def_handler(enable_foreign, set_str)
656 declare_def_snprint_defstr(enable_foreign, print_str,
657                            DEFAULT_ENABLE_FOREIGN)
658
659 static int
660 def_config_dir_handler(struct config *conf, vector strvec)
661 {
662         /* this is only valid in the main config file */
663         if (conf->processed_main_config)
664                 return 0;
665         return set_str(strvec, &conf->config_dir);
666 }
667 declare_def_snprint(config_dir, print_str)
668
669 #define declare_def_attr_handler(option, function)                      \
670 static int                                                              \
671 def_ ## option ## _handler (struct config *conf, vector strvec)         \
672 {                                                                       \
673         return function (strvec, &conf->option, &conf->attribute_flags);\
674 }
675
676 #define declare_def_attr_snprint(option, function)                      \
677 static int                                                              \
678 snprint_def_ ## option (struct config *conf, char * buff, int len,      \
679                         const void * data)                              \
680 {                                                                       \
681         return function (buff, len, conf->option,                       \
682                          conf->attribute_flags);                        \
683 }
684
685 #define declare_mp_attr_handler(option, function)                       \
686 static int                                                              \
687 mp_ ## option ## _handler (struct config *conf, vector strvec)          \
688 {                                                                       \
689         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);         \
690         if (!mpe)                                                       \
691                 return 1;                                               \
692         return function (strvec, &mpe->option, &mpe->attribute_flags);  \
693 }
694
695 #define declare_mp_attr_snprint(option, function)                       \
696 static int                                                              \
697 snprint_mp_ ## option (struct config *conf, char * buff, int len,       \
698                        const void * data)                               \
699 {                                                                       \
700         const struct mpentry * mpe = (const struct mpentry *)data;      \
701         return function (buff, len, mpe->option,                        \
702                          mpe->attribute_flags);                         \
703 }
704
705 static int
706 set_mode(vector strvec, void *ptr, int *flags)
707 {
708         mode_t mode;
709         mode_t *mode_ptr = (mode_t *)ptr;
710         char *buff;
711
712         buff = set_value(strvec);
713
714         if (!buff)
715                 return 1;
716
717         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
718                 *flags |= (1 << ATTR_MODE);
719                 *mode_ptr = mode;
720         }
721
722         FREE(buff);
723         return 0;
724 }
725
726 static int
727 set_uid(vector strvec, void *ptr, int *flags)
728 {
729         uid_t uid;
730         uid_t *uid_ptr = (uid_t *)ptr;
731         char *buff;
732         char passwd_buf[1024];
733         struct passwd info, *found;
734
735         buff = set_value(strvec);
736         if (!buff)
737                 return 1;
738         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
739                 *flags |= (1 << ATTR_UID);
740                 *uid_ptr = info.pw_uid;
741         }
742         else if (sscanf(buff, "%u", &uid) == 1){
743                 *flags |= (1 << ATTR_UID);
744                 *uid_ptr = uid;
745         }
746
747         FREE(buff);
748         return 0;
749 }
750
751 static int
752 set_gid(vector strvec, void *ptr, int *flags)
753 {
754         gid_t gid;
755         gid_t *gid_ptr = (gid_t *)ptr;
756         char *buff;
757         char passwd_buf[1024];
758         struct passwd info, *found;
759
760         buff = set_value(strvec);
761         if (!buff)
762                 return 1;
763
764         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
765                 *flags |= (1 << ATTR_GID);
766                 *gid_ptr = info.pw_gid;
767         }
768         else if (sscanf(buff, "%u", &gid) == 1){
769                 *flags |= (1 << ATTR_GID);
770                 *gid_ptr = gid;
771         }
772         FREE(buff);
773         return 0;
774 }
775
776 static int
777 print_mode(char * buff, int len, long v, int flags)
778 {
779         mode_t mode = (mode_t)v;
780         if ((flags & (1 << ATTR_MODE)) == 0)
781                 return 0;
782         return snprintf(buff, len, "0%o", mode);
783 }
784
785 static int
786 print_uid(char * buff, int len, long v, int flags)
787 {
788         uid_t uid = (uid_t)v;
789         if ((flags & (1 << ATTR_UID)) == 0)
790                 return 0;
791         return snprintf(buff, len, "0%o", uid);
792 }
793
794 static int
795 print_gid(char * buff, int len, long v, int flags)
796 {
797         gid_t gid = (gid_t)v;
798         if ((flags & (1 << ATTR_GID)) == 0)
799                 return 0;
800         return snprintf(buff, len, "0%o", gid);
801 }
802
803 declare_def_attr_handler(mode, set_mode)
804 declare_def_attr_snprint(mode, print_mode)
805 declare_mp_attr_handler(mode, set_mode)
806 declare_mp_attr_snprint(mode, print_mode)
807
808 declare_def_attr_handler(uid, set_uid)
809 declare_def_attr_snprint(uid, print_uid)
810 declare_mp_attr_handler(uid, set_uid)
811 declare_mp_attr_snprint(uid, print_uid)
812
813 declare_def_attr_handler(gid, set_gid)
814 declare_def_attr_snprint(gid, print_gid)
815 declare_mp_attr_handler(gid, set_gid)
816 declare_mp_attr_snprint(gid, print_gid)
817
818 static int
819 set_fast_io_fail(vector strvec, void *ptr)
820 {
821         char * buff;
822         int *int_ptr = (int *)ptr;
823
824         buff = set_value(strvec);
825         if (!buff)
826                 return 1;
827
828         if (strcmp(buff, "off") == 0)
829                 *int_ptr = MP_FAST_IO_FAIL_OFF;
830         else if (sscanf(buff, "%d", int_ptr) != 1 ||
831                  *int_ptr < MP_FAST_IO_FAIL_ZERO)
832                 *int_ptr = MP_FAST_IO_FAIL_UNSET;
833         else if (*int_ptr == 0)
834                 *int_ptr = MP_FAST_IO_FAIL_ZERO;
835
836         FREE(buff);
837         return 0;
838 }
839
840 int
841 print_fast_io_fail(char * buff, int len, long v)
842 {
843         if (v == MP_FAST_IO_FAIL_UNSET)
844                 return 0;
845         if (v == MP_FAST_IO_FAIL_OFF)
846                 return snprintf(buff, len, "\"off\"");
847         if (v == MP_FAST_IO_FAIL_ZERO)
848                 return snprintf(buff, len, "0");
849         return snprintf(buff, len, "%ld", v);
850 }
851
852 declare_def_handler(fast_io_fail, set_fast_io_fail)
853 declare_def_snprint_defint(fast_io_fail, print_fast_io_fail,
854                            DEFAULT_FAST_IO_FAIL)
855 declare_ovr_handler(fast_io_fail, set_fast_io_fail)
856 declare_ovr_snprint(fast_io_fail, print_fast_io_fail)
857 declare_hw_handler(fast_io_fail, set_fast_io_fail)
858 declare_hw_snprint(fast_io_fail, print_fast_io_fail)
859
860 static int
861 set_dev_loss(vector strvec, void *ptr)
862 {
863         char * buff;
864         unsigned int *uint_ptr = (unsigned int *)ptr;
865
866         buff = set_value(strvec);
867         if (!buff)
868                 return 1;
869
870         if (!strcmp(buff, "infinity"))
871                 *uint_ptr = MAX_DEV_LOSS_TMO;
872         else if (sscanf(buff, "%u", uint_ptr) != 1)
873                 *uint_ptr = 0;
874
875         FREE(buff);
876         return 0;
877 }
878
879 int
880 print_dev_loss(char * buff, int len, unsigned long v)
881 {
882         if (!v)
883                 return 0;
884         if (v >= MAX_DEV_LOSS_TMO)
885                 return snprintf(buff, len, "\"infinity\"");
886         return snprintf(buff, len, "%lu", v);
887 }
888
889 declare_def_handler(dev_loss, set_dev_loss)
890 declare_def_snprint(dev_loss, print_dev_loss)
891 declare_ovr_handler(dev_loss, set_dev_loss)
892 declare_ovr_snprint(dev_loss, print_dev_loss)
893 declare_hw_handler(dev_loss, set_dev_loss)
894 declare_hw_snprint(dev_loss, print_dev_loss)
895
896 static int
897 set_pgpolicy(vector strvec, void *ptr)
898 {
899         char * buff;
900         int *int_ptr = (int *)ptr;
901
902         buff = set_value(strvec);
903         if (!buff)
904                 return 1;
905
906         *int_ptr = get_pgpolicy_id(buff);
907         FREE(buff);
908
909         return 0;
910 }
911
912 int
913 print_pgpolicy(char * buff, int len, long pgpolicy)
914 {
915         char str[POLICY_NAME_SIZE];
916
917         if (!pgpolicy)
918                 return 0;
919
920         get_pgpolicy_name(str, POLICY_NAME_SIZE, pgpolicy);
921
922         return snprintf(buff, len, "\"%s\"", str);
923 }
924
925 declare_def_handler(pgpolicy, set_pgpolicy)
926 declare_def_snprint_defint(pgpolicy, print_pgpolicy, DEFAULT_PGPOLICY)
927 declare_ovr_handler(pgpolicy, set_pgpolicy)
928 declare_ovr_snprint(pgpolicy, print_pgpolicy)
929 declare_hw_handler(pgpolicy, set_pgpolicy)
930 declare_hw_snprint(pgpolicy, print_pgpolicy)
931 declare_mp_handler(pgpolicy, set_pgpolicy)
932 declare_mp_snprint(pgpolicy, print_pgpolicy)
933
934 int
935 get_sys_max_fds(int *max_fds)
936 {
937         FILE *file;
938         int nr_open;
939         int ret = 1;
940
941         file = fopen("/proc/sys/fs/nr_open", "r");
942         if (!file) {
943                 fprintf(stderr, "Cannot open /proc/sys/fs/nr_open : %s\n",
944                         strerror(errno));
945                 return 1;
946         }
947         if (fscanf(file, "%d", &nr_open) != 1) {
948                 fprintf(stderr, "Cannot read max open fds from /proc/sys/fs/nr_open");
949                 if (ferror(file))
950                         fprintf(stderr, " : %s\n", strerror(errno));
951                 else
952                         fprintf(stderr, "\n");
953         } else {
954                 *max_fds = nr_open;
955                 ret = 0;
956         }
957         fclose(file);
958         return ret;
959 }
960
961
962 static int
963 max_fds_handler(struct config *conf, vector strvec)
964 {
965         char * buff;
966         int r = 0, max_fds;
967
968         buff = set_value(strvec);
969
970         if (!buff)
971                 return 1;
972
973         r = get_sys_max_fds(&max_fds);
974         if (r) {
975                 /* Assume safe limit */
976                 max_fds = 4096;
977         }
978         if (strlen(buff) == 3 &&
979             !strcmp(buff, "max"))
980                 conf->max_fds = max_fds;
981         else
982                 conf->max_fds = atoi(buff);
983
984         if (conf->max_fds > max_fds)
985                 conf->max_fds = max_fds;
986
987         FREE(buff);
988
989         return r;
990 }
991
992 static int
993 snprint_max_fds (struct config *conf, char * buff, int len, const void * data)
994 {
995         int r = 0, max_fds;
996
997         if (!conf->max_fds)
998                 return 0;
999
1000         r = get_sys_max_fds(&max_fds);
1001         if (!r && conf->max_fds >= max_fds)
1002                 return snprintf(buff, len, "\"max\"");
1003         else
1004                 return snprintf(buff, len, "%d", conf->max_fds);
1005 }
1006
1007 static int
1008 set_rr_weight(vector strvec, void *ptr)
1009 {
1010         int *int_ptr = (int *)ptr;
1011         char * buff;
1012
1013         buff = set_value(strvec);
1014
1015         if (!buff)
1016                 return 1;
1017
1018         if (!strcmp(buff, "priorities"))
1019                 *int_ptr = RR_WEIGHT_PRIO;
1020
1021         if (!strcmp(buff, "uniform"))
1022                 *int_ptr = RR_WEIGHT_NONE;
1023
1024         FREE(buff);
1025
1026         return 0;
1027 }
1028
1029 int
1030 print_rr_weight (char * buff, int len, long v)
1031 {
1032         if (!v)
1033                 return 0;
1034         if (v == RR_WEIGHT_PRIO)
1035                 return snprintf(buff, len, "\"priorities\"");
1036         if (v == RR_WEIGHT_NONE)
1037                 return snprintf(buff, len, "\"uniform\"");
1038
1039         return 0;
1040 }
1041
1042 declare_def_handler(rr_weight, set_rr_weight)
1043 declare_def_snprint_defint(rr_weight, print_rr_weight, DEFAULT_RR_WEIGHT)
1044 declare_ovr_handler(rr_weight, set_rr_weight)
1045 declare_ovr_snprint(rr_weight, print_rr_weight)
1046 declare_hw_handler(rr_weight, set_rr_weight)
1047 declare_hw_snprint(rr_weight, print_rr_weight)
1048 declare_mp_handler(rr_weight, set_rr_weight)
1049 declare_mp_snprint(rr_weight, print_rr_weight)
1050
1051 static int
1052 set_pgfailback(vector strvec, void *ptr)
1053 {
1054         int *int_ptr = (int *)ptr;
1055         char * buff;
1056
1057         buff = set_value(strvec);
1058         if (!buff)
1059                 return 1;
1060
1061         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
1062                 *int_ptr = -FAILBACK_MANUAL;
1063         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
1064                 *int_ptr = -FAILBACK_IMMEDIATE;
1065         else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
1066                 *int_ptr = -FAILBACK_FOLLOWOVER;
1067         else
1068                 *int_ptr = atoi(buff);
1069
1070         FREE(buff);
1071
1072         return 0;
1073 }
1074
1075 int
1076 print_pgfailback (char * buff, int len, long v)
1077 {
1078         switch(v) {
1079         case  FAILBACK_UNDEF:
1080                 return 0;
1081         case -FAILBACK_MANUAL:
1082                 return snprintf(buff, len, "\"manual\"");
1083         case -FAILBACK_IMMEDIATE:
1084                 return snprintf(buff, len, "\"immediate\"");
1085         case -FAILBACK_FOLLOWOVER:
1086                 return snprintf(buff, len, "\"followover\"");
1087         default:
1088                 return snprintf(buff, len, "%li", v);
1089         }
1090 }
1091
1092 declare_def_handler(pgfailback, set_pgfailback)
1093 declare_def_snprint_defint(pgfailback, print_pgfailback, DEFAULT_FAILBACK)
1094 declare_ovr_handler(pgfailback, set_pgfailback)
1095 declare_ovr_snprint(pgfailback, print_pgfailback)
1096 declare_hw_handler(pgfailback, set_pgfailback)
1097 declare_hw_snprint(pgfailback, print_pgfailback)
1098 declare_mp_handler(pgfailback, set_pgfailback)
1099 declare_mp_snprint(pgfailback, print_pgfailback)
1100
1101 static int
1102 no_path_retry_helper(vector strvec, void *ptr)
1103 {
1104         int *int_ptr = (int *)ptr;
1105         char * buff;
1106
1107         buff = set_value(strvec);
1108         if (!buff)
1109                 return 1;
1110
1111         if (!strcmp(buff, "fail") || !strcmp(buff, "0"))
1112                 *int_ptr = NO_PATH_RETRY_FAIL;
1113         else if (!strcmp(buff, "queue"))
1114                 *int_ptr = NO_PATH_RETRY_QUEUE;
1115         else if ((*int_ptr = atoi(buff)) < 1)
1116                 *int_ptr = NO_PATH_RETRY_UNDEF;
1117
1118         FREE(buff);
1119         return 0;
1120 }
1121
1122 int
1123 print_no_path_retry(char * buff, int len, long v)
1124 {
1125         switch(v) {
1126         case NO_PATH_RETRY_UNDEF:
1127                 return 0;
1128         case NO_PATH_RETRY_FAIL:
1129                 return snprintf(buff, len, "\"fail\"");
1130         case NO_PATH_RETRY_QUEUE:
1131                 return snprintf(buff, len, "\"queue\"");
1132         default:
1133                 return snprintf(buff, len, "%li", v);
1134         }
1135 }
1136
1137 declare_def_handler(no_path_retry, no_path_retry_helper)
1138 declare_def_snprint(no_path_retry, print_no_path_retry)
1139 declare_ovr_handler(no_path_retry, no_path_retry_helper)
1140 declare_ovr_snprint(no_path_retry, print_no_path_retry)
1141 declare_hw_handler(no_path_retry, no_path_retry_helper)
1142 declare_hw_snprint(no_path_retry, print_no_path_retry)
1143 declare_mp_handler(no_path_retry, no_path_retry_helper)
1144 declare_mp_snprint(no_path_retry, print_no_path_retry)
1145
1146 static int
1147 def_log_checker_err_handler(struct config *conf, vector strvec)
1148 {
1149         char * buff;
1150
1151         buff = set_value(strvec);
1152
1153         if (!buff)
1154                 return 1;
1155
1156         if (strlen(buff) == 4 && !strcmp(buff, "once"))
1157                 conf->log_checker_err = LOG_CHKR_ERR_ONCE;
1158         else if (strlen(buff) == 6 && !strcmp(buff, "always"))
1159                 conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
1160
1161         free(buff);
1162         return 0;
1163 }
1164
1165 static int
1166 snprint_def_log_checker_err (struct config *conf, char * buff, int len,
1167                              const void * data)
1168 {
1169         if (conf->log_checker_err == LOG_CHKR_ERR_ONCE)
1170                 return snprintf(buff, len, "once");
1171         return snprintf(buff, len, "always");
1172 }
1173
1174 static int
1175 set_reservation_key(vector strvec, struct be64 *be64_ptr, uint8_t *flags_ptr,
1176                     int *source_ptr)
1177 {
1178         char *buff;
1179         uint64_t prkey;
1180         uint8_t sa_flags;
1181
1182         buff = set_value(strvec);
1183         if (!buff)
1184                 return 1;
1185
1186         if (strcmp(buff, "file") == 0) {
1187                 *source_ptr = PRKEY_SOURCE_FILE;
1188                 *flags_ptr = 0;
1189                 put_be64(*be64_ptr, 0);
1190                 FREE(buff);
1191                 return 0;
1192         }
1193
1194         if (parse_prkey_flags(buff, &prkey, &sa_flags) != 0) {
1195                 FREE(buff);
1196                 return 1;
1197         }
1198         *source_ptr = PRKEY_SOURCE_CONF;
1199         *flags_ptr = sa_flags;
1200         put_be64(*be64_ptr, prkey);
1201         FREE(buff);
1202         return 0;
1203 }
1204
1205 int
1206 print_reservation_key(char * buff, int len, struct be64 key, uint8_t flags,
1207                       int source)
1208 {
1209         char *flagstr = "";
1210         if (source == PRKEY_SOURCE_NONE)
1211                 return 0;
1212         if (source == PRKEY_SOURCE_FILE)
1213                 return snprintf(buff, len, "file");
1214         if (flags & MPATH_F_APTPL_MASK)
1215                 flagstr = ":aptpl";
1216         return snprintf(buff, len, "0x%" PRIx64 "%s", get_be64(key),
1217                         flagstr);
1218 }
1219
1220 static int
1221 def_reservation_key_handler(struct config *conf, vector strvec)
1222 {
1223         return set_reservation_key(strvec, &conf->reservation_key,
1224                                    &conf->sa_flags,
1225                                    &conf->prkey_source);
1226 }
1227
1228 static int
1229 snprint_def_reservation_key (struct config *conf, char * buff, int len,
1230                              const void * data)
1231 {
1232         return print_reservation_key(buff, len, conf->reservation_key,
1233                                      conf->sa_flags,
1234                                      conf->prkey_source);
1235 }
1236
1237 static int
1238 mp_reservation_key_handler(struct config *conf, vector strvec)
1239 {
1240         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1241         if (!mpe)
1242                 return 1;
1243         return set_reservation_key(strvec, &mpe->reservation_key,
1244                                    &mpe->sa_flags,
1245                                    &mpe->prkey_source);
1246 }
1247
1248 static int
1249 snprint_mp_reservation_key (struct config *conf, char * buff, int len,
1250                             const void * data)
1251 {
1252         const struct mpentry * mpe = (const struct mpentry *)data;
1253         return print_reservation_key(buff, len, mpe->reservation_key,
1254                                      mpe->sa_flags,
1255                                      mpe->prkey_source);
1256 }
1257
1258 static int
1259 set_off_int_undef(vector strvec, void *ptr)
1260 {
1261         int *int_ptr = (int *)ptr;
1262         char * buff;
1263
1264         buff = set_value(strvec);
1265         if (!buff)
1266                 return 1;
1267
1268         if (!strcmp(buff, "no") || !strcmp(buff, "0"))
1269                 *int_ptr = NU_NO;
1270         else if ((*int_ptr = atoi(buff)) < 1)
1271                 *int_ptr = NU_UNDEF;
1272
1273         FREE(buff);
1274         return 0;
1275 }
1276
1277 int
1278 print_off_int_undef(char * buff, int len, long v)
1279 {
1280         switch(v) {
1281         case NU_UNDEF:
1282                 return 0;
1283         case NU_NO:
1284                 return snprintf(buff, len, "\"no\"");
1285         default:
1286                 return snprintf(buff, len, "%li", v);
1287         }
1288 }
1289
1290 declare_def_handler(delay_watch_checks, set_off_int_undef)
1291 declare_def_snprint_defint(delay_watch_checks, print_off_int_undef,
1292                            DEFAULT_DELAY_CHECKS)
1293 declare_ovr_handler(delay_watch_checks, set_off_int_undef)
1294 declare_ovr_snprint(delay_watch_checks, print_off_int_undef)
1295 declare_hw_handler(delay_watch_checks, set_off_int_undef)
1296 declare_hw_snprint(delay_watch_checks, print_off_int_undef)
1297 declare_mp_handler(delay_watch_checks, set_off_int_undef)
1298 declare_mp_snprint(delay_watch_checks, print_off_int_undef)
1299 declare_def_handler(delay_wait_checks, set_off_int_undef)
1300 declare_def_snprint_defint(delay_wait_checks, print_off_int_undef,
1301                            DEFAULT_DELAY_CHECKS)
1302 declare_ovr_handler(delay_wait_checks, set_off_int_undef)
1303 declare_ovr_snprint(delay_wait_checks, print_off_int_undef)
1304 declare_hw_handler(delay_wait_checks, set_off_int_undef)
1305 declare_hw_snprint(delay_wait_checks, print_off_int_undef)
1306 declare_mp_handler(delay_wait_checks, set_off_int_undef)
1307 declare_mp_snprint(delay_wait_checks, print_off_int_undef)
1308 declare_def_handler(san_path_err_threshold, set_off_int_undef)
1309 declare_def_snprint_defint(san_path_err_threshold, print_off_int_undef,
1310                            DEFAULT_ERR_CHECKS)
1311 declare_ovr_handler(san_path_err_threshold, set_off_int_undef)
1312 declare_ovr_snprint(san_path_err_threshold, print_off_int_undef)
1313 declare_hw_handler(san_path_err_threshold, set_off_int_undef)
1314 declare_hw_snprint(san_path_err_threshold, print_off_int_undef)
1315 declare_mp_handler(san_path_err_threshold, set_off_int_undef)
1316 declare_mp_snprint(san_path_err_threshold, print_off_int_undef)
1317 declare_def_handler(san_path_err_forget_rate, set_off_int_undef)
1318 declare_def_snprint_defint(san_path_err_forget_rate, print_off_int_undef,
1319                            DEFAULT_ERR_CHECKS)
1320 declare_ovr_handler(san_path_err_forget_rate, set_off_int_undef)
1321 declare_ovr_snprint(san_path_err_forget_rate, print_off_int_undef)
1322 declare_hw_handler(san_path_err_forget_rate, set_off_int_undef)
1323 declare_hw_snprint(san_path_err_forget_rate, print_off_int_undef)
1324 declare_mp_handler(san_path_err_forget_rate, set_off_int_undef)
1325 declare_mp_snprint(san_path_err_forget_rate, print_off_int_undef)
1326 declare_def_handler(san_path_err_recovery_time, set_off_int_undef)
1327 declare_def_snprint_defint(san_path_err_recovery_time, print_off_int_undef,
1328                            DEFAULT_ERR_CHECKS)
1329 declare_ovr_handler(san_path_err_recovery_time, set_off_int_undef)
1330 declare_ovr_snprint(san_path_err_recovery_time, print_off_int_undef)
1331 declare_hw_handler(san_path_err_recovery_time, set_off_int_undef)
1332 declare_hw_snprint(san_path_err_recovery_time, print_off_int_undef)
1333 declare_mp_handler(san_path_err_recovery_time, set_off_int_undef)
1334 declare_mp_snprint(san_path_err_recovery_time, print_off_int_undef)
1335 declare_def_handler(marginal_path_err_sample_time, set_off_int_undef)
1336 declare_def_snprint_defint(marginal_path_err_sample_time, print_off_int_undef,
1337                            DEFAULT_ERR_CHECKS)
1338 declare_ovr_handler(marginal_path_err_sample_time, set_off_int_undef)
1339 declare_ovr_snprint(marginal_path_err_sample_time, print_off_int_undef)
1340 declare_hw_handler(marginal_path_err_sample_time, set_off_int_undef)
1341 declare_hw_snprint(marginal_path_err_sample_time, print_off_int_undef)
1342 declare_mp_handler(marginal_path_err_sample_time, set_off_int_undef)
1343 declare_mp_snprint(marginal_path_err_sample_time, print_off_int_undef)
1344 declare_def_handler(marginal_path_err_rate_threshold, set_off_int_undef)
1345 declare_def_snprint_defint(marginal_path_err_rate_threshold, print_off_int_undef,
1346                            DEFAULT_ERR_CHECKS)
1347 declare_ovr_handler(marginal_path_err_rate_threshold, set_off_int_undef)
1348 declare_ovr_snprint(marginal_path_err_rate_threshold, print_off_int_undef)
1349 declare_hw_handler(marginal_path_err_rate_threshold, set_off_int_undef)
1350 declare_hw_snprint(marginal_path_err_rate_threshold, print_off_int_undef)
1351 declare_mp_handler(marginal_path_err_rate_threshold, set_off_int_undef)
1352 declare_mp_snprint(marginal_path_err_rate_threshold, print_off_int_undef)
1353 declare_def_handler(marginal_path_err_recheck_gap_time, set_off_int_undef)
1354 declare_def_snprint_defint(marginal_path_err_recheck_gap_time, print_off_int_undef,
1355                            DEFAULT_ERR_CHECKS)
1356 declare_ovr_handler(marginal_path_err_recheck_gap_time, set_off_int_undef)
1357 declare_ovr_snprint(marginal_path_err_recheck_gap_time, print_off_int_undef)
1358 declare_hw_handler(marginal_path_err_recheck_gap_time, set_off_int_undef)
1359 declare_hw_snprint(marginal_path_err_recheck_gap_time, print_off_int_undef)
1360 declare_mp_handler(marginal_path_err_recheck_gap_time, set_off_int_undef)
1361 declare_mp_snprint(marginal_path_err_recheck_gap_time, print_off_int_undef)
1362 declare_def_handler(marginal_path_double_failed_time, set_off_int_undef)
1363 declare_def_snprint_defint(marginal_path_double_failed_time, print_off_int_undef,
1364                            DEFAULT_ERR_CHECKS)
1365 declare_ovr_handler(marginal_path_double_failed_time, set_off_int_undef)
1366 declare_ovr_snprint(marginal_path_double_failed_time, print_off_int_undef)
1367 declare_hw_handler(marginal_path_double_failed_time, set_off_int_undef)
1368 declare_hw_snprint(marginal_path_double_failed_time, print_off_int_undef)
1369 declare_mp_handler(marginal_path_double_failed_time, set_off_int_undef)
1370 declare_mp_snprint(marginal_path_double_failed_time, print_off_int_undef)
1371
1372 declare_def_handler(ghost_delay, set_off_int_undef)
1373 declare_def_snprint(ghost_delay, print_off_int_undef)
1374 declare_ovr_handler(ghost_delay, set_off_int_undef)
1375 declare_ovr_snprint(ghost_delay, print_off_int_undef)
1376 declare_hw_handler(ghost_delay, set_off_int_undef)
1377 declare_hw_snprint(ghost_delay, print_off_int_undef)
1378 declare_mp_handler(ghost_delay, set_off_int_undef)
1379 declare_mp_snprint(ghost_delay, print_off_int_undef)
1380
1381 declare_def_handler(all_tg_pt, set_yes_no_undef)
1382 declare_def_snprint_defint(all_tg_pt, print_yes_no_undef, DEFAULT_ALL_TG_PT)
1383 declare_ovr_handler(all_tg_pt, set_yes_no_undef)
1384 declare_ovr_snprint(all_tg_pt, print_yes_no_undef)
1385 declare_hw_handler(all_tg_pt, set_yes_no_undef)
1386 declare_hw_snprint(all_tg_pt, print_yes_no_undef)
1387
1388 declare_def_handler(marginal_pathgroups, set_yes_no)
1389 declare_def_snprint(marginal_pathgroups, print_yes_no)
1390
1391 static int
1392 def_uxsock_timeout_handler(struct config *conf, vector strvec)
1393 {
1394         unsigned int uxsock_timeout;
1395         char *buff;
1396
1397         buff = set_value(strvec);
1398         if (!buff)
1399                 return 1;
1400
1401         if (sscanf(buff, "%u", &uxsock_timeout) == 1 &&
1402             uxsock_timeout > DEFAULT_REPLY_TIMEOUT)
1403                 conf->uxsock_timeout = uxsock_timeout;
1404         else
1405                 conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
1406
1407         free(buff);
1408         return 0;
1409 }
1410
1411 static int
1412 hw_vpd_vendor_handler(struct config *conf, vector strvec)
1413 {
1414         int i;
1415         char *buff;
1416
1417         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1418         if (!hwe)
1419                 return 1;
1420
1421         buff = set_value(strvec);
1422         if (!buff)
1423                 return 1;
1424         for (i = 0; i < VPD_VP_ARRAY_SIZE; i++) {
1425                 if (strcmp(buff, vpd_vendor_pages[i].name) == 0) {
1426                         hwe->vpd_vendor_id = i;
1427                         goto out;
1428                 }
1429         }
1430         hwe->vpd_vendor_id = 0;
1431 out:
1432         FREE(buff);
1433         return 0;
1434 }
1435
1436 static int
1437 snprint_hw_vpd_vendor(struct config *conf, char * buff, int len,
1438                       const void * data)
1439 {
1440         const struct hwentry * hwe = (const struct hwentry *)data;
1441
1442         if (hwe->vpd_vendor_id > 0 && hwe->vpd_vendor_id < VPD_VP_ARRAY_SIZE)
1443                 return snprintf(buff, len, "%s",
1444                                 vpd_vendor_pages[hwe->vpd_vendor_id].name);
1445         return 0;
1446 }
1447
1448 /*
1449  * blacklist block handlers
1450  */
1451 static int
1452 blacklist_handler(struct config *conf, vector strvec)
1453 {
1454         if (!conf->blist_devnode)
1455                 conf->blist_devnode = vector_alloc();
1456         if (!conf->blist_wwid)
1457                 conf->blist_wwid = vector_alloc();
1458         if (!conf->blist_device)
1459                 conf->blist_device = vector_alloc();
1460         if (!conf->blist_property)
1461                 conf->blist_property = vector_alloc();
1462         if (!conf->blist_protocol)
1463                 conf->blist_protocol = vector_alloc();
1464
1465         if (!conf->blist_devnode || !conf->blist_wwid ||
1466             !conf->blist_device || !conf->blist_property ||
1467             !conf->blist_protocol)
1468                 return 1;
1469
1470         return 0;
1471 }
1472
1473 static int
1474 blacklist_exceptions_handler(struct config *conf, vector strvec)
1475 {
1476         if (!conf->elist_devnode)
1477                 conf->elist_devnode = vector_alloc();
1478         if (!conf->elist_wwid)
1479                 conf->elist_wwid = vector_alloc();
1480         if (!conf->elist_device)
1481                 conf->elist_device = vector_alloc();
1482         if (!conf->elist_property)
1483                 conf->elist_property = vector_alloc();
1484         if (!conf->elist_protocol)
1485                 conf->elist_protocol = vector_alloc();
1486
1487         if (!conf->elist_devnode || !conf->elist_wwid ||
1488             !conf->elist_device || !conf->elist_property ||
1489             !conf->elist_protocol)
1490                 return 1;
1491
1492         return 0;
1493 }
1494
1495 #define declare_ble_handler(option)                                     \
1496 static int                                                              \
1497 ble_ ## option ## _handler (struct config *conf, vector strvec)         \
1498 {                                                                       \
1499         char * buff;                                                    \
1500                                                                         \
1501         if (!conf->option)                                              \
1502                 return 1;                                               \
1503                                                                         \
1504         buff = set_value(strvec);                                       \
1505         if (!buff)                                                      \
1506                 return 1;                                               \
1507                                                                         \
1508         return store_ble(conf->option, buff, ORIGIN_CONFIG);            \
1509 }
1510
1511 #define declare_ble_device_handler(name, option, vend, prod)            \
1512 static int                                                              \
1513 ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
1514 {                                                                       \
1515         char * buff;                                                    \
1516                                                                         \
1517         if (!conf->option)                                              \
1518                 return 1;                                               \
1519                                                                         \
1520         buff = set_value(strvec);                                       \
1521         if (!buff)                                                      \
1522                 return 1;                                               \
1523                                                                         \
1524         return set_ble_device(conf->option, vend, prod, ORIGIN_CONFIG); \
1525 }
1526
1527 declare_ble_handler(blist_devnode)
1528 declare_ble_handler(elist_devnode)
1529 declare_ble_handler(blist_wwid)
1530 declare_ble_handler(elist_wwid)
1531 declare_ble_handler(blist_property)
1532 declare_ble_handler(elist_property)
1533 declare_ble_handler(blist_protocol)
1534 declare_ble_handler(elist_protocol)
1535
1536 static int
1537 snprint_def_uxsock_timeout(struct config *conf, char * buff, int len,
1538                            const void * data)
1539 {
1540         return snprintf(buff, len, "%u", conf->uxsock_timeout);
1541 }
1542
1543 static int
1544 snprint_ble_simple (struct config *conf, char * buff, int len,
1545                     const void * data)
1546 {
1547         const struct blentry * ble = (const struct blentry *)data;
1548
1549         return snprintf(buff, len, "\"%s\"", ble->str);
1550 }
1551
1552 static int
1553 ble_device_handler(struct config *conf, vector strvec)
1554 {
1555         return alloc_ble_device(conf->blist_device);
1556 }
1557
1558 static int
1559 ble_except_device_handler(struct config *conf, vector strvec)
1560 {
1561         return alloc_ble_device(conf->elist_device);
1562 }
1563
1564 declare_ble_device_handler(vendor, blist_device, buff, NULL)
1565 declare_ble_device_handler(vendor, elist_device, buff, NULL)
1566 declare_ble_device_handler(product, blist_device, NULL, buff)
1567 declare_ble_device_handler(product, elist_device, NULL, buff)
1568
1569 static int
1570 snprint_bled_vendor (struct config *conf, char * buff, int len,
1571                      const void * data)
1572 {
1573         const struct blentry_device * bled =
1574                 (const struct blentry_device *)data;
1575
1576         return snprintf(buff, len, "\"%s\"", bled->vendor);
1577 }
1578
1579 static int
1580 snprint_bled_product (struct config *conf, char * buff, int len,
1581                       const void * data)
1582 {
1583         const struct blentry_device * bled =
1584                 (const struct blentry_device *)data;
1585
1586         return snprintf(buff, len, "\"%s\"", bled->product);
1587 }
1588
1589 /*
1590  * devices block handlers
1591  */
1592 static int
1593 devices_handler(struct config *conf, vector strvec)
1594 {
1595         if (!conf->hwtable)
1596                 conf->hwtable = vector_alloc();
1597
1598         if (!conf->hwtable)
1599                 return 1;
1600
1601         return 0;
1602 }
1603
1604 static int
1605 device_handler(struct config *conf, vector strvec)
1606 {
1607         struct hwentry * hwe;
1608
1609         hwe = alloc_hwe();
1610
1611         if (!hwe)
1612                 return 1;
1613
1614         if (!vector_alloc_slot(conf->hwtable)) {
1615                 free_hwe(hwe);
1616                 return 1;
1617         }
1618         vector_set_slot(conf->hwtable, hwe);
1619
1620         return 0;
1621 }
1622
1623 declare_hw_handler(vendor, set_str)
1624 declare_hw_snprint(vendor, print_str)
1625
1626 declare_hw_handler(product, set_str)
1627 declare_hw_snprint(product, print_str)
1628
1629 declare_hw_handler(revision, set_str)
1630 declare_hw_snprint(revision, print_str)
1631
1632 declare_hw_handler(bl_product, set_str)
1633 declare_hw_snprint(bl_product, print_str)
1634
1635 declare_hw_handler(hwhandler, set_str)
1636 declare_hw_snprint(hwhandler, print_str)
1637
1638 /*
1639  * overrides handlers
1640  */
1641 static int
1642 overrides_handler(struct config *conf, vector strvec)
1643 {
1644         if (!conf->overrides)
1645                 conf->overrides = alloc_hwe();
1646
1647         if (!conf->overrides)
1648                 return 1;
1649
1650         return 0;
1651 }
1652
1653
1654
1655 /*
1656  * multipaths block handlers
1657  */
1658 static int
1659 multipaths_handler(struct config *conf, vector strvec)
1660 {
1661         if (!conf->mptable)
1662                 conf->mptable = vector_alloc();
1663
1664         if (!conf->mptable)
1665                 return 1;
1666
1667         return 0;
1668 }
1669
1670 static int
1671 multipath_handler(struct config *conf, vector strvec)
1672 {
1673         struct mpentry * mpe;
1674
1675         mpe = alloc_mpe();
1676
1677         if (!mpe)
1678                 return 1;
1679
1680         if (!vector_alloc_slot(conf->mptable)) {
1681                 free_mpe(mpe);
1682                 return 1;
1683         }
1684         vector_set_slot(conf->mptable, mpe);
1685
1686         return 0;
1687 }
1688
1689 declare_mp_handler(wwid, set_str)
1690 declare_mp_snprint(wwid, print_str)
1691
1692 declare_mp_handler(alias, set_str)
1693 declare_mp_snprint(alias, print_str)
1694
1695 /*
1696  * deprecated handlers
1697  */
1698
1699 static int
1700 deprecated_handler(struct config *conf, vector strvec)
1701 {
1702         char * buff;
1703
1704         buff = set_value(strvec);
1705
1706         if (!buff)
1707                 return 1;
1708
1709         FREE(buff);
1710         return 0;
1711 }
1712
1713 static int
1714 snprint_deprecated (struct config *conf, char * buff, int len,
1715                     const void * data)
1716 {
1717         return 0;
1718 }
1719
1720 #define __deprecated
1721
1722 /*
1723  * If you add or remove a keyword also update multipath/multipath.conf.5
1724  */
1725 void
1726 init_keywords(vector keywords)
1727 {
1728         install_keyword_root("defaults", NULL);
1729         install_keyword("verbosity", &def_verbosity_handler, &snprint_def_verbosity);
1730         install_keyword("polling_interval", &checkint_handler, &snprint_def_checkint);
1731         install_keyword("max_polling_interval", &def_max_checkint_handler, &snprint_def_max_checkint);
1732         install_keyword("reassign_maps", &def_reassign_maps_handler, &snprint_def_reassign_maps);
1733         install_keyword("multipath_dir", &def_multipath_dir_handler, &snprint_def_multipath_dir);
1734         install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
1735         install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_pgpolicy);
1736         install_keyword("uid_attrs", &uid_attrs_handler, &snprint_uid_attrs);
1737         install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute);
1738         install_keyword("getuid_callout", &def_getuid_handler, &snprint_def_getuid);
1739         install_keyword("prio", &def_prio_name_handler, &snprint_def_prio_name);
1740         install_keyword("prio_args", &def_prio_args_handler, &snprint_def_prio_args);
1741         install_keyword("features", &def_features_handler, &snprint_def_features);
1742         install_keyword("path_checker", &def_checker_name_handler, &snprint_def_checker_name);
1743         install_keyword("checker", &def_checker_name_handler, NULL);
1744         install_keyword("alias_prefix", &def_alias_prefix_handler, &snprint_def_alias_prefix);
1745         install_keyword("failback", &def_pgfailback_handler, &snprint_def_pgfailback);
1746         install_keyword("rr_min_io", &def_minio_handler, &snprint_def_minio);
1747         install_keyword("rr_min_io_rq", &def_minio_rq_handler, &snprint_def_minio_rq);
1748         install_keyword("max_fds", &max_fds_handler, &snprint_max_fds);
1749         install_keyword("rr_weight", &def_rr_weight_handler, &snprint_def_rr_weight);
1750         install_keyword("no_path_retry", &def_no_path_retry_handler, &snprint_def_no_path_retry);
1751         install_keyword("queue_without_daemon", &def_queue_without_daemon_handler, &snprint_def_queue_without_daemon);
1752         install_keyword("checker_timeout", &def_checker_timeout_handler, &snprint_def_checker_timeout);
1753         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1754         install_keyword("flush_on_last_del", &def_flush_on_last_del_handler, &snprint_def_flush_on_last_del);
1755         install_keyword("user_friendly_names", &def_user_friendly_names_handler, &snprint_def_user_friendly_names);
1756         install_keyword("mode", &def_mode_handler, &snprint_def_mode);
1757         install_keyword("uid", &def_uid_handler, &snprint_def_uid);
1758         install_keyword("gid", &def_gid_handler, &snprint_def_gid);
1759         install_keyword("fast_io_fail_tmo", &def_fast_io_fail_handler, &snprint_def_fast_io_fail);
1760         install_keyword("dev_loss_tmo", &def_dev_loss_handler, &snprint_def_dev_loss);
1761         install_keyword("bindings_file", &def_bindings_file_handler, &snprint_def_bindings_file);
1762         install_keyword("wwids_file", &def_wwids_file_handler, &snprint_def_wwids_file);
1763         install_keyword("prkeys_file", &def_prkeys_file_handler, &snprint_def_prkeys_file);
1764         install_keyword("log_checker_err", &def_log_checker_err_handler, &snprint_def_log_checker_err);
1765         install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key);
1766         install_keyword("all_tg_pt", &def_all_tg_pt_handler, &snprint_def_all_tg_pt);
1767         install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler);
1768         install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio);
1769         install_keyword("detect_checker", &def_detect_checker_handler, &snprint_def_detect_checker);
1770         install_keyword("force_sync", &def_force_sync_handler, &snprint_def_force_sync);
1771         install_keyword("strict_timing", &def_strict_timing_handler, &snprint_def_strict_timing);
1772         install_keyword("deferred_remove", &def_deferred_remove_handler, &snprint_def_deferred_remove);
1773         install_keyword("partition_delimiter", &def_partition_delim_handler, &snprint_def_partition_delim);
1774         install_keyword("config_dir", &def_config_dir_handler, &snprint_def_config_dir);
1775         install_keyword("delay_watch_checks", &def_delay_watch_checks_handler, &snprint_def_delay_watch_checks);
1776         install_keyword("delay_wait_checks", &def_delay_wait_checks_handler, &snprint_def_delay_wait_checks);
1777         install_keyword("san_path_err_threshold", &def_san_path_err_threshold_handler, &snprint_def_san_path_err_threshold);
1778         install_keyword("san_path_err_forget_rate", &def_san_path_err_forget_rate_handler, &snprint_def_san_path_err_forget_rate);
1779         install_keyword("san_path_err_recovery_time", &def_san_path_err_recovery_time_handler, &snprint_def_san_path_err_recovery_time);
1780         install_keyword("marginal_path_err_sample_time", &def_marginal_path_err_sample_time_handler, &snprint_def_marginal_path_err_sample_time);
1781         install_keyword("marginal_path_err_rate_threshold", &def_marginal_path_err_rate_threshold_handler, &snprint_def_marginal_path_err_rate_threshold);
1782         install_keyword("marginal_path_err_recheck_gap_time", &def_marginal_path_err_recheck_gap_time_handler, &snprint_def_marginal_path_err_recheck_gap_time);
1783         install_keyword("marginal_path_double_failed_time", &def_marginal_path_double_failed_time_handler, &snprint_def_marginal_path_double_failed_time);
1784
1785         install_keyword("find_multipaths", &def_find_multipaths_handler, &snprint_def_find_multipaths);
1786         install_keyword("uxsock_timeout", &def_uxsock_timeout_handler, &snprint_def_uxsock_timeout);
1787         install_keyword("retrigger_tries", &def_retrigger_tries_handler, &snprint_def_retrigger_tries);
1788         install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
1789         install_keyword("missing_uev_wait_timeout", &def_uev_wait_timeout_handler, &snprint_def_uev_wait_timeout);
1790         install_keyword("skip_kpartx", &def_skip_kpartx_handler, &snprint_def_skip_kpartx);
1791         install_keyword("disable_changed_wwids", &def_disable_changed_wwids_handler, &snprint_def_disable_changed_wwids);
1792         install_keyword("remove_retries", &def_remove_retries_handler, &snprint_def_remove_retries);
1793         install_keyword("max_sectors_kb", &def_max_sectors_kb_handler, &snprint_def_max_sectors_kb);
1794         install_keyword("ghost_delay", &def_ghost_delay_handler, &snprint_def_ghost_delay);
1795         install_keyword("find_multipaths_timeout",
1796                         &def_find_multipaths_timeout_handler,
1797                         &snprint_def_find_multipaths_timeout);
1798         install_keyword("enable_foreign", &def_enable_foreign_handler,
1799                         &snprint_def_enable_foreign);
1800         install_keyword("marginal_pathgroups", &def_marginal_pathgroups_handler, &snprint_def_marginal_pathgroups);
1801         __deprecated install_keyword("default_selector", &def_selector_handler, NULL);
1802         __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
1803         __deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
1804         __deprecated install_keyword("default_getuid_callout", &def_getuid_handler, NULL);
1805         __deprecated install_keyword("default_features", &def_features_handler, NULL);
1806         __deprecated install_keyword("default_path_checker", &def_checker_name_handler, NULL);
1807
1808         install_keyword_root("blacklist", &blacklist_handler);
1809         install_keyword_multi("devnode", &ble_blist_devnode_handler, &snprint_ble_simple);
1810         install_keyword_multi("wwid", &ble_blist_wwid_handler, &snprint_ble_simple);
1811         install_keyword_multi("property", &ble_blist_property_handler, &snprint_ble_simple);
1812         install_keyword_multi("protocol", &ble_blist_protocol_handler, &snprint_ble_simple);
1813         install_keyword_multi("device", &ble_device_handler, NULL);
1814         install_sublevel();
1815         install_keyword("vendor", &ble_blist_device_vendor_handler, &snprint_bled_vendor);
1816         install_keyword("product", &ble_blist_device_product_handler, &snprint_bled_product);
1817         install_sublevel_end();
1818         install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
1819         install_keyword_multi("devnode", &ble_elist_devnode_handler, &snprint_ble_simple);
1820         install_keyword_multi("wwid", &ble_elist_wwid_handler, &snprint_ble_simple);
1821         install_keyword_multi("property", &ble_elist_property_handler, &snprint_ble_simple);
1822         install_keyword_multi("protocol", &ble_elist_protocol_handler, &snprint_ble_simple);
1823         install_keyword_multi("device", &ble_except_device_handler, NULL);
1824         install_sublevel();
1825         install_keyword("vendor", &ble_elist_device_vendor_handler, &snprint_bled_vendor);
1826         install_keyword("product", &ble_elist_device_product_handler, &snprint_bled_product);
1827         install_sublevel_end();
1828
1829 #if 0
1830         __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler);
1831         __deprecated install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
1832         __deprecated install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
1833         __deprecated install_keyword("device", &ble_device_handler, NULL);
1834         __deprecated install_sublevel();
1835         __deprecated install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
1836         __deprecated install_keyword("product", &ble_product_handler, &snprint_bled_product);
1837         __deprecated install_sublevel_end();
1838 #endif
1839 /*
1840  * If you add or remove a "device subsection" keyword also update
1841  * multipath/multipath.conf.5 and the TEMPLATE in libmultipath/hwtable.c
1842  */
1843         install_keyword_root("devices", &devices_handler);
1844         install_keyword_multi("device", &device_handler, NULL);
1845         install_sublevel();
1846         install_keyword("vendor", &hw_vendor_handler, &snprint_hw_vendor);
1847         install_keyword("product", &hw_product_handler, &snprint_hw_product);
1848         install_keyword("revision", &hw_revision_handler, &snprint_hw_revision);
1849         install_keyword("product_blacklist", &hw_bl_product_handler, &snprint_hw_bl_product);
1850         install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_pgpolicy);
1851         install_keyword("uid_attribute", &hw_uid_attribute_handler, &snprint_hw_uid_attribute);
1852         install_keyword("getuid_callout", &hw_getuid_handler, &snprint_hw_getuid);
1853         install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
1854         install_keyword("path_checker", &hw_checker_name_handler, &snprint_hw_checker_name);
1855         install_keyword("checker", &hw_checker_name_handler, NULL);
1856         install_keyword("alias_prefix", &hw_alias_prefix_handler, &snprint_hw_alias_prefix);
1857         install_keyword("features", &hw_features_handler, &snprint_hw_features);
1858         install_keyword("hardware_handler", &hw_hwhandler_handler, &snprint_hw_hwhandler);
1859         install_keyword("prio", &hw_prio_name_handler, &snprint_hw_prio_name);
1860         install_keyword("prio_args", &hw_prio_args_handler, &snprint_hw_prio_args);
1861         install_keyword("failback", &hw_pgfailback_handler, &snprint_hw_pgfailback);
1862         install_keyword("rr_weight", &hw_rr_weight_handler, &snprint_hw_rr_weight);
1863         install_keyword("no_path_retry", &hw_no_path_retry_handler, &snprint_hw_no_path_retry);
1864         install_keyword("rr_min_io", &hw_minio_handler, &snprint_hw_minio);
1865         install_keyword("rr_min_io_rq", &hw_minio_rq_handler, &snprint_hw_minio_rq);
1866         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1867         install_keyword("flush_on_last_del", &hw_flush_on_last_del_handler, &snprint_hw_flush_on_last_del);
1868         install_keyword("fast_io_fail_tmo", &hw_fast_io_fail_handler, &snprint_hw_fast_io_fail);
1869         install_keyword("dev_loss_tmo", &hw_dev_loss_handler, &snprint_hw_dev_loss);
1870         install_keyword("user_friendly_names", &hw_user_friendly_names_handler, &snprint_hw_user_friendly_names);
1871         install_keyword("retain_attached_hw_handler", &hw_retain_hwhandler_handler, &snprint_hw_retain_hwhandler);
1872         install_keyword("detect_prio", &hw_detect_prio_handler, &snprint_hw_detect_prio);
1873         install_keyword("detect_checker", &hw_detect_checker_handler, &snprint_hw_detect_checker);
1874         install_keyword("deferred_remove", &hw_deferred_remove_handler, &snprint_hw_deferred_remove);
1875         install_keyword("delay_watch_checks", &hw_delay_watch_checks_handler, &snprint_hw_delay_watch_checks);
1876         install_keyword("delay_wait_checks", &hw_delay_wait_checks_handler, &snprint_hw_delay_wait_checks);
1877         install_keyword("san_path_err_threshold", &hw_san_path_err_threshold_handler, &snprint_hw_san_path_err_threshold);
1878         install_keyword("san_path_err_forget_rate", &hw_san_path_err_forget_rate_handler, &snprint_hw_san_path_err_forget_rate);
1879         install_keyword("san_path_err_recovery_time", &hw_san_path_err_recovery_time_handler, &snprint_hw_san_path_err_recovery_time);
1880         install_keyword("marginal_path_err_sample_time", &hw_marginal_path_err_sample_time_handler, &snprint_hw_marginal_path_err_sample_time);
1881         install_keyword("marginal_path_err_rate_threshold", &hw_marginal_path_err_rate_threshold_handler, &snprint_hw_marginal_path_err_rate_threshold);
1882         install_keyword("marginal_path_err_recheck_gap_time", &hw_marginal_path_err_recheck_gap_time_handler, &snprint_hw_marginal_path_err_recheck_gap_time);
1883         install_keyword("marginal_path_double_failed_time", &hw_marginal_path_double_failed_time_handler, &snprint_hw_marginal_path_double_failed_time);
1884         install_keyword("skip_kpartx", &hw_skip_kpartx_handler, &snprint_hw_skip_kpartx);
1885         install_keyword("max_sectors_kb", &hw_max_sectors_kb_handler, &snprint_hw_max_sectors_kb);
1886         install_keyword("ghost_delay", &hw_ghost_delay_handler, &snprint_hw_ghost_delay);
1887         install_keyword("all_tg_pt", &hw_all_tg_pt_handler, &snprint_hw_all_tg_pt);
1888         install_keyword("vpd_vendor", &hw_vpd_vendor_handler, &snprint_hw_vpd_vendor);
1889         install_sublevel_end();
1890
1891         install_keyword_root("overrides", &overrides_handler);
1892         install_keyword("path_grouping_policy", &ovr_pgpolicy_handler, &snprint_ovr_pgpolicy);
1893         install_keyword("uid_attribute", &ovr_uid_attribute_handler, &snprint_ovr_uid_attribute);
1894         install_keyword("getuid_callout", &ovr_getuid_handler, &snprint_ovr_getuid);
1895         install_keyword("path_selector", &ovr_selector_handler, &snprint_ovr_selector);
1896         install_keyword("path_checker", &ovr_checker_name_handler, &snprint_ovr_checker_name);
1897         install_keyword("checker", &ovr_checker_name_handler, NULL);
1898         install_keyword("alias_prefix", &ovr_alias_prefix_handler, &snprint_ovr_alias_prefix);
1899         install_keyword("features", &ovr_features_handler, &snprint_ovr_features);
1900         install_keyword("prio", &ovr_prio_name_handler, &snprint_ovr_prio_name);
1901         install_keyword("prio_args", &ovr_prio_args_handler, &snprint_ovr_prio_args);
1902         install_keyword("failback", &ovr_pgfailback_handler, &snprint_ovr_pgfailback);
1903         install_keyword("rr_weight", &ovr_rr_weight_handler, &snprint_ovr_rr_weight);
1904         install_keyword("no_path_retry", &ovr_no_path_retry_handler, &snprint_ovr_no_path_retry);
1905         install_keyword("rr_min_io", &ovr_minio_handler, &snprint_ovr_minio);
1906         install_keyword("rr_min_io_rq", &ovr_minio_rq_handler, &snprint_ovr_minio_rq);
1907         install_keyword("flush_on_last_del", &ovr_flush_on_last_del_handler, &snprint_ovr_flush_on_last_del);
1908         install_keyword("fast_io_fail_tmo", &ovr_fast_io_fail_handler, &snprint_ovr_fast_io_fail);
1909         install_keyword("dev_loss_tmo", &ovr_dev_loss_handler, &snprint_ovr_dev_loss);
1910         install_keyword("user_friendly_names", &ovr_user_friendly_names_handler, &snprint_ovr_user_friendly_names);
1911         install_keyword("retain_attached_hw_handler", &ovr_retain_hwhandler_handler, &snprint_ovr_retain_hwhandler);
1912         install_keyword("detect_prio", &ovr_detect_prio_handler, &snprint_ovr_detect_prio);
1913         install_keyword("detect_checker", &ovr_detect_checker_handler, &snprint_ovr_detect_checker);
1914         install_keyword("deferred_remove", &ovr_deferred_remove_handler, &snprint_ovr_deferred_remove);
1915         install_keyword("delay_watch_checks", &ovr_delay_watch_checks_handler, &snprint_ovr_delay_watch_checks);
1916         install_keyword("delay_wait_checks", &ovr_delay_wait_checks_handler, &snprint_ovr_delay_wait_checks);
1917         install_keyword("san_path_err_threshold", &ovr_san_path_err_threshold_handler, &snprint_ovr_san_path_err_threshold);
1918         install_keyword("san_path_err_forget_rate", &ovr_san_path_err_forget_rate_handler, &snprint_ovr_san_path_err_forget_rate);
1919         install_keyword("san_path_err_recovery_time", &ovr_san_path_err_recovery_time_handler, &snprint_ovr_san_path_err_recovery_time);
1920         install_keyword("marginal_path_err_sample_time", &ovr_marginal_path_err_sample_time_handler, &snprint_ovr_marginal_path_err_sample_time);
1921         install_keyword("marginal_path_err_rate_threshold", &ovr_marginal_path_err_rate_threshold_handler, &snprint_ovr_marginal_path_err_rate_threshold);
1922         install_keyword("marginal_path_err_recheck_gap_time", &ovr_marginal_path_err_recheck_gap_time_handler, &snprint_ovr_marginal_path_err_recheck_gap_time);
1923         install_keyword("marginal_path_double_failed_time", &ovr_marginal_path_double_failed_time_handler, &snprint_ovr_marginal_path_double_failed_time);
1924
1925         install_keyword("skip_kpartx", &ovr_skip_kpartx_handler, &snprint_ovr_skip_kpartx);
1926         install_keyword("max_sectors_kb", &ovr_max_sectors_kb_handler, &snprint_ovr_max_sectors_kb);
1927         install_keyword("ghost_delay", &ovr_ghost_delay_handler, &snprint_ovr_ghost_delay);
1928         install_keyword("all_tg_pt", &ovr_all_tg_pt_handler, &snprint_ovr_all_tg_pt);
1929
1930         install_keyword_root("multipaths", &multipaths_handler);
1931         install_keyword_multi("multipath", &multipath_handler, NULL);
1932         install_sublevel();
1933         install_keyword("wwid", &mp_wwid_handler, &snprint_mp_wwid);
1934         install_keyword("alias", &mp_alias_handler, &snprint_mp_alias);
1935         install_keyword("path_grouping_policy", &mp_pgpolicy_handler, &snprint_mp_pgpolicy);
1936         install_keyword("path_selector", &mp_selector_handler, &snprint_mp_selector);
1937         install_keyword("prio", &mp_prio_name_handler, &snprint_mp_prio_name);
1938         install_keyword("prio_args", &mp_prio_args_handler, &snprint_mp_prio_args);
1939         install_keyword("failback", &mp_pgfailback_handler, &snprint_mp_pgfailback);
1940         install_keyword("rr_weight", &mp_rr_weight_handler, &snprint_mp_rr_weight);
1941         install_keyword("no_path_retry", &mp_no_path_retry_handler, &snprint_mp_no_path_retry);
1942         install_keyword("rr_min_io", &mp_minio_handler, &snprint_mp_minio);
1943         install_keyword("rr_min_io_rq", &mp_minio_rq_handler, &snprint_mp_minio_rq);
1944         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1945         install_keyword("flush_on_last_del", &mp_flush_on_last_del_handler, &snprint_mp_flush_on_last_del);
1946         install_keyword("features", &mp_features_handler, &snprint_mp_features);
1947         install_keyword("mode", &mp_mode_handler, &snprint_mp_mode);
1948         install_keyword("uid", &mp_uid_handler, &snprint_mp_uid);
1949         install_keyword("gid", &mp_gid_handler, &snprint_mp_gid);
1950         install_keyword("reservation_key", &mp_reservation_key_handler, &snprint_mp_reservation_key);
1951         install_keyword("user_friendly_names", &mp_user_friendly_names_handler, &snprint_mp_user_friendly_names);
1952         install_keyword("deferred_remove", &mp_deferred_remove_handler, &snprint_mp_deferred_remove);
1953         install_keyword("delay_watch_checks", &mp_delay_watch_checks_handler, &snprint_mp_delay_watch_checks);
1954         install_keyword("delay_wait_checks", &mp_delay_wait_checks_handler, &snprint_mp_delay_wait_checks);
1955         install_keyword("san_path_err_threshold", &mp_san_path_err_threshold_handler, &snprint_mp_san_path_err_threshold);
1956         install_keyword("san_path_err_forget_rate", &mp_san_path_err_forget_rate_handler, &snprint_mp_san_path_err_forget_rate);
1957         install_keyword("san_path_err_recovery_time", &mp_san_path_err_recovery_time_handler, &snprint_mp_san_path_err_recovery_time);
1958         install_keyword("marginal_path_err_sample_time", &mp_marginal_path_err_sample_time_handler, &snprint_mp_marginal_path_err_sample_time);
1959         install_keyword("marginal_path_err_rate_threshold", &mp_marginal_path_err_rate_threshold_handler, &snprint_mp_marginal_path_err_rate_threshold);
1960         install_keyword("marginal_path_err_recheck_gap_time", &mp_marginal_path_err_recheck_gap_time_handler, &snprint_mp_marginal_path_err_recheck_gap_time);
1961         install_keyword("marginal_path_double_failed_time", &mp_marginal_path_double_failed_time_handler, &snprint_mp_marginal_path_double_failed_time);
1962         install_keyword("skip_kpartx", &mp_skip_kpartx_handler, &snprint_mp_skip_kpartx);
1963         install_keyword("max_sectors_kb", &mp_max_sectors_kb_handler, &snprint_mp_max_sectors_kb);
1964         install_keyword("ghost_delay", &mp_ghost_delay_handler, &snprint_mp_ghost_delay);
1965         install_sublevel_end();
1966 }