54a49b1af3a46489610e7d95eb0c355577bcff65
[multipath-tools/.git] / libmultipath / config.c
1 /*
2  * Copyright (c) 2004, 2005 Christophe Varoqui
3  * Copyright (c) 2005 Benjamin Marzinski, Redhat
4  * Copyright (c) 2005 Edward Goggin, EMC
5  */
6 #include <stdio.h>
7 #include <string.h>
8 #include <libudev.h>
9 #include <dirent.h>
10 #include <limits.h>
11 #include <errno.h>
12
13 #include "checkers.h"
14 #include "memory.h"
15 #include "util.h"
16 #include "debug.h"
17 #include "parser.h"
18 #include "dict.h"
19 #include "hwtable.h"
20 #include "vector.h"
21 #include "structs.h"
22 #include "config.h"
23 #include "blacklist.h"
24 #include "defaults.h"
25 #include "prio.h"
26 #include "devmapper.h"
27 #include "mpath_cmd.h"
28 #include "propsel.h"
29
30 static int
31 hwe_strmatch (const struct hwentry *hwe1, const struct hwentry *hwe2)
32 {
33         if ((hwe2->vendor && !hwe1->vendor) ||
34             (hwe1->vendor && (!hwe2->vendor ||
35                               strcmp(hwe1->vendor, hwe2->vendor))))
36                 return 1;
37
38         if ((hwe2->product && !hwe1->product) ||
39             (hwe1->product && (!hwe2->product ||
40                               strcmp(hwe1->product, hwe2->product))))
41                 return 1;
42
43         if ((hwe2->revision && !hwe1->revision) ||
44             (hwe1->revision && (!hwe2->revision ||
45                               strcmp(hwe1->revision, hwe2->revision))))
46                 return 1;
47
48         return 0;
49 }
50
51 static struct hwentry *
52 find_hwe_strmatch (const struct _vector *hwtable, const struct hwentry *hwe)
53 {
54         int i;
55         struct hwentry *tmp, *ret = NULL;
56
57         vector_foreach_slot (hwtable, tmp, i) {
58                 if (hwe_strmatch(tmp, hwe))
59                         continue;
60                 ret = tmp;
61                 break;
62         }
63         return ret;
64 }
65
66 static int
67 hwe_regmatch (const struct hwentry *hwe1, const char *vendor,
68               const char *product, const char *revision)
69 {
70         regex_t vre, pre, rre;
71         int retval = 1;
72
73         if (hwe1->vendor &&
74             regcomp(&vre, hwe1->vendor, REG_EXTENDED|REG_NOSUB))
75                 goto out;
76
77         if (hwe1->product &&
78             regcomp(&pre, hwe1->product, REG_EXTENDED|REG_NOSUB))
79                 goto out_vre;
80
81         if (hwe1->revision &&
82             regcomp(&rre, hwe1->revision, REG_EXTENDED|REG_NOSUB))
83                 goto out_pre;
84
85         if ((vendor || product || revision) &&
86             (!hwe1->vendor || !vendor ||
87              !regexec(&vre, vendor, 0, NULL, 0)) &&
88             (!hwe1->product || !product ||
89              !regexec(&pre, product, 0, NULL, 0)) &&
90             (!hwe1->revision || !revision ||
91              !regexec(&rre, revision, 0, NULL, 0)))
92                 retval = 0;
93
94         if (hwe1->revision)
95                 regfree(&rre);
96 out_pre:
97         if (hwe1->product)
98                 regfree(&pre);
99 out_vre:
100         if (hwe1->vendor)
101                 regfree(&vre);
102 out:
103         return retval;
104 }
105
106 static void _log_match(const char *fn, const struct hwentry *h,
107                        const char *vendor, const char *product,
108                        const char *revision)
109 {
110         condlog(4, "%s: found match /%s:%s:%s/ for '%s:%s:%s'", fn,
111                 h->vendor, h->product, h->revision,
112                 vendor, product, revision);
113 }
114 #define log_match(h, v, p, r) _log_match(__func__, (h), (v), (p), (r))
115
116 int
117 find_hwe (const struct _vector *hwtable,
118           const char * vendor, const char * product, const char * revision,
119           vector result)
120 {
121         int i, n = 0;
122         struct hwentry *tmp;
123
124         /*
125          * Search backwards here, and add forward.
126          * User modified entries are attached at the end of
127          * the list, so we have to check them first before
128          * continuing to the generic entries
129          */
130         vector_reset(result);
131         vector_foreach_slot_backwards (hwtable, tmp, i) {
132                 if (hwe_regmatch(tmp, vendor, product, revision))
133                         continue;
134                 if (vector_alloc_slot(result) != NULL) {
135                         vector_set_slot(result, tmp);
136                         n++;
137                 }
138                 log_match(tmp, vendor, product, revision);
139         }
140         condlog(n > 1 ? 3 : 4, "%s: found %d hwtable matches for %s:%s:%s",
141                 __func__, n, vendor, product, revision);
142         return n;
143 }
144
145 struct mpentry *find_mpe(vector mptable, char *wwid)
146 {
147         int i;
148         struct mpentry * mpe;
149
150         if (!wwid)
151                 return NULL;
152
153         vector_foreach_slot (mptable, mpe, i)
154                 if (mpe->wwid && !strcmp(mpe->wwid, wwid))
155                         return mpe;
156
157         return NULL;
158 }
159
160 char *get_mpe_wwid(vector mptable, char *alias)
161 {
162         int i;
163         struct mpentry * mpe;
164
165         if (!alias)
166                 return NULL;
167
168         vector_foreach_slot (mptable, mpe, i)
169                 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
170                         return mpe->wwid;
171
172         return NULL;
173 }
174
175 void
176 free_hwe (struct hwentry * hwe)
177 {
178         if (!hwe)
179                 return;
180
181         if (hwe->vendor)
182                 FREE(hwe->vendor);
183
184         if (hwe->product)
185                 FREE(hwe->product);
186
187         if (hwe->revision)
188                 FREE(hwe->revision);
189
190         if (hwe->getuid)
191                 FREE(hwe->getuid);
192
193         if (hwe->uid_attribute)
194                 FREE(hwe->uid_attribute);
195
196         if (hwe->features)
197                 FREE(hwe->features);
198
199         if (hwe->hwhandler)
200                 FREE(hwe->hwhandler);
201
202         if (hwe->selector)
203                 FREE(hwe->selector);
204
205         if (hwe->checker_name)
206                 FREE(hwe->checker_name);
207
208         if (hwe->prio_name)
209                 FREE(hwe->prio_name);
210
211         if (hwe->prio_args)
212                 FREE(hwe->prio_args);
213
214         if (hwe->alias_prefix)
215                 FREE(hwe->alias_prefix);
216
217         if (hwe->bl_product)
218                 FREE(hwe->bl_product);
219
220         FREE(hwe);
221 }
222
223 void
224 free_hwtable (vector hwtable)
225 {
226         int i;
227         struct hwentry * hwe;
228
229         if (!hwtable)
230                 return;
231
232         vector_foreach_slot (hwtable, hwe, i)
233                 free_hwe(hwe);
234
235         vector_free(hwtable);
236 }
237
238 void
239 free_mpe (struct mpentry * mpe)
240 {
241         if (!mpe)
242                 return;
243
244         if (mpe->wwid)
245                 FREE(mpe->wwid);
246
247         if (mpe->selector)
248                 FREE(mpe->selector);
249
250         if (mpe->getuid)
251                 FREE(mpe->getuid);
252
253         if (mpe->uid_attribute)
254                 FREE(mpe->uid_attribute);
255
256         if (mpe->alias)
257                 FREE(mpe->alias);
258
259         if (mpe->prio_name)
260                 FREE(mpe->prio_name);
261
262         if (mpe->prio_args)
263                 FREE(mpe->prio_args);
264
265         FREE(mpe);
266 }
267
268 void
269 free_mptable (vector mptable)
270 {
271         int i;
272         struct mpentry * mpe;
273
274         if (!mptable)
275                 return;
276
277         vector_foreach_slot (mptable, mpe, i)
278                 free_mpe(mpe);
279
280         vector_free(mptable);
281 }
282
283 struct mpentry *
284 alloc_mpe (void)
285 {
286         struct mpentry * mpe = (struct mpentry *)
287                                 MALLOC(sizeof(struct mpentry));
288
289         return mpe;
290 }
291
292 struct hwentry *
293 alloc_hwe (void)
294 {
295         struct hwentry * hwe = (struct hwentry *)
296                                 MALLOC(sizeof(struct hwentry));
297
298         return hwe;
299 }
300
301 static char *
302 set_param_str(const char * str)
303 {
304         char * dst;
305         int len;
306
307         if (!str)
308                 return NULL;
309
310         len = strlen(str);
311
312         if (!len)
313                 return NULL;
314
315         dst = (char *)MALLOC(len + 1);
316
317         if (!dst)
318                 return NULL;
319
320         strcpy(dst, str);
321         return dst;
322 }
323
324 #define merge_str(s) \
325         if (!dst->s && src->s) { \
326                 if (!(dst->s = set_param_str(src->s))) \
327                         return 1; \
328         }
329
330 #define merge_num(s) \
331         if (!dst->s && src->s) \
332                 dst->s = src->s
333
334
335 static int
336 merge_hwe (struct hwentry * dst, struct hwentry * src)
337 {
338         char id[SCSI_VENDOR_SIZE+PATH_PRODUCT_SIZE];
339         merge_str(vendor);
340         merge_str(product);
341         merge_str(revision);
342         merge_str(getuid);
343         merge_str(uid_attribute);
344         merge_str(features);
345         merge_str(hwhandler);
346         merge_str(selector);
347         merge_str(checker_name);
348         merge_str(prio_name);
349         merge_str(prio_args);
350         merge_str(alias_prefix);
351         merge_str(bl_product);
352         merge_num(pgpolicy);
353         merge_num(pgfailback);
354         merge_num(rr_weight);
355         merge_num(no_path_retry);
356         merge_num(minio);
357         merge_num(minio_rq);
358         merge_num(flush_on_last_del);
359         merge_num(fast_io_fail);
360         merge_num(dev_loss);
361         merge_num(user_friendly_names);
362         merge_num(retain_hwhandler);
363         merge_num(detect_prio);
364         merge_num(detect_checker);
365         merge_num(deferred_remove);
366         merge_num(delay_watch_checks);
367         merge_num(delay_wait_checks);
368         merge_num(skip_kpartx);
369         merge_num(max_sectors_kb);
370         merge_num(ghost_delay);
371         merge_num(all_tg_pt);
372         merge_num(san_path_err_threshold);
373         merge_num(san_path_err_forget_rate);
374         merge_num(san_path_err_recovery_time);
375         merge_num(marginal_path_err_sample_time);
376         merge_num(marginal_path_err_rate_threshold);
377         merge_num(marginal_path_err_recheck_gap_time);
378         merge_num(marginal_path_double_failed_time);
379
380         snprintf(id, sizeof(id), "%s/%s", dst->vendor, dst->product);
381         reconcile_features_with_options(id, &dst->features,
382                                         &dst->no_path_retry,
383                                         &dst->retain_hwhandler);
384         return 0;
385 }
386
387 static int
388 merge_mpe(struct mpentry *dst, struct mpentry *src)
389 {
390         if (!dst || !src)
391                 return 1;
392
393         merge_str(alias);
394         merge_str(uid_attribute);
395         merge_str(getuid);
396         merge_str(selector);
397         merge_str(features);
398         merge_str(prio_name);
399         merge_str(prio_args);
400
401         if (dst->prkey_source == PRKEY_SOURCE_NONE &&
402             src->prkey_source != PRKEY_SOURCE_NONE) {
403                 dst->prkey_source = src->prkey_source;
404                 dst->sa_flags = src->sa_flags;
405                 memcpy(&dst->reservation_key, &src->reservation_key,
406                        sizeof(dst->reservation_key));
407         }
408
409         merge_num(pgpolicy);
410         merge_num(pgfailback);
411         merge_num(rr_weight);
412         merge_num(no_path_retry);
413         merge_num(minio);
414         merge_num(minio_rq);
415         merge_num(flush_on_last_del);
416         merge_num(attribute_flags);
417         merge_num(user_friendly_names);
418         merge_num(deferred_remove);
419         merge_num(delay_watch_checks);
420         merge_num(delay_wait_checks);
421         merge_num(san_path_err_threshold);
422         merge_num(san_path_err_forget_rate);
423         merge_num(san_path_err_recovery_time);
424         merge_num(marginal_path_err_sample_time);
425         merge_num(marginal_path_err_rate_threshold);
426         merge_num(marginal_path_err_recheck_gap_time);
427         merge_num(marginal_path_double_failed_time);
428         merge_num(skip_kpartx);
429         merge_num(max_sectors_kb);
430         merge_num(ghost_delay);
431         merge_num(uid);
432         merge_num(gid);
433         merge_num(mode);
434
435         return 0;
436 }
437
438 void merge_mptable(vector mptable)
439 {
440         struct mpentry *mp1, *mp2;
441         int i, j;
442
443         vector_foreach_slot(mptable, mp1, i) {
444                 j = i + 1;
445                 vector_foreach_slot_after(mptable, mp2, j) {
446                         if (strcmp(mp1->wwid, mp2->wwid))
447                                 continue;
448                         condlog(1, "%s: duplicate multipath config section for %s",
449                                 __func__, mp1->wwid);
450                         merge_mpe(mp2, mp1);
451                         free_mpe(mp1);
452                         vector_del_slot(mptable, i);
453                         i--;
454                         break;
455                 }
456         }
457 }
458
459 int
460 store_hwe (vector hwtable, struct hwentry * dhwe)
461 {
462         struct hwentry * hwe;
463
464         if (find_hwe_strmatch(hwtable, dhwe))
465                 return 0;
466
467         if (!(hwe = alloc_hwe()))
468                 return 1;
469
470         if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
471                 goto out;
472
473         if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
474                 goto out;
475
476         if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
477                 goto out;
478
479         if (dhwe->uid_attribute && !(hwe->uid_attribute = set_param_str(dhwe->uid_attribute)))
480                 goto out;
481
482         if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
483                 goto out;
484
485         if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
486                 goto out;
487
488         if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
489                 goto out;
490
491         if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
492                 goto out;
493
494         if (dhwe->checker_name && !(hwe->checker_name = set_param_str(dhwe->checker_name)))
495                 goto out;
496
497         if (dhwe->prio_name && !(hwe->prio_name = set_param_str(dhwe->prio_name)))
498                 goto out;
499
500         if (dhwe->prio_args && !(hwe->prio_args = set_param_str(dhwe->prio_args)))
501                 goto out;
502
503         if (dhwe->alias_prefix && !(hwe->alias_prefix = set_param_str(dhwe->alias_prefix)))
504                 goto out;
505
506         hwe->pgpolicy = dhwe->pgpolicy;
507         hwe->pgfailback = dhwe->pgfailback;
508         hwe->rr_weight = dhwe->rr_weight;
509         hwe->no_path_retry = dhwe->no_path_retry;
510         hwe->minio = dhwe->minio;
511         hwe->minio_rq = dhwe->minio_rq;
512         hwe->flush_on_last_del = dhwe->flush_on_last_del;
513         hwe->fast_io_fail = dhwe->fast_io_fail;
514         hwe->dev_loss = dhwe->dev_loss;
515         hwe->user_friendly_names = dhwe->user_friendly_names;
516         hwe->retain_hwhandler = dhwe->retain_hwhandler;
517         hwe->detect_prio = dhwe->detect_prio;
518         hwe->detect_checker = dhwe->detect_checker;
519         hwe->ghost_delay = dhwe->ghost_delay;
520
521         if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
522                 goto out;
523
524         if (!vector_alloc_slot(hwtable))
525                 goto out;
526
527         vector_set_slot(hwtable, hwe);
528         return 0;
529 out:
530         free_hwe(hwe);
531         return 1;
532 }
533
534 static void
535 factorize_hwtable (vector hw, int n, const char *table_desc)
536 {
537         struct hwentry *hwe1, *hwe2;
538         int i, j;
539
540 restart:
541         vector_foreach_slot(hw, hwe1, i) {
542                 /* drop invalid device configs */
543                 if (i >= n && (!hwe1->vendor || !hwe1->product)) {
544                         condlog(0, "device config in %s missing vendor or product parameter",
545                                 table_desc);
546                         vector_del_slot(hw, i--);
547                         free_hwe(hwe1);
548                         continue;
549                 }
550                 j = n > i + 1 ? n : i + 1;
551                 vector_foreach_slot_after(hw, hwe2, j) {
552                         if (hwe_strmatch(hwe2, hwe1) == 0) {
553                                 condlog(i >= n ? 1 : 3,
554                                         "%s: duplicate device section for %s:%s:%s in %s",
555                                         __func__, hwe1->vendor, hwe1->product,
556                                         hwe1->revision, table_desc);
557                                 vector_del_slot(hw, i);
558                                 merge_hwe(hwe2, hwe1);
559                                 free_hwe(hwe1);
560                                 if (i < n)
561                                         n -= 1;
562                                 /*
563                                  * Play safe here; we have modified
564                                  * the original vector so the outer
565                                  * vector_foreach_slot() might
566                                  * become confused.
567                                  */
568                                 goto restart;
569                         }
570                 }
571         }
572         return;
573 }
574
575 struct config *
576 alloc_config (void)
577 {
578         return (struct config *)MALLOC(sizeof(struct config));
579 }
580
581 void
582 free_config (struct config * conf)
583 {
584         if (!conf)
585                 return;
586
587         if (conf->multipath_dir)
588                 FREE(conf->multipath_dir);
589
590         if (conf->selector)
591                 FREE(conf->selector);
592
593         if (conf->uid_attribute)
594                 FREE(conf->uid_attribute);
595
596         vector_reset(&conf->uid_attrs);
597
598         if (conf->getuid)
599                 FREE(conf->getuid);
600
601         if (conf->features)
602                 FREE(conf->features);
603
604         if (conf->hwhandler)
605                 FREE(conf->hwhandler);
606
607         if (conf->bindings_file)
608                 FREE(conf->bindings_file);
609
610         if (conf->wwids_file)
611                 FREE(conf->wwids_file);
612
613         if (conf->prkeys_file)
614                 FREE(conf->prkeys_file);
615
616         if (conf->prio_name)
617                 FREE(conf->prio_name);
618
619         if (conf->alias_prefix)
620                 FREE(conf->alias_prefix);
621         if (conf->partition_delim)
622                 FREE(conf->partition_delim);
623
624         if (conf->prio_args)
625                 FREE(conf->prio_args);
626
627         if (conf->checker_name)
628                 FREE(conf->checker_name);
629
630         if (conf->config_dir)
631                 FREE(conf->config_dir);
632
633         free_blacklist(conf->blist_devnode);
634         free_blacklist(conf->blist_wwid);
635         free_blacklist(conf->blist_property);
636         free_blacklist(conf->blist_protocol);
637         free_blacklist_device(conf->blist_device);
638
639         free_blacklist(conf->elist_devnode);
640         free_blacklist(conf->elist_wwid);
641         free_blacklist(conf->elist_property);
642         free_blacklist(conf->elist_protocol);
643         free_blacklist_device(conf->elist_device);
644
645         free_mptable(conf->mptable);
646         free_hwtable(conf->hwtable);
647         free_hwe(conf->overrides);
648         free_keywords(conf->keywords);
649         FREE(conf);
650 }
651
652 /* if multipath fails to process the config directory, it should continue,
653  * with just a warning message */
654 static void
655 process_config_dir(struct config *conf, char *dir)
656 {
657         struct dirent **namelist;
658         struct scandir_result sr;
659         int i, n;
660         char path[LINE_MAX];
661         int old_hwtable_size;
662
663         if (dir[0] != '/') {
664                 condlog(1, "config_dir '%s' must be a fully qualified path",
665                         dir);
666                 return;
667         }
668         n = scandir(dir, &namelist, NULL, alphasort);
669         if (n < 0) {
670                 if (errno == ENOENT)
671                         condlog(3, "No configuration dir '%s'", dir);
672                 else
673                         condlog(0, "couldn't open configuration dir '%s': %s",
674                                 dir, strerror(errno));
675                 return;
676         } else if (n == 0)
677                 return;
678         sr.di = namelist;
679         sr.n = n;
680         pthread_cleanup_push_cast(free_scandir_result, &sr);
681         for (i = 0; i < n; i++) {
682                 if (!strstr(namelist[i]->d_name, ".conf"))
683                         continue;
684                 old_hwtable_size = VECTOR_SIZE(conf->hwtable);
685                 snprintf(path, LINE_MAX, "%s/%s", dir, namelist[i]->d_name);
686                 path[LINE_MAX-1] = '\0';
687                 process_file(conf, path);
688                 factorize_hwtable(conf->hwtable, old_hwtable_size,
689                                   namelist[i]->d_name);
690         }
691         pthread_cleanup_pop(1);
692 }
693
694 struct config *
695 load_config (char * file)
696 {
697         struct config *conf = alloc_config();
698
699         if (!conf)
700                 return NULL;
701
702         /*
703          * internal defaults
704          */
705         conf->verbosity = DEFAULT_VERBOSITY;
706
707         get_sys_max_fds(&conf->max_fds);
708         conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
709         conf->wwids_file = set_default(DEFAULT_WWIDS_FILE);
710         conf->prkeys_file = set_default(DEFAULT_PRKEYS_FILE);
711         conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
712         conf->attribute_flags = 0;
713         conf->reassign_maps = DEFAULT_REASSIGN_MAPS;
714         conf->checkint = DEFAULT_CHECKINT;
715         conf->max_checkint = 0;
716         conf->force_sync = DEFAULT_FORCE_SYNC;
717         conf->partition_delim = (default_partition_delim != NULL ?
718                                  strdup(default_partition_delim) : NULL);
719         conf->processed_main_config = 0;
720         conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
721         conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
722         conf->retrigger_tries = DEFAULT_RETRIGGER_TRIES;
723         conf->retrigger_delay = DEFAULT_RETRIGGER_DELAY;
724         conf->uev_wait_timeout = DEFAULT_UEV_WAIT_TIMEOUT;
725         conf->remove_retries = 0;
726         conf->ghost_delay = DEFAULT_GHOST_DELAY;
727         conf->all_tg_pt = DEFAULT_ALL_TG_PT;
728         /*
729          * preload default hwtable
730          */
731         conf->hwtable = vector_alloc();
732         if (!conf->hwtable)
733                         goto out;
734         if (setup_default_hwtable(conf->hwtable))
735                 goto out;
736
737 #ifdef CHECK_BUILTIN_HWTABLE
738         factorize_hwtable(conf->hwtable, 0, "builtin");
739 #endif
740         /*
741          * read the config file
742          */
743         conf->keywords = vector_alloc();
744         init_keywords(conf->keywords);
745         if (filepresent(file)) {
746                 int builtin_hwtable_size;
747
748                 builtin_hwtable_size = VECTOR_SIZE(conf->hwtable);
749                 if (process_file(conf, file)) {
750                         condlog(0, "error parsing config file");
751                         goto out;
752                 }
753                 factorize_hwtable(conf->hwtable, builtin_hwtable_size, file);
754         }
755
756         conf->processed_main_config = 1;
757         if (conf->config_dir == NULL)
758                 conf->config_dir = set_default(DEFAULT_CONFIG_DIR);
759         if (conf->config_dir && conf->config_dir[0] != '\0')
760                 process_config_dir(conf, conf->config_dir);
761
762         /*
763          * fill the voids left in the config file
764          */
765         if (conf->max_checkint == 0)
766                 conf->max_checkint = MAX_CHECKINT(conf->checkint);
767         if (conf->blist_devnode == NULL) {
768                 conf->blist_devnode = vector_alloc();
769
770                 if (!conf->blist_devnode)
771                         goto out;
772         }
773         if (conf->blist_wwid == NULL) {
774                 conf->blist_wwid = vector_alloc();
775
776                 if (!conf->blist_wwid)
777                         goto out;
778         }
779         if (conf->blist_device == NULL) {
780                 conf->blist_device = vector_alloc();
781
782                 if (!conf->blist_device)
783                         goto out;
784         }
785         if (conf->blist_property == NULL) {
786                 conf->blist_property = vector_alloc();
787
788                 if (!conf->blist_property)
789                         goto out;
790         }
791         if (conf->blist_protocol == NULL) {
792                 conf->blist_protocol = vector_alloc();
793
794                 if (!conf->blist_protocol)
795                         goto out;
796         }
797
798         if (conf->elist_devnode == NULL) {
799                 conf->elist_devnode = vector_alloc();
800
801                 if (!conf->elist_devnode)
802                         goto out;
803         }
804         if (conf->elist_wwid == NULL) {
805                 conf->elist_wwid = vector_alloc();
806
807                 if (!conf->elist_wwid)
808                         goto out;
809         }
810
811         if (conf->elist_device == NULL) {
812                 conf->elist_device = vector_alloc();
813
814                 if (!conf->elist_device)
815                         goto out;
816         }
817
818         if (conf->elist_property == NULL) {
819                 conf->elist_property = vector_alloc();
820
821                 if (!conf->elist_property)
822                         goto out;
823         }
824         if (conf->elist_protocol == NULL) {
825                 conf->elist_protocol = vector_alloc();
826
827                 if (!conf->elist_protocol)
828                         goto out;
829         }
830
831         if (setup_default_blist(conf))
832                 goto out;
833
834         if (conf->mptable == NULL) {
835                 conf->mptable = vector_alloc();
836                 if (!conf->mptable)
837                         goto out;
838         }
839
840         merge_mptable(conf->mptable);
841         merge_blacklist(conf->blist_devnode);
842         merge_blacklist(conf->blist_property);
843         merge_blacklist(conf->blist_wwid);
844         merge_blacklist_device(conf->blist_device);
845         merge_blacklist(conf->elist_devnode);
846         merge_blacklist(conf->elist_property);
847         merge_blacklist(conf->elist_wwid);
848         merge_blacklist_device(conf->elist_device);
849
850         if (conf->bindings_file == NULL)
851                 conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
852
853         if (!conf->multipath_dir || !conf->bindings_file ||
854             !conf->wwids_file || !conf->prkeys_file)
855                 goto out;
856
857         return conf;
858 out:
859         free_config(conf);
860         return NULL;
861 }
862
863 char *get_uid_attribute_by_attrs(struct config *conf,
864                                  const char *path_dev)
865 {
866         vector uid_attrs = &conf->uid_attrs;
867         int j;
868         char *att, *col;
869
870         vector_foreach_slot(uid_attrs, att, j) {
871                 col = strrchr(att, ':');
872                 if (!col)
873                         continue;
874                 if (!strncmp(path_dev, att, col - att))
875                         return col + 1;
876         }
877         return NULL;
878 }
879
880 int parse_uid_attrs(char *uid_attrs, struct config *conf)
881 {
882         vector attrs  = &conf->uid_attrs;
883         char *uid_attr_record, *tmp;
884         int  ret = 0, count;
885
886         if (!uid_attrs)
887                 return 1;
888
889         count = get_word(uid_attrs, &uid_attr_record);
890         while (uid_attr_record) {
891                 tmp = strchr(uid_attr_record, ':');
892                 if (!tmp) {
893                         condlog(2, "invalid record in uid_attrs: %s",
894                                 uid_attr_record);
895                         free(uid_attr_record);
896                         ret = 1;
897                 } else if (!vector_alloc_slot(attrs)) {
898                         free(uid_attr_record);
899                         ret = 1;
900                 } else
901                         vector_set_slot(attrs, uid_attr_record);
902                 if (!count)
903                         break;
904                 uid_attrs += count;
905                 count = get_word(uid_attrs, &uid_attr_record);
906         }
907         return ret;
908 }