multipath.conf.5: clarify 'no_path_retry' default setting
[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 /*
26  * default block handlers
27  */
28 static int
29 polling_interval_handler(vector strvec)
30 {
31         char * buff;
32
33         buff = VECTOR_SLOT(strvec, 1);
34         conf->checkint = atoi(buff);
35         conf->max_checkint = MAX_CHECKINT(conf->checkint);
36
37         return 0;
38 }
39
40 static int
41 def_fast_io_fail_handler(vector strvec)
42 {
43         char * buff;
44
45         buff = set_value(strvec);
46         if (strlen(buff) == 3 && !strcmp(buff, "off"))
47                 conf->fast_io_fail = MP_FAST_IO_FAIL_OFF;
48         else if (sscanf(buff, "%d", &conf->fast_io_fail) != 1 ||
49                  conf->fast_io_fail < MP_FAST_IO_FAIL_ZERO)
50                 conf->fast_io_fail = MP_FAST_IO_FAIL_UNSET;
51         else if (conf->fast_io_fail == 0)
52                 conf->fast_io_fail = MP_FAST_IO_FAIL_ZERO;
53
54         FREE(buff);
55         return 0;
56 }
57
58 static int
59 def_dev_loss_handler(vector strvec)
60 {
61         char * buff;
62
63         buff = set_value(strvec);
64         if (!buff)
65                 return 1;
66
67         if (strlen(buff) == 8 && !strcmp(buff, "infinity"))
68                 conf->dev_loss = MAX_DEV_LOSS_TMO;
69         else if (sscanf(buff, "%u", &conf->dev_loss) != 1)
70                 conf->dev_loss = 0;
71
72         FREE(buff);
73         return 0;
74 }
75
76 static int
77 verbosity_handler(vector strvec)
78 {
79         char * buff;
80
81         buff = VECTOR_SLOT(strvec, 1);
82         conf->verbosity = atoi(buff);
83
84         return 0;
85 }
86
87 static int
88 max_polling_interval_handler(vector strvec)
89 {
90         char *buff;
91
92         buff = VECTOR_SLOT(strvec, 1);
93         conf->max_checkint = atoi(buff);
94
95         return 0;
96 }
97
98 static int
99 reassign_maps_handler(vector strvec)
100 {
101         char * buff;
102
103         buff = set_value(strvec);
104         if (!strcmp(buff, "yes"))
105                 conf->reassign_maps = 1;
106         else if (!strcmp(buff, "no"))
107                 conf->reassign_maps = 0;
108         else
109                 return 1;
110
111         return 0;
112 }
113
114 static int
115 multipath_dir_handler(vector strvec)
116 {
117         conf->multipath_dir = set_value(strvec);
118
119         if (!conf->multipath_dir)
120                 return 1;
121
122         return 0;
123 }
124
125 static int
126 def_selector_handler(vector strvec)
127 {
128         conf->selector = set_value(strvec);
129
130         if (!conf->selector)
131                 return 1;
132
133         return 0;
134 }
135
136 static int
137 def_pgpolicy_handler(vector strvec)
138 {
139         char * buff;
140
141         buff = set_value(strvec);
142
143         if (!buff)
144                 return 1;
145
146         conf->pgpolicy = get_pgpolicy_id(buff);
147         FREE(buff);
148
149         return 0;
150 }
151
152 static int
153 def_uid_attribute_handler(vector strvec)
154 {
155         conf->uid_attribute = set_value(strvec);
156
157         if (!conf->uid_attribute)
158                 return 1;
159
160         return 0;
161 }
162
163 static int
164 def_getuid_callout_handler(vector strvec)
165 {
166         conf->getuid = set_value(strvec);
167
168         if (!conf->getuid)
169                 return 1;
170
171         return 0;
172 }
173
174 static int
175 def_prio_handler(vector strvec)
176 {
177         conf->prio_name = set_value(strvec);
178
179         if (!conf->prio_name)
180                 return 1;
181
182         return 0;
183 }
184
185 static int
186 def_alias_prefix_handler(vector strvec)
187 {
188         conf->alias_prefix = set_value(strvec);
189
190         if (!conf->alias_prefix)
191                 return 1;
192
193         return 0;
194 }
195
196 static int
197 def_prio_args_handler(vector strvec)
198 {
199         conf->prio_args = set_value(strvec);
200
201         if (!conf->prio_args)
202                 return 1;
203
204         return 0;
205 }
206
207 static int
208 def_features_handler(vector strvec)
209 {
210         conf->features = set_value(strvec);
211
212         if (!conf->features)
213                 return 1;
214
215         return 0;
216 }
217
218 static int
219 def_path_checker_handler(vector strvec)
220 {
221         conf->checker_name = set_value(strvec);
222
223         if (!conf->checker_name)
224                 return 1;
225
226         return 0;
227 }
228
229 static int
230 def_minio_handler(vector strvec)
231 {
232         char * buff;
233
234         buff = set_value(strvec);
235
236         if (!buff)
237                 return 1;
238
239         conf->minio = atoi(buff);
240         FREE(buff);
241
242         return 0;
243 }
244
245 static int
246 def_minio_rq_handler(vector strvec)
247 {
248         char * buff;
249
250         buff = set_value(strvec);
251
252         if (!buff)
253                 return 1;
254
255         conf->minio_rq = atoi(buff);
256         FREE(buff);
257
258         return 0;
259 }
260
261 int
262 get_sys_max_fds(int *max_fds)
263 {
264         FILE *file;
265         int nr_open;
266         int ret = 1;
267
268         file = fopen("/proc/sys/fs/nr_open", "r");
269         if (!file) {
270                 fprintf(stderr, "Cannot open /proc/sys/fs/nr_open : %s\n",
271                         strerror(errno));
272                 return 1;
273         }
274         if (fscanf(file, "%d", &nr_open) != 1) {
275                 fprintf(stderr, "Cannot read max open fds from /proc/sys/fs/nr_open");
276                 if (ferror(file))
277                         fprintf(stderr, " : %s\n", strerror(errno));
278                 else
279                         fprintf(stderr, "\n");
280         } else {
281                 *max_fds = nr_open;
282                 ret = 0;
283         }
284         fclose(file);
285         return ret;
286 }
287
288
289 static int
290 max_fds_handler(vector strvec)
291 {
292         char * buff;
293         int r = 0;
294
295         buff = set_value(strvec);
296
297         if (!buff)
298                 return 1;
299
300         if (strlen(buff) == 3 &&
301             !strcmp(buff, "max"))
302                 r = get_sys_max_fds(&conf->max_fds);
303         else
304                 conf->max_fds = atoi(buff);
305         FREE(buff);
306
307         return r;
308 }
309
310 static int
311 def_mode_handler(vector strvec)
312 {
313         mode_t mode;
314         char *buff;
315
316         buff = set_value(strvec);
317
318         if (!buff)
319                 return 1;
320
321         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
322                 conf->attribute_flags |= (1 << ATTR_MODE);
323                 conf->mode = mode;
324         }
325
326         FREE(buff);
327         return 0;
328 }
329
330 static int
331 def_uid_handler(vector strvec)
332 {
333         uid_t uid;
334         char *buff;
335         char passwd_buf[1024];
336         struct passwd info, *found;
337
338         buff = set_value(strvec);
339         if (!buff)
340                 return 1;
341         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
342                 conf->attribute_flags |= (1 << ATTR_UID);
343                 conf->uid = info.pw_uid;
344         }
345         else if (sscanf(buff, "%u", &uid) == 1){
346                 conf->attribute_flags |= (1 << ATTR_UID);
347                 conf->uid = uid;
348         }
349
350         FREE(buff);
351         return 0;
352 }
353
354 static int
355 def_gid_handler(vector strvec)
356 {
357         gid_t gid;
358         char *buff;
359         char passwd_buf[1024];
360         struct passwd info, *found;
361
362         buff = set_value(strvec);
363         if (!buff)
364                 return 1;
365
366         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
367                 conf->attribute_flags |= (1 << ATTR_GID);
368                 conf->gid = info.pw_gid;
369         }
370         else if (sscanf(buff, "%u", &gid) == 1){
371                 conf->attribute_flags |= (1 << ATTR_GID);
372                 conf->gid = gid;
373         }
374         FREE(buff);
375         return 0;
376 }
377
378 static int
379 def_weight_handler(vector strvec)
380 {
381         char * buff;
382
383         buff = set_value(strvec);
384
385         if (!buff)
386                 return 1;
387
388         if (strlen(buff) == 10 &&
389             !strcmp(buff, "priorities"))
390                 conf->rr_weight = RR_WEIGHT_PRIO;
391
392         if (strlen(buff) == strlen("uniform") &&
393             !strcmp(buff, "uniform"))
394                 conf->rr_weight = RR_WEIGHT_NONE;
395
396         FREE(buff);
397
398         return 0;
399 }
400
401 static int
402 default_failback_handler(vector strvec)
403 {
404         char * buff;
405
406         buff = set_value(strvec);
407
408         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
409                 conf->pgfailback = -FAILBACK_MANUAL;
410         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
411                 conf->pgfailback = -FAILBACK_IMMEDIATE;
412         else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
413                 conf->pgfailback = -FAILBACK_FOLLOWOVER;
414         else
415                 conf->pgfailback = atoi(buff);
416
417         FREE(buff);
418
419         return 0;
420 }
421
422 static int
423 def_no_path_retry_handler(vector strvec)
424 {
425         char * buff;
426
427         buff = set_value(strvec);
428         if (!buff)
429                 return 1;
430
431         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
432             (strlen(buff) == 1 && !strcmp(buff, "0")))
433                 conf->no_path_retry = NO_PATH_RETRY_FAIL;
434         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
435                 conf->no_path_retry = NO_PATH_RETRY_QUEUE;
436         else if ((conf->no_path_retry = atoi(buff)) < 1)
437                 conf->no_path_retry = NO_PATH_RETRY_UNDEF;
438
439         FREE(buff);
440         return 0;
441 }
442
443 static int
444 def_queue_without_daemon(vector strvec)
445 {
446         char * buff;
447
448         buff = set_value(strvec);
449         if (!buff)
450                 return 1;
451
452         if (!strncmp(buff, "on", 2) || !strncmp(buff, "yes", 3) ||
453                  !strncmp(buff, "1", 1))
454                 conf->queue_without_daemon = QUE_NO_DAEMON_ON;
455         else
456                 conf->queue_without_daemon = QUE_NO_DAEMON_OFF;
457
458         free(buff);
459         return 0;
460 }
461
462 static int
463 def_checker_timeout_handler(vector strvec)
464 {
465         unsigned int checker_timeout;
466         char *buff;
467
468         buff = set_value(strvec);
469         if (!buff)
470                 return 1;
471
472         if (sscanf(buff, "%u", &checker_timeout) == 1)
473                 conf->checker_timeout = checker_timeout;
474         else
475                 conf->checker_timeout = 0;
476
477         free(buff);
478         return 0;
479 }
480
481 static int
482 def_pg_timeout_handler(vector strvec)
483 {
484         char * buff;
485
486         buff = set_value(strvec);
487
488         if (!buff)
489                 return 1;
490
491         /* Deprecated; device-mapper support has been removed */
492
493         FREE(buff);
494         return 0;
495 }
496
497 static int
498 def_flush_on_last_del_handler(vector strvec)
499 {
500         char * buff;
501
502         buff = set_value(strvec);
503         if (!buff)
504                 return 1;
505
506         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
507             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
508                 conf->flush_on_last_del = FLUSH_DISABLED;
509         else if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
510             (strlen(buff) == 1 && strcmp(buff, "1") == 0))
511                 conf->flush_on_last_del = FLUSH_ENABLED;
512         else
513                 conf->flush_on_last_del = FLUSH_UNDEF;
514
515         FREE(buff);
516         return 0;
517 }
518
519 static int
520 def_log_checker_err_handler(vector strvec)
521 {
522         char * buff;
523
524         buff = set_value(strvec);
525
526         if (!buff)
527                 return 1;
528
529         if (strlen(buff) == 4 && !strcmp(buff, "once"))
530                 conf->log_checker_err = LOG_CHKR_ERR_ONCE;
531         else if (strlen(buff) == 6 && !strcmp(buff, "always"))
532                 conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
533
534         free(buff);
535         return 0;
536 }
537
538 static int
539 def_reservation_key_handler(vector strvec)
540 {
541         char *buff;
542         char *tbuff;
543         int j, k;
544         int len;
545         uint64_t prkey;
546
547         buff = set_value(strvec);
548         if (!buff)
549                 return 1;
550
551         tbuff = buff;
552
553         if (!memcmp("0x",buff, 2))
554                 buff = buff + 2;
555
556         len = strlen(buff);
557
558         k = strspn(buff, "0123456789aAbBcCdDeEfF");
559
560         if (len != k) {
561                 FREE(tbuff);
562                 return 1;
563         }
564
565         if (1 != sscanf (buff, "%" SCNx64 "", &prkey))
566         {
567                 FREE(tbuff);
568                 return 1;
569         }
570
571         if (!conf->reservation_key)
572                 conf->reservation_key = (unsigned char *) malloc(8);
573
574         memset(conf->reservation_key, 0, 8);
575
576         for (j = 7; j >= 0; --j) {
577                 conf->reservation_key[j] = (prkey & 0xff);
578                 prkey >>= 8;
579         }
580
581         FREE(tbuff);
582         return 0;
583 }
584
585 static int
586 def_names_handler(vector strvec)
587 {
588         char * buff;
589
590         buff = set_value(strvec);
591
592         if (!buff)
593                 return 1;
594
595         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
596             (strlen(buff) == 1 && !strcmp(buff, "0")))
597                 conf->user_friendly_names = USER_FRIENDLY_NAMES_OFF;
598         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
599                  (strlen(buff) == 1 && !strcmp(buff, "1")))
600                 conf->user_friendly_names = USER_FRIENDLY_NAMES_ON;
601         else
602                 conf->user_friendly_names = USER_FRIENDLY_NAMES_UNDEF;
603
604         FREE(buff);
605         return 0;
606 }
607
608 static int
609 bindings_file_handler(vector strvec)
610 {
611         conf->bindings_file = set_value(strvec);
612
613         if (!conf->bindings_file)
614                 return 1;
615
616         return 0;
617 }
618
619 static int
620 wwids_file_handler(vector strvec)
621 {
622         conf->wwids_file = set_value(strvec);
623
624         if (!conf->wwids_file)
625                 return 1;
626
627         return 0;
628 }
629
630 static int
631 def_retain_hwhandler_handler(vector strvec)
632 {
633         char * buff;
634
635         buff = set_value(strvec);
636
637         if (!buff)
638                 return 1;
639
640         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
641             (strlen(buff) == 1 && !strcmp(buff, "0")))
642                 conf->retain_hwhandler = RETAIN_HWHANDLER_OFF;
643         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
644                  (strlen(buff) == 1 && !strcmp(buff, "1")))
645                 conf->retain_hwhandler = RETAIN_HWHANDLER_ON;
646         else
647                 conf->retain_hwhandler = RETAIN_HWHANDLER_UNDEF;
648
649         FREE(buff);
650         return 0;
651 }
652
653 static int
654 def_detect_prio_handler(vector strvec)
655 {
656         char * buff;
657
658         buff = set_value(strvec);
659
660         if (!buff)
661                 return 1;
662
663         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
664             (strlen(buff) == 1 && !strcmp(buff, "0")))
665                 conf->detect_prio = DETECT_PRIO_OFF;
666         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
667                  (strlen(buff) == 1 && !strcmp(buff, "1")))
668                 conf->detect_prio = DETECT_PRIO_ON;
669         else
670                 conf->detect_prio = DETECT_PRIO_UNDEF;
671
672         FREE(buff);
673         return 0;
674 }
675
676 /*
677  * blacklist block handlers
678  */
679 static int
680 blacklist_handler(vector strvec)
681 {
682         conf->blist_devnode = vector_alloc();
683         conf->blist_wwid = vector_alloc();
684         conf->blist_device = vector_alloc();
685
686         if (!conf->blist_devnode || !conf->blist_wwid || !conf->blist_device)
687                 return 1;
688
689         return 0;
690 }
691
692 static int
693 blacklist_exceptions_handler(vector strvec)
694 {
695         conf->elist_devnode = vector_alloc();
696         conf->elist_wwid = vector_alloc();
697         conf->elist_device = vector_alloc();
698
699         if (!conf->elist_devnode || !conf->elist_wwid || !conf->elist_device)
700                 return 1;
701
702         return 0;
703 }
704
705 static int
706 ble_devnode_handler(vector strvec)
707 {
708         char * buff;
709
710         buff = set_value(strvec);
711
712         if (!buff)
713                 return 1;
714
715         return store_ble(conf->blist_devnode, buff, ORIGIN_CONFIG);
716 }
717
718 static int
719 ble_except_devnode_handler(vector strvec)
720 {
721         char * buff;
722
723         buff = set_value(strvec);
724
725         if (!buff)
726                 return 1;
727
728         return store_ble(conf->elist_devnode, buff, ORIGIN_CONFIG);
729 }
730
731 static int
732 ble_wwid_handler(vector strvec)
733 {
734         char * buff;
735
736         buff = set_value(strvec);
737
738         if (!buff)
739                 return 1;
740
741         return store_ble(conf->blist_wwid, buff, ORIGIN_CONFIG);
742 }
743
744 static int
745 ble_except_wwid_handler(vector strvec)
746 {
747         char * buff;
748
749         buff = set_value(strvec);
750
751         if (!buff)
752                 return 1;
753
754         return store_ble(conf->elist_wwid, buff, ORIGIN_CONFIG);
755 }
756
757 static int
758 ble_device_handler(vector strvec)
759 {
760         return alloc_ble_device(conf->blist_device);
761 }
762
763 static int
764 ble_except_device_handler(vector strvec)
765 {
766         return alloc_ble_device(conf->elist_device);
767 }
768
769 static int
770 ble_vendor_handler(vector strvec)
771 {
772         char * buff;
773
774         buff = set_value(strvec);
775
776         if (!buff)
777                 return 1;
778
779         return set_ble_device(conf->blist_device, buff, NULL, ORIGIN_CONFIG);
780 }
781
782 static int
783 ble_except_vendor_handler(vector strvec)
784 {
785         char * buff;
786
787         buff = set_value(strvec);
788
789         if (!buff)
790                 return 1;
791
792         return set_ble_device(conf->elist_device, buff, NULL, ORIGIN_CONFIG);
793 }
794
795 static int
796 ble_product_handler(vector strvec)
797 {
798         char * buff;
799
800         buff = set_value(strvec);
801
802         if (!buff)
803                 return 1;
804
805         return set_ble_device(conf->blist_device, NULL, buff, ORIGIN_CONFIG);
806 }
807
808 static int
809 ble_except_product_handler(vector strvec)
810 {
811         char * buff;
812
813         buff = set_value(strvec);
814
815         if (!buff)
816                 return 1;
817
818         return set_ble_device(conf->elist_device, NULL, buff, ORIGIN_CONFIG);
819 }
820
821 /*
822  * devices block handlers
823  */
824 static int
825 devices_handler(vector strvec)
826 {
827         if (!conf->hwtable)
828                 conf->hwtable = vector_alloc();
829
830         if (!conf->hwtable)
831                 return 1;
832
833         return 0;
834 }
835
836 static int
837 device_handler(vector strvec)
838 {
839         struct hwentry * hwe;
840
841         hwe = alloc_hwe();
842
843         if (!hwe)
844                 return 1;
845
846         if (!vector_alloc_slot(conf->hwtable)) {
847                 free_hwe(hwe);
848                 return 1;
849         }
850         vector_set_slot(conf->hwtable, hwe);
851
852         return 0;
853 }
854
855 static int
856 vendor_handler(vector strvec)
857 {
858         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
859
860         if (!hwe)
861                 return 1;
862
863         hwe->vendor = set_value(strvec);
864
865         if (!hwe->vendor)
866                 return 1;
867
868         return 0;
869 }
870
871 static int
872 product_handler(vector strvec)
873 {
874         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
875
876         if (!hwe)
877                 return 1;
878
879         hwe->product = set_value(strvec);
880
881         if (!hwe->product)
882                 return 1;
883
884         return 0;
885 }
886
887 static int
888 revision_handler(vector strvec)
889 {
890         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
891
892         if (!hwe)
893                 return 1;
894
895         hwe->revision = set_value(strvec);
896
897         if (!hwe->revision)
898                 return 1;
899
900         return 0;
901 }
902
903 static int
904 bl_product_handler(vector strvec)
905 {
906         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
907
908         if (!hwe)
909                 return 1;
910
911         hwe->bl_product = set_value(strvec);
912         if (!hwe->bl_product)
913                 return 1;
914
915         return 0;
916 }
917
918 static int
919 hw_fast_io_fail_handler(vector strvec)
920 {
921         char * buff;
922         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
923
924         buff = set_value(strvec);
925         if (strlen(buff) == 3 && !strcmp(buff, "off"))
926                 hwe->fast_io_fail = MP_FAST_IO_FAIL_OFF;
927         else if (sscanf(buff, "%d", &hwe->fast_io_fail) != 1 ||
928                  hwe->fast_io_fail < MP_FAST_IO_FAIL_ZERO)
929                 hwe->fast_io_fail = MP_FAST_IO_FAIL_UNSET;
930         else if (hwe->fast_io_fail == 0)
931                 hwe->fast_io_fail = MP_FAST_IO_FAIL_ZERO;
932
933         FREE(buff);
934         return 0;
935 }
936
937 static int
938 hw_dev_loss_handler(vector strvec)
939 {
940         char * buff;
941         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
942
943         buff = set_value(strvec);
944         if (!buff)
945                 return 1;
946
947         if (strlen(buff) == 8 && !strcmp(buff, "infinity"))
948                 hwe->dev_loss = MAX_DEV_LOSS_TMO;
949         else if (sscanf(buff, "%u", &hwe->dev_loss) != 1)
950                 hwe->dev_loss = 0;
951
952         FREE(buff);
953         return 0;
954 }
955
956 static int
957 hw_pgpolicy_handler(vector strvec)
958 {
959         char * buff;
960         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
961
962         buff = set_value(strvec);
963
964         if (!buff)
965                 return 1;
966
967         hwe->pgpolicy = get_pgpolicy_id(buff);
968         FREE(buff);
969
970         return 0;
971 }
972
973 static int
974 hw_uid_attribute_handler(vector strvec)
975 {
976         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
977
978         hwe->uid_attribute = set_value(strvec);
979
980         if (!hwe->uid_attribute)
981                 return 1;
982
983         return 0;
984 }
985
986 static int
987 hw_getuid_callout_handler(vector strvec)
988 {
989         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
990
991         hwe->getuid = set_value(strvec);
992
993         if (!hwe->getuid)
994                 return 1;
995
996         return 0;
997 }
998
999 static int
1000 hw_selector_handler(vector strvec)
1001 {
1002         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1003
1004         if (!hwe)
1005                 return 1;
1006
1007         hwe->selector = set_value(strvec);
1008
1009         if (!hwe->selector)
1010                 return 1;
1011
1012         return 0;
1013 }
1014
1015 static int
1016 hw_path_checker_handler(vector strvec)
1017 {
1018         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1019
1020         if (!hwe)
1021                 return 1;
1022
1023         hwe->checker_name = set_value(strvec);
1024
1025         if (!hwe->checker_name)
1026                 return 1;
1027
1028         return 0;
1029 }
1030
1031 static int
1032 hw_features_handler(vector strvec)
1033 {
1034         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1035
1036         if (!hwe)
1037                 return 1;
1038
1039         hwe->features = set_value(strvec);
1040
1041         if (!hwe->features)
1042                 return 1;
1043
1044         return 0;
1045 }
1046
1047 static int
1048 hw_handler_handler(vector strvec)
1049 {
1050         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1051
1052         if (!hwe)
1053                 return 1;
1054
1055         hwe->hwhandler = set_value(strvec);
1056
1057         if (!hwe->hwhandler)
1058                 return 1;
1059
1060         return 0;
1061 }
1062
1063 static int
1064 hw_prio_handler(vector strvec)
1065 {
1066         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1067
1068         if (!hwe)
1069                 return 1;
1070
1071         hwe->prio_name = set_value(strvec);
1072
1073         if (!hwe->prio_name)
1074                 return 1;
1075
1076         return 0;
1077 }
1078
1079 static int
1080 hw_alias_prefix_handler(vector strvec)
1081 {
1082         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1083
1084         if (!hwe)
1085                 return 1;
1086
1087         hwe->alias_prefix = set_value(strvec);
1088
1089         if (!hwe->alias_prefix)
1090                 return 1;
1091
1092         return 0;
1093 }
1094
1095 static int
1096 hw_prio_args_handler(vector strvec)
1097 {
1098         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1099
1100         if (!hwe)
1101                 return 1;
1102
1103         hwe->prio_args = set_value(strvec);
1104
1105         if (!hwe->prio_args)
1106                 return 1;
1107
1108         return 0;
1109 }
1110
1111 static int
1112 hw_failback_handler(vector strvec)
1113 {
1114         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1115         char * buff;
1116
1117         if (!hwe)
1118                 return 1;
1119
1120         buff = set_value(strvec);
1121
1122         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
1123                 hwe->pgfailback = -FAILBACK_MANUAL;
1124         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
1125                 hwe->pgfailback = -FAILBACK_IMMEDIATE;
1126         else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
1127                 hwe->pgfailback = -FAILBACK_FOLLOWOVER;
1128         else
1129                 hwe->pgfailback = atoi(buff);
1130
1131         FREE(buff);
1132
1133         return 0;
1134 }
1135
1136 static int
1137 hw_weight_handler(vector strvec)
1138 {
1139         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
1140         char * buff;
1141
1142         if (!hwe)
1143                 return 1;
1144
1145         buff = set_value(strvec);
1146
1147         if (!buff)
1148                 return 1;
1149
1150         if (strlen(buff) == 10 &&
1151             !strcmp(buff, "priorities"))
1152                 hwe->rr_weight = RR_WEIGHT_PRIO;
1153
1154         if (strlen(buff) == strlen("uniform") &&
1155             !strcmp(buff, "uniform"))
1156                 hwe->rr_weight = RR_WEIGHT_NONE;
1157
1158         FREE(buff);
1159
1160         return 0;
1161 }
1162
1163 static int
1164 hw_no_path_retry_handler(vector strvec)
1165 {
1166         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1167         char *buff;
1168
1169         if (!hwe)
1170                 return 1;
1171
1172         buff = set_value(strvec);
1173         if (!buff)
1174                 return 1;
1175
1176         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
1177             (strlen(buff) == 1 && !strcmp(buff, "0")))
1178                 hwe->no_path_retry = NO_PATH_RETRY_FAIL;
1179         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
1180                 hwe->no_path_retry = NO_PATH_RETRY_QUEUE;
1181         else if ((hwe->no_path_retry = atoi(buff)) < 1)
1182                 hwe->no_path_retry = NO_PATH_RETRY_UNDEF;
1183
1184         FREE(buff);
1185         return 0;
1186 }
1187
1188 static int
1189 hw_minio_handler(vector strvec)
1190 {
1191         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1192         char * buff;
1193
1194         if (!hwe)
1195                 return 1;
1196
1197         buff = set_value(strvec);
1198
1199         if (!buff)
1200                 return 1;
1201
1202         hwe->minio = atoi(buff);
1203         FREE(buff);
1204
1205         return 0;
1206 }
1207
1208 static int
1209 hw_minio_rq_handler(vector strvec)
1210 {
1211         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1212         char * buff;
1213
1214         if (!hwe)
1215                 return 1;
1216
1217         buff = set_value(strvec);
1218
1219         if (!buff)
1220                 return 1;
1221
1222         hwe->minio_rq = atoi(buff);
1223         FREE(buff);
1224
1225         return 0;
1226 }
1227
1228 static int
1229 hw_pg_timeout_handler(vector strvec)
1230 {
1231         char *buff;
1232
1233         buff = set_value(strvec);
1234
1235         if (!buff)
1236                 return 1;
1237
1238         /* Deprecated; device-mapper support has been removed */
1239
1240         FREE(buff);
1241         return 0;
1242 }
1243
1244 static int
1245 hw_flush_on_last_del_handler(vector strvec)
1246 {
1247         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1248         char * buff;
1249
1250         if (!hwe)
1251                 return 1;
1252
1253         buff = set_value(strvec);
1254         if (!buff)
1255                 return 1;
1256
1257         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
1258             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
1259                 hwe->flush_on_last_del = FLUSH_DISABLED;
1260         else if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
1261             (strlen(buff) == 1 && strcmp(buff, "1") == 0))
1262                 hwe->flush_on_last_del = FLUSH_ENABLED;
1263         else
1264                 hwe->flush_on_last_del = FLUSH_UNDEF;
1265
1266         FREE(buff);
1267         return 0;
1268 }
1269
1270 static int
1271 hw_names_handler(vector strvec)
1272 {
1273         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1274         char * buff;
1275
1276         if (!hwe)
1277                 return 1;
1278
1279         buff = set_value(strvec);
1280         if (!buff)
1281                 return 1;
1282
1283         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
1284             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
1285                 hwe->user_friendly_names = USER_FRIENDLY_NAMES_OFF;
1286         else if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
1287                  (strlen(buff) == 1 && strcmp(buff, "1") == 0))
1288                 hwe->user_friendly_names = USER_FRIENDLY_NAMES_ON;
1289         else
1290                 hwe->user_friendly_names = USER_FRIENDLY_NAMES_UNDEF;
1291
1292         FREE(buff);
1293         return 0;
1294 }
1295
1296 static int
1297 hw_retain_hwhandler_handler(vector strvec)
1298 {
1299         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1300         char * buff;
1301
1302         if (!hwe)
1303                 return 1;
1304
1305         buff = set_value(strvec);
1306
1307         if (!buff)
1308                 return 1;
1309
1310         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
1311             (strlen(buff) == 1 && !strcmp(buff, "0")))
1312                 hwe->retain_hwhandler = RETAIN_HWHANDLER_OFF;
1313         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
1314                  (strlen(buff) == 1 && !strcmp(buff, "1")))
1315                 hwe->retain_hwhandler = RETAIN_HWHANDLER_ON;
1316         else
1317                 hwe->user_friendly_names = RETAIN_HWHANDLER_UNDEF;
1318
1319         FREE(buff);
1320         return 0;
1321 }
1322
1323 static int
1324 hw_detect_prio_handler(vector strvec)
1325 {
1326         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1327         char * buff;
1328
1329         if (!hwe)
1330                 return 1;
1331
1332         buff = set_value(strvec);
1333
1334         if (!buff)
1335                 return 1;
1336
1337         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
1338             (strlen(buff) == 1 && !strcmp(buff, "0")))
1339                 hwe->detect_prio = DETECT_PRIO_OFF;
1340         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
1341                  (strlen(buff) == 1 && !strcmp(buff, "1")))
1342                 hwe->detect_prio = DETECT_PRIO_ON;
1343         else
1344                 hwe->detect_prio = DETECT_PRIO_UNDEF;
1345
1346         FREE(buff);
1347         return 0;
1348 }
1349
1350 /*
1351  * multipaths block handlers
1352  */
1353 static int
1354 multipaths_handler(vector strvec)
1355 {
1356         conf->mptable = vector_alloc();
1357
1358         if (!conf->mptable)
1359                 return 1;
1360
1361         return 0;
1362 }
1363
1364 static int
1365 multipath_handler(vector strvec)
1366 {
1367         struct mpentry * mpe;
1368
1369         mpe = alloc_mpe();
1370
1371         if (!mpe)
1372                 return 1;
1373
1374         if (!vector_alloc_slot(conf->mptable)) {
1375                 free_mpe(mpe);
1376                 return 1;
1377         }
1378         vector_set_slot(conf->mptable, mpe);
1379
1380         return 0;
1381 }
1382
1383 static int
1384 wwid_handler(vector strvec)
1385 {
1386         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1387
1388         if (!mpe)
1389                 return 1;
1390
1391         mpe->wwid = set_value(strvec);
1392
1393         if (!mpe->wwid)
1394                 return 1;
1395
1396         return 0;
1397 }
1398
1399 static int
1400 alias_handler(vector strvec)
1401 {
1402         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1403
1404         if (!mpe)
1405                 return 1;
1406
1407         mpe->alias = set_value(strvec);
1408
1409         if (!mpe->alias)
1410                 return 1;
1411
1412         return 0;
1413 }
1414
1415 static int
1416 mp_pgpolicy_handler(vector strvec)
1417 {
1418         char * buff;
1419         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1420
1421         if (!mpe)
1422                 return 1;
1423
1424         buff = set_value(strvec);
1425
1426         if (!buff)
1427                 return 1;
1428
1429         mpe->pgpolicy = get_pgpolicy_id(buff);
1430         FREE(buff);
1431
1432         return 0;
1433 }
1434
1435 static int
1436 mp_selector_handler(vector strvec)
1437 {
1438         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1439
1440         if (!mpe)
1441                 return 1;
1442
1443         mpe->selector = set_value(strvec);
1444
1445         if (!mpe->selector)
1446                 return 1;
1447
1448         return 0;
1449 }
1450
1451 static int
1452 mp_failback_handler(vector strvec)
1453 {
1454         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1455         char * buff;
1456
1457         if (!mpe)
1458                 return 1;
1459
1460         buff = set_value(strvec);
1461
1462         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
1463                 mpe->pgfailback = -FAILBACK_MANUAL;
1464         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
1465                 mpe->pgfailback = -FAILBACK_IMMEDIATE;
1466         else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
1467                 mpe->pgfailback = -FAILBACK_FOLLOWOVER;
1468         else
1469                 mpe->pgfailback = atoi(buff);
1470
1471         FREE(buff);
1472
1473         return 0;
1474 }
1475
1476 static int
1477 mp_mode_handler(vector strvec)
1478 {
1479         mode_t mode;
1480         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1481         char *buff;
1482
1483         if (!mpe)
1484                 return 1;
1485
1486         buff = set_value(strvec);
1487         if (!buff)
1488                 return 1;
1489         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
1490                 mpe->attribute_flags |= (1 << ATTR_MODE);
1491                 mpe->mode = mode;
1492         }
1493
1494         FREE(buff);
1495         return 0;
1496 }
1497
1498 static int
1499 mp_uid_handler(vector strvec)
1500 {
1501         uid_t uid;
1502         char *buff;
1503         char passwd_buf[1024];
1504         struct passwd info, *found;
1505
1506         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1507
1508         if (!mpe)
1509                 return 1;
1510
1511         buff = set_value(strvec);
1512         if (!buff)
1513                 return 1;
1514
1515         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
1516                 mpe->attribute_flags |= (1 << ATTR_UID);
1517                 mpe->uid = info.pw_uid;
1518         }
1519         else if (sscanf(buff, "%u", &uid) == 1){
1520                 mpe->attribute_flags |= (1 << ATTR_UID);
1521                 mpe->uid = uid;
1522         }
1523         FREE(buff);
1524         return 0;
1525 }
1526
1527 static int
1528 mp_gid_handler(vector strvec)
1529 {
1530         gid_t gid;
1531         char *buff;
1532         char passwd_buf[1024];
1533         struct passwd info, *found;
1534
1535         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1536
1537         if (!mpe)
1538                 return 1;
1539
1540         buff = set_value(strvec);
1541         if (!buff)
1542                 return 1;
1543
1544         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
1545                 mpe->attribute_flags |= (1 << ATTR_GID);
1546                 mpe->gid = info.pw_gid;
1547         }
1548         else if (sscanf(buff, "%u", &gid) == 1) {
1549                 mpe->attribute_flags |= (1 << ATTR_GID);
1550                 mpe->gid = gid;
1551         }
1552         FREE(buff);
1553         return 0;
1554 }
1555
1556 static int
1557 mp_weight_handler(vector strvec)
1558 {
1559         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1560         char * buff;
1561
1562         if (!mpe)
1563                 return 1;
1564
1565         buff = set_value(strvec);
1566
1567         if (!buff)
1568                 return 1;
1569
1570         if (strlen(buff) == 10 &&
1571             !strcmp(buff, "priorities"))
1572                 mpe->rr_weight = RR_WEIGHT_PRIO;
1573
1574         if (strlen(buff) == strlen("uniform") &&
1575             !strcmp(buff, "uniform"))
1576                 mpe->rr_weight = RR_WEIGHT_NONE;
1577
1578         FREE(buff);
1579
1580         return 0;
1581 }
1582
1583 static int
1584 mp_no_path_retry_handler(vector strvec)
1585 {
1586         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1587         char *buff;
1588
1589         if (!mpe)
1590                 return 1;
1591
1592         buff = set_value(strvec);
1593         if (!buff)
1594                 return 1;
1595
1596         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
1597             (strlen(buff) == 1 && !strcmp(buff, "0")))
1598                 mpe->no_path_retry = NO_PATH_RETRY_FAIL;
1599         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
1600                 mpe->no_path_retry = NO_PATH_RETRY_QUEUE;
1601         else if ((mpe->no_path_retry = atoi(buff)) < 1)
1602                 mpe->no_path_retry = NO_PATH_RETRY_UNDEF;
1603
1604         FREE(buff);
1605         return 0;
1606 }
1607
1608 static int
1609 mp_minio_handler(vector strvec)
1610 {
1611         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1612         char * buff;
1613
1614         if (!mpe)
1615                 return 1;
1616
1617         buff = set_value(strvec);
1618
1619         if (!buff)
1620                 return 1;
1621
1622         mpe->minio = atoi(buff);
1623         FREE(buff);
1624
1625         return 0;
1626 }
1627
1628 static int
1629 mp_minio_rq_handler(vector strvec)
1630 {
1631         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1632         char * buff;
1633
1634         if (!mpe)
1635                 return 1;
1636
1637         buff = set_value(strvec);
1638
1639         if (!buff)
1640                 return 1;
1641
1642         mpe->minio_rq = atoi(buff);
1643         FREE(buff);
1644
1645         return 0;
1646 }
1647
1648 static int
1649 mp_pg_timeout_handler(vector strvec)
1650 {
1651         char *buff;
1652
1653         buff = set_value(strvec);
1654
1655         if (!buff)
1656                 return 1;
1657
1658         /* Deprecated; device-mapper support has been removed */
1659
1660         FREE(buff);
1661         return 0;
1662 }
1663
1664 static int
1665 mp_features_handler(vector strvec)
1666 {
1667         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1668
1669         if (!mpe)
1670                 return 1;
1671
1672         mpe->features = set_value(strvec);
1673
1674         if (!mpe->features)
1675                 return 1;
1676
1677         return 0;
1678 }
1679
1680 static int
1681 mp_flush_on_last_del_handler(vector strvec)
1682 {
1683         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1684         char * buff;
1685
1686         if (!mpe)
1687                 return 1;
1688
1689         buff = set_value(strvec);
1690         if (!buff)
1691                 return 1;
1692
1693         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
1694             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
1695                 mpe->flush_on_last_del = FLUSH_DISABLED;
1696         else if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
1697             (strlen(buff) == 1 && strcmp(buff, "1") == 0))
1698                 mpe->flush_on_last_del = FLUSH_ENABLED;
1699         else
1700                 mpe->flush_on_last_del = FLUSH_UNDEF;
1701
1702         FREE(buff);
1703         return 0;
1704 }
1705
1706 static int
1707 mp_prio_handler(vector strvec)
1708 {
1709         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1710
1711         if (!mpe)
1712                 return 1;
1713
1714         mpe->prio_name = set_value(strvec);
1715
1716         if (!mpe->prio_name)
1717                 return 1;
1718
1719         return 0;
1720 }
1721
1722 static int
1723 mp_prio_args_handler (vector strvec)
1724 {
1725         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1726
1727         if (!mpe)
1728                 return 1;
1729
1730         mpe->prio_args = set_value(strvec);
1731         if (!mpe->prio_args)
1732                 return 1;
1733
1734         return 0;
1735 }
1736
1737 static int
1738 mp_reservation_key_handler (vector strvec)
1739 {
1740         char *buff;
1741         char *tbuff;
1742         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1743
1744         int j, k, len;
1745         uint64_t prkey;
1746
1747         if (!mpe)
1748                 return 1;
1749
1750         buff = set_value(strvec);
1751         if (!buff)
1752                 return 1;
1753
1754         tbuff = buff;
1755         if (!memcmp(buff, "0x", 2))
1756                 buff = buff + 2;
1757
1758         len = strlen(buff);
1759
1760         k = strspn(buff, "0123456789aAbBcCdDeEfF");
1761         if (len != k) {
1762                 FREE(tbuff);
1763                 return 1;
1764         }
1765
1766         if (1 != sscanf (buff, "%" SCNx64 "", &prkey))
1767         {
1768                 FREE(tbuff);
1769                 return 1;
1770         }
1771
1772         if (!mpe->reservation_key)
1773                 mpe->reservation_key = (unsigned char *) malloc(8);
1774
1775         memset(mpe->reservation_key, 0, 8);
1776
1777         for (j = 7; j >= 0; --j) {
1778                 mpe->reservation_key[j] = (prkey & 0xff);
1779                 prkey >>= 8;
1780         }
1781
1782         FREE(tbuff);
1783         return 0;
1784 }
1785
1786 static int
1787 mp_names_handler(vector strvec)
1788 {
1789         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1790         char * buff;
1791
1792         if (!mpe)
1793                 return 1;
1794
1795         buff = set_value(strvec);
1796         if (!buff)
1797                 return 1;
1798
1799         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
1800             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
1801                 mpe->user_friendly_names = USER_FRIENDLY_NAMES_OFF;
1802         else if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
1803                  (strlen(buff) == 1 && strcmp(buff, "1") == 0))
1804                 mpe->user_friendly_names = USER_FRIENDLY_NAMES_ON;
1805         else
1806                 mpe->user_friendly_names = USER_FRIENDLY_NAMES_UNDEF;
1807
1808         FREE(buff);
1809         return 0;
1810 }
1811
1812 /*
1813  * config file keywords printing
1814  */
1815 static int
1816 snprint_mp_wwid (char * buff, int len, void * data)
1817 {
1818         struct mpentry * mpe = (struct mpentry *)data;
1819
1820         return snprintf(buff, len, "%s", mpe->wwid);
1821 }
1822
1823 static int
1824 snprint_mp_alias (char * buff, int len, void * data)
1825 {
1826         struct mpentry * mpe = (struct mpentry *)data;
1827
1828         if (!mpe->alias)
1829                 return 0;
1830
1831         return snprintf(buff, len, "%s", mpe->alias);
1832 }
1833
1834 static int
1835 snprint_mp_path_grouping_policy (char * buff, int len, void * data)
1836 {
1837         struct mpentry * mpe = (struct mpentry *)data;
1838         char str[POLICY_NAME_SIZE];
1839
1840         if (!mpe->pgpolicy)
1841                 return 0;
1842         get_pgpolicy_name(str, POLICY_NAME_SIZE, mpe->pgpolicy);
1843
1844         return snprintf(buff, len, "\"%s\"", str);
1845 }
1846
1847 static int
1848 snprint_mp_selector (char * buff, int len, void * data)
1849 {
1850         struct mpentry * mpe = (struct mpentry *)data;
1851
1852         if (!mpe->selector)
1853                 return 0;
1854
1855         return snprintf(buff, len, "\"%s\"", mpe->selector);
1856 }
1857
1858 static int
1859 snprint_mp_failback (char * buff, int len, void * data)
1860 {
1861         struct mpentry * mpe = (struct mpentry *)data;
1862
1863         if (!mpe->pgfailback)
1864                 return 0;
1865
1866         switch(mpe->pgfailback) {
1867         case  FAILBACK_UNDEF:
1868                 break;
1869         case -FAILBACK_MANUAL:
1870                 return snprintf(buff, len, "\"manual\"");
1871         case -FAILBACK_IMMEDIATE:
1872                 return snprintf(buff, len, "\"immediate\"");
1873         case -FAILBACK_FOLLOWOVER:
1874                 return snprintf(buff, len, "\"followover\"");
1875         default:
1876                 return snprintf(buff, len, "%i", mpe->pgfailback);
1877         }
1878         return 0;
1879 }
1880
1881 static int
1882 snprint_mp_mode(char * buff, int len, void * data)
1883 {
1884         struct mpentry * mpe = (struct mpentry *)data;
1885
1886         if ((mpe->attribute_flags & (1 << ATTR_MODE)) == 0)
1887                 return 0;
1888         return snprintf(buff, len, "0%o", mpe->mode);
1889 }
1890
1891 static int
1892 snprint_mp_uid(char * buff, int len, void * data)
1893 {
1894         struct mpentry * mpe = (struct mpentry *)data;
1895
1896         if ((mpe->attribute_flags & (1 << ATTR_UID)) == 0)
1897                 return 0;
1898         return snprintf(buff, len, "0%o", mpe->uid);
1899 }
1900
1901 static int
1902 snprint_mp_gid(char * buff, int len, void * data)
1903 {
1904         struct mpentry * mpe = (struct mpentry *)data;
1905
1906         if ((mpe->attribute_flags & (1 << ATTR_GID)) == 0)
1907                 return 0;
1908         return snprintf(buff, len, "0%o", mpe->gid);
1909 }
1910
1911 static int
1912 snprint_mp_rr_weight (char * buff, int len, void * data)
1913 {
1914         struct mpentry * mpe = (struct mpentry *)data;
1915
1916         if (!mpe->rr_weight)
1917                 return 0;
1918         if (mpe->rr_weight == RR_WEIGHT_PRIO)
1919                 return snprintf(buff, len, "\"priorities\"");
1920         if (mpe->rr_weight == RR_WEIGHT_NONE)
1921                 return snprintf(buff, len, "\"uniform\"");
1922
1923         return 0;
1924 }
1925
1926 static int
1927 snprint_mp_no_path_retry (char * buff, int len, void * data)
1928 {
1929         struct mpentry * mpe = (struct mpentry *)data;
1930
1931         if (!mpe->no_path_retry)
1932                 return 0;
1933
1934         switch(mpe->no_path_retry) {
1935         case NO_PATH_RETRY_UNDEF:
1936                 break;
1937         case NO_PATH_RETRY_FAIL:
1938                 return snprintf(buff, len, "\"fail\"");
1939         case NO_PATH_RETRY_QUEUE:
1940                 return snprintf(buff, len, "\"queue\"");
1941         default:
1942                 return snprintf(buff, len, "%i",
1943                                 mpe->no_path_retry);
1944         }
1945         return 0;
1946 }
1947
1948 static int
1949 snprint_mp_rr_min_io (char * buff, int len, void * data)
1950 {
1951         struct mpentry * mpe = (struct mpentry *)data;
1952
1953         if (!mpe->minio)
1954                 return 0;
1955
1956         return snprintf(buff, len, "%u", mpe->minio);
1957 }
1958
1959 static int
1960 snprint_mp_rr_min_io_rq (char * buff, int len, void * data)
1961 {
1962         struct mpentry * mpe = (struct mpentry *)data;
1963
1964         if (!mpe->minio_rq)
1965                 return 0;
1966
1967         return snprintf(buff, len, "%u", mpe->minio_rq);
1968 }
1969
1970 static int
1971 snprint_mp_pg_timeout (char * buff, int len, void * data)
1972 {
1973         return 0;
1974 }
1975
1976 static int
1977 snprint_mp_features (char * buff, int len, void * data)
1978 {
1979         struct mpentry * mpe = (struct mpentry *)data;
1980
1981         if (!mpe->features)
1982                 return 0;
1983         if (strlen(mpe->features) == strlen(conf->features) &&
1984             !strcmp(mpe->features, conf->features))
1985                 return 0;
1986
1987         return snprintf(buff, len, "\"%s\"", mpe->features);
1988 }
1989
1990 static int
1991 snprint_mp_flush_on_last_del (char * buff, int len, void * data)
1992 {
1993         struct mpentry * mpe = (struct mpentry *)data;
1994
1995         switch (mpe->flush_on_last_del) {
1996         case FLUSH_DISABLED:
1997                 return snprintf(buff, len, "\"no\"");
1998         case FLUSH_ENABLED:
1999                 return snprintf(buff, len, "\"yes\"");
2000         }
2001         return 0;
2002 }
2003
2004 static int
2005 snprint_mp_prio(char * buff, int len, void * data)
2006 {
2007         struct mpentry * mpe = (struct mpentry *)data;
2008
2009         if (!mpe->prio_name)
2010                 return 0;
2011
2012         return snprintf(buff, len, "\"%s\"", mpe->prio_name);
2013 }
2014
2015 static int
2016 snprint_mp_prio_args(char * buff, int len, void * data)
2017 {
2018         struct mpentry * mpe = (struct mpentry *)data;
2019
2020         if (!mpe->prio_args)
2021                 return 0;
2022
2023         return snprintf(buff, len, "\"%s\"", mpe->prio_args);
2024 }
2025
2026 static int
2027 snprint_mp_reservation_key (char * buff, int len, void * data)
2028 {
2029         int i;
2030         unsigned char *keyp;
2031         uint64_t prkey = 0;
2032         struct mpentry * mpe = (struct mpentry *)data;
2033
2034         if (!mpe->reservation_key)
2035                 return 0;
2036         keyp = (unsigned char *)mpe->reservation_key;
2037         for (i = 0; i < 8; i++) {
2038                 if (i > 0)
2039                         prkey <<= 8;
2040                 prkey |= *keyp;
2041                 keyp++;
2042         }
2043
2044         return snprintf(buff, len, "0x%" PRIx64, prkey);
2045 }
2046
2047         static int
2048 snprint_mp_user_friendly_names (char * buff, int len, void * data)
2049 {
2050         struct mpentry * mpe = (struct mpentry *)data;
2051
2052         if (mpe->user_friendly_names == USER_FRIENDLY_NAMES_UNDEF)
2053                 return 0;
2054         else if (mpe->user_friendly_names == USER_FRIENDLY_NAMES_OFF)
2055                 return snprintf(buff, len, "\"no\"");
2056         else
2057                 return snprintf(buff, len, "\"yes\"");
2058 }
2059
2060 static int
2061 snprint_hw_fast_io_fail(char * buff, int len, void * data)
2062 {
2063         struct hwentry * hwe = (struct hwentry *)data;
2064         if (hwe->fast_io_fail == MP_FAST_IO_FAIL_UNSET)
2065                 return 0;
2066         if (hwe->fast_io_fail == conf->fast_io_fail)
2067                 return 0;
2068         if (hwe->fast_io_fail == MP_FAST_IO_FAIL_OFF)
2069                 return snprintf(buff, len, "\"off\"");
2070         if (hwe->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
2071                 return snprintf(buff, len, "0");
2072         return snprintf(buff, len, "%d", hwe->fast_io_fail);
2073 }
2074
2075 static int
2076 snprint_hw_dev_loss(char * buff, int len, void * data)
2077 {
2078         struct hwentry * hwe = (struct hwentry *)data;
2079         if (!hwe->dev_loss)
2080                 return 0;
2081         if (hwe->dev_loss == conf->dev_loss)
2082                 return 0;
2083         if (hwe->dev_loss >= MAX_DEV_LOSS_TMO)
2084                 return snprintf(buff, len, "\"infinity\"");
2085
2086         return snprintf(buff, len, "%u", hwe->dev_loss);
2087 }
2088
2089 static int
2090 snprint_hw_vendor (char * buff, int len, void * data)
2091 {
2092         struct hwentry * hwe = (struct hwentry *)data;
2093
2094         if (!hwe->vendor)
2095                 return 0;
2096
2097         return snprintf(buff, len, "\"%s\"", hwe->vendor);
2098 }
2099
2100 static int
2101 snprint_hw_product (char * buff, int len, void * data)
2102 {
2103         struct hwentry * hwe = (struct hwentry *)data;
2104
2105         if (!hwe->product)
2106                 return 0;
2107
2108         return snprintf(buff, len, "\"%s\"", hwe->product);
2109 }
2110
2111 static int
2112 snprint_hw_revision (char * buff, int len, void * data)
2113 {
2114         struct hwentry * hwe = (struct hwentry *)data;
2115
2116         if (!hwe->revision)
2117                 return 0;
2118
2119         return snprintf(buff, len, "\"%s\"", hwe->revision);
2120 }
2121
2122 static int
2123 snprint_hw_bl_product (char * buff, int len, void * data)
2124 {
2125         struct hwentry * hwe = (struct hwentry *)data;
2126
2127         if (!hwe->bl_product)
2128                 return 0;
2129
2130         return snprintf(buff, len, "\"%s\"", hwe->bl_product);
2131 }
2132
2133 static int
2134 snprint_hw_uid_attribute (char * buff, int len, void * data)
2135 {
2136         struct hwentry * hwe = (struct hwentry *)data;
2137
2138         if (!hwe->uid_attribute)
2139                 return 0;
2140
2141         return snprintf(buff, len, "\"%s\"", hwe->uid_attribute);
2142 }
2143
2144 static int
2145 snprint_hw_getuid_callout (char * buff, int len, void * data)
2146 {
2147         struct hwentry * hwe = (struct hwentry *)data;
2148
2149         if (!hwe->getuid)
2150                 return 0;
2151
2152         return snprintf(buff, len, "\"%s\"", hwe->getuid);
2153 }
2154
2155 static int
2156 snprint_hw_prio (char * buff, int len, void * data)
2157 {
2158         struct hwentry * hwe = (struct hwentry *)data;
2159
2160         if (!hwe->prio_name)
2161                 return 0;
2162
2163         return snprintf(buff, len, "\"%s\"", hwe->prio_name);
2164 }
2165
2166 static int
2167 snprint_hw_alias_prefix (char * buff, int len, void * data)
2168 {
2169         struct hwentry * hwe = (struct hwentry *)data;
2170
2171         if (!hwe->alias_prefix)
2172                 return 0;
2173
2174         return snprintf(buff, len, "\"%s\"", hwe->alias_prefix);
2175 }
2176
2177 static int
2178 snprint_hw_prio_args (char * buff, int len, void * data)
2179 {
2180         struct hwentry * hwe = (struct hwentry *)data;
2181
2182         if (!hwe->prio_args)
2183                 return 0;
2184
2185         return snprintf(buff, len, "\"%s\"", hwe->prio_args);
2186 }
2187
2188 static int
2189 snprint_hw_features (char * buff, int len, void * data)
2190 {
2191         struct hwentry * hwe = (struct hwentry *)data;
2192
2193         if (!hwe->features)
2194                 return 0;
2195
2196         return snprintf(buff, len, "\"%s\"", hwe->features);
2197 }
2198
2199 static int
2200 snprint_hw_hardware_handler (char * buff, int len, void * data)
2201 {
2202         struct hwentry * hwe = (struct hwentry *)data;
2203
2204         if (!hwe->hwhandler)
2205                 return 0;
2206
2207         return snprintf(buff, len, "\"%s\"", hwe->hwhandler);
2208 }
2209
2210 static int
2211 snprint_hw_selector (char * buff, int len, void * data)
2212 {
2213         struct hwentry * hwe = (struct hwentry *)data;
2214
2215         if (!hwe->selector)
2216                 return 0;
2217
2218         return snprintf(buff, len, "\"%s\"", hwe->selector);
2219 }
2220
2221 static int
2222 snprint_hw_path_grouping_policy (char * buff, int len, void * data)
2223 {
2224         struct hwentry * hwe = (struct hwentry *)data;
2225
2226         char str[POLICY_NAME_SIZE];
2227
2228         if (!hwe->pgpolicy)
2229                 return 0;
2230
2231         get_pgpolicy_name(str, POLICY_NAME_SIZE, hwe->pgpolicy);
2232
2233         return snprintf(buff, len, "\"%s\"", str);
2234 }
2235
2236 static int
2237 snprint_hw_failback (char * buff, int len, void * data)
2238 {
2239         struct hwentry * hwe = (struct hwentry *)data;
2240
2241         if (!hwe->pgfailback)
2242                 return 0;
2243
2244         switch(hwe->pgfailback) {
2245         case  FAILBACK_UNDEF:
2246                 break;
2247         case -FAILBACK_MANUAL:
2248                 return snprintf(buff, len, "\"manual\"");
2249         case -FAILBACK_IMMEDIATE:
2250                 return snprintf(buff, len, "\"immediate\"");
2251         case -FAILBACK_FOLLOWOVER:
2252                 return snprintf(buff, len, "\"followover\"");
2253         default:
2254                 return snprintf(buff, len, "%i", hwe->pgfailback);
2255         }
2256         return 0;
2257 }
2258
2259 static int
2260 snprint_hw_rr_weight (char * buff, int len, void * data)
2261 {
2262         struct hwentry * hwe = (struct hwentry *)data;
2263
2264         if (!hwe->rr_weight)
2265                 return 0;
2266         if (hwe->rr_weight == RR_WEIGHT_PRIO)
2267                 return snprintf(buff, len, "\"priorities\"");
2268         if (hwe->rr_weight == RR_WEIGHT_NONE)
2269                 return snprintf(buff, len, "\"uniform\"");
2270
2271         return 0;
2272 }
2273
2274 static int
2275 snprint_hw_no_path_retry (char * buff, int len, void * data)
2276 {
2277         struct hwentry * hwe = (struct hwentry *)data;
2278
2279         if (!hwe->no_path_retry)
2280                 return 0;
2281
2282         switch(hwe->no_path_retry) {
2283         case NO_PATH_RETRY_UNDEF:
2284                 break;
2285         case NO_PATH_RETRY_FAIL:
2286                 return snprintf(buff, len, "\"fail\"");
2287         case NO_PATH_RETRY_QUEUE:
2288                 return snprintf(buff, len, "\"queue\"");
2289         default:
2290                 return snprintf(buff, len, "%i",
2291                                 hwe->no_path_retry);
2292         }
2293         return 0;
2294 }
2295
2296 static int
2297 snprint_hw_rr_min_io (char * buff, int len, void * data)
2298 {
2299         struct hwentry * hwe = (struct hwentry *)data;
2300
2301         if (!hwe->minio)
2302                 return 0;
2303
2304         return snprintf(buff, len, "%u", hwe->minio);
2305 }
2306
2307 static int
2308 snprint_hw_rr_min_io_rq (char * buff, int len, void * data)
2309 {
2310         struct hwentry * hwe = (struct hwentry *)data;
2311
2312         if (!hwe->minio_rq)
2313                 return 0;
2314
2315         return snprintf(buff, len, "%u", hwe->minio_rq);
2316 }
2317
2318 static int
2319 snprint_hw_pg_timeout (char * buff, int len, void * data)
2320 {
2321         return 0;
2322 }
2323
2324 static int
2325 snprint_hw_flush_on_last_del (char * buff, int len, void * data)
2326 {
2327         struct hwentry * hwe = (struct hwentry *)data;
2328
2329         switch (hwe->flush_on_last_del) {
2330         case FLUSH_DISABLED:
2331                 return snprintf(buff, len, "\"no\"");
2332         case FLUSH_ENABLED:
2333                 return snprintf(buff, len, "\"yes\"");
2334         }
2335         return 0;
2336 }
2337
2338 static int
2339 snprint_hw_path_checker (char * buff, int len, void * data)
2340 {
2341         struct hwentry * hwe = (struct hwentry *)data;
2342
2343         if (!hwe->checker_name)
2344                 return 0;
2345
2346         return snprintf(buff, len, "\"%s\"", hwe->checker_name);
2347 }
2348
2349         static int
2350 snprint_hw_user_friendly_names (char * buff, int len, void * data)
2351 {
2352         struct hwentry * hwe = (struct hwentry *)data;
2353
2354         if (hwe->user_friendly_names == USER_FRIENDLY_NAMES_UNDEF)
2355                 return 0;
2356         else if (hwe->user_friendly_names == USER_FRIENDLY_NAMES_OFF)
2357                 return snprintf(buff, len, "\"no\"");
2358         else
2359                 return snprintf(buff, len, "\"yes\"");
2360 }
2361
2362 static int
2363 snprint_hw_retain_hwhandler_handler(char * buff, int len, void * data)
2364 {
2365         struct hwentry * hwe = (struct hwentry *)data;
2366
2367         if (hwe->retain_hwhandler == RETAIN_HWHANDLER_ON)
2368                 return snprintf(buff, len, "\"yes\"");
2369         else if (hwe->retain_hwhandler == RETAIN_HWHANDLER_OFF)
2370                 return snprintf(buff, len, "\"no\"");
2371         else
2372                 return 0;
2373 }
2374
2375 static int
2376 snprint_detect_prio(char * buff, int len, void * data)
2377 {
2378         struct hwentry * hwe = (struct hwentry *)data;
2379
2380         if (hwe->detect_prio == DETECT_PRIO_ON)
2381                 return snprintf(buff, len, "\"yes\"");
2382         else if (hwe->detect_prio == DETECT_PRIO_OFF)
2383                 return snprintf(buff, len, "\"no\"");
2384         else
2385                 return 0;
2386 }
2387
2388 static int
2389 snprint_def_polling_interval (char * buff, int len, void * data)
2390 {
2391         return snprintf(buff, len, "%i", conf->checkint);
2392 }
2393
2394 static int
2395 snprint_def_fast_io_fail(char * buff, int len, void * data)
2396 {
2397         if (conf->fast_io_fail == MP_FAST_IO_FAIL_UNSET)
2398                 return 0;
2399         if (conf->fast_io_fail == MP_FAST_IO_FAIL_OFF)
2400                 return snprintf(buff, len, "\"off\"");
2401         if (conf->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
2402                 return snprintf(buff, len, "0");
2403         return snprintf(buff, len, "%d", conf->fast_io_fail);
2404 }
2405
2406 static int
2407 snprint_def_dev_loss(char * buff, int len, void * data)
2408 {
2409         if (!conf->dev_loss)
2410                 return 0;
2411         if (conf->dev_loss >= MAX_DEV_LOSS_TMO)
2412                 return snprintf(buff, len, "\"infinity\"");
2413         return snprintf(buff, len, "%u", conf->dev_loss);
2414 }
2415
2416 static int
2417 snprint_def_verbosity (char * buff, int len, void * data)
2418 {
2419         return snprintf(buff, len, "%i", conf->verbosity);
2420 }
2421
2422 static int
2423 snprint_def_max_polling_interval (char * buff, int len, void * data)
2424 {
2425         if (conf->max_checkint == MAX_CHECKINT(conf->checkint))
2426                 return 0;
2427         return snprintf(buff, len, "%i", conf->max_checkint);
2428 }
2429
2430 static int
2431 snprint_reassign_maps (char * buff, int len, void * data)
2432 {
2433         if (conf->reassign_maps == DEFAULT_REASSIGN_MAPS)
2434                 return 0;
2435         return snprintf(buff, len, "\"%s\"",
2436                         conf->reassign_maps?"yes":"no");
2437 }
2438
2439 static int
2440 snprint_def_multipath_dir (char * buff, int len, void * data)
2441 {
2442         if (!conf->multipath_dir)
2443                 return 0;
2444
2445         return snprintf(buff, len, "\"%s\"", conf->multipath_dir);
2446 }
2447
2448 static int
2449 snprint_def_selector (char * buff, int len, void * data)
2450 {
2451         if (!conf->selector)
2452                 return snprintf(buff, len, "\"%s\"", DEFAULT_SELECTOR);
2453
2454         return snprintf(buff, len, "\"%s\"", conf->selector);
2455 }
2456
2457 static int
2458 snprint_def_path_grouping_policy (char * buff, int len, void * data)
2459 {
2460         char str[POLICY_NAME_SIZE];
2461         int pgpolicy = conf->pgpolicy;
2462
2463         if (!pgpolicy)
2464                 pgpolicy = DEFAULT_PGPOLICY;
2465
2466         get_pgpolicy_name(str, POLICY_NAME_SIZE, pgpolicy);
2467
2468         return snprintf(buff, len, "\"%s\"", str);
2469 }
2470
2471 static int
2472 snprint_def_uid_attribute (char * buff, int len, void * data)
2473 {
2474         if (!conf->uid_attribute)
2475                 return snprintf(buff, len, "\"%s\"", DEFAULT_UID_ATTRIBUTE);
2476
2477         return snprintf(buff, len, "\"%s\"", conf->uid_attribute);
2478 }
2479
2480 static int
2481 snprint_def_getuid_callout (char * buff, int len, void * data)
2482 {
2483         if (!conf->getuid)
2484                 return 0;
2485
2486         return snprintf(buff, len, "\"%s\"", conf->getuid);
2487 }
2488
2489 static int
2490 snprint_def_prio (char * buff, int len, void * data)
2491 {
2492         if (!conf->prio_name)
2493                 return snprintf(buff, len, "\"%s\"", DEFAULT_PRIO);
2494
2495         return snprintf(buff, len, "\"%s\"", conf->prio_name);
2496 }
2497
2498 static int
2499 snprint_def_prio_args (char * buff, int len, void * data)
2500 {
2501         if (!conf->prio_args)
2502                 return snprintf(buff, len, "\"%s\"", DEFAULT_PRIO_ARGS);
2503
2504         return snprintf(buff, len, "\"%s\"", conf->prio_args);
2505 }
2506
2507 static int
2508 snprint_def_features (char * buff, int len, void * data)
2509 {
2510         if (!conf->features)
2511                 return snprintf(buff, len, "\"%s\"", DEFAULT_FEATURES);
2512
2513         return snprintf(buff, len, "\"%s\"", conf->features);
2514 }
2515
2516 static int
2517 snprint_def_path_checker (char * buff, int len, void * data)
2518 {
2519         if (!conf->checker_name)
2520                 return snprintf(buff, len, "\"%s\"", DEFAULT_CHECKER);
2521
2522         return snprintf(buff, len, "\"%s\"", conf->checker_name);
2523 }
2524
2525 static int
2526 snprint_def_failback (char * buff, int len, void * data)
2527 {
2528         int pgfailback = conf->pgfailback;
2529         if (!pgfailback)
2530                 pgfailback = DEFAULT_FAILBACK;
2531
2532         switch(conf->pgfailback) {
2533         case  FAILBACK_UNDEF:
2534                 break;
2535         case -FAILBACK_MANUAL:
2536                 return snprintf(buff, len, "\"manual\"");
2537         case -FAILBACK_IMMEDIATE:
2538                 return snprintf(buff, len, "\"immediate\"");
2539         case -FAILBACK_FOLLOWOVER:
2540                 return snprintf(buff, len, "\"followover\"");
2541         default:
2542                 return snprintf(buff, len, "%i", conf->pgfailback);
2543         }
2544         return 0;
2545 }
2546
2547 static int
2548 snprint_def_rr_min_io (char * buff, int len, void * data)
2549 {
2550         if (!conf->minio)
2551                 return 0;
2552
2553         return snprintf(buff, len, "%u", conf->minio);
2554 }
2555
2556 static int
2557 snprint_def_rr_min_io_rq (char * buff, int len, void * data)
2558 {
2559         if (!conf->minio_rq)
2560                 return 0;
2561
2562         return snprintf(buff, len, "%u", conf->minio_rq);
2563 }
2564
2565 static int
2566 snprint_max_fds (char * buff, int len, void * data)
2567 {
2568         if (!conf->max_fds)
2569                 return 0;
2570
2571         return snprintf(buff, len, "%d", conf->max_fds);
2572 }
2573
2574 static int
2575 snprint_def_mode(char * buff, int len, void * data)
2576 {
2577         if ((conf->attribute_flags & (1 << ATTR_MODE)) == 0)
2578                 return 0;
2579         return snprintf(buff, len, "0%o", conf->mode);
2580 }
2581
2582 static int
2583 snprint_def_uid(char * buff, int len, void * data)
2584 {
2585         if ((conf->attribute_flags & (1 << ATTR_UID)) == 0)
2586                 return 0;
2587         return snprintf(buff, len, "0%o", conf->uid);
2588 }
2589
2590 static int
2591 snprint_def_gid(char * buff, int len, void * data)
2592 {
2593         if ((conf->attribute_flags & (1 << ATTR_GID)) == 0)
2594                 return 0;
2595         return snprintf(buff, len, "0%o", conf->gid);
2596 }
2597
2598 static int
2599 snprint_def_rr_weight (char * buff, int len, void * data)
2600 {
2601         if (!conf->rr_weight || conf->rr_weight == RR_WEIGHT_NONE)
2602                 return snprintf(buff, len, "\"uniform\"");
2603         if (conf->rr_weight == RR_WEIGHT_PRIO)
2604                 return snprintf(buff, len, "\"priorities\"");
2605
2606         return 0;
2607 }
2608
2609 static int
2610 snprint_def_no_path_retry (char * buff, int len, void * data)
2611 {
2612         switch(conf->no_path_retry) {
2613         case NO_PATH_RETRY_UNDEF:
2614                 break;
2615         case NO_PATH_RETRY_FAIL:
2616                 return snprintf(buff, len, "\"fail\"");
2617         case NO_PATH_RETRY_QUEUE:
2618                 return snprintf(buff, len, "\"queue\"");
2619         default:
2620                 return snprintf(buff, len, "%i",
2621                                 conf->no_path_retry);
2622         }
2623         return 0;
2624 }
2625
2626 static int
2627 snprint_def_queue_without_daemon (char * buff, int len, void * data)
2628 {
2629         switch (conf->queue_without_daemon) {
2630         case QUE_NO_DAEMON_OFF:
2631                 return snprintf(buff, len, "\"no\"");
2632         case QUE_NO_DAEMON_ON:
2633                 return snprintf(buff, len, "\"yes\"");
2634         case QUE_NO_DAEMON_FORCE:
2635                 return snprintf(buff, len, "\"forced\"");
2636         }
2637         return 0;
2638 }
2639
2640 static int
2641 snprint_def_checker_timeout (char *buff, int len, void *data)
2642 {
2643         if (!conf->checker_timeout)
2644                 return 0;
2645
2646         return snprintf(buff, len, "%u", conf->checker_timeout);
2647 }
2648
2649 static int
2650 snprint_def_pg_timeout (char * buff, int len, void * data)
2651 {
2652         return 0;
2653 }
2654
2655 static int
2656 snprint_def_flush_on_last_del (char * buff, int len, void * data)
2657 {
2658         switch (conf->flush_on_last_del) {
2659         case FLUSH_UNDEF:
2660         case FLUSH_DISABLED:
2661                 return snprintf(buff, len, "\"no\"");
2662         case FLUSH_ENABLED:
2663         case FLUSH_IN_PROGRESS:
2664                 return snprintf(buff, len, "\"yes\"");
2665         }
2666         return 0;
2667 }
2668
2669 static int
2670 snprint_def_log_checker_err (char * buff, int len, void * data)
2671 {
2672         if (conf->log_checker_err == LOG_CHKR_ERR_ONCE)
2673                 return snprintf(buff, len, "once");
2674         return snprintf(buff, len, "always");
2675 }
2676
2677 static int
2678 snprint_def_user_friendly_names (char * buff, int len, void * data)
2679 {
2680         if (conf->user_friendly_names  == USER_FRIENDLY_NAMES_ON)
2681                 return snprintf(buff, len, "\"yes\"");
2682         else
2683                 return snprintf(buff, len, "\"no\"");
2684 }
2685
2686 static int
2687 snprint_def_alias_prefix (char * buff, int len, void * data)
2688 {
2689         if (!conf->alias_prefix)
2690                 return snprintf(buff, len, "\"%s\"", DEFAULT_ALIAS_PREFIX);
2691         return snprintf(buff, len, "\"%s\"", conf->alias_prefix);
2692 }
2693
2694 static int
2695 snprint_def_bindings_file (char * buff, int len, void * data)
2696 {
2697         if (conf->bindings_file == NULL)
2698                 return 0;
2699         return snprintf(buff, len, "\"%s\"", conf->bindings_file);
2700 }
2701
2702 static int
2703 snprint_def_wwids_file (char * buff, int len, void * data)
2704 {
2705         if (conf->wwids_file == NULL)
2706                 return 0;
2707         return snprintf(buff, len, "%s", conf->wwids_file);
2708 }
2709
2710 static int
2711 snprint_def_reservation_key(char * buff, int len, void * data)
2712 {
2713         int i;
2714         unsigned char *keyp;
2715         uint64_t prkey = 0;
2716
2717         if (!conf->reservation_key)
2718                 return 0;
2719         keyp = (unsigned char *)conf->reservation_key;
2720         for (i = 0; i < 8; i++) {
2721                 if (i > 0)
2722                         prkey <<= 8;
2723                 prkey |= *keyp;
2724                 keyp++;
2725         }
2726         return snprintf(buff, len, "0x%" PRIx64, prkey);
2727 }
2728
2729 static int
2730 snprint_def_retain_hwhandler_handler(char * buff, int len, void * data)
2731 {
2732         if (conf->retain_hwhandler == RETAIN_HWHANDLER_ON)
2733                 return snprintf(buff, len, "yes");
2734         else
2735                 return snprintf(buff, len, "no");
2736 }
2737
2738 static int
2739 snprint_def_detect_prio(char * buff, int len, void * data)
2740 {
2741         if (conf->detect_prio == DETECT_PRIO_ON)
2742                 return snprintf(buff, len, "yes");
2743         else
2744                 return snprintf(buff, len, "no");
2745 }
2746
2747 static int
2748 snprint_ble_simple (char * buff, int len, void * data)
2749 {
2750         struct blentry * ble = (struct blentry *)data;
2751
2752         return snprintf(buff, len, "\"%s\"", ble->str);
2753 }
2754
2755 static int
2756 snprint_bled_vendor (char * buff, int len, void * data)
2757 {
2758         struct blentry_device * bled = (struct blentry_device *)data;
2759
2760         return snprintf(buff, len, "\"%s\"", bled->vendor);
2761 }
2762
2763 static int
2764 snprint_bled_product (char * buff, int len, void * data)
2765 {
2766         struct blentry_device * bled = (struct blentry_device *)data;
2767
2768         return snprintf(buff, len, "\"%s\"", bled->product);
2769 }
2770
2771 #define __deprecated
2772
2773 void
2774 init_keywords(void)
2775 {
2776         install_keyword_root("defaults", NULL);
2777         install_keyword("verbosity", &verbosity_handler, &snprint_def_verbosity);
2778         install_keyword("polling_interval", &polling_interval_handler, &snprint_def_polling_interval);
2779         install_keyword("max_polling_interval", &max_polling_interval_handler, &snprint_def_max_polling_interval);
2780         install_keyword("reassign_maps", &reassign_maps_handler, &snprint_reassign_maps);
2781         install_keyword("multipath_dir", &multipath_dir_handler, &snprint_def_multipath_dir);
2782         install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
2783         install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_path_grouping_policy);
2784         install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute);
2785         install_keyword("getuid_callout", &def_getuid_callout_handler, &snprint_def_getuid_callout);
2786         install_keyword("prio", &def_prio_handler, &snprint_def_prio);
2787         install_keyword("prio_args", &def_prio_args_handler, &snprint_def_prio_args);
2788         install_keyword("features", &def_features_handler, &snprint_def_features);
2789         install_keyword("path_checker", &def_path_checker_handler, &snprint_def_path_checker);
2790         install_keyword("checker", &def_path_checker_handler, NULL);
2791         install_keyword("alias_prefix", &def_alias_prefix_handler, &snprint_def_alias_prefix);
2792         install_keyword("failback", &default_failback_handler, &snprint_def_failback);
2793         install_keyword("rr_min_io", &def_minio_handler, &snprint_def_rr_min_io);
2794         install_keyword("rr_min_io_rq", &def_minio_rq_handler, &snprint_def_rr_min_io_rq);
2795         install_keyword("max_fds", &max_fds_handler, &snprint_max_fds);
2796         install_keyword("rr_weight", &def_weight_handler, &snprint_def_rr_weight);
2797         install_keyword("no_path_retry", &def_no_path_retry_handler, &snprint_def_no_path_retry);
2798         install_keyword("queue_without_daemon", &def_queue_without_daemon, &snprint_def_queue_without_daemon);
2799         install_keyword("checker_timeout", &def_checker_timeout_handler, &snprint_def_checker_timeout);
2800         install_keyword("pg_timeout", &def_pg_timeout_handler, &snprint_def_pg_timeout);
2801         install_keyword("flush_on_last_del", &def_flush_on_last_del_handler, &snprint_def_flush_on_last_del);
2802         install_keyword("user_friendly_names", &def_names_handler, &snprint_def_user_friendly_names);
2803         install_keyword("mode", &def_mode_handler, &snprint_def_mode);
2804         install_keyword("uid", &def_uid_handler, &snprint_def_uid);
2805         install_keyword("gid", &def_gid_handler, &snprint_def_gid);
2806         install_keyword("fast_io_fail_tmo", &def_fast_io_fail_handler, &snprint_def_fast_io_fail);
2807         install_keyword("dev_loss_tmo", &def_dev_loss_handler, &snprint_def_dev_loss);
2808         install_keyword("bindings_file", &bindings_file_handler, &snprint_def_bindings_file);
2809         install_keyword("wwids_file", &wwids_file_handler, &snprint_def_wwids_file);
2810         install_keyword("log_checker_err", &def_log_checker_err_handler, &snprint_def_log_checker_err);
2811         install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key);
2812         install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler_handler);
2813         install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio);
2814         __deprecated install_keyword("default_selector", &def_selector_handler, NULL);
2815         __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
2816         __deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
2817         __deprecated install_keyword("default_getuid_callout", &def_getuid_callout_handler, NULL);
2818         __deprecated install_keyword("default_features", &def_features_handler, NULL);
2819         __deprecated install_keyword("default_path_checker", &def_path_checker_handler, NULL);
2820
2821         install_keyword_root("blacklist", &blacklist_handler);
2822         install_keyword_multi("devnode", &ble_devnode_handler, &snprint_ble_simple);
2823         install_keyword_multi("wwid", &ble_wwid_handler, &snprint_ble_simple);
2824         install_keyword_multi("device", &ble_device_handler, NULL);
2825         install_sublevel();
2826         install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
2827         install_keyword("product", &ble_product_handler, &snprint_bled_product);
2828         install_sublevel_end();
2829         install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
2830         install_keyword_multi("devnode", &ble_except_devnode_handler, &snprint_ble_simple);
2831         install_keyword_multi("wwid", &ble_except_wwid_handler, &snprint_ble_simple);
2832         install_keyword_multi("device", &ble_except_device_handler, NULL);
2833         install_sublevel();
2834         install_keyword("vendor", &ble_except_vendor_handler, &snprint_bled_vendor);
2835         install_keyword("product", &ble_except_product_handler, &snprint_bled_product);
2836         install_sublevel_end();
2837
2838 #if 0
2839         __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler);
2840         __deprecated install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
2841         __deprecated install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
2842         __deprecated install_keyword("device", &ble_device_handler, NULL);
2843         __deprecated install_sublevel();
2844         __deprecated install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
2845         __deprecated install_keyword("product", &ble_product_handler, &snprint_bled_product);
2846         __deprecated install_sublevel_end();
2847 #endif
2848
2849         install_keyword_root("devices", &devices_handler);
2850         install_keyword_multi("device", &device_handler, NULL);
2851         install_sublevel();
2852         install_keyword("vendor", &vendor_handler, &snprint_hw_vendor);
2853         install_keyword("product", &product_handler, &snprint_hw_product);
2854         install_keyword("revision", &revision_handler, &snprint_hw_revision);
2855         install_keyword("product_blacklist", &bl_product_handler, &snprint_hw_bl_product);
2856         install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_path_grouping_policy);
2857         install_keyword("uid_attribute", &hw_uid_attribute_handler, &snprint_hw_uid_attribute);
2858         install_keyword("getuid_callout", &hw_getuid_callout_handler, &snprint_hw_getuid_callout);
2859         install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
2860         install_keyword("path_checker", &hw_path_checker_handler, &snprint_hw_path_checker);
2861         install_keyword("checker", &hw_path_checker_handler, NULL);
2862         install_keyword("alias_prefix", &hw_alias_prefix_handler, &snprint_hw_alias_prefix);
2863         install_keyword("features", &hw_features_handler, &snprint_hw_features);
2864         install_keyword("hardware_handler", &hw_handler_handler, &snprint_hw_hardware_handler);
2865         install_keyword("prio", &hw_prio_handler, &snprint_hw_prio);
2866         install_keyword("prio_args", &hw_prio_args_handler, &snprint_hw_prio_args);
2867         install_keyword("failback", &hw_failback_handler, &snprint_hw_failback);
2868         install_keyword("rr_weight", &hw_weight_handler, &snprint_hw_rr_weight);
2869         install_keyword("no_path_retry", &hw_no_path_retry_handler, &snprint_hw_no_path_retry);
2870         install_keyword("rr_min_io", &hw_minio_handler, &snprint_hw_rr_min_io);
2871         install_keyword("rr_min_io_rq", &hw_minio_rq_handler, &snprint_hw_rr_min_io_rq);
2872         install_keyword("pg_timeout", &hw_pg_timeout_handler, &snprint_hw_pg_timeout);
2873         install_keyword("flush_on_last_del", &hw_flush_on_last_del_handler, &snprint_hw_flush_on_last_del);
2874         install_keyword("fast_io_fail_tmo", &hw_fast_io_fail_handler, &snprint_hw_fast_io_fail);
2875         install_keyword("dev_loss_tmo", &hw_dev_loss_handler, &snprint_hw_dev_loss);
2876         install_keyword("user_friendly_names", &hw_names_handler, &snprint_hw_user_friendly_names);
2877         install_keyword("retain_attached_hw_handler", &hw_retain_hwhandler_handler, &snprint_hw_retain_hwhandler_handler);
2878         install_keyword("detect_prio", &hw_detect_prio_handler, &snprint_detect_prio);
2879         install_sublevel_end();
2880
2881         install_keyword_root("multipaths", &multipaths_handler);
2882         install_keyword_multi("multipath", &multipath_handler, NULL);
2883         install_sublevel();
2884         install_keyword("wwid", &wwid_handler, &snprint_mp_wwid);
2885         install_keyword("alias", &alias_handler, &snprint_mp_alias);
2886         install_keyword("path_grouping_policy", &mp_pgpolicy_handler, &snprint_mp_path_grouping_policy);
2887         install_keyword("path_selector", &mp_selector_handler, &snprint_mp_selector);
2888         install_keyword("prio", &mp_prio_handler, &snprint_mp_prio);
2889         install_keyword("prio_args", &mp_prio_args_handler, &snprint_mp_prio_args);
2890         install_keyword("failback", &mp_failback_handler, &snprint_mp_failback);
2891         install_keyword("rr_weight", &mp_weight_handler, &snprint_mp_rr_weight);
2892         install_keyword("no_path_retry", &mp_no_path_retry_handler, &snprint_mp_no_path_retry);
2893         install_keyword("rr_min_io", &mp_minio_handler, &snprint_mp_rr_min_io);
2894         install_keyword("rr_min_io_rq", &mp_minio_rq_handler, &snprint_mp_rr_min_io_rq);
2895         install_keyword("pg_timeout", &mp_pg_timeout_handler, &snprint_mp_pg_timeout);
2896         install_keyword("flush_on_last_del", &mp_flush_on_last_del_handler, &snprint_mp_flush_on_last_del);
2897         install_keyword("features", &mp_features_handler, &snprint_mp_features);
2898         install_keyword("mode", &mp_mode_handler, &snprint_mp_mode);
2899         install_keyword("uid", &mp_uid_handler, &snprint_mp_uid);
2900         install_keyword("gid", &mp_gid_handler, &snprint_mp_gid);
2901         install_keyword("reservation_key", &mp_reservation_key_handler, &snprint_mp_reservation_key);
2902         install_keyword("user_friendly_names", &mp_names_handler, &snprint_mp_user_friendly_names);
2903         install_sublevel_end();
2904 }