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