6e4ec7163390ec8bdad693805a7cdb046aa00750
[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 <errno.h>
23 #include <inttypes.h>
24 #include "mpath_cmd.h"
25
26 static int
27 set_int(vector strvec, void *ptr)
28 {
29         int *int_ptr = (int *)ptr;
30         char * buff;
31
32         buff = VECTOR_SLOT(strvec, 1);
33         *int_ptr = atoi(buff);
34
35         return 0;
36 }
37
38 static int
39 set_str(vector strvec, void *ptr)
40 {
41         char **str_ptr = (char **)ptr;
42
43         if (*str_ptr)
44                 FREE(*str_ptr);
45         *str_ptr = set_value(strvec);
46
47         if (!*str_ptr)
48                 return 1;
49
50         return 0;
51 }
52
53 static int
54 set_yes_no(vector strvec, void *ptr)
55 {
56         char * buff;
57         int *int_ptr = (int *)ptr;
58
59         buff = set_value(strvec);
60         if (!buff)
61                 return 1;
62
63         if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
64                 *int_ptr = YN_YES;
65         else
66                 *int_ptr = YN_NO;
67
68         FREE(buff);
69         return 0;
70 }
71
72 static int
73 set_yes_no_undef(vector strvec, void *ptr)
74 {
75         char * buff;
76         int *int_ptr = (int *)ptr;
77
78         buff = set_value(strvec);
79         if (!buff)
80                 return 1;
81
82         if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
83                 *int_ptr = YNU_NO;
84         else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
85                 *int_ptr = YNU_YES;
86         else
87                 *int_ptr = YNU_UNDEF;
88
89         FREE(buff);
90         return 0;
91 }
92
93 static int
94 print_int (char *buff, int len, void *ptr)
95 {
96         int *int_ptr = (int *)ptr;
97         return snprintf(buff, len, "%i", *int_ptr);
98 }
99
100 static int
101 print_nonzero (char *buff, int len, void *ptr)
102 {
103         int *int_ptr = (int *)ptr;
104         if (!*int_ptr)
105                 return 0;
106         return snprintf(buff, len, "%i", *int_ptr);
107 }
108
109 static int
110 print_str (char *buff, int len, void *ptr)
111 {
112         char **str_ptr = (char **)ptr;
113         if (!*str_ptr)
114                 return 0;
115         return snprintf(buff, len, "\"%s\"", *str_ptr);
116 }
117
118 static int
119 print_yes_no (char *buff, int len, void *ptr)
120 {
121         int *int_ptr = (int *)ptr;
122         return snprintf(buff, len, "\"%s\"",
123                         (*int_ptr == YN_NO)? "no" : "yes");
124 }
125
126 static int
127 print_yes_no_undef (char *buff, int len, void *ptr)
128 {
129         int *int_ptr = (int *)ptr;
130         if (!*int_ptr)
131                 return 0;
132         return snprintf(buff, len, "\"%s\"",
133                         (*int_ptr == YNU_NO)? "no" : "yes");
134 }
135
136 #define declare_def_handler(option, function)                           \
137 static int                                                              \
138 def_ ## option ## _handler (struct config *conf, vector strvec)         \
139 {                                                                       \
140         return function (strvec, &conf->option);                        \
141 }
142
143 #define declare_def_snprint(option, function)                           \
144 static int                                                              \
145 snprint_def_ ## option (struct config *conf, char * buff, int len, void * data) \
146 {                                                                       \
147         return function (buff, len, &conf->option);                     \
148 }
149
150 #define declare_def_snprint_defint(option, function, value)             \
151 static int                                                              \
152 snprint_def_ ## option (struct config *conf, char * buff, int len, void * data) \
153 {                                                                       \
154         int i = value;                                                  \
155         if (!conf->option)                                              \
156                 return function (buff, len, &i);                        \
157         return function (buff, len, &conf->option);                     \
158 }
159
160 #define declare_def_snprint_defstr(option, function, value)             \
161 static int                                                              \
162 snprint_def_ ## option (struct config *conf, char * buff, int len, void * data) \
163 {                                                                       \
164         char *s = value;                                                \
165         if (!conf->option)                                              \
166                 return function (buff, len, &s);                        \
167         return function (buff, len, &conf->option);                     \
168 }
169
170 #define declare_hw_handler(option, function)                            \
171 static int                                                              \
172 hw_ ## option ## _handler (struct config *conf, vector strvec)          \
173 {                                                                       \
174         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);         \
175         if (!hwe)                                                       \
176                 return 1;                                               \
177         return function (strvec, &hwe->option);                         \
178 }
179
180 #define declare_hw_snprint(option, function)                            \
181 static int                                                              \
182 snprint_hw_ ## option (struct config *conf, char * buff, int len, void * data) \
183 {                                                                       \
184         struct hwentry * hwe = (struct hwentry *)data;                  \
185         return function (buff, len, &hwe->option);                      \
186 }
187
188 #define declare_ovr_handler(option, function)                           \
189 static int                                                              \
190 ovr_ ## option ## _handler (struct config *conf, vector strvec)         \
191 {                                                                       \
192         if (!conf->overrides)                                           \
193                 return 1;                                               \
194         return function (strvec, &conf->overrides->option);             \
195 }
196
197 #define declare_ovr_snprint(option, function)                           \
198 static int                                                              \
199 snprint_ovr_ ## option (struct config *conf, char * buff, int len, void * data) \
200 {                                                                       \
201         return function (buff, len, &conf->overrides->option);          \
202 }
203
204 #define declare_mp_handler(option, function)                            \
205 static int                                                              \
206 mp_ ## option ## _handler (struct config *conf, vector strvec)          \
207 {                                                                       \
208         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);         \
209         if (!mpe)                                                       \
210                 return 1;                                               \
211         return function (strvec, &mpe->option);                         \
212 }
213
214 #define declare_mp_snprint(option, function)                            \
215 static int                                                              \
216 snprint_mp_ ## option (struct config *conf, char * buff, int len, void * data) \
217 {                                                                       \
218         struct mpentry * mpe = (struct mpentry *)data;                  \
219         return function (buff, len, &mpe->option);                      \
220 }
221
222 declare_def_handler(checkint, set_int)
223 declare_def_snprint(checkint, print_int)
224
225 declare_def_handler(max_checkint, set_int)
226 declare_def_snprint(max_checkint, print_int)
227
228 declare_def_handler(verbosity, set_int)
229 declare_def_snprint(verbosity, print_int)
230
231 declare_def_handler(reassign_maps, set_yes_no)
232 declare_def_snprint(reassign_maps, print_yes_no)
233
234 declare_def_handler(multipath_dir, set_str)
235 declare_def_snprint(multipath_dir, print_str)
236
237 declare_def_handler(partition_delim, set_str)
238 declare_def_snprint(partition_delim, print_str)
239
240 declare_def_handler(find_multipaths, set_yes_no)
241 declare_def_snprint(find_multipaths, print_yes_no)
242
243 declare_def_handler(selector, set_str)
244 declare_def_snprint_defstr(selector, print_str, DEFAULT_SELECTOR)
245 declare_hw_handler(selector, set_str)
246 declare_hw_snprint(selector, print_str)
247 declare_ovr_handler(selector, set_str)
248 declare_ovr_snprint(selector, print_str)
249 declare_mp_handler(selector, set_str)
250 declare_mp_snprint(selector, print_str)
251
252 declare_def_handler(uid_attribute, set_str)
253 declare_def_snprint_defstr(uid_attribute, print_str, DEFAULT_UID_ATTRIBUTE)
254 declare_ovr_handler(uid_attribute, set_str)
255 declare_ovr_snprint(uid_attribute, print_str)
256 declare_hw_handler(uid_attribute, set_str)
257 declare_hw_snprint(uid_attribute, print_str)
258
259 declare_def_handler(getuid, set_str)
260 declare_def_snprint(getuid, print_str)
261 declare_ovr_handler(getuid, set_str)
262 declare_ovr_snprint(getuid, print_str)
263 declare_hw_handler(getuid, set_str)
264 declare_hw_snprint(getuid, print_str)
265
266 declare_def_handler(prio_name, set_str)
267 declare_def_snprint_defstr(prio_name, print_str, DEFAULT_PRIO)
268 declare_ovr_handler(prio_name, set_str)
269 declare_ovr_snprint(prio_name, print_str)
270 declare_hw_handler(prio_name, set_str)
271 declare_hw_snprint(prio_name, print_str)
272 declare_mp_handler(prio_name, set_str)
273 declare_mp_snprint(prio_name, print_str)
274
275 declare_def_handler(alias_prefix, set_str)
276 declare_def_snprint_defstr(alias_prefix, print_str, DEFAULT_ALIAS_PREFIX)
277 declare_ovr_handler(alias_prefix, set_str)
278 declare_ovr_snprint(alias_prefix, print_str)
279 declare_hw_handler(alias_prefix, set_str)
280 declare_hw_snprint(alias_prefix, print_str)
281
282 declare_def_handler(prio_args, set_str)
283 declare_def_snprint_defstr(prio_args, print_str, DEFAULT_PRIO_ARGS)
284 declare_ovr_handler(prio_args, set_str)
285 declare_ovr_snprint(prio_args, print_str)
286 declare_hw_handler(prio_args, set_str)
287 declare_hw_snprint(prio_args, print_str)
288 declare_mp_handler(prio_args, set_str)
289 declare_mp_snprint(prio_args, print_str)
290
291 declare_def_handler(features, set_str)
292 declare_def_snprint_defstr(features, print_str, DEFAULT_FEATURES)
293 declare_ovr_handler(features, set_str)
294 declare_ovr_snprint(features, print_str)
295 declare_hw_handler(features, set_str)
296 declare_hw_snprint(features, print_str)
297 declare_mp_handler(features, set_str)
298 declare_mp_snprint(features, print_str)
299
300 declare_def_handler(checker_name, set_str)
301 declare_def_snprint_defstr(checker_name, print_str, DEFAULT_CHECKER)
302 declare_ovr_handler(checker_name, set_str)
303 declare_ovr_snprint(checker_name, print_str)
304 declare_hw_handler(checker_name, set_str)
305 declare_hw_snprint(checker_name, print_str)
306
307 declare_def_handler(minio, set_int)
308 declare_def_snprint_defint(minio, print_int, DEFAULT_MINIO)
309 declare_ovr_handler(minio, set_int)
310 declare_ovr_snprint(minio, print_nonzero)
311 declare_hw_handler(minio, set_int)
312 declare_hw_snprint(minio, print_nonzero)
313 declare_mp_handler(minio, set_int)
314 declare_mp_snprint(minio, print_nonzero)
315
316 declare_def_handler(minio_rq, set_int)
317 declare_def_snprint_defint(minio_rq, print_int, DEFAULT_MINIO_RQ)
318 declare_ovr_handler(minio_rq, set_int)
319 declare_ovr_snprint(minio_rq, print_nonzero)
320 declare_hw_handler(minio_rq, set_int)
321 declare_hw_snprint(minio_rq, print_nonzero)
322 declare_mp_handler(minio_rq, set_int)
323 declare_mp_snprint(minio_rq, print_nonzero)
324
325 declare_def_handler(queue_without_daemon, set_yes_no)
326 static int
327 snprint_def_queue_without_daemon (struct config *conf,
328                                   char * buff, int len, void * data)
329 {
330         switch (conf->queue_without_daemon) {
331         case QUE_NO_DAEMON_OFF:
332                 return snprintf(buff, len, "\"no\"");
333         case QUE_NO_DAEMON_ON:
334                 return snprintf(buff, len, "\"yes\"");
335         case QUE_NO_DAEMON_FORCE:
336                 return snprintf(buff, len, "\"forced\"");
337         }
338         return 0;
339 }
340
341 declare_def_handler(checker_timeout, set_int)
342 declare_def_snprint(checker_timeout, print_nonzero)
343
344 declare_def_handler(flush_on_last_del, set_yes_no_undef)
345 declare_def_snprint_defint(flush_on_last_del, print_yes_no_undef, YNU_NO)
346 declare_ovr_handler(flush_on_last_del, set_yes_no_undef)
347 declare_ovr_snprint(flush_on_last_del, print_yes_no_undef)
348 declare_hw_handler(flush_on_last_del, set_yes_no_undef)
349 declare_hw_snprint(flush_on_last_del, print_yes_no_undef)
350 declare_mp_handler(flush_on_last_del, set_yes_no_undef)
351 declare_mp_snprint(flush_on_last_del, print_yes_no_undef)
352
353 declare_def_handler(user_friendly_names, set_yes_no_undef)
354 declare_def_snprint_defint(user_friendly_names, print_yes_no_undef, YNU_NO)
355 declare_ovr_handler(user_friendly_names, set_yes_no_undef)
356 declare_ovr_snprint(user_friendly_names, print_yes_no_undef)
357 declare_hw_handler(user_friendly_names, set_yes_no_undef)
358 declare_hw_snprint(user_friendly_names, print_yes_no_undef)
359 declare_mp_handler(user_friendly_names, set_yes_no_undef)
360 declare_mp_snprint(user_friendly_names, print_yes_no_undef)
361
362 declare_def_handler(bindings_file, set_str)
363 declare_def_snprint(bindings_file, print_str)
364
365 declare_def_handler(wwids_file, set_str)
366 declare_def_snprint(wwids_file, print_str)
367
368 declare_def_handler(retain_hwhandler, set_yes_no_undef)
369 declare_def_snprint_defint(retain_hwhandler, print_yes_no_undef, YNU_NO)
370 declare_ovr_handler(retain_hwhandler, set_yes_no_undef)
371 declare_ovr_snprint(retain_hwhandler, print_yes_no_undef)
372 declare_hw_handler(retain_hwhandler, set_yes_no_undef)
373 declare_hw_snprint(retain_hwhandler, print_yes_no_undef)
374
375 declare_def_handler(detect_prio, set_yes_no_undef)
376 declare_def_snprint_defint(detect_prio, print_yes_no_undef, YNU_NO)
377 declare_ovr_handler(detect_prio, set_yes_no_undef)
378 declare_ovr_snprint(detect_prio, print_yes_no_undef)
379 declare_hw_handler(detect_prio, set_yes_no_undef)
380 declare_hw_snprint(detect_prio, print_yes_no_undef)
381
382 declare_def_handler(force_sync, set_yes_no)
383 declare_def_snprint(force_sync, print_yes_no)
384
385 declare_def_handler(deferred_remove, set_yes_no_undef)
386 declare_def_snprint_defint(deferred_remove, print_yes_no_undef, YNU_NO)
387 declare_ovr_handler(deferred_remove, set_yes_no_undef)
388 declare_ovr_snprint(deferred_remove, print_yes_no_undef)
389 declare_hw_handler(deferred_remove, set_yes_no_undef)
390 declare_hw_snprint(deferred_remove, print_yes_no_undef)
391 declare_mp_handler(deferred_remove, set_yes_no_undef)
392 declare_mp_snprint(deferred_remove, print_yes_no_undef)
393
394 declare_def_handler(retrigger_tries, set_int)
395 declare_def_snprint(retrigger_tries, print_int)
396
397 declare_def_handler(retrigger_delay, set_int)
398 declare_def_snprint(retrigger_delay, print_int)
399
400 declare_def_handler(uev_wait_timeout, set_int)
401 declare_def_snprint(uev_wait_timeout, print_int)
402
403 declare_def_handler(strict_timing, set_yes_no)
404 declare_def_snprint(strict_timing, print_yes_no)
405
406 declare_def_handler(skip_kpartx, set_yes_no_undef)
407 declare_def_snprint_defint(skip_kpartx, print_yes_no_undef, YNU_NO)
408 declare_ovr_handler(skip_kpartx, set_yes_no_undef)
409 declare_ovr_snprint(skip_kpartx, print_yes_no_undef)
410 declare_hw_handler(skip_kpartx, set_yes_no_undef)
411 declare_hw_snprint(skip_kpartx, print_yes_no_undef)
412 declare_mp_handler(skip_kpartx, set_yes_no_undef)
413 declare_mp_snprint(skip_kpartx, print_yes_no_undef)
414
415 declare_def_handler(disable_changed_wwids, set_yes_no)
416 declare_def_snprint(disable_changed_wwids, print_yes_no)
417
418 declare_def_handler(remove_retries, set_int)
419 declare_def_snprint(remove_retries, print_int)
420
421 static int
422 def_config_dir_handler(struct config *conf, vector strvec)
423 {
424         /* this is only valid in the main config file */
425         if (conf->processed_main_config)
426                 return 0;
427         return set_str(strvec, &conf->config_dir);
428 }
429 declare_def_snprint(config_dir, print_str)
430
431 #define declare_def_attr_handler(option, function)                      \
432 static int                                                              \
433 def_ ## option ## _handler (struct config *conf, vector strvec)         \
434 {                                                                       \
435         return function (strvec, &conf->option, &conf->attribute_flags);\
436 }
437
438 #define declare_def_attr_snprint(option, function)                      \
439 static int                                                              \
440 snprint_def_ ## option (struct config *conf, char * buff, int len, void * data) \
441 {                                                                       \
442         return function (buff, len, &conf->option,                      \
443                          &conf->attribute_flags);                       \
444 }
445
446 #define declare_mp_attr_handler(option, function)                       \
447 static int                                                              \
448 mp_ ## option ## _handler (struct config *conf, vector strvec)          \
449 {                                                                       \
450         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);         \
451         if (!mpe)                                                       \
452                 return 1;                                               \
453         return function (strvec, &mpe->option, &mpe->attribute_flags);  \
454 }
455
456 #define declare_mp_attr_snprint(option, function)                       \
457 static int                                                              \
458 snprint_mp_ ## option (struct config *conf, char * buff, int len, void * data) \
459 {                                                                       \
460         struct mpentry * mpe = (struct mpentry *)data;                  \
461         return function (buff, len, &mpe->option,                       \
462                          &mpe->attribute_flags);                        \
463 }
464
465 static int
466 set_mode(vector strvec, void *ptr, int *flags)
467 {
468         mode_t mode;
469         mode_t *mode_ptr = (mode_t *)ptr;
470         char *buff;
471
472         buff = set_value(strvec);
473
474         if (!buff)
475                 return 1;
476
477         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
478                 *flags |= (1 << ATTR_MODE);
479                 *mode_ptr = mode;
480         }
481
482         FREE(buff);
483         return 0;
484 }
485
486 static int
487 set_uid(vector strvec, void *ptr, int *flags)
488 {
489         uid_t uid;
490         uid_t *uid_ptr = (uid_t *)ptr;
491         char *buff;
492         char passwd_buf[1024];
493         struct passwd info, *found;
494
495         buff = set_value(strvec);
496         if (!buff)
497                 return 1;
498         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
499                 *flags |= (1 << ATTR_UID);
500                 *uid_ptr = info.pw_uid;
501         }
502         else if (sscanf(buff, "%u", &uid) == 1){
503                 *flags |= (1 << ATTR_UID);
504                 *uid_ptr = uid;
505         }
506
507         FREE(buff);
508         return 0;
509 }
510
511 static int
512 set_gid(vector strvec, void *ptr, int *flags)
513 {
514         gid_t gid;
515         gid_t *gid_ptr = (gid_t *)ptr;
516         char *buff;
517         char passwd_buf[1024];
518         struct passwd info, *found;
519
520         buff = set_value(strvec);
521         if (!buff)
522                 return 1;
523
524         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
525                 *flags |= (1 << ATTR_GID);
526                 *gid_ptr = info.pw_gid;
527         }
528         else if (sscanf(buff, "%u", &gid) == 1){
529                 *flags |= (1 << ATTR_GID);
530                 *gid_ptr = gid;
531         }
532         FREE(buff);
533         return 0;
534 }
535
536 static int
537 print_mode(char * buff, int len, void *ptr, int *flags)
538 {
539         mode_t *mode_ptr = (mode_t *)ptr;
540         if ((*flags & (1 << ATTR_MODE)) == 0)
541                 return 0;
542         return snprintf(buff, len, "0%o", *mode_ptr);
543 }
544
545 static int
546 print_uid(char * buff, int len, void *ptr, int *flags)
547 {
548         uid_t *uid_ptr = (uid_t *)ptr;
549         if ((*flags & (1 << ATTR_UID)) == 0)
550                 return 0;
551         return snprintf(buff, len, "0%o", *uid_ptr);
552 }
553
554 static int
555 print_gid(char * buff, int len, void *ptr, int *flags)
556 {
557         gid_t *gid_ptr = (gid_t *)ptr;
558         if ((*flags & (1 << ATTR_GID)) == 0)
559                 return 0;
560         return snprintf(buff, len, "0%o", *gid_ptr);
561 }
562
563 declare_def_attr_handler(mode, set_mode)
564 declare_def_attr_snprint(mode, print_mode)
565 declare_mp_attr_handler(mode, set_mode)
566 declare_mp_attr_snprint(mode, print_mode)
567
568 declare_def_attr_handler(uid, set_uid)
569 declare_def_attr_snprint(uid, print_uid)
570 declare_mp_attr_handler(uid, set_uid)
571 declare_mp_attr_snprint(uid, print_uid)
572
573 declare_def_attr_handler(gid, set_gid)
574 declare_def_attr_snprint(gid, print_gid)
575 declare_mp_attr_handler(gid, set_gid)
576 declare_mp_attr_snprint(gid, print_gid)
577
578 static int
579 set_fast_io_fail(vector strvec, void *ptr)
580 {
581         char * buff;
582         int *int_ptr = (int *)ptr;
583
584         buff = set_value(strvec);
585         if (!buff)
586                 return 1;
587
588         if (strcmp(buff, "off") == 0)
589                 *int_ptr = MP_FAST_IO_FAIL_OFF;
590         else if (sscanf(buff, "%d", int_ptr) != 1 ||
591                  *int_ptr < MP_FAST_IO_FAIL_ZERO)
592                 *int_ptr = MP_FAST_IO_FAIL_UNSET;
593         else if (*int_ptr == 0)
594                 *int_ptr = MP_FAST_IO_FAIL_ZERO;
595
596         FREE(buff);
597         return 0;
598 }
599
600 int
601 print_fast_io_fail(char * buff, int len, void *ptr)
602 {
603         int *int_ptr = (int *)ptr;
604
605         if (*int_ptr == MP_FAST_IO_FAIL_UNSET)
606                 return 0;
607         if (*int_ptr == MP_FAST_IO_FAIL_OFF)
608                 return snprintf(buff, len, "\"off\"");
609         if (*int_ptr == MP_FAST_IO_FAIL_ZERO)
610                 return snprintf(buff, len, "0");
611         return snprintf(buff, len, "%d", *int_ptr);
612 }
613
614 declare_def_handler(fast_io_fail, set_fast_io_fail)
615 declare_def_snprint(fast_io_fail, print_fast_io_fail)
616 declare_ovr_handler(fast_io_fail, set_fast_io_fail)
617 declare_ovr_snprint(fast_io_fail, print_fast_io_fail)
618 declare_hw_handler(fast_io_fail, set_fast_io_fail)
619 declare_hw_snprint(fast_io_fail, print_fast_io_fail)
620
621 static int
622 set_dev_loss(vector strvec, void *ptr)
623 {
624         char * buff;
625         unsigned int *uint_ptr = (unsigned int *)ptr;
626
627         buff = set_value(strvec);
628         if (!buff)
629                 return 1;
630
631         if (!strcmp(buff, "infinity"))
632                 *uint_ptr = MAX_DEV_LOSS_TMO;
633         else if (sscanf(buff, "%u", uint_ptr) != 1)
634                 *uint_ptr = 0;
635
636         FREE(buff);
637         return 0;
638 }
639
640 int
641 print_dev_loss(char * buff, int len, void *ptr)
642 {
643         unsigned int *uint_ptr = (unsigned int *)ptr;
644
645         if (!*uint_ptr)
646                 return 0;
647         if (*uint_ptr >= MAX_DEV_LOSS_TMO)
648                 return snprintf(buff, len, "\"infinity\"");
649         return snprintf(buff, len, "%u", *uint_ptr);
650 }
651
652 declare_def_handler(dev_loss, set_dev_loss)
653 declare_def_snprint(dev_loss, print_dev_loss)
654 declare_ovr_handler(dev_loss, set_dev_loss)
655 declare_ovr_snprint(dev_loss, print_dev_loss)
656 declare_hw_handler(dev_loss, set_dev_loss)
657 declare_hw_snprint(dev_loss, print_dev_loss)
658
659 static int
660 set_pgpolicy(vector strvec, void *ptr)
661 {
662         char * buff;
663         int *int_ptr = (int *)ptr;
664
665         buff = set_value(strvec);
666         if (!buff)
667                 return 1;
668
669         *int_ptr = get_pgpolicy_id(buff);
670         FREE(buff);
671
672         return 0;
673 }
674
675 int
676 print_pgpolicy(char * buff, int len, void *ptr)
677 {
678         char str[POLICY_NAME_SIZE];
679         int pgpolicy = *(int *)ptr;
680
681         if (!pgpolicy)
682                 return 0;
683
684         get_pgpolicy_name(str, POLICY_NAME_SIZE, pgpolicy);
685
686         return snprintf(buff, len, "\"%s\"", str);
687 }
688
689 declare_def_handler(pgpolicy, set_pgpolicy)
690 declare_def_snprint_defint(pgpolicy, print_pgpolicy, DEFAULT_PGPOLICY)
691 declare_ovr_handler(pgpolicy, set_pgpolicy)
692 declare_ovr_snprint(pgpolicy, print_pgpolicy)
693 declare_hw_handler(pgpolicy, set_pgpolicy)
694 declare_hw_snprint(pgpolicy, print_pgpolicy)
695 declare_mp_handler(pgpolicy, set_pgpolicy)
696 declare_mp_snprint(pgpolicy, print_pgpolicy)
697
698 int
699 get_sys_max_fds(int *max_fds)
700 {
701         FILE *file;
702         int nr_open;
703         int ret = 1;
704
705         file = fopen("/proc/sys/fs/nr_open", "r");
706         if (!file) {
707                 fprintf(stderr, "Cannot open /proc/sys/fs/nr_open : %s\n",
708                         strerror(errno));
709                 return 1;
710         }
711         if (fscanf(file, "%d", &nr_open) != 1) {
712                 fprintf(stderr, "Cannot read max open fds from /proc/sys/fs/nr_open");
713                 if (ferror(file))
714                         fprintf(stderr, " : %s\n", strerror(errno));
715                 else
716                         fprintf(stderr, "\n");
717         } else {
718                 *max_fds = nr_open;
719                 ret = 0;
720         }
721         fclose(file);
722         return ret;
723 }
724
725
726 static int
727 max_fds_handler(struct config *conf, vector strvec)
728 {
729         char * buff;
730         int r = 0, max_fds;
731
732         buff = set_value(strvec);
733
734         if (!buff)
735                 return 1;
736
737         r = get_sys_max_fds(&max_fds);
738         if (r) {
739                 /* Assume safe limit */
740                 max_fds = 4096;
741         }
742         if (strlen(buff) == 3 &&
743             !strcmp(buff, "max"))
744                 conf->max_fds = max_fds;
745         else
746                 conf->max_fds = atoi(buff);
747
748         if (conf->max_fds > max_fds)
749                 conf->max_fds = max_fds;
750
751         FREE(buff);
752
753         return r;
754 }
755
756 static int
757 snprint_max_fds (struct config *conf, char * buff, int len, void * data)
758 {
759         int r = 0, max_fds;
760
761         if (!conf->max_fds)
762                 return 0;
763
764         r = get_sys_max_fds(&max_fds);
765         if (!r && conf->max_fds >= max_fds)
766                 return snprintf(buff, len, "\"max\"");
767         else
768                 return snprintf(buff, len, "%d", conf->max_fds);
769 }
770
771 static int
772 set_rr_weight(vector strvec, void *ptr)
773 {
774         int *int_ptr = (int *)ptr;
775         char * buff;
776
777         buff = set_value(strvec);
778
779         if (!buff)
780                 return 1;
781
782         if (!strcmp(buff, "priorities"))
783                 *int_ptr = RR_WEIGHT_PRIO;
784
785         if (!strcmp(buff, "uniform"))
786                 *int_ptr = RR_WEIGHT_NONE;
787
788         FREE(buff);
789
790         return 0;
791 }
792
793 int
794 print_rr_weight (char * buff, int len, void *ptr)
795 {
796         int *int_ptr = (int *)ptr;
797
798         if (!*int_ptr)
799                 return 0;
800         if (*int_ptr == RR_WEIGHT_PRIO)
801                 return snprintf(buff, len, "\"priorities\"");
802         if (*int_ptr == RR_WEIGHT_NONE)
803                 return snprintf(buff, len, "\"uniform\"");
804
805         return 0;
806 }
807
808 declare_def_handler(rr_weight, set_rr_weight)
809 declare_def_snprint_defint(rr_weight, print_rr_weight, RR_WEIGHT_NONE)
810 declare_ovr_handler(rr_weight, set_rr_weight)
811 declare_ovr_snprint(rr_weight, print_rr_weight)
812 declare_hw_handler(rr_weight, set_rr_weight)
813 declare_hw_snprint(rr_weight, print_rr_weight)
814 declare_mp_handler(rr_weight, set_rr_weight)
815 declare_mp_snprint(rr_weight, print_rr_weight)
816
817 static int
818 set_pgfailback(vector strvec, void *ptr)
819 {
820         int *int_ptr = (int *)ptr;
821         char * buff;
822
823         buff = set_value(strvec);
824         if (!buff)
825                 return 1;
826
827         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
828                 *int_ptr = -FAILBACK_MANUAL;
829         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
830                 *int_ptr = -FAILBACK_IMMEDIATE;
831         else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
832                 *int_ptr = -FAILBACK_FOLLOWOVER;
833         else
834                 *int_ptr = atoi(buff);
835
836         FREE(buff);
837
838         return 0;
839 }
840
841 int
842 print_pgfailback (char * buff, int len, void *ptr)
843 {
844         int *int_ptr = (int *)ptr;
845
846         switch(*int_ptr) {
847         case  FAILBACK_UNDEF:
848                 return 0;
849         case -FAILBACK_MANUAL:
850                 return snprintf(buff, len, "\"manual\"");
851         case -FAILBACK_IMMEDIATE:
852                 return snprintf(buff, len, "\"immediate\"");
853         case -FAILBACK_FOLLOWOVER:
854                 return snprintf(buff, len, "\"followover\"");
855         default:
856                 return snprintf(buff, len, "%i", *int_ptr);
857         }
858 }
859
860 declare_def_handler(pgfailback, set_pgfailback)
861 declare_def_snprint_defint(pgfailback, print_pgfailback, DEFAULT_FAILBACK)
862 declare_ovr_handler(pgfailback, set_pgfailback)
863 declare_ovr_snprint(pgfailback, print_pgfailback)
864 declare_hw_handler(pgfailback, set_pgfailback)
865 declare_hw_snprint(pgfailback, print_pgfailback)
866 declare_mp_handler(pgfailback, set_pgfailback)
867 declare_mp_snprint(pgfailback, print_pgfailback)
868
869 static int
870 set_no_path_retry(vector strvec, void *ptr)
871 {
872         int *int_ptr = (int *)ptr;
873         char * buff;
874
875         buff = set_value(strvec);
876         if (!buff)
877                 return 1;
878
879         if (!strcmp(buff, "fail") || !strcmp(buff, "0"))
880                 *int_ptr = NO_PATH_RETRY_FAIL;
881         else if (!strcmp(buff, "queue"))
882                 *int_ptr = NO_PATH_RETRY_QUEUE;
883         else if ((*int_ptr = atoi(buff)) < 1)
884                 *int_ptr = NO_PATH_RETRY_UNDEF;
885
886         FREE(buff);
887         return 0;
888 }
889
890 int
891 print_no_path_retry(char * buff, int len, void *ptr)
892 {
893         int *int_ptr = (int *)ptr;
894
895         switch(*int_ptr) {
896         case NO_PATH_RETRY_UNDEF:
897                 return 0;
898         case NO_PATH_RETRY_FAIL:
899                 return snprintf(buff, len, "\"fail\"");
900         case NO_PATH_RETRY_QUEUE:
901                 return snprintf(buff, len, "\"queue\"");
902         default:
903                 return snprintf(buff, len, "%i", *int_ptr);
904         }
905 }
906
907 declare_def_handler(no_path_retry, set_no_path_retry)
908 declare_def_snprint(no_path_retry, print_no_path_retry)
909 declare_ovr_handler(no_path_retry, set_no_path_retry)
910 declare_ovr_snprint(no_path_retry, print_no_path_retry)
911 declare_hw_handler(no_path_retry, set_no_path_retry)
912 declare_hw_snprint(no_path_retry, print_no_path_retry)
913 declare_mp_handler(no_path_retry, set_no_path_retry)
914 declare_mp_snprint(no_path_retry, print_no_path_retry)
915
916 static int
917 def_log_checker_err_handler(struct config *conf, vector strvec)
918 {
919         char * buff;
920
921         buff = set_value(strvec);
922
923         if (!buff)
924                 return 1;
925
926         if (strlen(buff) == 4 && !strcmp(buff, "once"))
927                 conf->log_checker_err = LOG_CHKR_ERR_ONCE;
928         else if (strlen(buff) == 6 && !strcmp(buff, "always"))
929                 conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
930
931         free(buff);
932         return 0;
933 }
934
935 static int
936 snprint_def_log_checker_err (struct config *conf, char * buff, int len, void * data)
937 {
938         if (conf->log_checker_err == LOG_CHKR_ERR_ONCE)
939                 return snprintf(buff, len, "once");
940         return snprintf(buff, len, "always");
941 }
942
943 static int
944 set_reservation_key(vector strvec, void *ptr)
945 {
946         unsigned char **uchar_ptr = (unsigned char **)ptr;
947         char *buff;
948         char *tbuff;
949         int j, k;
950         int len;
951         uint64_t prkey;
952
953         buff = set_value(strvec);
954         if (!buff)
955                 return 1;
956
957         tbuff = buff;
958
959         if (!memcmp("0x",buff, 2))
960                 buff = buff + 2;
961
962         len = strlen(buff);
963
964         k = strspn(buff, "0123456789aAbBcCdDeEfF");
965
966         if (len != k) {
967                 FREE(tbuff);
968                 return 1;
969         }
970
971         if (1 != sscanf (buff, "%" SCNx64 "", &prkey))
972         {
973                 FREE(tbuff);
974                 return 1;
975         }
976
977         if (!*uchar_ptr)
978                 *uchar_ptr = (unsigned char *) malloc(8);
979
980         memset(*uchar_ptr, 0, 8);
981
982         for (j = 7; j >= 0; --j) {
983                 (*uchar_ptr)[j] = (prkey & 0xff);
984                 prkey >>= 8;
985         }
986
987         FREE(tbuff);
988         return 0;
989 }
990
991 int
992 print_reservation_key(char * buff, int len, void * ptr)
993 {
994         unsigned char **uchar_ptr = (unsigned char **)ptr;
995         int i;
996         unsigned char *keyp;
997         uint64_t prkey = 0;
998
999         if (!*uchar_ptr)
1000                 return 0;
1001         keyp = (unsigned char *)(*uchar_ptr);
1002         for (i = 0; i < 8; i++) {
1003                 if (i > 0)
1004                         prkey <<= 8;
1005                 prkey |= *keyp;
1006                 keyp++;
1007         }
1008         return snprintf(buff, len, "0x%" PRIx64, prkey);
1009 }
1010
1011 declare_def_handler(reservation_key, set_reservation_key)
1012 declare_def_snprint(reservation_key, print_reservation_key)
1013 declare_mp_handler(reservation_key, set_reservation_key)
1014 declare_mp_snprint(reservation_key, print_reservation_key)
1015
1016 static int
1017 set_delay_checks(vector strvec, void *ptr)
1018 {
1019         int *int_ptr = (int *)ptr;
1020         char * buff;
1021
1022         buff = set_value(strvec);
1023         if (!buff)
1024                 return 1;
1025
1026         if (!strcmp(buff, "no") || !strcmp(buff, "0"))
1027                 *int_ptr = DELAY_CHECKS_OFF;
1028         else if ((*int_ptr = atoi(buff)) < 1)
1029                 *int_ptr = DELAY_CHECKS_UNDEF;
1030
1031         FREE(buff);
1032         return 0;
1033 }
1034
1035 int
1036 print_delay_checks(char * buff, int len, void *ptr)
1037 {
1038         int *int_ptr = (int *)ptr;
1039
1040         switch(*int_ptr) {
1041         case DELAY_CHECKS_UNDEF:
1042                 return 0;
1043         case DELAY_CHECKS_OFF:
1044                 return snprintf(buff, len, "\"off\"");
1045         default:
1046                 return snprintf(buff, len, "%i", *int_ptr);
1047         }
1048 }
1049
1050 declare_def_handler(delay_watch_checks, set_delay_checks)
1051 declare_def_snprint(delay_watch_checks, print_delay_checks)
1052 declare_ovr_handler(delay_watch_checks, set_delay_checks)
1053 declare_ovr_snprint(delay_watch_checks, print_delay_checks)
1054 declare_hw_handler(delay_watch_checks, set_delay_checks)
1055 declare_hw_snprint(delay_watch_checks, print_delay_checks)
1056 declare_mp_handler(delay_watch_checks, set_delay_checks)
1057 declare_mp_snprint(delay_watch_checks, print_delay_checks)
1058
1059 declare_def_handler(delay_wait_checks, set_delay_checks)
1060 declare_def_snprint(delay_wait_checks, print_delay_checks)
1061 declare_ovr_handler(delay_wait_checks, set_delay_checks)
1062 declare_ovr_snprint(delay_wait_checks, print_delay_checks)
1063 declare_hw_handler(delay_wait_checks, set_delay_checks)
1064 declare_hw_snprint(delay_wait_checks, print_delay_checks)
1065 declare_mp_handler(delay_wait_checks, set_delay_checks)
1066 declare_mp_snprint(delay_wait_checks, print_delay_checks)
1067
1068 static int
1069 def_uxsock_timeout_handler(struct config *conf, vector strvec)
1070 {
1071         unsigned int uxsock_timeout;
1072         char *buff;
1073
1074         buff = set_value(strvec);
1075         if (!buff)
1076                 return 1;
1077
1078         if (sscanf(buff, "%u", &uxsock_timeout) == 1 &&
1079             uxsock_timeout > DEFAULT_REPLY_TIMEOUT)
1080                 conf->uxsock_timeout = uxsock_timeout;
1081         else
1082                 conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
1083
1084         free(buff);
1085         return 0;
1086 }
1087
1088 /*
1089  * blacklist block handlers
1090  */
1091 static int
1092 blacklist_handler(struct config *conf, vector strvec)
1093 {
1094         if (!conf->blist_devnode)
1095                 conf->blist_devnode = vector_alloc();
1096         if (!conf->blist_wwid)
1097                 conf->blist_wwid = vector_alloc();
1098         if (!conf->blist_device)
1099                 conf->blist_device = vector_alloc();
1100         if (!conf->blist_property)
1101                 conf->blist_property = vector_alloc();
1102
1103         if (!conf->blist_devnode || !conf->blist_wwid ||
1104             !conf->blist_device || !conf->blist_property)
1105                 return 1;
1106
1107         return 0;
1108 }
1109
1110 static int
1111 blacklist_exceptions_handler(struct config *conf, vector strvec)
1112 {
1113         if (!conf->elist_devnode)
1114                 conf->elist_devnode = vector_alloc();
1115         if (!conf->elist_wwid)
1116                 conf->elist_wwid = vector_alloc();
1117         if (!conf->elist_device)
1118                 conf->elist_device = vector_alloc();
1119         if (!conf->elist_property)
1120                 conf->elist_property = vector_alloc();
1121
1122         if (!conf->elist_devnode || !conf->elist_wwid ||
1123             !conf->elist_device || !conf->elist_property)
1124                 return 1;
1125
1126         return 0;
1127 }
1128
1129 #define declare_ble_handler(option)                                     \
1130 static int                                                              \
1131 ble_ ## option ## _handler (struct config *conf, vector strvec)         \
1132 {                                                                       \
1133         char * buff;                                                    \
1134                                                                         \
1135         if (!conf->option)                                              \
1136                 return 1;                                               \
1137                                                                         \
1138         buff = set_value(strvec);                                       \
1139         if (!buff)                                                      \
1140                 return 1;                                               \
1141                                                                         \
1142         return store_ble(conf->option, buff, ORIGIN_CONFIG);            \
1143 }
1144
1145 #define declare_ble_device_handler(name, option, vend, prod)            \
1146 static int                                                              \
1147 ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
1148 {                                                                       \
1149         char * buff;                                                    \
1150                                                                         \
1151         if (!conf->option)                                              \
1152                 return 1;                                               \
1153                                                                         \
1154         buff = set_value(strvec);                                       \
1155         if (!buff)                                                      \
1156                 return 1;                                               \
1157                                                                         \
1158         return set_ble_device(conf->option, vend, prod, ORIGIN_CONFIG); \
1159 }
1160
1161 declare_ble_handler(blist_devnode)
1162 declare_ble_handler(elist_devnode)
1163 declare_ble_handler(blist_wwid)
1164 declare_ble_handler(elist_wwid)
1165 declare_ble_handler(blist_property)
1166 declare_ble_handler(elist_property)
1167
1168 static int
1169 snprint_def_uxsock_timeout(struct config *conf, char * buff, int len, void * data)
1170 {
1171         return snprintf(buff, len, "%u", conf->uxsock_timeout);
1172 }
1173
1174 static int
1175 snprint_ble_simple (struct config *conf, char * buff, int len, void * data)
1176 {
1177         struct blentry * ble = (struct blentry *)data;
1178
1179         return snprintf(buff, len, "\"%s\"", ble->str);
1180 }
1181
1182 static int
1183 ble_device_handler(struct config *conf, vector strvec)
1184 {
1185         return alloc_ble_device(conf->blist_device);
1186 }
1187
1188 static int
1189 ble_except_device_handler(struct config *conf, vector strvec)
1190 {
1191         return alloc_ble_device(conf->elist_device);
1192 }
1193
1194 declare_ble_device_handler(vendor, blist_device, buff, NULL)
1195 declare_ble_device_handler(vendor, elist_device, buff, NULL)
1196 declare_ble_device_handler(product, blist_device, NULL, buff)
1197 declare_ble_device_handler(product, elist_device, NULL, buff)
1198
1199 static int
1200 snprint_bled_vendor (struct config *conf, char * buff, int len, void * data)
1201 {
1202         struct blentry_device * bled = (struct blentry_device *)data;
1203
1204         return snprintf(buff, len, "\"%s\"", bled->vendor);
1205 }
1206
1207 static int
1208 snprint_bled_product (struct config *conf, char * buff, int len, void * data)
1209 {
1210         struct blentry_device * bled = (struct blentry_device *)data;
1211
1212         return snprintf(buff, len, "\"%s\"", bled->product);
1213 }
1214
1215 /*
1216  * devices block handlers
1217  */
1218 static int
1219 devices_handler(struct config *conf, vector strvec)
1220 {
1221         if (!conf->hwtable)
1222                 conf->hwtable = vector_alloc();
1223
1224         if (!conf->hwtable)
1225                 return 1;
1226
1227         return 0;
1228 }
1229
1230 static int
1231 device_handler(struct config *conf, vector strvec)
1232 {
1233         struct hwentry * hwe;
1234
1235         hwe = alloc_hwe();
1236
1237         if (!hwe)
1238                 return 1;
1239
1240         if (!vector_alloc_slot(conf->hwtable)) {
1241                 free_hwe(hwe);
1242                 return 1;
1243         }
1244         vector_set_slot(conf->hwtable, hwe);
1245
1246         return 0;
1247 }
1248
1249 declare_hw_handler(vendor, set_str)
1250 declare_hw_snprint(vendor, print_str)
1251
1252 declare_hw_handler(product, set_str)
1253 declare_hw_snprint(product, print_str)
1254
1255 declare_hw_handler(revision, set_str)
1256 declare_hw_snprint(revision, print_str)
1257
1258 declare_hw_handler(bl_product, set_str)
1259 declare_hw_snprint(bl_product, print_str)
1260
1261 declare_hw_handler(hwhandler, set_str)
1262 declare_hw_snprint(hwhandler, print_str)
1263
1264 /*
1265  * overrides handlers
1266  */
1267 static int
1268 overrides_handler(struct config *conf, vector strvec)
1269 {
1270         if (!conf->overrides)
1271                 conf->overrides = alloc_hwe();
1272
1273         if (!conf->overrides)
1274                 return 1;
1275
1276         return 0;
1277 }
1278
1279
1280
1281 /*
1282  * multipaths block handlers
1283  */
1284 static int
1285 multipaths_handler(struct config *conf, vector strvec)
1286 {
1287         if (!conf->mptable)
1288                 conf->mptable = vector_alloc();
1289
1290         if (!conf->mptable)
1291                 return 1;
1292
1293         return 0;
1294 }
1295
1296 static int
1297 multipath_handler(struct config *conf, vector strvec)
1298 {
1299         struct mpentry * mpe;
1300
1301         mpe = alloc_mpe();
1302
1303         if (!mpe)
1304                 return 1;
1305
1306         if (!vector_alloc_slot(conf->mptable)) {
1307                 free_mpe(mpe);
1308                 return 1;
1309         }
1310         vector_set_slot(conf->mptable, mpe);
1311
1312         return 0;
1313 }
1314
1315 declare_mp_handler(wwid, set_str)
1316 declare_mp_snprint(wwid, print_str)
1317
1318 declare_mp_handler(alias, set_str)
1319 declare_mp_snprint(alias, print_str)
1320
1321 /*
1322  * deprecated handlers
1323  */
1324
1325 static int
1326 deprecated_handler(struct config *conf, vector strvec)
1327 {
1328         char * buff;
1329
1330         buff = set_value(strvec);
1331
1332         if (!buff)
1333                 return 1;
1334
1335         FREE(buff);
1336         return 0;
1337 }
1338
1339 static int
1340 snprint_deprecated (struct config *conf, char * buff, int len, void * data)
1341 {
1342         return 0;
1343 }
1344
1345 #define __deprecated
1346
1347 /*
1348  * If you add or remove a keyword also update multipath/multipath.conf.5
1349  */
1350 void
1351 init_keywords(vector keywords)
1352 {
1353         install_keyword_root("defaults", NULL);
1354         install_keyword("verbosity", &def_verbosity_handler, &snprint_def_verbosity);
1355         install_keyword("polling_interval", &def_checkint_handler, &snprint_def_checkint);
1356         install_keyword("max_polling_interval", &def_max_checkint_handler, &snprint_def_max_checkint);
1357         install_keyword("reassign_maps", &def_reassign_maps_handler, &snprint_def_reassign_maps);
1358         install_keyword("multipath_dir", &def_multipath_dir_handler, &snprint_def_multipath_dir);
1359         install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
1360         install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_pgpolicy);
1361         install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute);
1362         install_keyword("getuid_callout", &def_getuid_handler, &snprint_def_getuid);
1363         install_keyword("prio", &def_prio_name_handler, &snprint_def_prio_name);
1364         install_keyword("prio_args", &def_prio_args_handler, &snprint_def_prio_args);
1365         install_keyword("features", &def_features_handler, &snprint_def_features);
1366         install_keyword("path_checker", &def_checker_name_handler, &snprint_def_checker_name);
1367         install_keyword("checker", &def_checker_name_handler, NULL);
1368         install_keyword("alias_prefix", &def_alias_prefix_handler, &snprint_def_alias_prefix);
1369         install_keyword("failback", &def_pgfailback_handler, &snprint_def_pgfailback);
1370         install_keyword("rr_min_io", &def_minio_handler, &snprint_def_minio);
1371         install_keyword("rr_min_io_rq", &def_minio_rq_handler, &snprint_def_minio_rq);
1372         install_keyword("max_fds", &max_fds_handler, &snprint_max_fds);
1373         install_keyword("rr_weight", &def_rr_weight_handler, &snprint_def_rr_weight);
1374         install_keyword("no_path_retry", &def_no_path_retry_handler, &snprint_def_no_path_retry);
1375         install_keyword("queue_without_daemon", &def_queue_without_daemon_handler, &snprint_def_queue_without_daemon);
1376         install_keyword("checker_timeout", &def_checker_timeout_handler, &snprint_def_checker_timeout);
1377         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1378         install_keyword("flush_on_last_del", &def_flush_on_last_del_handler, &snprint_def_flush_on_last_del);
1379         install_keyword("user_friendly_names", &def_user_friendly_names_handler, &snprint_def_user_friendly_names);
1380         install_keyword("mode", &def_mode_handler, &snprint_def_mode);
1381         install_keyword("uid", &def_uid_handler, &snprint_def_uid);
1382         install_keyword("gid", &def_gid_handler, &snprint_def_gid);
1383         install_keyword("fast_io_fail_tmo", &def_fast_io_fail_handler, &snprint_def_fast_io_fail);
1384         install_keyword("dev_loss_tmo", &def_dev_loss_handler, &snprint_def_dev_loss);
1385         install_keyword("bindings_file", &def_bindings_file_handler, &snprint_def_bindings_file);
1386         install_keyword("wwids_file", &def_wwids_file_handler, &snprint_def_wwids_file);
1387         install_keyword("log_checker_err", &def_log_checker_err_handler, &snprint_def_log_checker_err);
1388         install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key);
1389         install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler);
1390         install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio);
1391         install_keyword("force_sync", &def_force_sync_handler, &snprint_def_force_sync);
1392         install_keyword("strict_timing", &def_strict_timing_handler, &snprint_def_strict_timing);
1393         install_keyword("deferred_remove", &def_deferred_remove_handler, &snprint_def_deferred_remove);
1394         install_keyword("partition_delimiter", &def_partition_delim_handler, &snprint_def_partition_delim);
1395         install_keyword("config_dir", &def_config_dir_handler, &snprint_def_config_dir);
1396         install_keyword("delay_watch_checks", &def_delay_watch_checks_handler, &snprint_def_delay_watch_checks);
1397         install_keyword("delay_wait_checks", &def_delay_wait_checks_handler, &snprint_def_delay_wait_checks);
1398         install_keyword("find_multipaths", &def_find_multipaths_handler, &snprint_def_find_multipaths);
1399         install_keyword("uxsock_timeout", &def_uxsock_timeout_handler, &snprint_def_uxsock_timeout);
1400         install_keyword("retrigger_tries", &def_retrigger_tries_handler, &snprint_def_retrigger_tries);
1401         install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
1402         install_keyword("missing_uev_wait_timeout", &def_uev_wait_timeout_handler, &snprint_def_uev_wait_timeout);
1403         install_keyword("skip_kpartx", &def_skip_kpartx_handler, &snprint_def_skip_kpartx);
1404         install_keyword("disable_changed_wwids", &def_disable_changed_wwids_handler, &snprint_def_disable_changed_wwids);
1405         install_keyword("remove_retries", &def_remove_retries_handler, &snprint_def_remove_retries);
1406         __deprecated install_keyword("default_selector", &def_selector_handler, NULL);
1407         __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
1408         __deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
1409         __deprecated install_keyword("default_getuid_callout", &def_getuid_handler, NULL);
1410         __deprecated install_keyword("default_features", &def_features_handler, NULL);
1411         __deprecated install_keyword("default_path_checker", &def_checker_name_handler, NULL);
1412
1413         install_keyword_root("blacklist", &blacklist_handler);
1414         install_keyword_multi("devnode", &ble_blist_devnode_handler, &snprint_ble_simple);
1415         install_keyword_multi("wwid", &ble_blist_wwid_handler, &snprint_ble_simple);
1416         install_keyword_multi("property", &ble_blist_property_handler, &snprint_ble_simple);
1417         install_keyword_multi("device", &ble_device_handler, NULL);
1418         install_sublevel();
1419         install_keyword("vendor", &ble_blist_device_vendor_handler, &snprint_bled_vendor);
1420         install_keyword("product", &ble_blist_device_product_handler, &snprint_bled_product);
1421         install_sublevel_end();
1422         install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
1423         install_keyword_multi("devnode", &ble_elist_devnode_handler, &snprint_ble_simple);
1424         install_keyword_multi("wwid", &ble_elist_wwid_handler, &snprint_ble_simple);
1425         install_keyword_multi("property", &ble_elist_property_handler, &snprint_ble_simple);
1426         install_keyword_multi("device", &ble_except_device_handler, NULL);
1427         install_sublevel();
1428         install_keyword("vendor", &ble_elist_device_vendor_handler, &snprint_bled_vendor);
1429         install_keyword("product", &ble_elist_device_product_handler, &snprint_bled_product);
1430         install_sublevel_end();
1431
1432 #if 0
1433         __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler);
1434         __deprecated install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
1435         __deprecated install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
1436         __deprecated install_keyword("device", &ble_device_handler, NULL);
1437         __deprecated install_sublevel();
1438         __deprecated install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
1439         __deprecated install_keyword("product", &ble_product_handler, &snprint_bled_product);
1440         __deprecated install_sublevel_end();
1441 #endif
1442 /*
1443  * If you add or remove a "device subsection" keyword also update
1444  * multipath/multipath.conf.5 and the TEMPLATE in libmultipath/hwtable.c
1445  */
1446         install_keyword_root("devices", &devices_handler);
1447         install_keyword_multi("device", &device_handler, NULL);
1448         install_sublevel();
1449         install_keyword("vendor", &hw_vendor_handler, &snprint_hw_vendor);
1450         install_keyword("product", &hw_product_handler, &snprint_hw_product);
1451         install_keyword("revision", &hw_revision_handler, &snprint_hw_revision);
1452         install_keyword("product_blacklist", &hw_bl_product_handler, &snprint_hw_bl_product);
1453         install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_pgpolicy);
1454         install_keyword("uid_attribute", &hw_uid_attribute_handler, &snprint_hw_uid_attribute);
1455         install_keyword("getuid_callout", &hw_getuid_handler, &snprint_hw_getuid);
1456         install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
1457         install_keyword("path_checker", &hw_checker_name_handler, &snprint_hw_checker_name);
1458         install_keyword("checker", &hw_checker_name_handler, NULL);
1459         install_keyword("alias_prefix", &hw_alias_prefix_handler, &snprint_hw_alias_prefix);
1460         install_keyword("features", &hw_features_handler, &snprint_hw_features);
1461         install_keyword("hardware_handler", &hw_hwhandler_handler, &snprint_hw_hwhandler);
1462         install_keyword("prio", &hw_prio_name_handler, &snprint_hw_prio_name);
1463         install_keyword("prio_args", &hw_prio_args_handler, &snprint_hw_prio_args);
1464         install_keyword("failback", &hw_pgfailback_handler, &snprint_hw_pgfailback);
1465         install_keyword("rr_weight", &hw_rr_weight_handler, &snprint_hw_rr_weight);
1466         install_keyword("no_path_retry", &hw_no_path_retry_handler, &snprint_hw_no_path_retry);
1467         install_keyword("rr_min_io", &hw_minio_handler, &snprint_hw_minio);
1468         install_keyword("rr_min_io_rq", &hw_minio_rq_handler, &snprint_hw_minio_rq);
1469         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1470         install_keyword("flush_on_last_del", &hw_flush_on_last_del_handler, &snprint_hw_flush_on_last_del);
1471         install_keyword("fast_io_fail_tmo", &hw_fast_io_fail_handler, &snprint_hw_fast_io_fail);
1472         install_keyword("dev_loss_tmo", &hw_dev_loss_handler, &snprint_hw_dev_loss);
1473         install_keyword("user_friendly_names", &hw_user_friendly_names_handler, &snprint_hw_user_friendly_names);
1474         install_keyword("retain_attached_hw_handler", &hw_retain_hwhandler_handler, &snprint_hw_retain_hwhandler);
1475         install_keyword("detect_prio", &hw_detect_prio_handler, &snprint_hw_detect_prio);
1476         install_keyword("deferred_remove", &hw_deferred_remove_handler, &snprint_hw_deferred_remove);
1477         install_keyword("delay_watch_checks", &hw_delay_watch_checks_handler, &snprint_hw_delay_watch_checks);
1478         install_keyword("delay_wait_checks", &hw_delay_wait_checks_handler, &snprint_hw_delay_wait_checks);
1479         install_keyword("skip_kpartx", &hw_skip_kpartx_handler, &snprint_hw_skip_kpartx);
1480         install_sublevel_end();
1481
1482         install_keyword_root("overrides", &overrides_handler);
1483         install_keyword("path_grouping_policy", &ovr_pgpolicy_handler, &snprint_ovr_pgpolicy);
1484         install_keyword("uid_attribute", &ovr_uid_attribute_handler, &snprint_ovr_uid_attribute);
1485         install_keyword("getuid_callout", &ovr_getuid_handler, &snprint_ovr_getuid);
1486         install_keyword("path_selector", &ovr_selector_handler, &snprint_ovr_selector);
1487         install_keyword("path_checker", &ovr_checker_name_handler, &snprint_ovr_checker_name);
1488         install_keyword("checker", &ovr_checker_name_handler, NULL);
1489         install_keyword("alias_prefix", &ovr_alias_prefix_handler, &snprint_ovr_alias_prefix);
1490         install_keyword("features", &ovr_features_handler, &snprint_ovr_features);
1491         install_keyword("prio", &ovr_prio_name_handler, &snprint_ovr_prio_name);
1492         install_keyword("prio_args", &ovr_prio_args_handler, &snprint_ovr_prio_args);
1493         install_keyword("failback", &ovr_pgfailback_handler, &snprint_ovr_pgfailback);
1494         install_keyword("rr_weight", &ovr_rr_weight_handler, &snprint_ovr_rr_weight);
1495         install_keyword("no_path_retry", &ovr_no_path_retry_handler, &snprint_ovr_no_path_retry);
1496         install_keyword("rr_min_io", &ovr_minio_handler, &snprint_ovr_minio);
1497         install_keyword("rr_min_io_rq", &ovr_minio_rq_handler, &snprint_ovr_minio_rq);
1498         install_keyword("flush_on_last_del", &ovr_flush_on_last_del_handler, &snprint_ovr_flush_on_last_del);
1499         install_keyword("fast_io_fail_tmo", &ovr_fast_io_fail_handler, &snprint_ovr_fast_io_fail);
1500         install_keyword("dev_loss_tmo", &ovr_dev_loss_handler, &snprint_ovr_dev_loss);
1501         install_keyword("user_friendly_names", &ovr_user_friendly_names_handler, &snprint_ovr_user_friendly_names);
1502         install_keyword("retain_attached_hw_handler", &ovr_retain_hwhandler_handler, &snprint_ovr_retain_hwhandler);
1503         install_keyword("detect_prio", &ovr_detect_prio_handler, &snprint_ovr_detect_prio);
1504         install_keyword("deferred_remove", &ovr_deferred_remove_handler, &snprint_ovr_deferred_remove);
1505         install_keyword("delay_watch_checks", &ovr_delay_watch_checks_handler, &snprint_ovr_delay_watch_checks);
1506         install_keyword("delay_wait_checks", &ovr_delay_wait_checks_handler, &snprint_ovr_delay_wait_checks);
1507         install_keyword("skip_kpartx", &ovr_skip_kpartx_handler, &snprint_ovr_skip_kpartx);
1508
1509         install_keyword_root("multipaths", &multipaths_handler);
1510         install_keyword_multi("multipath", &multipath_handler, NULL);
1511         install_sublevel();
1512         install_keyword("wwid", &mp_wwid_handler, &snprint_mp_wwid);
1513         install_keyword("alias", &mp_alias_handler, &snprint_mp_alias);
1514         install_keyword("path_grouping_policy", &mp_pgpolicy_handler, &snprint_mp_pgpolicy);
1515         install_keyword("path_selector", &mp_selector_handler, &snprint_mp_selector);
1516         install_keyword("prio", &mp_prio_name_handler, &snprint_mp_prio_name);
1517         install_keyword("prio_args", &mp_prio_args_handler, &snprint_mp_prio_args);
1518         install_keyword("failback", &mp_pgfailback_handler, &snprint_mp_pgfailback);
1519         install_keyword("rr_weight", &mp_rr_weight_handler, &snprint_mp_rr_weight);
1520         install_keyword("no_path_retry", &mp_no_path_retry_handler, &snprint_mp_no_path_retry);
1521         install_keyword("rr_min_io", &mp_minio_handler, &snprint_mp_minio);
1522         install_keyword("rr_min_io_rq", &mp_minio_rq_handler, &snprint_mp_minio_rq);
1523         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1524         install_keyword("flush_on_last_del", &mp_flush_on_last_del_handler, &snprint_mp_flush_on_last_del);
1525         install_keyword("features", &mp_features_handler, &snprint_mp_features);
1526         install_keyword("mode", &mp_mode_handler, &snprint_mp_mode);
1527         install_keyword("uid", &mp_uid_handler, &snprint_mp_uid);
1528         install_keyword("gid", &mp_gid_handler, &snprint_mp_gid);
1529         install_keyword("reservation_key", &mp_reservation_key_handler, &snprint_mp_reservation_key);
1530         install_keyword("user_friendly_names", &mp_user_friendly_names_handler, &snprint_mp_user_friendly_names);
1531         install_keyword("deferred_remove", &mp_deferred_remove_handler, &snprint_mp_deferred_remove);
1532         install_keyword("delay_watch_checks", &mp_delay_watch_checks_handler, &snprint_mp_delay_watch_checks);
1533         install_keyword("delay_wait_checks", &mp_delay_wait_checks_handler, &snprint_mp_delay_wait_checks);
1534         install_keyword("skip_kpartx", &mp_skip_kpartx_handler, &snprint_mp_skip_kpartx);
1535         install_sublevel_end();
1536 }