add disable_changed_wwids option
[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 static int
419 def_config_dir_handler(struct config *conf, vector strvec)
420 {
421         /* this is only valid in the main config file */
422         if (conf->processed_main_config)
423                 return 0;
424         return set_str(strvec, &conf->config_dir);
425 }
426 declare_def_snprint(config_dir, print_str)
427
428 #define declare_def_attr_handler(option, function)                      \
429 static int                                                              \
430 def_ ## option ## _handler (struct config *conf, vector strvec)         \
431 {                                                                       \
432         return function (strvec, &conf->option, &conf->attribute_flags);\
433 }
434
435 #define declare_def_attr_snprint(option, function)                      \
436 static int                                                              \
437 snprint_def_ ## option (struct config *conf, char * buff, int len, void * data) \
438 {                                                                       \
439         return function (buff, len, &conf->option,                      \
440                          &conf->attribute_flags);                       \
441 }
442
443 #define declare_mp_attr_handler(option, function)                       \
444 static int                                                              \
445 mp_ ## option ## _handler (struct config *conf, vector strvec)          \
446 {                                                                       \
447         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);         \
448         if (!mpe)                                                       \
449                 return 1;                                               \
450         return function (strvec, &mpe->option, &mpe->attribute_flags);  \
451 }
452
453 #define declare_mp_attr_snprint(option, function)                       \
454 static int                                                              \
455 snprint_mp_ ## option (struct config *conf, char * buff, int len, void * data) \
456 {                                                                       \
457         struct mpentry * mpe = (struct mpentry *)data;                  \
458         return function (buff, len, &mpe->option,                       \
459                          &mpe->attribute_flags);                        \
460 }
461
462 static int
463 set_mode(vector strvec, void *ptr, int *flags)
464 {
465         mode_t mode;
466         mode_t *mode_ptr = (mode_t *)ptr;
467         char *buff;
468
469         buff = set_value(strvec);
470
471         if (!buff)
472                 return 1;
473
474         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
475                 *flags |= (1 << ATTR_MODE);
476                 *mode_ptr = mode;
477         }
478
479         FREE(buff);
480         return 0;
481 }
482
483 static int
484 set_uid(vector strvec, void *ptr, int *flags)
485 {
486         uid_t uid;
487         uid_t *uid_ptr = (uid_t *)ptr;
488         char *buff;
489         char passwd_buf[1024];
490         struct passwd info, *found;
491
492         buff = set_value(strvec);
493         if (!buff)
494                 return 1;
495         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
496                 *flags |= (1 << ATTR_UID);
497                 *uid_ptr = info.pw_uid;
498         }
499         else if (sscanf(buff, "%u", &uid) == 1){
500                 *flags |= (1 << ATTR_UID);
501                 *uid_ptr = uid;
502         }
503
504         FREE(buff);
505         return 0;
506 }
507
508 static int
509 set_gid(vector strvec, void *ptr, int *flags)
510 {
511         gid_t gid;
512         gid_t *gid_ptr = (gid_t *)ptr;
513         char *buff;
514         char passwd_buf[1024];
515         struct passwd info, *found;
516
517         buff = set_value(strvec);
518         if (!buff)
519                 return 1;
520
521         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
522                 *flags |= (1 << ATTR_GID);
523                 *gid_ptr = info.pw_gid;
524         }
525         else if (sscanf(buff, "%u", &gid) == 1){
526                 *flags |= (1 << ATTR_GID);
527                 *gid_ptr = gid;
528         }
529         FREE(buff);
530         return 0;
531 }
532
533 static int
534 print_mode(char * buff, int len, void *ptr, int *flags)
535 {
536         mode_t *mode_ptr = (mode_t *)ptr;
537         if ((*flags & (1 << ATTR_MODE)) == 0)
538                 return 0;
539         return snprintf(buff, len, "0%o", *mode_ptr);
540 }
541
542 static int
543 print_uid(char * buff, int len, void *ptr, int *flags)
544 {
545         uid_t *uid_ptr = (uid_t *)ptr;
546         if ((*flags & (1 << ATTR_UID)) == 0)
547                 return 0;
548         return snprintf(buff, len, "0%o", *uid_ptr);
549 }
550
551 static int
552 print_gid(char * buff, int len, void *ptr, int *flags)
553 {
554         gid_t *gid_ptr = (gid_t *)ptr;
555         if ((*flags & (1 << ATTR_GID)) == 0)
556                 return 0;
557         return snprintf(buff, len, "0%o", *gid_ptr);
558 }
559
560 declare_def_attr_handler(mode, set_mode)
561 declare_def_attr_snprint(mode, print_mode)
562 declare_mp_attr_handler(mode, set_mode)
563 declare_mp_attr_snprint(mode, print_mode)
564
565 declare_def_attr_handler(uid, set_uid)
566 declare_def_attr_snprint(uid, print_uid)
567 declare_mp_attr_handler(uid, set_uid)
568 declare_mp_attr_snprint(uid, print_uid)
569
570 declare_def_attr_handler(gid, set_gid)
571 declare_def_attr_snprint(gid, print_gid)
572 declare_mp_attr_handler(gid, set_gid)
573 declare_mp_attr_snprint(gid, print_gid)
574
575 static int
576 set_fast_io_fail(vector strvec, void *ptr)
577 {
578         char * buff;
579         int *int_ptr = (int *)ptr;
580
581         buff = set_value(strvec);
582         if (!buff)
583                 return 1;
584
585         if (strcmp(buff, "off") == 0)
586                 *int_ptr = MP_FAST_IO_FAIL_OFF;
587         else if (sscanf(buff, "%d", int_ptr) != 1 ||
588                  *int_ptr < MP_FAST_IO_FAIL_ZERO)
589                 *int_ptr = MP_FAST_IO_FAIL_UNSET;
590         else if (*int_ptr == 0)
591                 *int_ptr = MP_FAST_IO_FAIL_ZERO;
592
593         FREE(buff);
594         return 0;
595 }
596
597 int
598 print_fast_io_fail(char * buff, int len, void *ptr)
599 {
600         int *int_ptr = (int *)ptr;
601
602         if (*int_ptr == MP_FAST_IO_FAIL_UNSET)
603                 return 0;
604         if (*int_ptr == MP_FAST_IO_FAIL_OFF)
605                 return snprintf(buff, len, "\"off\"");
606         if (*int_ptr == MP_FAST_IO_FAIL_ZERO)
607                 return snprintf(buff, len, "0");
608         return snprintf(buff, len, "%d", *int_ptr);
609 }
610
611 declare_def_handler(fast_io_fail, set_fast_io_fail)
612 declare_def_snprint(fast_io_fail, print_fast_io_fail)
613 declare_ovr_handler(fast_io_fail, set_fast_io_fail)
614 declare_ovr_snprint(fast_io_fail, print_fast_io_fail)
615 declare_hw_handler(fast_io_fail, set_fast_io_fail)
616 declare_hw_snprint(fast_io_fail, print_fast_io_fail)
617
618 static int
619 set_dev_loss(vector strvec, void *ptr)
620 {
621         char * buff;
622         unsigned int *uint_ptr = (unsigned int *)ptr;
623
624         buff = set_value(strvec);
625         if (!buff)
626                 return 1;
627
628         if (!strcmp(buff, "infinity"))
629                 *uint_ptr = MAX_DEV_LOSS_TMO;
630         else if (sscanf(buff, "%u", uint_ptr) != 1)
631                 *uint_ptr = 0;
632
633         FREE(buff);
634         return 0;
635 }
636
637 int
638 print_dev_loss(char * buff, int len, void *ptr)
639 {
640         unsigned int *uint_ptr = (unsigned int *)ptr;
641
642         if (!*uint_ptr)
643                 return 0;
644         if (*uint_ptr >= MAX_DEV_LOSS_TMO)
645                 return snprintf(buff, len, "\"infinity\"");
646         return snprintf(buff, len, "%u", *uint_ptr);
647 }
648
649 declare_def_handler(dev_loss, set_dev_loss)
650 declare_def_snprint(dev_loss, print_dev_loss)
651 declare_ovr_handler(dev_loss, set_dev_loss)
652 declare_ovr_snprint(dev_loss, print_dev_loss)
653 declare_hw_handler(dev_loss, set_dev_loss)
654 declare_hw_snprint(dev_loss, print_dev_loss)
655
656 static int
657 set_pgpolicy(vector strvec, void *ptr)
658 {
659         char * buff;
660         int *int_ptr = (int *)ptr;
661
662         buff = set_value(strvec);
663         if (!buff)
664                 return 1;
665
666         *int_ptr = get_pgpolicy_id(buff);
667         FREE(buff);
668
669         return 0;
670 }
671
672 int
673 print_pgpolicy(char * buff, int len, void *ptr)
674 {
675         char str[POLICY_NAME_SIZE];
676         int pgpolicy = *(int *)ptr;
677
678         if (!pgpolicy)
679                 return 0;
680
681         get_pgpolicy_name(str, POLICY_NAME_SIZE, pgpolicy);
682
683         return snprintf(buff, len, "\"%s\"", str);
684 }
685
686 declare_def_handler(pgpolicy, set_pgpolicy)
687 declare_def_snprint_defint(pgpolicy, print_pgpolicy, DEFAULT_PGPOLICY)
688 declare_ovr_handler(pgpolicy, set_pgpolicy)
689 declare_ovr_snprint(pgpolicy, print_pgpolicy)
690 declare_hw_handler(pgpolicy, set_pgpolicy)
691 declare_hw_snprint(pgpolicy, print_pgpolicy)
692 declare_mp_handler(pgpolicy, set_pgpolicy)
693 declare_mp_snprint(pgpolicy, print_pgpolicy)
694
695 int
696 get_sys_max_fds(int *max_fds)
697 {
698         FILE *file;
699         int nr_open;
700         int ret = 1;
701
702         file = fopen("/proc/sys/fs/nr_open", "r");
703         if (!file) {
704                 fprintf(stderr, "Cannot open /proc/sys/fs/nr_open : %s\n",
705                         strerror(errno));
706                 return 1;
707         }
708         if (fscanf(file, "%d", &nr_open) != 1) {
709                 fprintf(stderr, "Cannot read max open fds from /proc/sys/fs/nr_open");
710                 if (ferror(file))
711                         fprintf(stderr, " : %s\n", strerror(errno));
712                 else
713                         fprintf(stderr, "\n");
714         } else {
715                 *max_fds = nr_open;
716                 ret = 0;
717         }
718         fclose(file);
719         return ret;
720 }
721
722
723 static int
724 max_fds_handler(struct config *conf, vector strvec)
725 {
726         char * buff;
727         int r = 0, max_fds;
728
729         buff = set_value(strvec);
730
731         if (!buff)
732                 return 1;
733
734         r = get_sys_max_fds(&max_fds);
735         if (r) {
736                 /* Assume safe limit */
737                 max_fds = 4096;
738         }
739         if (strlen(buff) == 3 &&
740             !strcmp(buff, "max"))
741                 conf->max_fds = max_fds;
742         else
743                 conf->max_fds = atoi(buff);
744
745         if (conf->max_fds > max_fds)
746                 conf->max_fds = max_fds;
747
748         FREE(buff);
749
750         return r;
751 }
752
753 static int
754 snprint_max_fds (struct config *conf, char * buff, int len, void * data)
755 {
756         int r = 0, max_fds;
757
758         if (!conf->max_fds)
759                 return 0;
760
761         r = get_sys_max_fds(&max_fds);
762         if (!r && conf->max_fds >= max_fds)
763                 return snprintf(buff, len, "\"max\"");
764         else
765                 return snprintf(buff, len, "%d", conf->max_fds);
766 }
767
768 static int
769 set_rr_weight(vector strvec, void *ptr)
770 {
771         int *int_ptr = (int *)ptr;
772         char * buff;
773
774         buff = set_value(strvec);
775
776         if (!buff)
777                 return 1;
778
779         if (!strcmp(buff, "priorities"))
780                 *int_ptr = RR_WEIGHT_PRIO;
781
782         if (!strcmp(buff, "uniform"))
783                 *int_ptr = RR_WEIGHT_NONE;
784
785         FREE(buff);
786
787         return 0;
788 }
789
790 int
791 print_rr_weight (char * buff, int len, void *ptr)
792 {
793         int *int_ptr = (int *)ptr;
794
795         if (!*int_ptr)
796                 return 0;
797         if (*int_ptr == RR_WEIGHT_PRIO)
798                 return snprintf(buff, len, "\"priorities\"");
799         if (*int_ptr == RR_WEIGHT_NONE)
800                 return snprintf(buff, len, "\"uniform\"");
801
802         return 0;
803 }
804
805 declare_def_handler(rr_weight, set_rr_weight)
806 declare_def_snprint_defint(rr_weight, print_rr_weight, RR_WEIGHT_NONE)
807 declare_ovr_handler(rr_weight, set_rr_weight)
808 declare_ovr_snprint(rr_weight, print_rr_weight)
809 declare_hw_handler(rr_weight, set_rr_weight)
810 declare_hw_snprint(rr_weight, print_rr_weight)
811 declare_mp_handler(rr_weight, set_rr_weight)
812 declare_mp_snprint(rr_weight, print_rr_weight)
813
814 static int
815 set_pgfailback(vector strvec, void *ptr)
816 {
817         int *int_ptr = (int *)ptr;
818         char * buff;
819
820         buff = set_value(strvec);
821         if (!buff)
822                 return 1;
823
824         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
825                 *int_ptr = -FAILBACK_MANUAL;
826         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
827                 *int_ptr = -FAILBACK_IMMEDIATE;
828         else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
829                 *int_ptr = -FAILBACK_FOLLOWOVER;
830         else
831                 *int_ptr = atoi(buff);
832
833         FREE(buff);
834
835         return 0;
836 }
837
838 int
839 print_pgfailback (char * buff, int len, void *ptr)
840 {
841         int *int_ptr = (int *)ptr;
842
843         switch(*int_ptr) {
844         case  FAILBACK_UNDEF:
845                 return 0;
846         case -FAILBACK_MANUAL:
847                 return snprintf(buff, len, "\"manual\"");
848         case -FAILBACK_IMMEDIATE:
849                 return snprintf(buff, len, "\"immediate\"");
850         case -FAILBACK_FOLLOWOVER:
851                 return snprintf(buff, len, "\"followover\"");
852         default:
853                 return snprintf(buff, len, "%i", *int_ptr);
854         }
855 }
856
857 declare_def_handler(pgfailback, set_pgfailback)
858 declare_def_snprint_defint(pgfailback, print_pgfailback, DEFAULT_FAILBACK)
859 declare_ovr_handler(pgfailback, set_pgfailback)
860 declare_ovr_snprint(pgfailback, print_pgfailback)
861 declare_hw_handler(pgfailback, set_pgfailback)
862 declare_hw_snprint(pgfailback, print_pgfailback)
863 declare_mp_handler(pgfailback, set_pgfailback)
864 declare_mp_snprint(pgfailback, print_pgfailback)
865
866 static int
867 set_no_path_retry(vector strvec, void *ptr)
868 {
869         int *int_ptr = (int *)ptr;
870         char * buff;
871
872         buff = set_value(strvec);
873         if (!buff)
874                 return 1;
875
876         if (!strcmp(buff, "fail") || !strcmp(buff, "0"))
877                 *int_ptr = NO_PATH_RETRY_FAIL;
878         else if (!strcmp(buff, "queue"))
879                 *int_ptr = NO_PATH_RETRY_QUEUE;
880         else if ((*int_ptr = atoi(buff)) < 1)
881                 *int_ptr = NO_PATH_RETRY_UNDEF;
882
883         FREE(buff);
884         return 0;
885 }
886
887 int
888 print_no_path_retry(char * buff, int len, void *ptr)
889 {
890         int *int_ptr = (int *)ptr;
891
892         switch(*int_ptr) {
893         case NO_PATH_RETRY_UNDEF:
894                 return 0;
895         case NO_PATH_RETRY_FAIL:
896                 return snprintf(buff, len, "\"fail\"");
897         case NO_PATH_RETRY_QUEUE:
898                 return snprintf(buff, len, "\"queue\"");
899         default:
900                 return snprintf(buff, len, "%i", *int_ptr);
901         }
902 }
903
904 declare_def_handler(no_path_retry, set_no_path_retry)
905 declare_def_snprint(no_path_retry, print_no_path_retry)
906 declare_ovr_handler(no_path_retry, set_no_path_retry)
907 declare_ovr_snprint(no_path_retry, print_no_path_retry)
908 declare_hw_handler(no_path_retry, set_no_path_retry)
909 declare_hw_snprint(no_path_retry, print_no_path_retry)
910 declare_mp_handler(no_path_retry, set_no_path_retry)
911 declare_mp_snprint(no_path_retry, print_no_path_retry)
912
913 static int
914 def_log_checker_err_handler(struct config *conf, vector strvec)
915 {
916         char * buff;
917
918         buff = set_value(strvec);
919
920         if (!buff)
921                 return 1;
922
923         if (strlen(buff) == 4 && !strcmp(buff, "once"))
924                 conf->log_checker_err = LOG_CHKR_ERR_ONCE;
925         else if (strlen(buff) == 6 && !strcmp(buff, "always"))
926                 conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
927
928         free(buff);
929         return 0;
930 }
931
932 static int
933 snprint_def_log_checker_err (struct config *conf, char * buff, int len, void * data)
934 {
935         if (conf->log_checker_err == LOG_CHKR_ERR_ONCE)
936                 return snprintf(buff, len, "once");
937         return snprintf(buff, len, "always");
938 }
939
940 static int
941 set_reservation_key(vector strvec, void *ptr)
942 {
943         unsigned char **uchar_ptr = (unsigned char **)ptr;
944         char *buff;
945         char *tbuff;
946         int j, k;
947         int len;
948         uint64_t prkey;
949
950         buff = set_value(strvec);
951         if (!buff)
952                 return 1;
953
954         tbuff = buff;
955
956         if (!memcmp("0x",buff, 2))
957                 buff = buff + 2;
958
959         len = strlen(buff);
960
961         k = strspn(buff, "0123456789aAbBcCdDeEfF");
962
963         if (len != k) {
964                 FREE(tbuff);
965                 return 1;
966         }
967
968         if (1 != sscanf (buff, "%" SCNx64 "", &prkey))
969         {
970                 FREE(tbuff);
971                 return 1;
972         }
973
974         if (!*uchar_ptr)
975                 *uchar_ptr = (unsigned char *) malloc(8);
976
977         memset(*uchar_ptr, 0, 8);
978
979         for (j = 7; j >= 0; --j) {
980                 (*uchar_ptr)[j] = (prkey & 0xff);
981                 prkey >>= 8;
982         }
983
984         FREE(tbuff);
985         return 0;
986 }
987
988 int
989 print_reservation_key(char * buff, int len, void * ptr)
990 {
991         unsigned char **uchar_ptr = (unsigned char **)ptr;
992         int i;
993         unsigned char *keyp;
994         uint64_t prkey = 0;
995
996         if (!*uchar_ptr)
997                 return 0;
998         keyp = (unsigned char *)(*uchar_ptr);
999         for (i = 0; i < 8; i++) {
1000                 if (i > 0)
1001                         prkey <<= 8;
1002                 prkey |= *keyp;
1003                 keyp++;
1004         }
1005         return snprintf(buff, len, "0x%" PRIx64, prkey);
1006 }
1007
1008 declare_def_handler(reservation_key, set_reservation_key)
1009 declare_def_snprint(reservation_key, print_reservation_key)
1010 declare_mp_handler(reservation_key, set_reservation_key)
1011 declare_mp_snprint(reservation_key, print_reservation_key)
1012
1013 static int
1014 set_delay_checks(vector strvec, void *ptr)
1015 {
1016         int *int_ptr = (int *)ptr;
1017         char * buff;
1018
1019         buff = set_value(strvec);
1020         if (!buff)
1021                 return 1;
1022
1023         if (!strcmp(buff, "no") || !strcmp(buff, "0"))
1024                 *int_ptr = DELAY_CHECKS_OFF;
1025         else if ((*int_ptr = atoi(buff)) < 1)
1026                 *int_ptr = DELAY_CHECKS_UNDEF;
1027
1028         FREE(buff);
1029         return 0;
1030 }
1031
1032 int
1033 print_delay_checks(char * buff, int len, void *ptr)
1034 {
1035         int *int_ptr = (int *)ptr;
1036
1037         switch(*int_ptr) {
1038         case DELAY_CHECKS_UNDEF:
1039                 return 0;
1040         case DELAY_CHECKS_OFF:
1041                 return snprintf(buff, len, "\"off\"");
1042         default:
1043                 return snprintf(buff, len, "%i", *int_ptr);
1044         }
1045 }
1046
1047 declare_def_handler(delay_watch_checks, set_delay_checks)
1048 declare_def_snprint(delay_watch_checks, print_delay_checks)
1049 declare_ovr_handler(delay_watch_checks, set_delay_checks)
1050 declare_ovr_snprint(delay_watch_checks, print_delay_checks)
1051 declare_hw_handler(delay_watch_checks, set_delay_checks)
1052 declare_hw_snprint(delay_watch_checks, print_delay_checks)
1053 declare_mp_handler(delay_watch_checks, set_delay_checks)
1054 declare_mp_snprint(delay_watch_checks, print_delay_checks)
1055
1056 declare_def_handler(delay_wait_checks, set_delay_checks)
1057 declare_def_snprint(delay_wait_checks, print_delay_checks)
1058 declare_ovr_handler(delay_wait_checks, set_delay_checks)
1059 declare_ovr_snprint(delay_wait_checks, print_delay_checks)
1060 declare_hw_handler(delay_wait_checks, set_delay_checks)
1061 declare_hw_snprint(delay_wait_checks, print_delay_checks)
1062 declare_mp_handler(delay_wait_checks, set_delay_checks)
1063 declare_mp_snprint(delay_wait_checks, print_delay_checks)
1064
1065 static int
1066 def_uxsock_timeout_handler(struct config *conf, vector strvec)
1067 {
1068         unsigned int uxsock_timeout;
1069         char *buff;
1070
1071         buff = set_value(strvec);
1072         if (!buff)
1073                 return 1;
1074
1075         if (sscanf(buff, "%u", &uxsock_timeout) == 1 &&
1076             uxsock_timeout > DEFAULT_REPLY_TIMEOUT)
1077                 conf->uxsock_timeout = uxsock_timeout;
1078         else
1079                 conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
1080
1081         free(buff);
1082         return 0;
1083 }
1084
1085 /*
1086  * blacklist block handlers
1087  */
1088 static int
1089 blacklist_handler(struct config *conf, vector strvec)
1090 {
1091         if (!conf->blist_devnode)
1092                 conf->blist_devnode = vector_alloc();
1093         if (!conf->blist_wwid)
1094                 conf->blist_wwid = vector_alloc();
1095         if (!conf->blist_device)
1096                 conf->blist_device = vector_alloc();
1097         if (!conf->blist_property)
1098                 conf->blist_property = vector_alloc();
1099
1100         if (!conf->blist_devnode || !conf->blist_wwid ||
1101             !conf->blist_device || !conf->blist_property)
1102                 return 1;
1103
1104         return 0;
1105 }
1106
1107 static int
1108 blacklist_exceptions_handler(struct config *conf, vector strvec)
1109 {
1110         if (!conf->elist_devnode)
1111                 conf->elist_devnode = vector_alloc();
1112         if (!conf->elist_wwid)
1113                 conf->elist_wwid = vector_alloc();
1114         if (!conf->elist_device)
1115                 conf->elist_device = vector_alloc();
1116         if (!conf->elist_property)
1117                 conf->elist_property = vector_alloc();
1118
1119         if (!conf->elist_devnode || !conf->elist_wwid ||
1120             !conf->elist_device || !conf->elist_property)
1121                 return 1;
1122
1123         return 0;
1124 }
1125
1126 #define declare_ble_handler(option)                                     \
1127 static int                                                              \
1128 ble_ ## option ## _handler (struct config *conf, vector strvec)         \
1129 {                                                                       \
1130         char * buff;                                                    \
1131                                                                         \
1132         if (!conf->option)                                              \
1133                 return 1;                                               \
1134                                                                         \
1135         buff = set_value(strvec);                                       \
1136         if (!buff)                                                      \
1137                 return 1;                                               \
1138                                                                         \
1139         return store_ble(conf->option, buff, ORIGIN_CONFIG);            \
1140 }
1141
1142 #define declare_ble_device_handler(name, option, vend, prod)            \
1143 static int                                                              \
1144 ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \
1145 {                                                                       \
1146         char * buff;                                                    \
1147                                                                         \
1148         if (!conf->option)                                              \
1149                 return 1;                                               \
1150                                                                         \
1151         buff = set_value(strvec);                                       \
1152         if (!buff)                                                      \
1153                 return 1;                                               \
1154                                                                         \
1155         return set_ble_device(conf->option, vend, prod, ORIGIN_CONFIG); \
1156 }
1157
1158 declare_ble_handler(blist_devnode)
1159 declare_ble_handler(elist_devnode)
1160 declare_ble_handler(blist_wwid)
1161 declare_ble_handler(elist_wwid)
1162 declare_ble_handler(blist_property)
1163 declare_ble_handler(elist_property)
1164
1165 static int
1166 snprint_def_uxsock_timeout(struct config *conf, char * buff, int len, void * data)
1167 {
1168         return snprintf(buff, len, "%u", conf->uxsock_timeout);
1169 }
1170
1171 static int
1172 snprint_ble_simple (struct config *conf, char * buff, int len, void * data)
1173 {
1174         struct blentry * ble = (struct blentry *)data;
1175
1176         return snprintf(buff, len, "\"%s\"", ble->str);
1177 }
1178
1179 static int
1180 ble_device_handler(struct config *conf, vector strvec)
1181 {
1182         return alloc_ble_device(conf->blist_device);
1183 }
1184
1185 static int
1186 ble_except_device_handler(struct config *conf, vector strvec)
1187 {
1188         return alloc_ble_device(conf->elist_device);
1189 }
1190
1191 declare_ble_device_handler(vendor, blist_device, buff, NULL)
1192 declare_ble_device_handler(vendor, elist_device, buff, NULL)
1193 declare_ble_device_handler(product, blist_device, NULL, buff)
1194 declare_ble_device_handler(product, elist_device, NULL, buff)
1195
1196 static int
1197 snprint_bled_vendor (struct config *conf, char * buff, int len, void * data)
1198 {
1199         struct blentry_device * bled = (struct blentry_device *)data;
1200
1201         return snprintf(buff, len, "\"%s\"", bled->vendor);
1202 }
1203
1204 static int
1205 snprint_bled_product (struct config *conf, char * buff, int len, void * data)
1206 {
1207         struct blentry_device * bled = (struct blentry_device *)data;
1208
1209         return snprintf(buff, len, "\"%s\"", bled->product);
1210 }
1211
1212 /*
1213  * devices block handlers
1214  */
1215 static int
1216 devices_handler(struct config *conf, vector strvec)
1217 {
1218         if (!conf->hwtable)
1219                 conf->hwtable = vector_alloc();
1220
1221         if (!conf->hwtable)
1222                 return 1;
1223
1224         return 0;
1225 }
1226
1227 static int
1228 device_handler(struct config *conf, vector strvec)
1229 {
1230         struct hwentry * hwe;
1231
1232         hwe = alloc_hwe();
1233
1234         if (!hwe)
1235                 return 1;
1236
1237         if (!vector_alloc_slot(conf->hwtable)) {
1238                 free_hwe(hwe);
1239                 return 1;
1240         }
1241         vector_set_slot(conf->hwtable, hwe);
1242
1243         return 0;
1244 }
1245
1246 declare_hw_handler(vendor, set_str)
1247 declare_hw_snprint(vendor, print_str)
1248
1249 declare_hw_handler(product, set_str)
1250 declare_hw_snprint(product, print_str)
1251
1252 declare_hw_handler(revision, set_str)
1253 declare_hw_snprint(revision, print_str)
1254
1255 declare_hw_handler(bl_product, set_str)
1256 declare_hw_snprint(bl_product, print_str)
1257
1258 declare_hw_handler(hwhandler, set_str)
1259 declare_hw_snprint(hwhandler, print_str)
1260
1261 /*
1262  * overrides handlers
1263  */
1264 static int
1265 overrides_handler(struct config *conf, vector strvec)
1266 {
1267         if (!conf->overrides)
1268                 conf->overrides = alloc_hwe();
1269
1270         if (!conf->overrides)
1271                 return 1;
1272
1273         return 0;
1274 }
1275
1276
1277
1278 /*
1279  * multipaths block handlers
1280  */
1281 static int
1282 multipaths_handler(struct config *conf, vector strvec)
1283 {
1284         if (!conf->mptable)
1285                 conf->mptable = vector_alloc();
1286
1287         if (!conf->mptable)
1288                 return 1;
1289
1290         return 0;
1291 }
1292
1293 static int
1294 multipath_handler(struct config *conf, vector strvec)
1295 {
1296         struct mpentry * mpe;
1297
1298         mpe = alloc_mpe();
1299
1300         if (!mpe)
1301                 return 1;
1302
1303         if (!vector_alloc_slot(conf->mptable)) {
1304                 free_mpe(mpe);
1305                 return 1;
1306         }
1307         vector_set_slot(conf->mptable, mpe);
1308
1309         return 0;
1310 }
1311
1312 declare_mp_handler(wwid, set_str)
1313 declare_mp_snprint(wwid, print_str)
1314
1315 declare_mp_handler(alias, set_str)
1316 declare_mp_snprint(alias, print_str)
1317
1318 /*
1319  * deprecated handlers
1320  */
1321
1322 static int
1323 deprecated_handler(struct config *conf, vector strvec)
1324 {
1325         char * buff;
1326
1327         buff = set_value(strvec);
1328
1329         if (!buff)
1330                 return 1;
1331
1332         FREE(buff);
1333         return 0;
1334 }
1335
1336 static int
1337 snprint_deprecated (struct config *conf, char * buff, int len, void * data)
1338 {
1339         return 0;
1340 }
1341
1342 #define __deprecated
1343
1344 /*
1345  * If you add or remove a keyword also update multipath/multipath.conf.5
1346  */
1347 void
1348 init_keywords(vector keywords)
1349 {
1350         install_keyword_root("defaults", NULL);
1351         install_keyword("verbosity", &def_verbosity_handler, &snprint_def_verbosity);
1352         install_keyword("polling_interval", &def_checkint_handler, &snprint_def_checkint);
1353         install_keyword("max_polling_interval", &def_max_checkint_handler, &snprint_def_max_checkint);
1354         install_keyword("reassign_maps", &def_reassign_maps_handler, &snprint_def_reassign_maps);
1355         install_keyword("multipath_dir", &def_multipath_dir_handler, &snprint_def_multipath_dir);
1356         install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
1357         install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_pgpolicy);
1358         install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute);
1359         install_keyword("getuid_callout", &def_getuid_handler, &snprint_def_getuid);
1360         install_keyword("prio", &def_prio_name_handler, &snprint_def_prio_name);
1361         install_keyword("prio_args", &def_prio_args_handler, &snprint_def_prio_args);
1362         install_keyword("features", &def_features_handler, &snprint_def_features);
1363         install_keyword("path_checker", &def_checker_name_handler, &snprint_def_checker_name);
1364         install_keyword("checker", &def_checker_name_handler, NULL);
1365         install_keyword("alias_prefix", &def_alias_prefix_handler, &snprint_def_alias_prefix);
1366         install_keyword("failback", &def_pgfailback_handler, &snprint_def_pgfailback);
1367         install_keyword("rr_min_io", &def_minio_handler, &snprint_def_minio);
1368         install_keyword("rr_min_io_rq", &def_minio_rq_handler, &snprint_def_minio_rq);
1369         install_keyword("max_fds", &max_fds_handler, &snprint_max_fds);
1370         install_keyword("rr_weight", &def_rr_weight_handler, &snprint_def_rr_weight);
1371         install_keyword("no_path_retry", &def_no_path_retry_handler, &snprint_def_no_path_retry);
1372         install_keyword("queue_without_daemon", &def_queue_without_daemon_handler, &snprint_def_queue_without_daemon);
1373         install_keyword("checker_timeout", &def_checker_timeout_handler, &snprint_def_checker_timeout);
1374         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1375         install_keyword("flush_on_last_del", &def_flush_on_last_del_handler, &snprint_def_flush_on_last_del);
1376         install_keyword("user_friendly_names", &def_user_friendly_names_handler, &snprint_def_user_friendly_names);
1377         install_keyword("mode", &def_mode_handler, &snprint_def_mode);
1378         install_keyword("uid", &def_uid_handler, &snprint_def_uid);
1379         install_keyword("gid", &def_gid_handler, &snprint_def_gid);
1380         install_keyword("fast_io_fail_tmo", &def_fast_io_fail_handler, &snprint_def_fast_io_fail);
1381         install_keyword("dev_loss_tmo", &def_dev_loss_handler, &snprint_def_dev_loss);
1382         install_keyword("bindings_file", &def_bindings_file_handler, &snprint_def_bindings_file);
1383         install_keyword("wwids_file", &def_wwids_file_handler, &snprint_def_wwids_file);
1384         install_keyword("log_checker_err", &def_log_checker_err_handler, &snprint_def_log_checker_err);
1385         install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key);
1386         install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler);
1387         install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio);
1388         install_keyword("force_sync", &def_force_sync_handler, &snprint_def_force_sync);
1389         install_keyword("strict_timing", &def_strict_timing_handler, &snprint_def_strict_timing);
1390         install_keyword("deferred_remove", &def_deferred_remove_handler, &snprint_def_deferred_remove);
1391         install_keyword("partition_delimiter", &def_partition_delim_handler, &snprint_def_partition_delim);
1392         install_keyword("config_dir", &def_config_dir_handler, &snprint_def_config_dir);
1393         install_keyword("delay_watch_checks", &def_delay_watch_checks_handler, &snprint_def_delay_watch_checks);
1394         install_keyword("delay_wait_checks", &def_delay_wait_checks_handler, &snprint_def_delay_wait_checks);
1395         install_keyword("find_multipaths", &def_find_multipaths_handler, &snprint_def_find_multipaths);
1396         install_keyword("uxsock_timeout", &def_uxsock_timeout_handler, &snprint_def_uxsock_timeout);
1397         install_keyword("retrigger_tries", &def_retrigger_tries_handler, &snprint_def_retrigger_tries);
1398         install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
1399         install_keyword("missing_uev_wait_timeout", &def_uev_wait_timeout_handler, &snprint_def_uev_wait_timeout);
1400         install_keyword("skip_kpartx", &def_skip_kpartx_handler, &snprint_def_skip_kpartx);
1401         install_keyword("disable_changed_wwids", &def_disable_changed_wwids_handler, &snprint_def_disable_changed_wwids);
1402         __deprecated install_keyword("default_selector", &def_selector_handler, NULL);
1403         __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
1404         __deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
1405         __deprecated install_keyword("default_getuid_callout", &def_getuid_handler, NULL);
1406         __deprecated install_keyword("default_features", &def_features_handler, NULL);
1407         __deprecated install_keyword("default_path_checker", &def_checker_name_handler, NULL);
1408
1409         install_keyword_root("blacklist", &blacklist_handler);
1410         install_keyword_multi("devnode", &ble_blist_devnode_handler, &snprint_ble_simple);
1411         install_keyword_multi("wwid", &ble_blist_wwid_handler, &snprint_ble_simple);
1412         install_keyword_multi("property", &ble_blist_property_handler, &snprint_ble_simple);
1413         install_keyword_multi("device", &ble_device_handler, NULL);
1414         install_sublevel();
1415         install_keyword("vendor", &ble_blist_device_vendor_handler, &snprint_bled_vendor);
1416         install_keyword("product", &ble_blist_device_product_handler, &snprint_bled_product);
1417         install_sublevel_end();
1418         install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
1419         install_keyword_multi("devnode", &ble_elist_devnode_handler, &snprint_ble_simple);
1420         install_keyword_multi("wwid", &ble_elist_wwid_handler, &snprint_ble_simple);
1421         install_keyword_multi("property", &ble_elist_property_handler, &snprint_ble_simple);
1422         install_keyword_multi("device", &ble_except_device_handler, NULL);
1423         install_sublevel();
1424         install_keyword("vendor", &ble_elist_device_vendor_handler, &snprint_bled_vendor);
1425         install_keyword("product", &ble_elist_device_product_handler, &snprint_bled_product);
1426         install_sublevel_end();
1427
1428 #if 0
1429         __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler);
1430         __deprecated install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
1431         __deprecated install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
1432         __deprecated install_keyword("device", &ble_device_handler, NULL);
1433         __deprecated install_sublevel();
1434         __deprecated install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
1435         __deprecated install_keyword("product", &ble_product_handler, &snprint_bled_product);
1436         __deprecated install_sublevel_end();
1437 #endif
1438 /*
1439  * If you add or remove a "device subsection" keyword also update
1440  * multipath/multipath.conf.5 and the TEMPLATE in libmultipath/hwtable.c
1441  */
1442         install_keyword_root("devices", &devices_handler);
1443         install_keyword_multi("device", &device_handler, NULL);
1444         install_sublevel();
1445         install_keyword("vendor", &hw_vendor_handler, &snprint_hw_vendor);
1446         install_keyword("product", &hw_product_handler, &snprint_hw_product);
1447         install_keyword("revision", &hw_revision_handler, &snprint_hw_revision);
1448         install_keyword("product_blacklist", &hw_bl_product_handler, &snprint_hw_bl_product);
1449         install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_pgpolicy);
1450         install_keyword("uid_attribute", &hw_uid_attribute_handler, &snprint_hw_uid_attribute);
1451         install_keyword("getuid_callout", &hw_getuid_handler, &snprint_hw_getuid);
1452         install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
1453         install_keyword("path_checker", &hw_checker_name_handler, &snprint_hw_checker_name);
1454         install_keyword("checker", &hw_checker_name_handler, NULL);
1455         install_keyword("alias_prefix", &hw_alias_prefix_handler, &snprint_hw_alias_prefix);
1456         install_keyword("features", &hw_features_handler, &snprint_hw_features);
1457         install_keyword("hardware_handler", &hw_hwhandler_handler, &snprint_hw_hwhandler);
1458         install_keyword("prio", &hw_prio_name_handler, &snprint_hw_prio_name);
1459         install_keyword("prio_args", &hw_prio_args_handler, &snprint_hw_prio_args);
1460         install_keyword("failback", &hw_pgfailback_handler, &snprint_hw_pgfailback);
1461         install_keyword("rr_weight", &hw_rr_weight_handler, &snprint_hw_rr_weight);
1462         install_keyword("no_path_retry", &hw_no_path_retry_handler, &snprint_hw_no_path_retry);
1463         install_keyword("rr_min_io", &hw_minio_handler, &snprint_hw_minio);
1464         install_keyword("rr_min_io_rq", &hw_minio_rq_handler, &snprint_hw_minio_rq);
1465         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1466         install_keyword("flush_on_last_del", &hw_flush_on_last_del_handler, &snprint_hw_flush_on_last_del);
1467         install_keyword("fast_io_fail_tmo", &hw_fast_io_fail_handler, &snprint_hw_fast_io_fail);
1468         install_keyword("dev_loss_tmo", &hw_dev_loss_handler, &snprint_hw_dev_loss);
1469         install_keyword("user_friendly_names", &hw_user_friendly_names_handler, &snprint_hw_user_friendly_names);
1470         install_keyword("retain_attached_hw_handler", &hw_retain_hwhandler_handler, &snprint_hw_retain_hwhandler);
1471         install_keyword("detect_prio", &hw_detect_prio_handler, &snprint_hw_detect_prio);
1472         install_keyword("deferred_remove", &hw_deferred_remove_handler, &snprint_hw_deferred_remove);
1473         install_keyword("delay_watch_checks", &hw_delay_watch_checks_handler, &snprint_hw_delay_watch_checks);
1474         install_keyword("delay_wait_checks", &hw_delay_wait_checks_handler, &snprint_hw_delay_wait_checks);
1475         install_keyword("skip_kpartx", &hw_skip_kpartx_handler, &snprint_hw_skip_kpartx);
1476         install_sublevel_end();
1477
1478         install_keyword_root("overrides", &overrides_handler);
1479         install_keyword("path_grouping_policy", &ovr_pgpolicy_handler, &snprint_ovr_pgpolicy);
1480         install_keyword("uid_attribute", &ovr_uid_attribute_handler, &snprint_ovr_uid_attribute);
1481         install_keyword("getuid_callout", &ovr_getuid_handler, &snprint_ovr_getuid);
1482         install_keyword("path_selector", &ovr_selector_handler, &snprint_ovr_selector);
1483         install_keyword("path_checker", &ovr_checker_name_handler, &snprint_ovr_checker_name);
1484         install_keyword("checker", &ovr_checker_name_handler, NULL);
1485         install_keyword("alias_prefix", &ovr_alias_prefix_handler, &snprint_ovr_alias_prefix);
1486         install_keyword("features", &ovr_features_handler, &snprint_ovr_features);
1487         install_keyword("prio", &ovr_prio_name_handler, &snprint_ovr_prio_name);
1488         install_keyword("prio_args", &ovr_prio_args_handler, &snprint_ovr_prio_args);
1489         install_keyword("failback", &ovr_pgfailback_handler, &snprint_ovr_pgfailback);
1490         install_keyword("rr_weight", &ovr_rr_weight_handler, &snprint_ovr_rr_weight);
1491         install_keyword("no_path_retry", &ovr_no_path_retry_handler, &snprint_ovr_no_path_retry);
1492         install_keyword("rr_min_io", &ovr_minio_handler, &snprint_ovr_minio);
1493         install_keyword("rr_min_io_rq", &ovr_minio_rq_handler, &snprint_ovr_minio_rq);
1494         install_keyword("flush_on_last_del", &ovr_flush_on_last_del_handler, &snprint_ovr_flush_on_last_del);
1495         install_keyword("fast_io_fail_tmo", &ovr_fast_io_fail_handler, &snprint_ovr_fast_io_fail);
1496         install_keyword("dev_loss_tmo", &ovr_dev_loss_handler, &snprint_ovr_dev_loss);
1497         install_keyword("user_friendly_names", &ovr_user_friendly_names_handler, &snprint_ovr_user_friendly_names);
1498         install_keyword("retain_attached_hw_handler", &ovr_retain_hwhandler_handler, &snprint_ovr_retain_hwhandler);
1499         install_keyword("detect_prio", &ovr_detect_prio_handler, &snprint_ovr_detect_prio);
1500         install_keyword("deferred_remove", &ovr_deferred_remove_handler, &snprint_ovr_deferred_remove);
1501         install_keyword("delay_watch_checks", &ovr_delay_watch_checks_handler, &snprint_ovr_delay_watch_checks);
1502         install_keyword("delay_wait_checks", &ovr_delay_wait_checks_handler, &snprint_ovr_delay_wait_checks);
1503         install_keyword("skip_kpartx", &ovr_skip_kpartx_handler, &snprint_ovr_skip_kpartx);
1504
1505         install_keyword_root("multipaths", &multipaths_handler);
1506         install_keyword_multi("multipath", &multipath_handler, NULL);
1507         install_sublevel();
1508         install_keyword("wwid", &mp_wwid_handler, &snprint_mp_wwid);
1509         install_keyword("alias", &mp_alias_handler, &snprint_mp_alias);
1510         install_keyword("path_grouping_policy", &mp_pgpolicy_handler, &snprint_mp_pgpolicy);
1511         install_keyword("path_selector", &mp_selector_handler, &snprint_mp_selector);
1512         install_keyword("prio", &mp_prio_name_handler, &snprint_mp_prio_name);
1513         install_keyword("prio_args", &mp_prio_args_handler, &snprint_mp_prio_args);
1514         install_keyword("failback", &mp_pgfailback_handler, &snprint_mp_pgfailback);
1515         install_keyword("rr_weight", &mp_rr_weight_handler, &snprint_mp_rr_weight);
1516         install_keyword("no_path_retry", &mp_no_path_retry_handler, &snprint_mp_no_path_retry);
1517         install_keyword("rr_min_io", &mp_minio_handler, &snprint_mp_minio);
1518         install_keyword("rr_min_io_rq", &mp_minio_rq_handler, &snprint_mp_minio_rq);
1519         install_keyword("pg_timeout", &deprecated_handler, &snprint_deprecated);
1520         install_keyword("flush_on_last_del", &mp_flush_on_last_del_handler, &snprint_mp_flush_on_last_del);
1521         install_keyword("features", &mp_features_handler, &snprint_mp_features);
1522         install_keyword("mode", &mp_mode_handler, &snprint_mp_mode);
1523         install_keyword("uid", &mp_uid_handler, &snprint_mp_uid);
1524         install_keyword("gid", &mp_gid_handler, &snprint_mp_gid);
1525         install_keyword("reservation_key", &mp_reservation_key_handler, &snprint_mp_reservation_key);
1526         install_keyword("user_friendly_names", &mp_user_friendly_names_handler, &snprint_mp_user_friendly_names);
1527         install_keyword("deferred_remove", &mp_deferred_remove_handler, &snprint_mp_deferred_remove);
1528         install_keyword("delay_watch_checks", &mp_delay_watch_checks_handler, &snprint_mp_delay_watch_checks);
1529         install_keyword("delay_wait_checks", &mp_delay_wait_checks_handler, &snprint_mp_delay_wait_checks);
1530         install_keyword("skip_kpartx", &mp_skip_kpartx_handler, &snprint_mp_skip_kpartx);
1531         install_sublevel_end();
1532 }