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