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