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