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