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