[lib] adapt checker print function to Ben's change
[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 "checkers.h"
8 #include "vector.h"
9 #include "hwtable.h"
10 #include "structs.h"
11 #include "parser.h"
12 #include "config.h"
13 #include "debug.h"
14 #include "memory.h"
15 #include "pgpolicies.h"
16 #include "blacklist.h"
17 #include "defaults.h"
18 #include "prio.h"
19
20 /*
21  * default block handlers
22  */
23 static int
24 polling_interval_handler(vector strvec)
25 {
26         char * buff;
27
28         buff = VECTOR_SLOT(strvec, 1);
29         conf->checkint = atoi(buff);
30         conf->max_checkint = MAX_CHECKINT(conf->checkint);
31
32         return 0;
33 }
34
35 static int
36 udev_dir_handler(vector strvec)
37 {
38         conf->udev_dir = set_value(strvec);
39
40         if (!conf->udev_dir)
41                 return 1;
42
43         return 0;
44 }
45
46 static int
47 multipath_dir_handler(vector strvec)
48 {
49         conf->multipath_dir = set_value(strvec);
50
51         if (!conf->multipath_dir)
52                 return 1;
53
54         return 0;
55 }
56
57 static int
58 def_selector_handler(vector strvec)
59 {
60         conf->selector = set_value(strvec);
61
62         if (!conf->selector)
63                 return 1;
64
65         return 0;
66 }
67
68 static int
69 def_pgpolicy_handler(vector strvec)
70 {
71         char * buff;
72
73         buff = set_value(strvec);
74
75         if (!buff)
76                 return 1;
77
78         conf->pgpolicy = get_pgpolicy_id(buff);
79         FREE(buff);
80
81         return 0;
82 }
83
84 static int
85 def_getuid_callout_handler(vector strvec)
86 {
87         conf->getuid = set_value(strvec);
88
89         if (!conf->getuid)
90                 return 1;
91         
92         return 0;
93 }
94
95 static int
96 def_prio_handler(vector strvec)
97 {
98         char * buff;
99
100         buff = set_value(strvec);
101         if (!buff)
102                 return 1;
103
104         conf->prio = prio_lookup(buff);
105         FREE(buff);
106         return 0;
107 }
108
109 static int
110 def_features_handler(vector strvec)
111 {
112         conf->features = set_value(strvec);
113
114         if (!conf->features)
115                 return 1;
116
117         return 0;
118 }
119
120 static int
121 def_path_checker_handler(vector strvec)
122 {
123         conf->checker_name = set_value(strvec);
124
125         if (!conf->checker_name)
126                 return 1;
127         
128         return 0;
129 }
130
131 static int
132 def_minio_handler(vector strvec)
133 {
134         char * buff;
135
136         buff = set_value(strvec);
137
138         if (!buff)
139                 return 1;
140
141         conf->minio = atoi(buff);
142         FREE(buff);
143
144         return 0;
145 }
146
147 static int
148 max_fds_handler(vector strvec)
149 {
150         char * buff;
151
152         buff = set_value(strvec);
153
154         if (!buff)
155                 return 1;
156
157         if (strlen(buff) == 9 &&
158             !strcmp(buff, "unlimited"))
159                 conf->max_fds = MAX_FDS_UNLIMITED;
160         else
161                 conf->max_fds = atoi(buff);
162         FREE(buff);
163
164         return 0;
165 }
166
167 static int
168 def_weight_handler(vector strvec)
169 {
170         char * buff;
171
172         buff = set_value(strvec);
173
174         if (!buff)
175                 return 1;
176
177         if (strlen(buff) == 10 &&
178             !strcmp(buff, "priorities"))
179                 conf->rr_weight = RR_WEIGHT_PRIO;
180
181         FREE(buff);
182
183         return 0;
184 }
185
186 static int
187 default_failback_handler(vector strvec)
188 {
189         char * buff;
190
191         buff = set_value(strvec);
192
193         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
194                 conf->pgfailback = -FAILBACK_MANUAL;
195         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
196                 conf->pgfailback = -FAILBACK_IMMEDIATE;
197         else
198                 conf->pgfailback = atoi(buff);
199
200         FREE(buff);
201
202         return 0;
203 }
204
205 static int
206 def_no_path_retry_handler(vector strvec)
207 {
208         char * buff;
209
210         buff = set_value(strvec);
211         if (!buff)
212                 return 1;
213
214         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
215             (strlen(buff) == 1 && !strcmp(buff, "0")))
216                 conf->no_path_retry = NO_PATH_RETRY_FAIL;
217         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
218                 conf->no_path_retry = NO_PATH_RETRY_QUEUE;
219         else if ((conf->no_path_retry = atoi(buff)) < 1)
220                 conf->no_path_retry = NO_PATH_RETRY_UNDEF;
221
222         FREE(buff);
223         return 0;
224 }
225
226 static int
227 def_pg_timeout_handler(vector strvec)
228 {
229         int pg_timeout;
230         char * buff;
231
232         buff = set_value(strvec);
233
234         if (!buff)
235                 return 1;
236
237         if (strlen(buff) == 4 && !strcmp(buff, "none"))
238                 conf->pg_timeout = -PGTIMEOUT_NONE;
239         else if (sscanf(buff, "%d", &pg_timeout) == 1 && pg_timeout >= 0) {
240                 if (pg_timeout == 0)
241                         conf->pg_timeout = -PGTIMEOUT_NONE;
242                 else
243                         conf->pg_timeout = pg_timeout;
244         }
245         else
246                 conf->pg_timeout = PGTIMEOUT_UNDEF;
247
248         FREE(buff);
249         return 0;
250 }
251
252 static int
253 names_handler(vector strvec)
254 {
255         char * buff;
256
257         buff = set_value(strvec);
258
259         if (!buff)
260                 return 1;
261
262         if ((strlen(buff) == 2 && !strcmp(buff, "no")) ||
263             (strlen(buff) == 1 && !strcmp(buff, "0")))
264                 conf->user_friendly_names = 0;
265         else if ((strlen(buff) == 3 && !strcmp(buff, "yes")) ||
266                  (strlen(buff) == 1 && !strcmp(buff, "1")))
267                 conf->user_friendly_names = 1;
268
269         FREE(buff);
270         return 0;
271 }
272
273 /*
274  * blacklist block handlers
275  */
276 static int
277 blacklist_handler(vector strvec)
278 {
279         conf->blist_devnode = vector_alloc();
280         conf->blist_wwid = vector_alloc();
281         conf->blist_device = vector_alloc();
282
283         if (!conf->blist_devnode || !conf->blist_wwid || !conf->blist_device)
284                 return 1;
285
286         return 0;
287 }
288
289 static int
290 blacklist_exceptions_handler(vector strvec)
291 {
292         conf->elist_devnode = vector_alloc();
293         conf->elist_wwid = vector_alloc();
294         conf->elist_device = vector_alloc();
295
296         if (!conf->elist_devnode || !conf->elist_wwid || !conf->elist_device)
297                 return 1;
298
299         return 0;
300 }
301
302 static int
303 ble_devnode_handler(vector strvec)
304 {
305         char * buff;
306
307         buff = set_value(strvec);
308
309         if (!buff)
310                 return 1;
311
312         return store_ble(conf->blist_devnode, buff, ORIGIN_CONFIG);
313 }
314
315 static int
316 ble_except_devnode_handler(vector strvec)
317 {
318         char * buff;
319
320         buff = set_value(strvec);
321
322         if (!buff)
323                 return 1;
324
325         return store_ble(conf->elist_devnode, buff, ORIGIN_CONFIG);
326 }
327
328 static int
329 ble_wwid_handler(vector strvec)
330 {
331         char * buff;
332
333         buff = set_value(strvec);
334
335         if (!buff)
336                 return 1;
337
338         return store_ble(conf->blist_wwid, buff, ORIGIN_CONFIG);
339 }
340
341 static int
342 ble_except_wwid_handler(vector strvec)
343 {
344         char * buff;
345
346         buff = set_value(strvec);
347
348         if (!buff)
349                 return 1;
350
351         return store_ble(conf->elist_wwid, buff, ORIGIN_CONFIG);
352 }
353
354 static int
355 ble_device_handler(vector strvec)
356 {
357         return alloc_ble_device(conf->blist_device);
358 }
359
360 static int
361 ble_except_device_handler(vector strvec)
362 {
363         return alloc_ble_device(conf->elist_device);
364 }
365
366 static int
367 ble_vendor_handler(vector strvec)
368 {
369         char * buff;
370
371         buff = set_value(strvec);
372
373         if (!buff)
374                 return 1;
375
376         return set_ble_device(conf->blist_device, buff, NULL, ORIGIN_CONFIG);
377 }
378
379 static int
380 ble_except_vendor_handler(vector strvec)
381 {
382         char * buff;
383
384         buff = set_value(strvec);
385
386         if (!buff)
387                 return 1;
388
389         return set_ble_device(conf->elist_device, buff, NULL, ORIGIN_CONFIG);
390 }
391
392 static int
393 ble_product_handler(vector strvec)
394 {
395         char * buff;
396
397         buff = set_value(strvec);
398
399         if (!buff)
400                 return 1;
401
402         return set_ble_device(conf->blist_device, NULL, buff, ORIGIN_CONFIG);
403 }
404
405 static int
406 ble_except_product_handler(vector strvec)
407 {
408         char * buff;
409
410         buff = set_value(strvec);
411
412         if (!buff)
413                 return 1;
414
415         return set_ble_device(conf->elist_device, NULL, buff, ORIGIN_CONFIG);
416 }
417
418 /*
419  * devices block handlers
420  */
421 static int
422 devices_handler(vector strvec)
423 {
424         conf->hwtable = vector_alloc();
425
426         if (!conf->hwtable)
427                 return 1;
428
429         return 0;
430 }
431
432 static int
433 device_handler(vector strvec)
434 {
435         struct hwentry * hwe;
436
437         hwe = (struct hwentry *)MALLOC(sizeof(struct hwentry));
438
439         if (!hwe)
440                 return 1;
441
442         if (!vector_alloc_slot(conf->hwtable)) {
443                 FREE(hwe);
444                 return 1;
445         }
446         vector_set_slot(conf->hwtable, hwe);
447
448         return 0;
449 }
450
451 static int
452 vendor_handler(vector strvec)
453 {
454         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
455
456         if (!hwe)
457                 return 1;
458         
459         hwe->vendor = set_value(strvec);
460
461         if (!hwe->vendor)
462                 return 1;
463
464         return 0;
465 }
466
467 static int
468 product_handler(vector strvec)
469 {
470         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
471
472         if (!hwe)
473                 return 1;
474         
475         hwe->product = set_value(strvec);
476
477         if (!hwe->product)
478                 return 1;
479
480         return 0;
481 }
482
483 static int
484 bl_product_handler(vector strvec)
485 {
486         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
487
488         if (!hwe)
489                 return 1;
490
491         hwe->bl_product = set_value(strvec);
492         if (!hwe->bl_product)
493                 return 1;
494
495         return 0;
496 }
497
498 static int
499 hw_pgpolicy_handler(vector strvec)
500 {
501         char * buff;
502         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
503
504         buff = set_value(strvec);
505
506         if (!buff)
507                 return 1;
508
509         hwe->pgpolicy = get_pgpolicy_id(buff);
510         FREE(buff);
511
512         return 0;
513 }
514
515 static int
516 hw_getuid_callout_handler(vector strvec)
517 {
518         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
519
520         hwe->getuid = set_value(strvec);
521
522         if (!hwe->getuid)
523                 return 1;
524
525         return 0;
526 }
527
528 static int
529 hw_selector_handler(vector strvec)
530 {
531         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
532         
533         if (!hwe)
534                 return 1;
535
536         hwe->selector = set_value(strvec);
537
538         if (!hwe->selector)
539                 return 1;
540
541         return 0;
542 }
543
544 static int
545 hw_path_checker_handler(vector strvec)
546 {
547         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
548
549         if (!hwe)
550                 return 1;
551
552         hwe->checker_name = set_value(strvec);
553
554         if (!hwe->checker_name)
555                 return 1;
556         
557         return 0;
558 }
559
560 static int
561 hw_features_handler(vector strvec)
562 {
563         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
564         
565         if (!hwe)
566                 return 1;
567
568         hwe->features = set_value(strvec);
569
570         if (!hwe->features)
571                 return 1;
572
573         return 0;
574 }
575
576 static int
577 hw_handler_handler(vector strvec)
578 {
579         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
580         
581         if (!hwe)
582                 return 1;
583
584         hwe->hwhandler = set_value(strvec);
585
586         if (!hwe->hwhandler)
587                 return 1;
588
589         return 0;
590 }
591
592 static int
593 hw_prio_handler(vector strvec)
594 {
595         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
596         char * buff;
597         
598         if (!hwe)
599                 return 1;
600
601         buff = set_value(strvec);
602         if (!buff)
603                 return 1;
604         
605         hwe->prio = prio_lookup(buff);
606         FREE(buff);
607         return 0;
608 }
609
610 static int
611 hw_failback_handler(vector strvec)
612 {
613         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
614         char * buff;
615
616         if (!hwe)
617                 return 1;
618
619         buff = set_value(strvec);
620
621         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
622                 hwe->pgfailback = -FAILBACK_MANUAL;
623         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
624                 hwe->pgfailback = -FAILBACK_IMMEDIATE;
625         else
626                 hwe->pgfailback = atoi(buff);
627
628         FREE(buff);
629
630         return 0;
631 }
632
633 static int
634 hw_weight_handler(vector strvec)
635 {
636         struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
637         char * buff;
638
639         if (!hwe)
640                 return 1;
641
642         buff = set_value(strvec);
643
644         if (!buff)
645                 return 1;
646
647         if (strlen(buff) == 10 &&
648             !strcmp(buff, "priorities"))
649                 hwe->rr_weight = RR_WEIGHT_PRIO;
650
651         FREE(buff);
652
653         return 0;
654 }
655
656 static int
657 hw_no_path_retry_handler(vector strvec)
658 {
659         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
660         char *buff;
661
662         if (!hwe)
663                 return 1;
664
665         buff = set_value(strvec);
666         if (!buff)
667                 return 1;
668
669         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
670             (strlen(buff) == 1 && !strcmp(buff, "0")))
671                 hwe->no_path_retry = NO_PATH_RETRY_FAIL;
672         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
673                 hwe->no_path_retry = NO_PATH_RETRY_QUEUE;
674         else if ((hwe->no_path_retry = atoi(buff)) < 1)
675                 hwe->no_path_retry = NO_PATH_RETRY_UNDEF;
676
677         FREE(buff);
678         return 0;
679 }
680
681 static int
682 hw_minio_handler(vector strvec)
683 {
684         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
685         char * buff;
686
687         if (!hwe)
688                 return 1;
689
690         buff = set_value(strvec);
691
692         if (!buff)
693                 return 1;
694
695         hwe->minio = atoi(buff);
696         FREE(buff);
697
698         return 0;
699 }
700
701 static int
702 hw_pg_timeout_handler(vector strvec)
703 {
704         int pg_timeout;
705         struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
706         char *buff;
707
708         if (!hwe)
709                 return 1;
710
711         buff = set_value(strvec);
712
713         if (!buff)
714                 return 1;
715
716         if (strlen(buff) == 4 && !strcmp(buff, "none"))
717                 hwe->pg_timeout = -PGTIMEOUT_NONE;
718         else if (sscanf(buff, "%d", &pg_timeout) == 1 && pg_timeout >= 0) {
719                 if (pg_timeout == 0)
720                         hwe->pg_timeout = -PGTIMEOUT_NONE;
721                 else
722                         hwe->pg_timeout = pg_timeout;
723         }
724         else
725                 hwe->pg_timeout = PGTIMEOUT_UNDEF;
726
727         FREE(buff);
728         return 0;
729 }
730
731 /*
732  * multipaths block handlers
733  */
734 static int
735 multipaths_handler(vector strvec)
736 {
737         conf->mptable = vector_alloc();
738
739         if (!conf->mptable)
740                 return 1;
741
742         return 0;
743 }
744
745 static int
746 multipath_handler(vector strvec)
747 {
748         struct mpentry * mpe;
749
750         mpe = (struct mpentry *)MALLOC(sizeof(struct mpentry));
751
752         if (!mpe)
753                 return 1;
754
755         if (!vector_alloc_slot(conf->mptable)) {
756                 FREE(mpe);
757                 return 1;
758         }
759         vector_set_slot(conf->mptable, mpe);
760
761         return 0;
762 }
763
764 static int
765 wwid_handler(vector strvec)
766 {
767         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
768
769         if (!mpe)
770                 return 1;
771
772         mpe->wwid = set_value(strvec);
773
774         if (!mpe->wwid)
775                 return 1;
776
777         return 0;
778 }
779
780 static int
781 alias_handler(vector strvec)
782 {
783         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
784
785         if (!mpe)
786                 return 1;
787
788         mpe->alias = set_value(strvec);
789
790         if (!mpe->alias)
791                 return 1;
792
793         return 0;
794 }
795
796 static int
797 mp_pgpolicy_handler(vector strvec)
798 {
799         char * buff;
800         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
801
802         if (!mpe)
803                 return 1;
804
805         buff = set_value(strvec);
806
807         if (!buff)
808                 return 1;
809
810         mpe->pgpolicy = get_pgpolicy_id(buff);
811         FREE(buff);
812
813         return 0;
814 }
815
816 static int
817 mp_selector_handler(vector strvec)
818 {
819         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
820         
821         if (!mpe)
822                 return 1;
823
824         mpe->selector = set_value(strvec);
825
826         if (!mpe->selector)
827                 return 1;
828
829         return 0;
830 }
831
832 static int
833 mp_failback_handler(vector strvec)
834 {
835         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
836         char * buff;
837
838         if (!mpe)
839                 return 1;
840
841         buff = set_value(strvec);
842
843         if (strlen(buff) == 6 && !strcmp(buff, "manual"))
844                 mpe->pgfailback = -FAILBACK_MANUAL;
845         else if (strlen(buff) == 9 && !strcmp(buff, "immediate"))
846                 mpe->pgfailback = -FAILBACK_IMMEDIATE;
847         else
848                 mpe->pgfailback = atoi(buff);
849
850         FREE(buff);
851
852         return 0;
853 }
854
855 static int
856 mp_weight_handler(vector strvec)
857 {
858         struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable);
859         char * buff;
860
861         if (!mpe)
862                 return 1;
863
864         buff = set_value(strvec);
865
866         if (!buff)
867                 return 1;
868
869         if (strlen(buff) == 10 &&
870             !strcmp(buff, "priorities"))
871                 mpe->rr_weight = RR_WEIGHT_PRIO;
872
873         FREE(buff);
874
875         return 0;
876 }
877
878 static int
879 mp_no_path_retry_handler(vector strvec)
880 {
881         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
882         char *buff;
883
884         if (!mpe)
885                 return 1;
886
887         buff = set_value(strvec);
888         if (!buff)
889                 return 1;
890
891         if ((strlen(buff) == 4 && !strcmp(buff, "fail")) ||
892             (strlen(buff) == 1 && !strcmp(buff, "0")))
893                 mpe->no_path_retry = NO_PATH_RETRY_FAIL;
894         else if (strlen(buff) == 5 && !strcmp(buff, "queue"))
895                 mpe->no_path_retry = NO_PATH_RETRY_QUEUE;
896         else if ((mpe->no_path_retry = atoi(buff)) < 1)
897                 mpe->no_path_retry = NO_PATH_RETRY_UNDEF;
898
899         FREE(buff);
900         return 0;
901 }
902
903 static int
904 mp_minio_handler(vector strvec)
905 {
906         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
907         char * buff;
908
909         if (!mpe)
910                 return 1;
911
912         buff = set_value(strvec);
913
914         if (!buff)
915                 return 1;
916
917         mpe->minio = atoi(buff);
918         FREE(buff);
919
920         return 0;
921 }
922
923 static int
924 mp_pg_timeout_handler(vector strvec)
925 {
926         int pg_timeout;
927         struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
928         char *buff;
929
930         if (!mpe)
931                 return 1;
932
933         buff = set_value(strvec);
934
935         if (!buff)
936                 return 1;
937         if (strlen(buff) == 4 && !strcmp(buff, "none"))
938                 mpe->pg_timeout = -PGTIMEOUT_NONE;
939         else if (sscanf(buff, "%d", &pg_timeout) == 1 && pg_timeout >= 0) {
940                 if (pg_timeout == 0)
941                         mpe->pg_timeout = -PGTIMEOUT_NONE;
942                 else
943                         mpe->pg_timeout = pg_timeout;
944         }
945         else
946                 mpe->pg_timeout = PGTIMEOUT_UNDEF;
947
948         FREE(buff);
949         return 0;
950 }
951
952 /*
953  * config file keywords printing
954  */
955 static int
956 snprint_mp_wwid (char * buff, int len, void * data)
957 {
958         struct mpentry * mpe = (struct mpentry *)data;
959
960         return snprintf(buff, len, "%s", mpe->wwid);
961 }
962
963 static int
964 snprint_mp_alias (char * buff, int len, void * data)
965 {
966         struct mpentry * mpe = (struct mpentry *)data;
967
968         if (!mpe->alias)
969                 return 0;
970
971         if (conf->user_friendly_names &&
972             (strlen(mpe->alias) == strlen("mpath")) &&
973             !strcmp(mpe->alias, "mpath"))
974                 return 0;
975
976         return snprintf(buff, len, "%s", mpe->alias);
977 }
978
979 static int
980 snprint_mp_path_grouping_policy (char * buff, int len, void * data)
981 {
982         struct mpentry * mpe = (struct mpentry *)data;
983         char str[POLICY_NAME_SIZE];
984
985         if (!mpe->pgpolicy)
986                 return 0;
987         get_pgpolicy_name(str, POLICY_NAME_SIZE, mpe->pgpolicy);
988         
989         return snprintf(buff, len, "%s", str);
990 }
991
992 static int
993 snprint_mp_selector (char * buff, int len, void * data)
994 {
995         struct mpentry * mpe = (struct mpentry *)data;
996
997         if (!mpe->selector)
998                 return 0;
999
1000         return snprintf(buff, len, "%s", mpe->selector);
1001 }
1002
1003 static int
1004 snprint_mp_failback (char * buff, int len, void * data)
1005 {
1006         struct mpentry * mpe = (struct mpentry *)data;
1007
1008         if (!mpe->pgfailback)
1009                 return 0;
1010
1011         switch(mpe->pgfailback) {
1012         case  FAILBACK_UNDEF:
1013                 break;
1014         case -FAILBACK_MANUAL:
1015                 return snprintf(buff, len, "manual");
1016         case -FAILBACK_IMMEDIATE:
1017                 return snprintf(buff, len, "immediate");
1018         default:
1019                 return snprintf(buff, len, "%i", mpe->pgfailback);
1020         }
1021         return 0;
1022 }
1023
1024 static int
1025 snprint_mp_rr_weight (char * buff, int len, void * data)
1026 {
1027         struct mpentry * mpe = (struct mpentry *)data;
1028
1029         if (!mpe->rr_weight)
1030                 return 0;
1031         if (mpe->rr_weight == RR_WEIGHT_PRIO)
1032                 return snprintf(buff, len, "priorities");
1033
1034         return 0;
1035 }
1036
1037 static int
1038 snprint_mp_no_path_retry (char * buff, int len, void * data)
1039 {
1040         struct mpentry * mpe = (struct mpentry *)data;
1041
1042         if (!mpe->no_path_retry)
1043                 return 0;
1044
1045         switch(mpe->no_path_retry) {
1046         case NO_PATH_RETRY_UNDEF:
1047                 break;
1048         case NO_PATH_RETRY_FAIL:
1049                 return snprintf(buff, len, "fail");
1050         case NO_PATH_RETRY_QUEUE:
1051                 return snprintf(buff, len, "queue");
1052         default:
1053                 return snprintf(buff, len, "%i",
1054                                 mpe->no_path_retry);
1055         }
1056         return 0;
1057 }
1058
1059 static int
1060 snprint_mp_rr_min_io (char * buff, int len, void * data)
1061 {
1062         struct mpentry * mpe = (struct mpentry *)data;
1063
1064         if (!mpe->minio)
1065                 return 0;
1066
1067         return snprintf(buff, len, "%u", mpe->minio);
1068 }
1069
1070 static int
1071 snprint_mp_pg_timeout (char * buff, int len, void * data)
1072 {
1073         struct mpentry * mpe = (struct mpentry *)data;
1074
1075         switch (mpe->pg_timeout) {
1076         case PGTIMEOUT_UNDEF:
1077                 break;
1078         case -PGTIMEOUT_NONE:
1079                 return snprintf(buff, len, "none");
1080         default:
1081                 return snprintf(buff, len, "%i", mpe->pg_timeout);
1082         }
1083         return 0;
1084 }
1085
1086 static int
1087 snprint_hw_vendor (char * buff, int len, void * data)
1088 {
1089         struct hwentry * hwe = (struct hwentry *)data;
1090
1091         if (!hwe->vendor)
1092                 return 0;
1093
1094         return snprintf(buff, len, "%s", hwe->vendor);
1095 }
1096
1097 static int
1098 snprint_hw_product (char * buff, int len, void * data)
1099 {
1100         struct hwentry * hwe = (struct hwentry *)data;
1101
1102         if (!hwe->product)
1103                 return 0;
1104
1105         return snprintf(buff, len, "%s", hwe->product);
1106 }
1107
1108 static int
1109 snprint_hw_bl_product (char * buff, int len, void * data)
1110 {
1111         struct hwentry * hwe = (struct hwentry *)data;
1112
1113         if (!hwe->bl_product)
1114                 return 0;
1115
1116         return snprintf(buff, len, "%s", hwe->bl_product);
1117 }
1118
1119 static int
1120 snprint_hw_getuid_callout (char * buff, int len, void * data)
1121 {
1122         struct hwentry * hwe = (struct hwentry *)data;
1123
1124         if (!hwe->getuid)
1125                 return 0;
1126         if (strlen(hwe->getuid) == strlen(conf->getuid) &&
1127             !strcmp(hwe->getuid, conf->getuid))
1128                 return 0;
1129
1130         return snprintf(buff, len, "%s", hwe->getuid);
1131 }
1132
1133 static int
1134 snprint_hw_prio (char * buff, int len, void * data)
1135 {
1136         struct hwentry * hwe = (struct hwentry *)data;
1137
1138         if (!hwe->prio)
1139                 return 0;
1140         if (hwe->prio == conf->prio)
1141                 return 0;
1142         
1143         return snprintf(buff, len, "%s", prio_name(hwe->prio));
1144 }
1145
1146 static int
1147 snprint_hw_features (char * buff, int len, void * data)
1148 {
1149         struct hwentry * hwe = (struct hwentry *)data;
1150
1151         if (!hwe->features)
1152                 return 0;
1153         if (strlen(hwe->features) == strlen(conf->features) &&
1154             !strcmp(hwe->features, conf->features))
1155                 return 0;
1156
1157         return snprintf(buff, len, "%s", hwe->features);
1158 }
1159
1160 static int
1161 snprint_hw_hardware_handler (char * buff, int len, void * data)
1162 {
1163         struct hwentry * hwe = (struct hwentry *)data;
1164
1165         if (!hwe->hwhandler)
1166                 return 0;
1167         if (strlen(hwe->hwhandler) == strlen(conf->hwhandler) &&
1168             !strcmp(hwe->hwhandler, conf->hwhandler))
1169                 return 0;
1170
1171         return snprintf(buff, len, "%s", hwe->hwhandler);
1172 }
1173
1174 static int
1175 snprint_hw_selector (char * buff, int len, void * data)
1176 {
1177         struct hwentry * hwe = (struct hwentry *)data;
1178
1179         if (!hwe->selector)
1180                 return 0;
1181         if (strlen(hwe->selector) == strlen(conf->selector) &&
1182             !strcmp(hwe->selector, conf->selector))
1183                 return 0;
1184
1185         return snprintf(buff, len, "%s", hwe->selector);
1186 }
1187
1188 static int
1189 snprint_hw_path_grouping_policy (char * buff, int len, void * data)
1190 {
1191         struct hwentry * hwe = (struct hwentry *)data;
1192
1193         char str[POLICY_NAME_SIZE];
1194
1195         if (!hwe->pgpolicy)
1196                 return 0;
1197         if (hwe->pgpolicy == conf->pgpolicy)
1198                 return 0;
1199
1200         get_pgpolicy_name(str, POLICY_NAME_SIZE, hwe->pgpolicy);
1201         
1202         return snprintf(buff, len, "%s", str);
1203 }
1204
1205 static int
1206 snprint_hw_failback (char * buff, int len, void * data)
1207 {
1208         struct hwentry * hwe = (struct hwentry *)data;
1209
1210         if (!hwe->pgfailback)
1211                 return 0;
1212         if (hwe->pgfailback == conf->pgfailback)
1213                 return 0;
1214
1215         switch(hwe->pgfailback) {
1216         case  FAILBACK_UNDEF:
1217                 break;
1218         case -FAILBACK_MANUAL:
1219                 return snprintf(buff, len, "manual");
1220         case -FAILBACK_IMMEDIATE:
1221                 return snprintf(buff, len, "immediate");
1222         default:
1223                 return snprintf(buff, len, "%i", hwe->pgfailback);
1224         }
1225         return 0;
1226 }
1227
1228 static int
1229 snprint_hw_rr_weight (char * buff, int len, void * data)
1230 {
1231         struct hwentry * hwe = (struct hwentry *)data;
1232
1233         if (!hwe->rr_weight)
1234                 return 0;
1235         if (hwe->rr_weight == conf->rr_weight)
1236                 return 0;
1237         if (hwe->rr_weight == RR_WEIGHT_PRIO)
1238                 return snprintf(buff, len, "priorities");
1239
1240         return 0;
1241 }
1242
1243 static int
1244 snprint_hw_no_path_retry (char * buff, int len, void * data)
1245 {
1246         struct hwentry * hwe = (struct hwentry *)data;
1247
1248         if (!hwe->no_path_retry)
1249                 return 0;
1250         if (hwe->no_path_retry == conf->no_path_retry)
1251                 return 0;
1252
1253         switch(hwe->no_path_retry) {
1254         case NO_PATH_RETRY_UNDEF:
1255                 break;
1256         case NO_PATH_RETRY_FAIL:
1257                 return snprintf(buff, len, "fail");
1258         case NO_PATH_RETRY_QUEUE:
1259                 return snprintf(buff, len, "queue");
1260         default:
1261                 return snprintf(buff, len, "%i",
1262                                 hwe->no_path_retry);
1263         }
1264         return 0;
1265 }
1266
1267 static int
1268 snprint_hw_rr_min_io (char * buff, int len, void * data)
1269 {
1270         struct hwentry * hwe = (struct hwentry *)data;
1271
1272         if (!hwe->minio)
1273                 return 0;
1274         if (hwe->minio == conf->minio)
1275                 return 0;
1276
1277         return snprintf(buff, len, "%u", hwe->minio);
1278 }
1279
1280 static int
1281 snprint_hw_pg_timeout (char * buff, int len, void * data)
1282 {
1283         struct hwentry * hwe = (struct hwentry *)data;
1284
1285         if (!hwe->pg_timeout)
1286                 return 0;
1287         if (hwe->pg_timeout == conf->pg_timeout)
1288                 return 0;
1289
1290         switch (hwe->pg_timeout) {
1291         case PGTIMEOUT_UNDEF:
1292                 break;
1293         case -PGTIMEOUT_NONE:
1294                 return snprintf(buff, len, "none");
1295         default:
1296                 return snprintf(buff, len, "%i", hwe->pg_timeout);
1297         }
1298         return 0;
1299 }
1300
1301 static int
1302 snprint_hw_path_checker (char * buff, int len, void * data)
1303 {
1304         struct hwentry * hwe = (struct hwentry *)data;
1305
1306         if (!hwe->checker_name)
1307                 return 0;
1308         if (!strcmp(hwe->checker_name, conf->checker_name))
1309                 return 0;
1310         
1311         return snprintf(buff, len, "%s", hwe->checker_name);
1312 }
1313
1314 static int
1315 snprint_def_polling_interval (char * buff, int len, void * data)
1316 {
1317         if (conf->checkint == DEFAULT_CHECKINT)
1318                 return 0;
1319         return snprintf(buff, len, "%i", conf->checkint);
1320 }
1321
1322 static int
1323 snprint_def_udev_dir (char * buff, int len, void * data)
1324 {
1325         if (!conf->udev_dir)
1326                 return 0;
1327         if (strlen(DEFAULT_UDEVDIR) == strlen(conf->udev_dir) &&
1328             !strcmp(conf->udev_dir, DEFAULT_UDEVDIR))
1329                 return 0;
1330
1331         return snprintf(buff, len, "%s", conf->udev_dir);
1332 }
1333
1334 static int
1335 snprint_def_multipath_dir (char * buff, int len, void * data)
1336 {
1337         if (!conf->udev_dir)
1338                 return 0;
1339         if (strlen(DEFAULT_MULTIPATHDIR) == strlen(conf->multipath_dir) &&
1340             !strcmp(conf->multipath_dir, DEFAULT_MULTIPATHDIR))
1341                 return 0;
1342
1343         return snprintf(buff, len, "%s", conf->multipath_dir);
1344 }
1345
1346 static int
1347 snprint_def_selector (char * buff, int len, void * data)
1348 {
1349         if (!conf->selector)
1350                 return 0;
1351         if (strlen(conf->selector) == strlen(DEFAULT_SELECTOR) &&
1352             !strcmp(conf->selector, DEFAULT_SELECTOR))
1353                 return 0;
1354
1355         return snprintf(buff, len, "%s", conf->selector);
1356 }
1357
1358 static int
1359 snprint_def_path_grouping_policy (char * buff, int len, void * data)
1360 {
1361         char str[POLICY_NAME_SIZE];
1362
1363         if (!conf->pgpolicy)
1364                 return 0;
1365         if (conf->pgpolicy == DEFAULT_PGPOLICY)
1366                 return 0;
1367
1368         get_pgpolicy_name(str, POLICY_NAME_SIZE, conf->pgpolicy);
1369         
1370         return snprintf(buff, len, "%s", str);
1371 }
1372
1373 static int
1374 snprint_def_getuid_callout (char * buff, int len, void * data)
1375 {
1376         if (!conf->getuid)
1377                 return 0;
1378         if (strlen(conf->getuid) == strlen(DEFAULT_GETUID) &&
1379             !strcmp(conf->getuid, DEFAULT_GETUID))
1380                 return 0;
1381
1382         return snprintf(buff, len, "%s", conf->getuid);
1383 }
1384
1385 static int
1386 snprint_def_prio (char * buff, int len, void * data)
1387 {
1388         if (!conf->prio)
1389                 return 0;
1390
1391         return snprintf(buff, len, "%s", prio_name(conf->prio));
1392 }
1393
1394 static int
1395 snprint_def_features (char * buff, int len, void * data)
1396 {
1397         if (!conf->features)
1398                 return 0;
1399         if (strlen(conf->features) == strlen(DEFAULT_FEATURES) &&
1400             !strcmp(conf->features, DEFAULT_FEATURES))
1401                 return 0;
1402
1403         return snprintf(buff, len, "%s", conf->features);
1404 }
1405
1406 static int
1407 snprint_def_path_checker (char * buff, int len, void * data)
1408 {
1409         if (!conf->checker_name)
1410                 return 0;
1411         if (strlen(conf->checker_name) == strlen(DEFAULT_CHECKER) &&
1412             !strcmp(conf->checker_name, DEFAULT_CHECKER))
1413                 return 0;
1414         
1415         return snprintf(buff, len, "%s", conf->checker_name);
1416 }
1417
1418 static int
1419 snprint_def_failback (char * buff, int len, void * data)
1420 {
1421         if (!conf->pgfailback)
1422                 return 0;
1423         if (conf->pgfailback == DEFAULT_FAILBACK)
1424                 return 0;
1425
1426         switch(conf->pgfailback) {
1427         case  FAILBACK_UNDEF:
1428                 break;
1429         case -FAILBACK_MANUAL:
1430                 return snprintf(buff, len, "manual");
1431         case -FAILBACK_IMMEDIATE:
1432                 return snprintf(buff, len, "immediate");
1433         default:
1434                 return snprintf(buff, len, "%i", conf->pgfailback);
1435         }
1436         return 0;
1437 }
1438
1439 static int
1440 snprint_def_rr_min_io (char * buff, int len, void * data)
1441 {
1442         if (!conf->minio)
1443                 return 0;
1444         if (conf->minio == DEFAULT_MINIO)
1445                 return 0;
1446
1447         return snprintf(buff, len, "%u", conf->minio);
1448 }
1449
1450 static int
1451 snprint_max_fds (char * buff, int len, void * data)
1452 {
1453         if (!conf->max_fds)
1454                 return 0;
1455
1456         if (conf->max_fds < 0)
1457                 return snprintf(buff, len, "unlimited");        
1458         return snprintf(buff, len, "%d", conf->max_fds);
1459 }
1460
1461 static int
1462 snprint_def_rr_weight (char * buff, int len, void * data)
1463 {
1464         if (!conf->rr_weight)
1465                 return 0;
1466         if (conf->rr_weight == DEFAULT_RR_WEIGHT)
1467                 return 0;
1468         if (conf->rr_weight == RR_WEIGHT_PRIO)
1469                 return snprintf(buff, len, "priorities");
1470
1471         return 0;
1472 }
1473
1474 static int
1475 snprint_def_no_path_retry (char * buff, int len, void * data)
1476 {
1477         if (conf->no_path_retry == DEFAULT_NO_PATH_RETRY)
1478                 return 0;
1479
1480         switch(conf->no_path_retry) {
1481         case NO_PATH_RETRY_UNDEF:
1482                 break;
1483         case NO_PATH_RETRY_FAIL:
1484                 return snprintf(buff, len, "fail");
1485         case NO_PATH_RETRY_QUEUE:
1486                 return snprintf(buff, len, "queue");
1487         default:
1488                 return snprintf(buff, len, "%i",
1489                                 conf->no_path_retry);
1490         }
1491         return 0;
1492 }
1493
1494 static int
1495 snprint_def_pg_timeout (char * buff, int len, void * data)
1496 {
1497         if (conf->pg_timeout == DEFAULT_PGTIMEOUT)
1498                 return 0;
1499
1500         switch (conf->pg_timeout) {
1501         case PGTIMEOUT_UNDEF:
1502                 break;
1503         case -PGTIMEOUT_NONE:
1504                 return snprintf(buff, len, "none");
1505         default:
1506                 return snprintf(buff, len, "%i", conf->pg_timeout);
1507         }
1508         return 0;
1509 }
1510
1511 static int
1512 snprint_def_user_friendly_names (char * buff, int len, void * data)
1513 {
1514         if (conf->user_friendly_names == DEFAULT_USER_FRIENDLY_NAMES)
1515                 return 0;
1516         if (!conf->user_friendly_names)
1517                 return snprintf(buff, len, "no");
1518
1519         return snprintf(buff, len, "yes");
1520 }
1521
1522 static int
1523 snprint_ble_simple (char * buff, int len, void * data)
1524 {
1525         struct blentry * ble = (struct blentry *)data;
1526
1527         return snprintf(buff, len, "%s", ble->str);
1528 }
1529
1530 static int
1531 snprint_bled_vendor (char * buff, int len, void * data)
1532 {
1533         struct blentry_device * bled = (struct blentry_device *)data;
1534
1535         return snprintf(buff, len, "%s", bled->vendor);
1536 }
1537         
1538 static int
1539 snprint_bled_product (char * buff, int len, void * data)
1540 {
1541         struct blentry_device * bled = (struct blentry_device *)data;
1542
1543         return snprintf(buff, len, "%s", bled->product);
1544 }
1545         
1546 #define __deprecated
1547
1548 void
1549 init_keywords(void)
1550 {
1551         install_keyword_root("defaults", NULL);
1552         install_keyword("polling_interval", &polling_interval_handler, &snprint_def_polling_interval);
1553         install_keyword("udev_dir", &udev_dir_handler, &snprint_def_udev_dir);
1554         install_keyword("multipath_dir", &multipath_dir_handler, &snprint_def_multipath_dir);
1555         install_keyword("selector", &def_selector_handler, &snprint_def_selector);
1556         install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_path_grouping_policy);
1557         install_keyword("getuid_callout", &def_getuid_callout_handler, &snprint_def_getuid_callout);
1558         install_keyword("prio", &def_prio_handler, &snprint_def_prio);
1559         install_keyword("features", &def_features_handler, &snprint_def_features);
1560         install_keyword("path_checker", &def_path_checker_handler, &snprint_def_path_checker);
1561         install_keyword("checker", &def_path_checker_handler, &snprint_def_path_checker);
1562         install_keyword("failback", &default_failback_handler, &snprint_def_failback);
1563         install_keyword("rr_min_io", &def_minio_handler, &snprint_def_rr_min_io);
1564         install_keyword("max_fds", &max_fds_handler, &snprint_max_fds);
1565         install_keyword("rr_weight", &def_weight_handler, &snprint_def_rr_weight);
1566         install_keyword("no_path_retry", &def_no_path_retry_handler, &snprint_def_no_path_retry);
1567         install_keyword("pg_timeout", &def_pg_timeout_handler, &snprint_def_pg_timeout);
1568         install_keyword("user_friendly_names", &names_handler, &snprint_def_user_friendly_names);
1569         __deprecated install_keyword("default_selector", &def_selector_handler, NULL);
1570         __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
1571         __deprecated install_keyword("default_getuid_callout", &def_getuid_callout_handler, NULL);
1572         __deprecated install_keyword("default_features", &def_features_handler, NULL);
1573         __deprecated install_keyword("default_path_checker", &def_path_checker_handler, NULL);
1574
1575         install_keyword_root("blacklist", &blacklist_handler);
1576         install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
1577         install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
1578         install_keyword("device", &ble_device_handler, NULL);
1579         install_sublevel();
1580         install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
1581         install_keyword("product", &ble_product_handler, &snprint_bled_product);
1582         install_sublevel_end();
1583         install_keyword_root("blacklist_exceptions", &blacklist_exceptions_handler);
1584         install_keyword("devnode", &ble_except_devnode_handler, &snprint_ble_simple);
1585         install_keyword("wwid", &ble_except_wwid_handler, &snprint_ble_simple);
1586         install_keyword("device", &ble_except_device_handler, NULL);
1587         install_sublevel();
1588         install_keyword("vendor", &ble_except_vendor_handler, &snprint_bled_vendor);
1589         install_keyword("product", &ble_except_product_handler, &snprint_bled_product);
1590         install_sublevel_end();
1591
1592 #if 0
1593         __deprecated install_keyword_root("devnode_blacklist", &blacklist_handler);
1594         __deprecated install_keyword("devnode", &ble_devnode_handler, &snprint_ble_simple);
1595         __deprecated install_keyword("wwid", &ble_wwid_handler, &snprint_ble_simple);
1596         __deprecated install_keyword("device", &ble_device_handler, NULL);
1597         __deprecated install_sublevel();
1598         __deprecated install_keyword("vendor", &ble_vendor_handler, &snprint_bled_vendor);
1599         __deprecated install_keyword("product", &ble_product_handler, &snprint_bled_product);
1600         __deprecated install_sublevel_end();
1601 #endif
1602
1603         install_keyword_root("devices", &devices_handler);
1604         install_keyword("device", &device_handler, NULL);
1605         install_sublevel();
1606         install_keyword("vendor", &vendor_handler, &snprint_hw_vendor);
1607         install_keyword("product", &product_handler, &snprint_hw_product);
1608         install_keyword("product_blacklist", &bl_product_handler, &snprint_hw_bl_product);
1609         install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_path_grouping_policy);
1610         install_keyword("getuid_callout", &hw_getuid_callout_handler, &snprint_hw_getuid_callout);
1611         install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
1612         install_keyword("path_checker", &hw_path_checker_handler, &snprint_hw_path_checker);
1613         install_keyword("checker", &hw_path_checker_handler, &snprint_hw_path_checker);
1614         install_keyword("features", &hw_features_handler, &snprint_hw_features);
1615         install_keyword("hardware_handler", &hw_handler_handler, &snprint_hw_hardware_handler);
1616         install_keyword("prio", &hw_prio_handler, &snprint_hw_prio);
1617         install_keyword("failback", &hw_failback_handler, &snprint_hw_failback);
1618         install_keyword("rr_weight", &hw_weight_handler, &snprint_hw_rr_weight);
1619         install_keyword("no_path_retry", &hw_no_path_retry_handler, &snprint_hw_no_path_retry);
1620         install_keyword("rr_min_io", &hw_minio_handler, &snprint_hw_rr_min_io);
1621         install_keyword("pg_timeout", &hw_pg_timeout_handler, &snprint_hw_pg_timeout);
1622         install_sublevel_end();
1623
1624         install_keyword_root("multipaths", &multipaths_handler);
1625         install_keyword("multipath", &multipath_handler, NULL);
1626         install_sublevel();
1627         install_keyword("wwid", &wwid_handler, &snprint_mp_wwid);
1628         install_keyword("alias", &alias_handler, &snprint_mp_alias);
1629         install_keyword("path_grouping_policy", &mp_pgpolicy_handler, &snprint_mp_path_grouping_policy);
1630         install_keyword("path_selector", &mp_selector_handler, &snprint_mp_selector);
1631         install_keyword("failback", &mp_failback_handler, &snprint_mp_failback);
1632         install_keyword("rr_weight", &mp_weight_handler, &snprint_mp_rr_weight);
1633         install_keyword("no_path_retry", &mp_no_path_retry_handler, &snprint_mp_no_path_retry);
1634         install_keyword("rr_min_io", &mp_minio_handler, &snprint_mp_rr_min_io);
1635         install_keyword("pg_timeout", &mp_pg_timeout_handler, &snprint_mp_pg_timeout);
1636         install_sublevel_end();
1637 }