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