multipath: standardize on path_selector
[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
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
24 /*
25  * default block handlers
26  */
27 static int
28 polling_interval_handler(vector strvec)
29 {
30         char * buff;
31
32         buff = VECTOR_SLOT(strvec, 1);
33         conf->checkint = atoi(buff);
34         conf->max_checkint = MAX_CHECKINT(conf->checkint);
35
36         return 0;
37 }
38
39 static int
40 def_fast_io_fail_handler(vector strvec)
41 {
42         char * buff;
43
44         buff = set_value(strvec);
45         if (strlen(buff) == 3 && !strcmp(buff, "off"))
46                 conf->fast_io_fail = -1;
47         else if (sscanf(buff, "%d", &conf->fast_io_fail) != 1 ||
48                  conf->fast_io_fail < -1)
49                 conf->fast_io_fail = 0;
50
51         FREE(buff);
52         return 0;
53 }
54
55 static int
56 def_dev_loss_handler(vector strvec)
57 {
58         char * buff;
59
60         buff = set_value(strvec);
61         if (sscanf(buff, "%u", &conf->dev_loss) != 1)
62                 conf->dev_loss = 0;
63
64         FREE(buff);
65         return 0;
66 }
67
68 static int
69 verbosity_handler(vector strvec)
70 {
71         char * buff;
72
73         buff = VECTOR_SLOT(strvec, 1);
74         conf->verbosity = atoi(buff);
75
76         return 0;
77 }
78
79 static int
80 udev_dir_handler(vector strvec)
81 {
82         conf->udev_dir = set_value(strvec);
83
84         if (!conf->udev_dir)
85                 return 1;
86
87         return 0;
88 }
89
90 static int
91 multipath_dir_handler(vector strvec)
92 {
93         conf->multipath_dir = set_value(strvec);
94
95         if (!conf->multipath_dir)
96                 return 1;
97
98         return 0;
99 }
100
101 static int
102 def_selector_handler(vector strvec)
103 {
104         conf->selector = set_value(strvec);
105
106         if (!conf->selector)
107                 return 1;
108
109         return 0;
110 }
111
112 static int
113 def_pgpolicy_handler(vector strvec)
114 {
115         char * buff;
116
117         buff = set_value(strvec);
118
119         if (!buff)
120                 return 1;
121
122         conf->pgpolicy = get_pgpolicy_id(buff);
123         FREE(buff);
124
125         return 0;
126 }
127
128 static int
129 def_getuid_callout_handler(vector strvec)
130 {
131         conf->getuid = set_value(strvec);
132
133         if (!conf->getuid)
134                 return 1;
135
136         return 0;
137 }
138
139 static int
140 def_prio_handler(vector strvec)
141 {
142         conf->prio_name = set_value(strvec);
143
144         if (!conf->prio_name)
145                 return 1;
146
147         return 0;
148 }
149
150 static int
151 def_alias_prefix_handler(vector strvec)
152 {
153         conf->alias_prefix = set_value(strvec);
154
155         if (!conf->alias_prefix)
156                 return 1;
157
158         return 0;
159 }
160
161 static int
162 def_prio_args_handler(vector strvec)
163 {
164         conf->prio_args = set_value(strvec);
165
166         if (!conf->prio_args)
167                 return 1;
168
169         return 0;
170 }
171
172 static int
173 def_features_handler(vector strvec)
174 {
175         conf->features = set_value(strvec);
176
177         if (!conf->features)
178                 return 1;
179
180         return 0;
181 }
182
183 static int
184 def_path_checker_handler(vector strvec)
185 {
186         conf->checker_name = set_value(strvec);
187
188         if (!conf->checker_name)
189                 return 1;
190
191         return 0;
192 }
193
194 static int
195 def_minio_handler(vector strvec)
196 {
197         char * buff;
198
199         buff = set_value(strvec);
200
201         if (!buff)
202                 return 1;
203
204         conf->minio = atoi(buff);
205         FREE(buff);
206
207         return 0;
208 }
209
210 static int
211 get_sys_max_fds(int *max_fds)
212 {
213         FILE *file;
214         int nr_open;
215         int ret = 1;
216
217         file = fopen("/proc/sys/fs/nr_open", "r");
218         if (!file) {
219                 fprintf(stderr, "Cannot open /proc/sys/fs/nr_open : %s\n",
220                         strerror(errno));
221                 return 1;
222         }
223         if (fscanf(file, "%d", &nr_open) != 1) {
224                 fprintf(stderr, "Cannot read max open fds from /proc/sys/fs/nr_open");
225                 if (ferror(file))
226                         fprintf(stderr, " : %s\n", strerror(errno));
227                 else
228                         fprintf(stderr, "\n");
229         } else {
230                 *max_fds = nr_open;
231                 ret = 0;
232         }
233         fclose(file);
234         return ret;
235 }
236
237
238 static int
239 max_fds_handler(vector strvec)
240 {
241         char * buff;
242         int r = 0;
243
244         buff = set_value(strvec);
245
246         if (!buff)
247                 return 1;
248
249         if (strlen(buff) == 3 &&
250             !strcmp(buff, "max"))
251                 r = get_sys_max_fds(&conf->max_fds);
252         else
253                 conf->max_fds = atoi(buff);
254         FREE(buff);
255
256         return r;
257 }
258
259 static int
260 def_mode_handler(vector strvec)
261 {
262         mode_t mode;
263         char *buff;
264
265         buff = set_value(strvec);
266
267         if (!buff)
268                 return 1;
269
270         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
271                 conf->attribute_flags |= (1 << ATTR_MODE);
272                 conf->mode = mode;
273         }
274
275         FREE(buff);
276         return 0;
277 }
278
279 static int
280 def_uid_handler(vector strvec)
281 {
282         uid_t uid;
283         char *buff;
284         char passwd_buf[1024];
285         struct passwd info, *found;
286
287         buff = set_value(strvec);
288         if (!buff)
289                 return 1;
290         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
291                 conf->attribute_flags |= (1 << ATTR_UID);
292                 conf->uid = info.pw_uid;
293         }
294         else if (sscanf(buff, "%u", &uid) == 1){
295                 conf->attribute_flags |= (1 << ATTR_UID);
296                 conf->uid = uid;
297         }
298
299         FREE(buff);
300         return 0;
301 }
302
303 static int
304 def_gid_handler(vector strvec)
305 {
306         gid_t gid;
307         char *buff;
308         char passwd_buf[1024];
309         struct passwd info, *found;
310
311         buff = set_value(strvec);
312         if (!buff)
313                 return 1;
314
315         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
316                 conf->attribute_flags |= (1 << ATTR_GID);
317                 conf->gid = info.pw_gid;
318         }
319         else if (sscanf(buff, "%u", &gid) == 1){
320                 conf->attribute_flags |= (1 << ATTR_GID);
321                 conf->gid = gid;
322         }
323         FREE(buff);
324         return 0;
325 }
326
327 static int
328 def_weight_handler(vector strvec)
329 {
330         char * buff;
331
332         buff = set_value(strvec);
333
334         if (!buff)
335                 return 1;
336
337         if (strlen(buff) == 10 &&
338             !strcmp(buff, "priorities"))
339                 conf->rr_weight = RR_WEIGHT_PRIO;
340
341         FREE(buff);
342
343         return 0;
344 }
345
346 static int
347 default_failback_handler(vector strvec)
348 {
349         char * buff;
350
351         buff = set_value(strvec);
352
353         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
354                 conf->pgfailback = -FAILBACK_MANUAL;
355         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
356                 conf->pgfailback = -FAILBACK_IMMEDIATE;
357         else
358                 conf->pgfailback = atoi(buff);
359
360         FREE(buff);
361
362         return 0;
363 }
364
365 static int
366 def_no_path_retry_handler(vector strvec)
367 {
368         char * buff;
369
370         buff = set_value(strvec);
371         if (!buff)
372                 return 1;
373
374         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
375             (strlen(buff) == 1 && !strcmp(buff, "0")))
376                 conf->no_path_retry = NO_PATH_RETRY_FAIL;
377         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
378                 conf->no_path_retry = NO_PATH_RETRY_QUEUE;
379         else if ((conf->no_path_retry = atoi(buff)) < 1)
380                 conf->no_path_retry = NO_PATH_RETRY_UNDEF;
381
382         FREE(buff);
383         return 0;
384 }
385
386 static int
387 def_queue_without_daemon(vector strvec)
388 {
389         char * buff;
390
391         buff = set_value(strvec);
392         if (!buff)
393                 return 1;
394
395         if (!strncmp(buff, "off", 3) || !strncmp(buff, "no", 2) ||
396             !strncmp(buff, "0", 1))
397                 conf->queue_without_daemon = QUE_NO_DAEMON_OFF;
398         else if (!strncmp(buff, "on", 2) || !strncmp(buff, "yes", 3) ||
399                  !strncmp(buff, "1", 1))
400                 conf->queue_without_daemon = QUE_NO_DAEMON_ON;
401         else
402                 conf->queue_without_daemon = QUE_NO_DAEMON_UNDEF;
403
404         free(buff);
405         return 0;
406 }
407
408 static int
409 def_checker_timeout_handler(vector strvec)
410 {
411         unsigned int checker_timeout;
412         char *buff;
413
414         buff = set_value(strvec);
415         if (!buff)
416                 return 1;
417
418         if (sscanf(buff, "%u", &checker_timeout) == 1)
419                 conf->checker_timeout = checker_timeout;
420         else
421                 conf->checker_timeout = 0;
422
423         free(buff);
424         return 0;
425 }
426
427 static int
428 def_pg_timeout_handler(vector strvec)
429 {
430         int pg_timeout;
431         char * buff;
432
433         buff = set_value(strvec);
434
435         if (!buff)
436                 return 1;
437
438         if (strlen(buff) == 4 && !strcmp(buff, "none"))
439                 conf->pg_timeout = -PGTIMEOUT_NONE;
440         else if (sscanf(buff, "%d", &pg_timeout) == 1 && pg_timeout >= 0) {
441                 if (pg_timeout == 0)
442                         conf->pg_timeout = -PGTIMEOUT_NONE;
443                 else
444                         conf->pg_timeout = pg_timeout;
445         }
446         else
447                 conf->pg_timeout = PGTIMEOUT_UNDEF;
448
449         FREE(buff);
450         return 0;
451 }
452
453 static int
454 def_flush_on_last_del_handler(vector strvec)
455 {
456         char * buff;
457
458         buff = set_value(strvec);
459         if (!buff)
460                 return 1;
461
462         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
463             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
464                 conf->flush_on_last_del = FLUSH_DISABLED;
465         if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
466             (strlen(buff) == 1 && strcmp(buff, "1") == 0))
467                 conf->flush_on_last_del = FLUSH_ENABLED;
468         else
469                 conf->flush_on_last_del = FLUSH_UNDEF;
470
471         FREE(buff);
472         return 0;
473 }
474
475 static int
476 names_handler(vector strvec)
477 {
478         char * buff;
479
480         buff = set_value(strvec);
481
482         if (!buff)
483                 return 1;
484
485         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
486             (strlen(buff) == 1 && !strcmp(buff, "0")))
487                 conf->user_friendly_names = 0;
488         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
489                  (strlen(buff) == 1 && !strcmp(buff, "1")))
490                 conf->user_friendly_names = 1;
491
492         FREE(buff);
493         return 0;
494 }
495
496 /*
497  * blacklist block handlers
498  */
499 static int
500 blacklist_handler(vector strvec)
501 {
502         conf->blist_devnode = vector_alloc();
503         conf->blist_wwid = vector_alloc();
504         conf->blist_device = vector_alloc();
505
506         if (!conf->blist_devnode || !conf->blist_wwid || !conf->blist_device)
507                 return 1;
508
509         return 0;
510 }
511
512 static int
513 blacklist_exceptions_handler(vector strvec)
514 {
515         conf->elist_devnode = vector_alloc();
516         conf->elist_wwid = vector_alloc();
517         conf->elist_device = vector_alloc();
518
519         if (!conf->elist_devnode || !conf->elist_wwid || !conf->elist_device)
520                 return 1;
521
522         return 0;
523 }
524
525 static int
526 ble_devnode_handler(vector strvec)
527 {
528         char * buff;
529
530         buff = set_value(strvec);
531
532         if (!buff)
533                 return 1;
534
535         return store_ble(conf->blist_devnode, buff, ORIGIN_CONFIG);
536 }
537
538 static int
539 ble_except_devnode_handler(vector strvec)
540 {
541         char * buff;
542
543         buff = set_value(strvec);
544
545         if (!buff)
546                 return 1;
547
548         return store_ble(conf->elist_devnode, buff, ORIGIN_CONFIG);
549 }
550
551 static int
552 ble_wwid_handler(vector strvec)
553 {
554         char * buff;
555
556         buff = set_value(strvec);
557
558         if (!buff)
559                 return 1;
560
561         return store_ble(conf->blist_wwid, buff, ORIGIN_CONFIG);
562 }
563
564 static int
565 ble_except_wwid_handler(vector strvec)
566 {
567         char * buff;
568
569         buff = set_value(strvec);
570
571         if (!buff)
572                 return 1;
573
574         return store_ble(conf->elist_wwid, buff, ORIGIN_CONFIG);
575 }
576
577 static int
578 ble_device_handler(vector strvec)
579 {
580         return alloc_ble_device(conf->blist_device);
581 }
582
583 static int
584 ble_except_device_handler(vector strvec)
585 {
586         return alloc_ble_device(conf->elist_device);
587 }
588
589 static int
590 ble_vendor_handler(vector strvec)
591 {
592         char * buff;
593
594         buff = set_value(strvec);
595
596         if (!buff)
597                 return 1;
598
599         return set_ble_device(conf->blist_device, buff, NULL, ORIGIN_CONFIG);
600 }
601
602 static int
603 ble_except_vendor_handler(vector strvec)
604 {
605         char * buff;
606
607         buff = set_value(strvec);
608
609         if (!buff)
610                 return 1;
611
612         return set_ble_device(conf->elist_device, buff, NULL, ORIGIN_CONFIG);
613 }
614
615 static int
616 ble_product_handler(vector strvec)
617 {
618         char * buff;
619
620         buff = set_value(strvec);
621
622         if (!buff)
623                 return 1;
624
625         return set_ble_device(conf->blist_device, NULL, buff, ORIGIN_CONFIG);
626 }
627
628 static int
629 ble_except_product_handler(vector strvec)
630 {
631         char * buff;
632
633         buff = set_value(strvec);
634
635         if (!buff)
636                 return 1;
637
638         return set_ble_device(conf->elist_device, NULL, buff, ORIGIN_CONFIG);
639 }
640
641 /*
642  * devices block handlers
643  */
644 static int
645 devices_handler(vector strvec)
646 {
647         if (!conf->hwtable)
648                 conf->hwtable = vector_alloc();
649
650         if (!conf->hwtable)
651                 return 1;
652
653         return 0;
654 }
655
656 static int
657 device_handler(vector strvec)
658 {
659         struct hwentry * hwe;
660
661         hwe = alloc_hwe();
662
663         if (!hwe)
664                 return 1;
665
666         if (!vector_alloc_slot(conf->hwtable)) {
667                 free_hwe(hwe);
668                 return 1;
669         }
670         vector_set_slot(conf->hwtable, hwe);
671
672         return 0;
673 }
674
675 static int
676 vendor_handler(vector strvec)
677 {
678         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
679
680         if (!hwe)
681                 return 1;
682
683         hwe->vendor = set_value(strvec);
684
685         if (!hwe->vendor)
686                 return 1;
687
688         return 0;
689 }
690
691 static int
692 product_handler(vector strvec)
693 {
694         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
695
696         if (!hwe)
697                 return 1;
698
699         hwe->product = set_value(strvec);
700
701         if (!hwe->product)
702                 return 1;
703
704         return 0;
705 }
706
707 static int
708 bl_product_handler(vector strvec)
709 {
710         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
711
712         if (!hwe)
713                 return 1;
714
715         hwe->bl_product = set_value(strvec);
716         if (!hwe->bl_product)
717                 return 1;
718
719         return 0;
720 }
721
722 static int
723 hw_fast_io_fail_handler(vector strvec)
724 {
725         char * buff;
726         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
727
728         buff = set_value(strvec);
729         if (strlen(buff) == 3 && !strcmp(buff, "off"))
730                 hwe->fast_io_fail = -1;
731         else if (sscanf(buff, "%d", &hwe->fast_io_fail) != 1 ||
732                  hwe->fast_io_fail < -1)
733                 hwe->fast_io_fail = 0;
734
735         FREE(buff);
736         return 0;
737 }
738
739 static int
740 hw_dev_loss_handler(vector strvec)
741 {
742         char * buff;
743         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
744
745         buff = set_value(strvec);
746         if (sscanf(buff, "%u", &hwe->dev_loss) != 1)
747                 hwe->dev_loss = 0;
748
749         FREE(buff);
750         return 0;
751 }
752
753 static int
754 hw_pgpolicy_handler(vector strvec)
755 {
756         char * buff;
757         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
758
759         buff = set_value(strvec);
760
761         if (!buff)
762                 return 1;
763
764         hwe->pgpolicy = get_pgpolicy_id(buff);
765         FREE(buff);
766
767         return 0;
768 }
769
770 static int
771 hw_getuid_callout_handler(vector strvec)
772 {
773         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
774
775         hwe->getuid = set_value(strvec);
776
777         if (!hwe->getuid)
778                 return 1;
779
780         return 0;
781 }
782
783 static int
784 hw_selector_handler(vector strvec)
785 {
786         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
787
788         if (!hwe)
789                 return 1;
790
791         hwe->selector = set_value(strvec);
792
793         if (!hwe->selector)
794                 return 1;
795
796         return 0;
797 }
798
799 static int
800 hw_path_checker_handler(vector strvec)
801 {
802         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
803
804         if (!hwe)
805                 return 1;
806
807         hwe->checker_name = set_value(strvec);
808
809         if (!hwe->checker_name)
810                 return 1;
811
812         return 0;
813 }
814
815 static int
816 hw_features_handler(vector strvec)
817 {
818         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
819
820         if (!hwe)
821                 return 1;
822
823         hwe->features = set_value(strvec);
824
825         if (!hwe->features)
826                 return 1;
827
828         return 0;
829 }
830
831 static int
832 hw_handler_handler(vector strvec)
833 {
834         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
835
836         if (!hwe)
837                 return 1;
838
839         hwe->hwhandler = set_value(strvec);
840
841         if (!hwe->hwhandler)
842                 return 1;
843
844         return 0;
845 }
846
847 static int
848 hw_prio_handler(vector strvec)
849 {
850         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
851
852         if (!hwe)
853                 return 1;
854
855         hwe->prio_name = set_value(strvec);
856
857         if (!hwe->prio_name)
858                 return 1;
859
860         return 0;
861 }
862
863 static int
864 hw_alias_prefix_handler(vector strvec)
865 {
866         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
867
868         if (!hwe)
869                 return 1;
870
871         hwe->alias_prefix = set_value(strvec);
872
873         if (!hwe->alias_prefix)
874                 return 1;
875
876         return 0;
877 }
878
879 static int
880 hw_prio_args_handler(vector strvec)
881 {
882         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
883
884         if (!hwe)
885                 return 1;
886
887         hwe->prio_args = set_value(strvec);
888
889         if (!hwe->prio_args)
890                 return 1;
891
892         return 0;
893 }
894
895 static int
896 hw_failback_handler(vector strvec)
897 {
898         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
899         char * buff;
900
901         if (!hwe)
902                 return 1;
903
904         buff = set_value(strvec);
905
906         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
907                 hwe->pgfailback = -FAILBACK_MANUAL;
908         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
909                 hwe->pgfailback = -FAILBACK_IMMEDIATE;
910         else
911                 hwe->pgfailback = atoi(buff);
912
913         FREE(buff);
914
915         return 0;
916 }
917
918 static int
919 hw_weight_handler(vector strvec)
920 {
921         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
922         char * buff;
923
924         if (!hwe)
925                 return 1;
926
927         buff = set_value(strvec);
928
929         if (!buff)
930                 return 1;
931
932         if (strlen(buff) == 10 &&
933             !strcmp(buff, "priorities"))
934                 hwe->rr_weight = RR_WEIGHT_PRIO;
935
936         FREE(buff);
937
938         return 0;
939 }
940
941 static int
942 hw_no_path_retry_handler(vector strvec)
943 {
944         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
945         char *buff;
946
947         if (!hwe)
948                 return 1;
949
950         buff = set_value(strvec);
951         if (!buff)
952                 return 1;
953
954         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
955             (strlen(buff) == 1 && !strcmp(buff, "0")))
956                 hwe->no_path_retry = NO_PATH_RETRY_FAIL;
957         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
958                 hwe->no_path_retry = NO_PATH_RETRY_QUEUE;
959         else if ((hwe->no_path_retry = atoi(buff)) < 1)
960                 hwe->no_path_retry = NO_PATH_RETRY_UNDEF;
961
962         FREE(buff);
963         return 0;
964 }
965
966 static int
967 hw_minio_handler(vector strvec)
968 {
969         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
970         char * buff;
971
972         if (!hwe)
973                 return 1;
974
975         buff = set_value(strvec);
976
977         if (!buff)
978                 return 1;
979
980         hwe->minio = atoi(buff);
981         FREE(buff);
982
983         return 0;
984 }
985
986 static int
987 hw_pg_timeout_handler(vector strvec)
988 {
989         int pg_timeout;
990         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
991         char *buff;
992
993         if (!hwe)
994                 return 1;
995
996         buff = set_value(strvec);
997
998         if (!buff)
999                 return 1;
1000
1001         if (strlen(buff) == 4 && !strcmp(buff, "none"))
1002                 hwe->pg_timeout = -PGTIMEOUT_NONE;
1003         else if (sscanf(buff, "%d", &pg_timeout) == 1 && pg_timeout >= 0) {
1004                 if (pg_timeout == 0)
1005                         hwe->pg_timeout = -PGTIMEOUT_NONE;
1006                 else
1007                         hwe->pg_timeout = pg_timeout;
1008         }
1009         else
1010                 hwe->pg_timeout = PGTIMEOUT_UNDEF;
1011
1012         FREE(buff);
1013         return 0;
1014 }
1015
1016 static int
1017 hw_flush_on_last_del_handler(vector strvec)
1018 {
1019         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
1020         char * buff;
1021
1022         if (!hwe)
1023                 return 1;
1024
1025         buff = set_value(strvec);
1026         if (!buff)
1027                 return 1;
1028
1029         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
1030             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
1031                 hwe->flush_on_last_del = FLUSH_DISABLED;
1032         if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
1033             (strlen(buff) == 1 && strcmp(buff, "1") == 0))
1034                 hwe->flush_on_last_del = FLUSH_ENABLED;
1035         else
1036                 hwe->flush_on_last_del = FLUSH_UNDEF;
1037
1038         FREE(buff);
1039         return 0;
1040 }
1041
1042 /*
1043  * multipaths block handlers
1044  */
1045 static int
1046 multipaths_handler(vector strvec)
1047 {
1048         conf->mptable = vector_alloc();
1049
1050         if (!conf->mptable)
1051                 return 1;
1052
1053         return 0;
1054 }
1055
1056 static int
1057 multipath_handler(vector strvec)
1058 {
1059         struct mpentry * mpe;
1060
1061         mpe = alloc_mpe();
1062
1063         if (!mpe)
1064                 return 1;
1065
1066         if (!vector_alloc_slot(conf->mptable)) {
1067                 free_mpe(mpe);
1068                 return 1;
1069         }
1070         vector_set_slot(conf->mptable, mpe);
1071
1072         return 0;
1073 }
1074
1075 static int
1076 wwid_handler(vector strvec)
1077 {
1078         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1079
1080         if (!mpe)
1081                 return 1;
1082
1083         mpe->wwid = set_value(strvec);
1084
1085         if (!mpe->wwid)
1086                 return 1;
1087
1088         return 0;
1089 }
1090
1091 static int
1092 alias_handler(vector strvec)
1093 {
1094         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1095
1096         if (!mpe)
1097                 return 1;
1098
1099         mpe->alias = set_value(strvec);
1100
1101         if (!mpe->alias)
1102                 return 1;
1103
1104         return 0;
1105 }
1106
1107 static int
1108 mp_pgpolicy_handler(vector strvec)
1109 {
1110         char * buff;
1111         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1112
1113         if (!mpe)
1114                 return 1;
1115
1116         buff = set_value(strvec);
1117
1118         if (!buff)
1119                 return 1;
1120
1121         mpe->pgpolicy = get_pgpolicy_id(buff);
1122         FREE(buff);
1123
1124         return 0;
1125 }
1126
1127 static int
1128 mp_selector_handler(vector strvec)
1129 {
1130         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1131
1132         if (!mpe)
1133                 return 1;
1134
1135         mpe->selector = set_value(strvec);
1136
1137         if (!mpe->selector)
1138                 return 1;
1139
1140         return 0;
1141 }
1142
1143 static int
1144 mp_failback_handler(vector strvec)
1145 {
1146         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1147         char * buff;
1148
1149         if (!mpe)
1150                 return 1;
1151
1152         buff = set_value(strvec);
1153
1154         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
1155                 mpe->pgfailback = -FAILBACK_MANUAL;
1156         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
1157                 mpe->pgfailback = -FAILBACK_IMMEDIATE;
1158         else
1159                 mpe->pgfailback = atoi(buff);
1160
1161         FREE(buff);
1162
1163         return 0;
1164 }
1165
1166 static int
1167 mp_mode_handler(vector strvec)
1168 {
1169         mode_t mode;
1170         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1171         char *buff;
1172
1173         if (!mpe)
1174                 return 1;
1175
1176         buff = set_value(strvec);
1177         if (!buff)
1178                 return 1;
1179         if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
1180                 mpe->attribute_flags |= (1 << ATTR_MODE);
1181                 mpe->mode = mode;
1182         }
1183
1184         FREE(buff);
1185         return 0;
1186 }
1187
1188 static int
1189 mp_uid_handler(vector strvec)
1190 {
1191         uid_t uid;
1192         char *buff;
1193         char passwd_buf[1024];
1194         struct passwd info, *found;
1195
1196         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1197
1198         if (!mpe)
1199                 return 1;
1200
1201         buff = set_value(strvec);
1202         if (!buff)
1203                 return 1;
1204
1205         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
1206                 mpe->attribute_flags |= (1 << ATTR_UID);
1207                 mpe->uid = info.pw_uid;
1208         }
1209         else if (sscanf(buff, "%u", &uid) == 1){
1210                 mpe->attribute_flags |= (1 << ATTR_UID);
1211                 mpe->uid = uid;
1212         }
1213         FREE(buff);
1214         return 0;
1215 }
1216
1217 static int
1218 mp_gid_handler(vector strvec)
1219 {
1220         gid_t gid;
1221         char *buff;
1222         char passwd_buf[1024];
1223         struct passwd info, *found;
1224
1225         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1226
1227         if (!mpe)
1228                 return 1;
1229
1230         buff = set_value(strvec);
1231         if (!buff)
1232                 return 1;
1233
1234         if (getpwnam_r(buff, &info, passwd_buf, 1024, &found) == 0 && found) {
1235                 mpe->attribute_flags |= (1 << ATTR_GID);
1236                 mpe->gid = info.pw_gid;
1237         }
1238         else if (sscanf(buff, "%u", &gid) == 1) {
1239                 mpe->attribute_flags |= (1 << ATTR_GID);
1240                 mpe->gid = gid;
1241         }
1242         FREE(buff);
1243         return 0;
1244 }
1245
1246 static int
1247 mp_weight_handler(vector strvec)
1248 {
1249         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
1250         char * buff;
1251
1252         if (!mpe)
1253                 return 1;
1254
1255         buff = set_value(strvec);
1256
1257         if (!buff)
1258                 return 1;
1259
1260         if (strlen(buff) == 10 &&
1261             !strcmp(buff, "priorities"))
1262                 mpe->rr_weight = RR_WEIGHT_PRIO;
1263
1264         FREE(buff);
1265
1266         return 0;
1267 }
1268
1269 static int
1270 mp_no_path_retry_handler(vector strvec)
1271 {
1272         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1273         char *buff;
1274
1275         if (!mpe)
1276                 return 1;
1277
1278         buff = set_value(strvec);
1279         if (!buff)
1280                 return 1;
1281
1282         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
1283             (strlen(buff) == 1 && !strcmp(buff, "0")))
1284                 mpe->no_path_retry = NO_PATH_RETRY_FAIL;
1285         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
1286                 mpe->no_path_retry = NO_PATH_RETRY_QUEUE;
1287         else if ((mpe->no_path_retry = atoi(buff)) < 1)
1288                 mpe->no_path_retry = NO_PATH_RETRY_UNDEF;
1289
1290         FREE(buff);
1291         return 0;
1292 }
1293
1294 static int
1295 mp_minio_handler(vector strvec)
1296 {
1297         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1298         char * buff;
1299
1300         if (!mpe)
1301                 return 1;
1302
1303         buff = set_value(strvec);
1304
1305         if (!buff)
1306                 return 1;
1307
1308         mpe->minio = atoi(buff);
1309         FREE(buff);
1310
1311         return 0;
1312 }
1313
1314 static int
1315 mp_pg_timeout_handler(vector strvec)
1316 {
1317         int pg_timeout;
1318         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1319         char *buff;
1320
1321         if (!mpe)
1322                 return 1;
1323
1324         buff = set_value(strvec);
1325
1326         if (!buff)
1327                 return 1;
1328         if (strlen(buff) == 4 && !strcmp(buff, "none"))
1329                 mpe->pg_timeout = -PGTIMEOUT_NONE;
1330         else if (sscanf(buff, "%d", &pg_timeout) == 1 && pg_timeout >= 0) {
1331                 if (pg_timeout == 0)
1332                         mpe->pg_timeout = -PGTIMEOUT_NONE;
1333                 else
1334                         mpe->pg_timeout = pg_timeout;
1335         }
1336         else
1337                 mpe->pg_timeout = PGTIMEOUT_UNDEF;
1338
1339         FREE(buff);
1340         return 0;
1341 }
1342
1343 static int
1344 mp_flush_on_last_del_handler(vector strvec)
1345 {
1346         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
1347         char * buff;
1348
1349         if (!mpe)
1350                 return 1;
1351
1352         buff = set_value(strvec);
1353         if (!buff)
1354                 return 1;
1355
1356         if ((strlen(buff) == 2 && strcmp(buff, "no") == 0) ||
1357             (strlen(buff) == 1 && strcmp(buff, "0") == 0))
1358                 mpe->flush_on_last_del = FLUSH_DISABLED;
1359         if ((strlen(buff) == 3 && strcmp(buff, "yes") == 0) ||
1360             (strlen(buff) == 1 && strcmp(buff, "1") == 0))
1361                 mpe->flush_on_last_del = FLUSH_ENABLED;
1362         else
1363                 mpe->flush_on_last_del = FLUSH_UNDEF;
1364
1365         FREE(buff);
1366         return 0;
1367 }
1368
1369 /*
1370  * config file keywords printing
1371  */
1372 static int
1373 snprint_mp_wwid (char * buff, int len, void * data)
1374 {
1375         struct mpentry * mpe = (struct mpentry *)data;
1376
1377         return snprintf(buff, len, "%s", mpe->wwid);
1378 }
1379
1380 static int
1381 snprint_mp_alias (char * buff, int len, void * data)
1382 {
1383         struct mpentry * mpe = (struct mpentry *)data;
1384
1385         if (!mpe->alias)
1386                 return 0;
1387
1388         if (conf->user_friendly_names &&
1389             (strlen(mpe->alias) == strlen("mpath")) &&
1390             !strcmp(mpe->alias, "mpath"))
1391                 return 0;
1392
1393         return snprintf(buff, len, "%s", mpe->alias);
1394 }
1395
1396 static int
1397 snprint_mp_path_grouping_policy (char * buff, int len, void * data)
1398 {
1399         struct mpentry * mpe = (struct mpentry *)data;
1400         char str[POLICY_NAME_SIZE];
1401
1402         if (!mpe->pgpolicy)
1403                 return 0;
1404         get_pgpolicy_name(str, POLICY_NAME_SIZE, mpe->pgpolicy);
1405
1406         return snprintf(buff, len, "%s", str);
1407 }
1408
1409 static int
1410 snprint_mp_selector (char * buff, int len, void * data)
1411 {
1412         struct mpentry * mpe = (struct mpentry *)data;
1413
1414         if (!mpe->selector)
1415                 return 0;
1416
1417         return snprintf(buff, len, "%s", mpe->selector);
1418 }
1419
1420 static int
1421 snprint_mp_failback (char * buff, int len, void * data)
1422 {
1423         struct mpentry * mpe = (struct mpentry *)data;
1424
1425         if (!mpe->pgfailback)
1426                 return 0;
1427
1428         switch(mpe->pgfailback) {
1429         case  FAILBACK_UNDEF:
1430                 break;
1431         case -FAILBACK_MANUAL:
1432                 return snprintf(buff, len, "manual");
1433         case -FAILBACK_IMMEDIATE:
1434                 return snprintf(buff, len, "immediate");
1435         default:
1436                 return snprintf(buff, len, "%i", mpe->pgfailback);
1437         }
1438         return 0;
1439 }
1440
1441 static int
1442 snprint_mp_mode(char * buff, int len, void * data)
1443 {
1444         struct mpentry * mpe = (struct mpentry *)data;
1445
1446         if ((mpe->attribute_flags & (1 << ATTR_MODE)) == 0)
1447                 return 0;
1448         return snprintf(buff, len, "0%o", mpe->mode);
1449 }
1450
1451 static int
1452 snprint_mp_uid(char * buff, int len, void * data)
1453 {
1454         struct mpentry * mpe = (struct mpentry *)data;
1455
1456         if ((mpe->attribute_flags & (1 << ATTR_UID)) == 0)
1457                 return 0;
1458         return snprintf(buff, len, "0%o", mpe->uid);
1459 }
1460
1461 static int
1462 snprint_mp_gid(char * buff, int len, void * data)
1463 {
1464         struct mpentry * mpe = (struct mpentry *)data;
1465
1466         if ((mpe->attribute_flags & (1 << ATTR_GID)) == 0)
1467                 return 0;
1468         return snprintf(buff, len, "0%o", mpe->gid);
1469 }
1470
1471 static int
1472 snprint_mp_rr_weight (char * buff, int len, void * data)
1473 {
1474         struct mpentry * mpe = (struct mpentry *)data;
1475
1476         if (!mpe->rr_weight)
1477                 return 0;
1478         if (mpe->rr_weight == RR_WEIGHT_PRIO)
1479                 return snprintf(buff, len, "priorities");
1480
1481         return 0;
1482 }
1483
1484 static int
1485 snprint_mp_no_path_retry (char * buff, int len, void * data)
1486 {
1487         struct mpentry * mpe = (struct mpentry *)data;
1488
1489         if (!mpe->no_path_retry)
1490                 return 0;
1491
1492         switch(mpe->no_path_retry) {
1493         case NO_PATH_RETRY_UNDEF:
1494                 break;
1495         case NO_PATH_RETRY_FAIL:
1496                 return snprintf(buff, len, "fail");
1497         case NO_PATH_RETRY_QUEUE:
1498                 return snprintf(buff, len, "queue");
1499         default:
1500                 return snprintf(buff, len, "%i",
1501                                 mpe->no_path_retry);
1502         }
1503         return 0;
1504 }
1505
1506 static int
1507 snprint_mp_rr_min_io (char * buff, int len, void * data)
1508 {
1509         struct mpentry * mpe = (struct mpentry *)data;
1510
1511         if (!mpe->minio)
1512                 return 0;
1513
1514         return snprintf(buff, len, "%u", mpe->minio);
1515 }
1516
1517 static int
1518 snprint_mp_pg_timeout (char * buff, int len, void * data)
1519 {
1520         struct mpentry * mpe = (struct mpentry *)data;
1521
1522         switch (mpe->pg_timeout) {
1523         case PGTIMEOUT_UNDEF:
1524                 break;
1525         case -PGTIMEOUT_NONE:
1526                 return snprintf(buff, len, "none");
1527         default:
1528                 return snprintf(buff, len, "%i", mpe->pg_timeout);
1529         }
1530         return 0;
1531 }
1532
1533 static int
1534 snprint_mp_flush_on_last_del (char * buff, int len, void * data)
1535 {
1536         struct mpentry * mpe = (struct mpentry *)data;
1537
1538         switch (mpe->flush_on_last_del) {
1539         case FLUSH_DISABLED:
1540                 return snprintf(buff, len, "no");
1541         case FLUSH_ENABLED:
1542                 return snprintf(buff, len, "yes");
1543         }
1544         return 0;
1545 }
1546
1547 static int
1548 snprint_hw_fast_io_fail(char * buff, int len, void * data)
1549 {
1550         struct hwentry * hwe = (struct hwentry *)data;
1551         if (!hwe->fast_io_fail)
1552                 return 0;
1553         if (hwe->fast_io_fail == -1)
1554                 return snprintf(buff, len, "off");
1555         return snprintf(buff, len, "%d", hwe->fast_io_fail);
1556 }
1557
1558 static int
1559 snprint_hw_dev_loss(char * buff, int len, void * data)
1560 {
1561         struct hwentry * hwe = (struct hwentry *)data;
1562         if (!hwe->dev_loss)
1563                 return 0;
1564         return snprintf(buff, len, "%u", hwe->dev_loss);
1565 }
1566
1567 static int
1568 snprint_hw_vendor (char * buff, int len, void * data)
1569 {
1570         struct hwentry * hwe = (struct hwentry *)data;
1571
1572         if (!hwe->vendor)
1573                 return 0;
1574
1575         return snprintf(buff, len, "\"%s\"", hwe->vendor);
1576 }
1577
1578 static int
1579 snprint_hw_product (char * buff, int len, void * data)
1580 {
1581         struct hwentry * hwe = (struct hwentry *)data;
1582
1583         if (!hwe->product)
1584                 return 0;
1585
1586         return snprintf(buff, len, "\"%s\"", hwe->product);
1587 }
1588
1589 static int
1590 snprint_hw_bl_product (char * buff, int len, void * data)
1591 {
1592         struct hwentry * hwe = (struct hwentry *)data;
1593
1594         if (!hwe->bl_product)
1595                 return 0;
1596
1597         return snprintf(buff, len, "\"%s\"", hwe->bl_product);
1598 }
1599
1600 static int
1601 snprint_hw_getuid_callout (char * buff, int len, void * data)
1602 {
1603         struct hwentry * hwe = (struct hwentry *)data;
1604
1605         if (!hwe->getuid)
1606                 return 0;
1607         if (conf->getuid &&
1608             strlen(hwe->getuid) == strlen(conf->getuid) &&
1609             !strcmp(hwe->getuid, conf->getuid))
1610                 return 0;
1611
1612         return snprintf(buff, len, "\"%s\"", hwe->getuid);
1613 }
1614
1615 static int
1616 snprint_hw_prio (char * buff, int len, void * data)
1617 {
1618         struct hwentry * hwe = (struct hwentry *)data;
1619
1620         if (!hwe->prio_name || (strlen(hwe->prio_name) == 0))
1621                 return 0;
1622         if (conf->prio_name && !strcmp(hwe->prio_name, conf->prio_name))
1623                 return 0;
1624
1625         return snprintf(buff, len, "%s", hwe->prio_name);
1626 }
1627
1628 static int
1629 snprint_hw_alias_prefix (char * buff, int len, void * data)
1630 {
1631         struct hwentry * hwe = (struct hwentry *)data;
1632
1633         if (!hwe->alias_prefix || (strlen(hwe->alias_prefix) == 0))
1634                 return 0;
1635         if (conf->alias_prefix && !strcmp(hwe->alias_prefix, conf->alias_prefix))
1636                 return 0;
1637
1638         return snprintf(buff, len, "%s", hwe->alias_prefix);
1639 }
1640
1641 static int
1642 snprint_hw_prio_args (char * buff, int len, void * data)
1643 {
1644         struct hwentry * hwe = (struct hwentry *)data;
1645
1646         if (!hwe->prio_args || (strlen(hwe->prio_args) == 0))
1647                 return 0;
1648         if (conf->prio_args && !strcmp(hwe->prio_args, conf->prio_args))
1649                 return 0;
1650
1651         return snprintf(buff, len, "%s", hwe->prio_args);
1652 }
1653
1654 static int
1655 snprint_hw_features (char * buff, int len, void * data)
1656 {
1657         struct hwentry * hwe = (struct hwentry *)data;
1658
1659         if (!hwe->features)
1660                 return 0;
1661         if (conf->features &&
1662             strlen(hwe->features) == strlen(conf->features) &&
1663             !strcmp(hwe->features, conf->features))
1664                 return 0;
1665
1666         return snprintf(buff, len, "\"%s\"", hwe->features);
1667 }
1668
1669 static int
1670 snprint_hw_hardware_handler (char * buff, int len, void * data)
1671 {
1672         struct hwentry * hwe = (struct hwentry *)data;
1673
1674         if (!hwe->hwhandler)
1675                 return 0;
1676         if (conf->hwhandler &&
1677             strlen(hwe->hwhandler) == strlen(conf->hwhandler) &&
1678             !strcmp(hwe->hwhandler, conf->hwhandler))
1679                 return 0;
1680
1681         return snprintf(buff, len, "\"%s\"", hwe->hwhandler);
1682 }
1683
1684 static int
1685 snprint_hw_selector (char * buff, int len, void * data)
1686 {
1687         struct hwentry * hwe = (struct hwentry *)data;
1688
1689         if (!hwe->selector)
1690                 return 0;
1691         if (conf->selector &&
1692             strlen(hwe->selector) == strlen(conf->selector) &&
1693             !strcmp(hwe->selector, conf->selector))
1694                 return 0;
1695
1696         return snprintf(buff, len, "%s", hwe->selector);
1697 }
1698
1699 static int
1700 snprint_hw_path_grouping_policy (char * buff, int len, void * data)
1701 {
1702         struct hwentry * hwe = (struct hwentry *)data;
1703
1704         char str[POLICY_NAME_SIZE];
1705
1706         if (!hwe->pgpolicy)
1707                 return 0;
1708         if (conf->pgpolicy && hwe->pgpolicy == conf->pgpolicy)
1709                 return 0;
1710
1711         get_pgpolicy_name(str, POLICY_NAME_SIZE, hwe->pgpolicy);
1712
1713         return snprintf(buff, len, "%s", str);
1714 }
1715
1716 static int
1717 snprint_hw_failback (char * buff, int len, void * data)
1718 {
1719         struct hwentry * hwe = (struct hwentry *)data;
1720
1721         if (!hwe->pgfailback)
1722                 return 0;
1723         if (conf->pgfailback && hwe->pgfailback == conf->pgfailback)
1724                 return 0;
1725
1726         switch(hwe->pgfailback) {
1727         case  FAILBACK_UNDEF:
1728                 break;
1729         case -FAILBACK_MANUAL:
1730                 return snprintf(buff, len, "manual");
1731         case -FAILBACK_IMMEDIATE:
1732                 return snprintf(buff, len, "immediate");
1733         default:
1734                 return snprintf(buff, len, "%i", hwe->pgfailback);
1735         }
1736         return 0;
1737 }
1738
1739 static int
1740 snprint_hw_rr_weight (char * buff, int len, void * data)
1741 {
1742         struct hwentry * hwe = (struct hwentry *)data;
1743
1744         if (!hwe->rr_weight)
1745                 return 0;
1746         if (conf->rr_weight && hwe->rr_weight == conf->rr_weight)
1747                 return 0;
1748         if (hwe->rr_weight == RR_WEIGHT_PRIO)
1749                 return snprintf(buff, len, "priorities");
1750
1751         return 0;
1752 }
1753
1754 static int
1755 snprint_hw_no_path_retry (char * buff, int len, void * data)
1756 {
1757         struct hwentry * hwe = (struct hwentry *)data;
1758
1759         if (!hwe->no_path_retry)
1760                 return 0;
1761         if (hwe->no_path_retry == conf->no_path_retry)
1762                 return 0;
1763
1764         switch(hwe->no_path_retry) {
1765         case NO_PATH_RETRY_UNDEF:
1766                 break;
1767         case NO_PATH_RETRY_FAIL:
1768                 return snprintf(buff, len, "fail");
1769         case NO_PATH_RETRY_QUEUE:
1770                 return snprintf(buff, len, "queue");
1771         default:
1772                 return snprintf(buff, len, "%i",
1773                                 hwe->no_path_retry);
1774         }
1775         return 0;
1776 }
1777
1778 static int
1779 snprint_hw_rr_min_io (char * buff, int len, void * data)
1780 {
1781         struct hwentry * hwe = (struct hwentry *)data;
1782
1783         if (!hwe->minio)
1784                 return 0;
1785         if (hwe->minio == conf->minio)
1786                 return 0;
1787
1788         return snprintf(buff, len, "%u", hwe->minio);
1789 }
1790
1791 static int
1792 snprint_hw_pg_timeout (char * buff, int len, void * data)
1793 {
1794         struct hwentry * hwe = (struct hwentry *)data;
1795
1796         if (!hwe->pg_timeout)
1797                 return 0;
1798         if (hwe->pg_timeout == conf->pg_timeout)
1799                 return 0;
1800
1801         switch (hwe->pg_timeout) {
1802         case PGTIMEOUT_UNDEF:
1803                 break;
1804         case -PGTIMEOUT_NONE:
1805                 return snprintf(buff, len, "none");
1806         default:
1807                 return snprintf(buff, len, "%i", hwe->pg_timeout);
1808         }
1809         return 0;
1810 }
1811
1812 static int
1813 snprint_hw_flush_on_last_del (char * buff, int len, void * data)
1814 {
1815         struct hwentry * hwe = (struct hwentry *)data;
1816
1817         switch (hwe->flush_on_last_del) {
1818         case FLUSH_DISABLED:
1819                 return snprintf(buff, len, "no");
1820         case FLUSH_ENABLED:
1821                 return snprintf(buff, len, "yes");
1822         }
1823         return 0;
1824 }
1825
1826 static int
1827 snprint_hw_path_checker (char * buff, int len, void * data)
1828 {
1829         struct hwentry * hwe = (struct hwentry *)data;
1830
1831         if (!hwe->checker_name)
1832                 return 0;
1833         if (conf->checker_name &&
1834             !strcmp(hwe->checker_name, conf->checker_name))
1835                 return 0;
1836
1837         return snprintf(buff, len, "%s", hwe->checker_name);
1838 }
1839
1840 static int
1841 snprint_def_polling_interval (char * buff, int len, void * data)
1842 {
1843         if (conf->checkint == DEFAULT_CHECKINT)
1844                 return 0;
1845         return snprintf(buff, len, "%i", conf->checkint);
1846 }
1847
1848 static int
1849 snprint_def_fast_io_fail(char * buff, int len, void * data)
1850 {
1851         if (!conf->fast_io_fail)
1852                 return 0;
1853         if (conf->fast_io_fail == -1)
1854                 return snprintf(buff, len, "off");
1855         return snprintf(buff, len, "%d", conf->fast_io_fail);
1856 }
1857
1858 static int
1859 snprint_def_dev_loss(char * buff, int len, void * data)
1860 {
1861         if (!conf->dev_loss)
1862                 return 0;
1863         return snprintf(buff, len, "%u", conf->dev_loss);
1864 }
1865
1866 static int
1867 snprint_def_verbosity (char * buff, int len, void * data)
1868 {
1869         if (conf->checkint == DEFAULT_VERBOSITY)
1870                 return 0;
1871         return snprintf(buff, len, "%i", conf->verbosity);
1872 }
1873
1874 static int
1875 snprint_def_udev_dir (char * buff, int len, void * data)
1876 {
1877         if (!conf->udev_dir)
1878                 return 0;
1879         if (strlen(DEFAULT_UDEVDIR) == strlen(conf->udev_dir) &&
1880             !strcmp(conf->udev_dir, DEFAULT_UDEVDIR))
1881                 return 0;
1882
1883         return snprintf(buff, len, "\"%s\"", conf->udev_dir);
1884 }
1885
1886 static int
1887 snprint_def_multipath_dir (char * buff, int len, void * data)
1888 {
1889         if (!conf->udev_dir)
1890                 return 0;
1891         if (strlen(DEFAULT_MULTIPATHDIR) == strlen(conf->multipath_dir) &&
1892             !strcmp(conf->multipath_dir, DEFAULT_MULTIPATHDIR))
1893                 return 0;
1894
1895         return snprintf(buff, len, "\"%s\"", conf->multipath_dir);
1896 }
1897
1898 static int
1899 snprint_def_selector (char * buff, int len, void * data)
1900 {
1901         if (!conf->selector)
1902                 return 0;
1903         if (strlen(conf->selector) == strlen(DEFAULT_SELECTOR) &&
1904             !strcmp(conf->selector, DEFAULT_SELECTOR))
1905                 return 0;
1906
1907         return snprintf(buff, len, "%s", conf->selector);
1908 }
1909
1910 static int
1911 snprint_def_path_grouping_policy (char * buff, int len, void * data)
1912 {
1913         char str[POLICY_NAME_SIZE];
1914
1915         if (!conf->pgpolicy)
1916                 return 0;
1917         if (conf->pgpolicy == DEFAULT_PGPOLICY)
1918                 return 0;
1919
1920         get_pgpolicy_name(str, POLICY_NAME_SIZE, conf->pgpolicy);
1921
1922         return snprintf(buff, len, "%s", str);
1923 }
1924
1925 static int
1926 snprint_def_getuid_callout (char * buff, int len, void * data)
1927 {
1928         if (!conf->getuid)
1929                 return 0;
1930         if (strlen(conf->getuid) == strlen(DEFAULT_GETUID) &&
1931             !strcmp(conf->getuid, DEFAULT_GETUID))
1932                 return 0;
1933
1934         return snprintf(buff, len, "\"%s\"", conf->getuid);
1935 }
1936
1937 static int
1938 snprint_def_prio (char * buff, int len, void * data)
1939 {
1940         if (!conf->prio_name)
1941                 return 0;
1942
1943         if (strlen(conf->prio_name) == strlen(DEFAULT_PRIO) &&
1944             !strcmp(conf->prio_name, DEFAULT_PRIO))
1945                 return 0;
1946
1947         return snprintf(buff, len, "%s", conf->prio_name);
1948 }
1949
1950 static int
1951 snprint_def_prio_args (char * buff, int len, void * data)
1952 {
1953         if (!conf->prio_args)
1954                 return 0;
1955
1956         if (strlen(conf->prio_args) == strlen(DEFAULT_PRIO_ARGS) &&
1957             !strcmp(conf->prio_args, DEFAULT_PRIO_ARGS))
1958                 return 0;
1959
1960         return snprintf(buff, len, "%s", conf->prio_args);
1961 }
1962
1963 static int
1964 snprint_def_features (char * buff, int len, void * data)
1965 {
1966         if (!conf->features)
1967                 return 0;
1968         if (strlen(conf->features) == strlen(DEFAULT_FEATURES) &&
1969             !strcmp(conf->features, DEFAULT_FEATURES))
1970                 return 0;
1971
1972         return snprintf(buff, len, "\"%s\"", conf->features);
1973 }
1974
1975 static int
1976 snprint_def_path_checker (char * buff, int len, void * data)
1977 {
1978         if (!conf->checker_name)
1979                 return 0;
1980         if (strlen(conf->checker_name) == strlen(DEFAULT_CHECKER) &&
1981             !strcmp(conf->checker_name, DEFAULT_CHECKER))
1982                 return 0;
1983
1984         return snprintf(buff, len, "%s", conf->checker_name);
1985 }
1986
1987 static int
1988 snprint_def_failback (char * buff, int len, void * data)
1989 {
1990         if (!conf->pgfailback)
1991                 return 0;
1992         if (conf->pgfailback == DEFAULT_FAILBACK)
1993                 return 0;
1994
1995         switch(conf->pgfailback) {
1996         case  FAILBACK_UNDEF:
1997                 break;
1998         case -FAILBACK_MANUAL:
1999                 return snprintf(buff, len, "manual");
2000         case -FAILBACK_IMMEDIATE:
2001                 return snprintf(buff, len, "immediate");
2002         default:
2003                 return snprintf(buff, len, "%i", conf->pgfailback);
2004         }
2005         return 0;
2006 }
2007
2008 static int
2009 snprint_def_rr_min_io (char * buff, int len, void * data)
2010 {
2011         if (!conf->minio)
2012                 return 0;
2013         if (conf->minio == DEFAULT_MINIO)
2014                 return 0;
2015
2016         return snprintf(buff, len, "%u", conf->minio);
2017 }
2018
2019 static int
2020 snprint_max_fds (char * buff, int len, void * data)
2021 {
2022         if (!conf->max_fds)
2023                 return 0;
2024
2025         return snprintf(buff, len, "%d", conf->max_fds);
2026 }
2027
2028 static int
2029 snprint_def_mode(char * buff, int len, void * data)
2030 {
2031         if ((conf->attribute_flags & (1 << ATTR_MODE)) == 0)
2032                 return 0;
2033         return snprintf(buff, len, "0%o", conf->mode);
2034 }
2035
2036 static int
2037 snprint_def_uid(char * buff, int len, void * data)
2038 {
2039         if ((conf->attribute_flags & (1 << ATTR_UID)) == 0)
2040                 return 0;
2041         return snprintf(buff, len, "0%o", conf->uid);
2042 }
2043
2044 static int
2045 snprint_def_gid(char * buff, int len, void * data)
2046 {
2047         if ((conf->attribute_flags & (1 << ATTR_GID)) == 0)
2048                 return 0;
2049         return snprintf(buff, len, "0%o", conf->gid);
2050 }
2051
2052 static int
2053 snprint_def_rr_weight (char * buff, int len, void * data)
2054 {
2055         if (!conf->rr_weight)
2056                 return 0;
2057         if (conf->rr_weight == DEFAULT_RR_WEIGHT)
2058                 return 0;
2059         if (conf->rr_weight == RR_WEIGHT_PRIO)
2060                 return snprintf(buff, len, "priorities");
2061
2062         return 0;
2063 }
2064
2065 static int
2066 snprint_def_no_path_retry (char * buff, int len, void * data)
2067 {
2068         if (conf->no_path_retry == DEFAULT_NO_PATH_RETRY)
2069                 return 0;
2070
2071         switch(conf->no_path_retry) {
2072         case NO_PATH_RETRY_UNDEF:
2073                 break;
2074         case NO_PATH_RETRY_FAIL:
2075                 return snprintf(buff, len, "fail");
2076         case NO_PATH_RETRY_QUEUE:
2077                 return snprintf(buff, len, "queue");
2078         default:
2079                 return snprintf(buff, len, "%i",
2080                                 conf->no_path_retry);
2081         }
2082         return 0;
2083 }
2084
2085 static int
2086 snprint_def_queue_without_daemon (char * buff, int len, void * data)
2087 {
2088         switch (conf->queue_without_daemon) {
2089         case QUE_NO_DAEMON_OFF:
2090                 return snprintf(buff, len, "no");
2091         case QUE_NO_DAEMON_ON:
2092                 return snprintf(buff, len, "yes");
2093         }
2094         return 0;
2095 }
2096
2097 static int
2098 snprint_def_checker_timeout (char *buff, int len, void *data)
2099 {
2100         if (!conf->checker_timeout)
2101                 return 0;
2102
2103         return snprintf(buff, len, "%u", conf->checker_timeout);
2104 }
2105
2106 static int
2107 snprint_def_pg_timeout (char * buff, int len, void * data)
2108 {
2109         if (conf->pg_timeout == DEFAULT_PGTIMEOUT)
2110                 return 0;
2111
2112         switch (conf->pg_timeout) {
2113         case PGTIMEOUT_UNDEF:
2114                 break;
2115         case -PGTIMEOUT_NONE:
2116                 return snprintf(buff, len, "none");
2117         default:
2118                 return snprintf(buff, len, "%i", conf->pg_timeout);
2119         }
2120         return 0;
2121 }
2122
2123 static int
2124 snprint_def_flush_on_last_del (char * buff, int len, void * data)
2125 {
2126         switch (conf->flush_on_last_del) {
2127         case FLUSH_DISABLED:
2128                 return snprintf(buff, len, "no");
2129         case FLUSH_ENABLED:
2130                 return snprintf(buff, len, "yes");
2131         }
2132         return 0;
2133 }
2134
2135 static int
2136 snprint_def_user_friendly_names (char * buff, int len, void * data)
2137 {
2138         if (conf->user_friendly_names == DEFAULT_USER_FRIENDLY_NAMES)
2139                 return 0;
2140         if (!conf->user_friendly_names)
2141                 return snprintf(buff, len, "no");
2142
2143         return snprintf(buff, len, "yes");
2144 }
2145
2146 static int
2147 snprint_def_alias_prefix (char * buff, int len, void * data)
2148 {
2149         if (!conf->alias_prefix)
2150                 return 0;
2151         if (!strcmp(conf->alias_prefix, DEFAULT_ALIAS_PREFIX))
2152                 return 0;
2153         return snprintf(buff, len, conf->alias_prefix);
2154 }
2155
2156 static int
2157 snprint_ble_simple (char * buff, int len, void * data)
2158 {
2159         struct blentry * ble = (struct blentry *)data;
2160
2161         return snprintf(buff, len, "\"%s\"", ble->str);
2162 }
2163
2164 static int
2165 snprint_bled_vendor (char * buff, int len, void * data)
2166 {
2167         struct blentry_device * bled = (struct blentry_device *)data;
2168
2169         return snprintf(buff, len, "\"%s\"", bled->vendor);
2170 }
2171
2172 static int
2173 snprint_bled_product (char * buff, int len, void * data)
2174 {
2175         struct blentry_device * bled = (struct blentry_device *)data;
2176
2177         return snprintf(buff, len, "\"%s\"", bled->product);
2178 }
2179
2180 #define __deprecated
2181
2182 void
2183 init_keywords(void)
2184 {
2185         install_keyword_root("defaults", NULL);
2186         install_keyword("verbosity", &verbosity_handler, &snprint_def_verbosity);
2187         install_keyword("polling_interval", &polling_interval_handler, &snprint_def_polling_interval);
2188         install_keyword("udev_dir", &udev_dir_handler, &snprint_def_udev_dir);
2189         install_keyword("multipath_dir", &multipath_dir_handler, &snprint_def_multipath_dir);
2190         install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
2191         install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_path_grouping_policy);
2192         install_keyword("getuid_callout", &def_getuid_callout_handler, &snprint_def_getuid_callout);
2193         install_keyword("prio", &def_prio_handler, &snprint_def_prio);
2194         install_keyword("prio_args", &def_prio_args_handler, &snprint_def_prio_args);
2195         install_keyword("features", &def_features_handler, &snprint_def_features);
2196         install_keyword("path_checker", &def_path_checker_handler, &snprint_def_path_checker);
2197         install_keyword("checker", &def_path_checker_handler, &snprint_def_path_checker);
2198         install_keyword("alias_prefix", &def_alias_prefix_handler, &snprint_def_alias_prefix);
2199         install_keyword("failback", &default_failback_handler, &snprint_def_failback);
2200         install_keyword("rr_min_io", &def_minio_handler, &snprint_def_rr_min_io);
2201         install_keyword("max_fds", &max_fds_handler, &snprint_max_fds);
2202         install_keyword("rr_weight", &def_weight_handler, &snprint_def_rr_weight);
2203         install_keyword("no_path_retry", &def_no_path_retry_handler, &snprint_def_no_path_retry);
2204         install_keyword("queue_without_daemon", &def_queue_without_daemon, &snprint_def_queue_without_daemon);
2205         install_keyword("checker_timeout", &def_checker_timeout_handler, &snprint_def_checker_timeout);
2206         install_keyword("pg_timeout", &def_pg_timeout_handler, &snprint_def_pg_timeout);
2207         install_keyword("flush_on_last_del", &def_flush_on_last_del_handler, &snprint_def_flush_on_last_del);
2208         install_keyword("user_friendly_names", &names_handler, &snprint_def_user_friendly_names);
2209         install_keyword("mode", &def_mode_handler, &snprint_def_mode);
2210         install_keyword("uid", &def_uid_handler, &snprint_def_uid);
2211         install_keyword("gid", &def_gid_handler, &snprint_def_gid);
2212         install_keyword("fast_io_fail_tmo", &def_fast_io_fail_handler, &snprint_def_fast_io_fail);
2213         install_keyword("dev_loss_tmo", &def_dev_loss_handler, &snprint_def_dev_loss);
2214         __deprecated install_keyword("default_selector", &def_selector_handler, NULL);
2215         __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
2216         __deprecated install_keyword("default_getuid_callout", &def_getuid_callout_handler, NULL);
2217         __deprecated install_keyword("default_features", &def_features_handler, NULL);
2218         __deprecated install_keyword("default_path_checker", &def_path_checker_handler, NULL);
2219
2220         install_keyword_root("blacklist", &blacklist_handler);
2221         install_keyword_multi("devnode", &ble_devnode_handler, &snprint_ble_simple);
2222         install_keyword_multi("wwid", &ble_wwid_handler, &snprint_ble_simple);
2223         install_keyword_multi("device", &ble_device_handler, NULL);
2224         install_sublevel();
2225         install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
2226         install_keyword("product", &ble_product_handler, &snprint_bled_product);
2227         install_sublevel_end();
2228         install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
2229         install_keyword_multi("devnode", &ble_except_devnode_handler, &snprint_ble_simple);
2230         install_keyword_multi("wwid", &ble_except_wwid_handler, &snprint_ble_simple);
2231         install_keyword_multi("device", &ble_except_device_handler, NULL);
2232         install_sublevel();
2233         install_keyword("vendor", &ble_except_vendor_handler, &snprint_bled_vendor);
2234         install_keyword("product", &ble_except_product_handler, &snprint_bled_product);
2235         install_sublevel_end();
2236
2237 #if 0
2238         __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler);
2239         __deprecated install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
2240         __deprecated install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
2241         __deprecated install_keyword("device", &ble_device_handler, NULL);
2242         __deprecated install_sublevel();
2243         __deprecated install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
2244         __deprecated install_keyword("product", &ble_product_handler, &snprint_bled_product);
2245         __deprecated install_sublevel_end();
2246 #endif
2247
2248         install_keyword_root("devices", &devices_handler);
2249         install_keyword_multi("device", &device_handler, NULL);
2250         install_sublevel();
2251         install_keyword("vendor", &vendor_handler, &snprint_hw_vendor);
2252         install_keyword("product", &product_handler, &snprint_hw_product);
2253         install_keyword("product_blacklist", &bl_product_handler, &snprint_hw_bl_product);
2254         install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_path_grouping_policy);
2255         install_keyword("getuid_callout", &hw_getuid_callout_handler, &snprint_hw_getuid_callout);
2256         install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
2257         install_keyword("path_checker", &hw_path_checker_handler, &snprint_hw_path_checker);
2258         install_keyword("checker", &hw_path_checker_handler, &snprint_hw_path_checker);
2259         install_keyword("alias_prefix", &hw_alias_prefix_handler, &snprint_hw_alias_prefix);
2260         install_keyword("features", &hw_features_handler, &snprint_hw_features);
2261         install_keyword("hardware_handler", &hw_handler_handler, &snprint_hw_hardware_handler);
2262         install_keyword("prio", &hw_prio_handler, &snprint_hw_prio);
2263         install_keyword("prio_args", &hw_prio_args_handler, &snprint_hw_prio_args);
2264         install_keyword("failback", &hw_failback_handler, &snprint_hw_failback);
2265         install_keyword("rr_weight", &hw_weight_handler, &snprint_hw_rr_weight);
2266         install_keyword("no_path_retry", &hw_no_path_retry_handler, &snprint_hw_no_path_retry);
2267         install_keyword("rr_min_io", &hw_minio_handler, &snprint_hw_rr_min_io);
2268         install_keyword("pg_timeout", &hw_pg_timeout_handler, &snprint_hw_pg_timeout);
2269         install_keyword("flush_on_last_del", &hw_flush_on_last_del_handler, &snprint_hw_flush_on_last_del);
2270         install_keyword("fast_io_fail_tmo", &hw_fast_io_fail_handler, &snprint_hw_fast_io_fail);
2271         install_keyword("dev_loss_tmo", &hw_dev_loss_handler, &snprint_hw_dev_loss);
2272         install_sublevel_end();
2273
2274         install_keyword_root("multipaths", &multipaths_handler);
2275         install_keyword_multi("multipath", &multipath_handler, NULL);
2276         install_sublevel();
2277         install_keyword("wwid", &wwid_handler, &snprint_mp_wwid);
2278         install_keyword("alias", &alias_handler, &snprint_mp_alias);
2279         install_keyword("path_grouping_policy", &mp_pgpolicy_handler, &snprint_mp_path_grouping_policy);
2280         install_keyword("path_selector", &mp_selector_handler, &snprint_mp_selector);
2281         install_keyword("failback", &mp_failback_handler, &snprint_mp_failback);
2282         install_keyword("rr_weight", &mp_weight_handler, &snprint_mp_rr_weight);
2283         install_keyword("no_path_retry", &mp_no_path_retry_handler, &snprint_mp_no_path_retry);
2284         install_keyword("rr_min_io", &mp_minio_handler, &snprint_mp_rr_min_io);
2285         install_keyword("pg_timeout", &mp_pg_timeout_handler, &snprint_mp_pg_timeout);
2286         install_keyword("flush_on_last_del", &mp_flush_on_last_del_handler, &snprint_mp_flush_on_last_del);
2287         install_keyword("mode", &mp_mode_handler, &snprint_mp_mode);
2288         install_keyword("uid", &mp_uid_handler, &snprint_mp_uid);
2289         install_keyword("gid", &mp_gid_handler, &snprint_mp_gid);
2290         install_sublevel_end();
2291 }