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