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