2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2005 Benjamin Marzinski, Redhat
4 * Copyright (c) 2005 Edward Goggin, EMC
19 #include "blacklist.h"
22 #include "devmapper.h"
25 hwe_strmatch (struct hwentry *hwe1, struct hwentry *hwe2)
27 if (hwe1->vendor && hwe2->vendor && strcmp(hwe1->vendor, hwe2->vendor))
30 if (hwe1->product && hwe2->product && strcmp(hwe1->product, hwe2->product))
33 if (hwe1->revision && hwe2->revision && strcmp(hwe1->revision, hwe2->revision))
39 static struct hwentry *
40 find_hwe_strmatch (vector hwtable, struct hwentry *hwe)
43 struct hwentry *tmp, *ret = NULL;
45 vector_foreach_slot (hwtable, tmp, i) {
46 if (hwe_strmatch(tmp, hwe))
55 hwe_regmatch (struct hwentry *hwe1, struct hwentry *hwe2)
57 regex_t vre, pre, rre;
61 regcomp(&vre, hwe1->vendor, REG_EXTENDED|REG_NOSUB))
65 regcomp(&pre, hwe1->product, REG_EXTENDED|REG_NOSUB))
69 regcomp(&rre, hwe1->revision, REG_EXTENDED|REG_NOSUB))
72 if ((!hwe1->vendor || !hwe2->vendor ||
73 !regexec(&vre, hwe2->vendor, 0, NULL, 0)) &&
74 (!hwe1->product || !hwe2->product ||
75 !regexec(&pre, hwe2->product, 0, NULL, 0)) &&
76 (!hwe1->revision || !hwe2->revision ||
77 !regexec(&rre, hwe2->revision, 0, NULL, 0)))
93 find_hwe (vector hwtable, char * vendor, char * product, char * revision)
96 struct hwentry hwe, *tmp, *ret = NULL;
99 hwe.product = product;
100 hwe.revision = revision;
102 * Search backwards here.
103 * User modified entries are attached at the end of
104 * the list, so we have to check them first before
105 * continuing to the generic entries
107 vector_foreach_slot_backwards (hwtable, tmp, i) {
108 if (hwe_regmatch(tmp, &hwe))
116 extern struct mpentry *
117 find_mpe (char * wwid)
120 struct mpentry * mpe;
125 vector_foreach_slot (conf->mptable, mpe, i)
126 if (mpe->wwid && !strcmp(mpe->wwid, wwid))
133 get_mpe_wwid (char * alias)
136 struct mpentry * mpe;
141 vector_foreach_slot (conf->mptable, mpe, i)
142 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
149 free_hwe (struct hwentry * hwe)
170 FREE(hwe->hwhandler);
175 if (hwe->checker_name)
176 FREE(hwe->checker_name);
179 FREE(hwe->prio_name);
182 FREE(hwe->prio_args);
184 if (hwe->alias_prefix)
185 FREE(hwe->alias_prefix);
188 FREE(hwe->bl_product);
194 free_hwtable (vector hwtable)
197 struct hwentry * hwe;
202 vector_foreach_slot (hwtable, hwe, i)
205 vector_free(hwtable);
209 free_mpe (struct mpentry * mpe)
227 FREE(mpe->prio_name);
230 FREE(mpe->prio_args);
236 free_mptable (vector mptable)
239 struct mpentry * mpe;
244 vector_foreach_slot (mptable, mpe, i)
247 vector_free(mptable);
253 struct mpentry * mpe = (struct mpentry *)
254 MALLOC(sizeof(struct mpentry));
262 struct hwentry * hwe = (struct hwentry *)
263 MALLOC(sizeof(struct hwentry));
269 set_param_str(char * str)
282 dst = (char *)MALLOC(len + 1);
291 #define merge_str(s) \
292 if (!dst->s && src->s) { \
293 if (!(dst->s = set_param_str(src->s))) \
297 #define merge_num(s) \
298 if (!dst->s && src->s) \
303 merge_hwe (struct hwentry * dst, struct hwentry * src)
310 merge_str(hwhandler);
312 merge_str(checker_name);
313 merge_str(prio_name);
314 merge_str(prio_args);
315 merge_str(alias_prefix);
316 merge_str(bl_product);
318 merge_num(pgfailback);
319 merge_num(rr_weight);
320 merge_num(no_path_retry);
328 store_hwe (vector hwtable, struct hwentry * dhwe)
330 struct hwentry * hwe;
332 if (find_hwe_strmatch(hwtable, dhwe))
335 if (!(hwe = alloc_hwe()))
338 if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
341 if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
344 if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
347 if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
350 if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
353 if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
356 if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
359 if (dhwe->checker_name && !(hwe->checker_name = set_param_str(dhwe->checker_name)))
362 if (dhwe->prio_name && !(hwe->prio_name = set_param_str(dhwe->prio_name)))
365 if (dhwe->prio_args && !(hwe->prio_args = set_param_str(dhwe->prio_args)))
368 if (dhwe->alias_prefix && !(hwe->alias_prefix = set_param_str(dhwe->alias_prefix)))
371 hwe->pgpolicy = dhwe->pgpolicy;
372 hwe->pgfailback = dhwe->pgfailback;
373 hwe->rr_weight = dhwe->rr_weight;
374 hwe->no_path_retry = dhwe->no_path_retry;
375 hwe->minio = dhwe->minio;
376 hwe->minio_rq = dhwe->minio_rq;
378 if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
381 if (!vector_alloc_slot(hwtable))
384 vector_set_slot(hwtable, hwe);
392 factorize_hwtable (vector hw, int n)
394 struct hwentry *hwe1, *hwe2;
397 vector_foreach_slot(hw, hwe1, i) {
401 vector_foreach_slot_after(hw, hwe2, j) {
402 if (hwe_regmatch(hwe1, hwe2))
405 merge_hwe(hwe2, hwe1);
414 return (struct config *)MALLOC(sizeof(struct config));
418 free_config (struct config * conf)
427 FREE(conf->udev_dir);
429 if (conf->multipath_dir)
430 FREE(conf->multipath_dir);
433 FREE(conf->selector);
439 FREE(conf->features);
442 FREE(conf->hwhandler);
444 if (conf->bindings_file)
445 FREE(conf->bindings_file);
448 FREE(conf->prio_name);
450 if (conf->alias_prefix)
451 FREE(conf->alias_prefix);
454 FREE(conf->prio_args);
456 if (conf->checker_name)
457 FREE(conf->checker_name);
459 free_blacklist(conf->blist_devnode);
460 free_blacklist(conf->blist_wwid);
461 free_blacklist_device(conf->blist_device);
463 free_blacklist(conf->elist_devnode);
464 free_blacklist(conf->elist_wwid);
465 free_blacklist_device(conf->elist_device);
467 free_mptable(conf->mptable);
468 free_hwtable(conf->hwtable);
469 free_keywords(conf->keywords);
474 load_config (char * file)
477 conf = alloc_config();
485 if (!conf->verbosity)
486 conf->verbosity = DEFAULT_VERBOSITY;
488 conf->dmrq = dm_drv_get_rq();
489 conf->dev_type = DEV_NONE;
490 conf->minio = DEFAULT_MINIO;
491 conf->minio_rq = DEFAULT_MINIO_RQ;
493 conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
494 conf->bindings_read_only = 0;
495 conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
496 conf->flush_on_last_del = 0;
497 conf->attribute_flags = 0;
498 conf->reassign_maps = DEFAULT_REASSIGN_MAPS;
501 * preload default hwtable
503 if (conf->hwtable == NULL) {
504 conf->hwtable = vector_alloc();
509 if (setup_default_hwtable(conf->hwtable))
513 * read the config file
515 set_current_keywords(&conf->keywords);
517 if (filepresent(file)) {
518 int builtin_hwtable_size;
520 builtin_hwtable_size = VECTOR_SIZE(conf->hwtable);
521 if (init_data(file, init_keywords)) {
522 condlog(0, "error parsing config file");
525 if (VECTOR_SIZE(conf->hwtable) > builtin_hwtable_size) {
527 * remove duplica in hwtable. config file
528 * takes precedence over build-in hwtable
530 factorize_hwtable(conf->hwtable, builtin_hwtable_size);
538 * fill the voids left in the config file
540 if (conf->blist_devnode == NULL) {
541 conf->blist_devnode = vector_alloc();
543 if (!conf->blist_devnode)
546 if (conf->blist_wwid == NULL) {
547 conf->blist_wwid = vector_alloc();
549 if (!conf->blist_wwid)
552 if (conf->blist_device == NULL) {
553 conf->blist_device = vector_alloc();
555 if (!conf->blist_device)
558 if (setup_default_blist(conf))
561 if (conf->elist_devnode == NULL) {
562 conf->elist_devnode = vector_alloc();
564 if (!conf->elist_devnode)
567 if (conf->elist_wwid == NULL) {
568 conf->elist_wwid = vector_alloc();
570 if (!conf->elist_wwid)
574 if (conf->elist_device == NULL) {
575 conf->elist_device = vector_alloc();
577 if (!conf->elist_device)
581 if (conf->mptable == NULL) {
582 conf->mptable = vector_alloc();
586 if (conf->udev_dir == NULL)
587 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
589 if (conf->bindings_file == NULL)
590 conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
592 if (!conf->udev_dir || !conf->multipath_dir ||
593 !conf->bindings_file)