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