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"
24 hwe_strmatch (struct hwentry *hwe1, struct hwentry *hwe2)
26 if (hwe1->vendor && hwe2->vendor && strcmp(hwe1->vendor, hwe2->vendor))
29 if (hwe1->product && hwe2->product && strcmp(hwe1->product, hwe2->product))
32 if (hwe1->revision && hwe2->revision && strcmp(hwe1->revision, hwe2->revision))
38 static struct hwentry *
39 find_hwe_strmatch (vector hwtable, struct hwentry *hwe)
42 struct hwentry *tmp, *ret = NULL;
44 vector_foreach_slot (hwtable, tmp, i) {
45 if (hwe_strmatch(tmp, hwe))
54 find_hwe (vector hwtable, char * vendor, char * product, char * revision)
57 struct hwentry *hwe, *ret = NULL;
58 regex_t vre, pre, rre;
60 vector_foreach_slot (hwtable, hwe, i) {
62 regcomp(&vre, hwe->vendor, REG_EXTENDED|REG_NOSUB))
65 regcomp(&pre, hwe->product, REG_EXTENDED|REG_NOSUB)) {
70 regcomp(&rre, hwe->revision, REG_EXTENDED|REG_NOSUB)) {
75 if ((!hwe->vendor || !regexec(&vre, vendor, 0, NULL, 0)) &&
76 (!hwe->product || !regexec(&pre, product, 0, NULL, 0)) &&
77 (!hwe->revision || !regexec(&rre, revision, 0, NULL, 0)))
93 extern struct mpentry *
94 find_mpe (char * wwid)
102 vector_foreach_slot (conf->mptable, mpe, i)
103 if (mpe->wwid && !strcmp(mpe->wwid, wwid))
110 get_mpe_wwid (char * alias)
113 struct mpentry * mpe;
118 vector_foreach_slot (conf->mptable, mpe, i)
119 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
126 free_hwe (struct hwentry * hwe)
147 FREE(hwe->hwhandler);
152 if (hwe->checker_name)
153 FREE(hwe->checker_name);
156 FREE(hwe->prio_name);
159 FREE(hwe->prio_args);
161 if (hwe->alias_prefix)
162 FREE(hwe->alias_prefix);
165 FREE(hwe->bl_product);
171 free_hwtable (vector hwtable)
174 struct hwentry * hwe;
179 vector_foreach_slot (hwtable, hwe, i)
182 vector_free(hwtable);
186 free_mpe (struct mpentry * mpe)
207 free_mptable (vector mptable)
210 struct mpentry * mpe;
215 vector_foreach_slot (mptable, mpe, i)
218 vector_free(mptable);
224 struct mpentry * mpe = (struct mpentry *)
225 MALLOC(sizeof(struct mpentry));
233 struct hwentry * hwe = (struct hwentry *)
234 MALLOC(sizeof(struct hwentry));
240 set_param_str(char * str)
253 dst = (char *)MALLOC(len + 1);
262 #define merge_str(s) \
266 if (!(hwe1->s = set_param_str(hwe2->s))) \
270 #define merge_num(s) \
276 merge_hwe (struct hwentry * hwe1, struct hwentry * hwe2)
283 merge_str(hwhandler);
285 merge_str(checker_name);
286 merge_str(prio_name);
287 merge_str(prio_args);
288 merge_str(alias_prefix);
289 merge_str(bl_product);
291 merge_num(pgfailback);
292 merge_num(rr_weight);
293 merge_num(no_path_retry);
300 store_hwe (vector hwtable, struct hwentry * dhwe)
302 struct hwentry * hwe;
304 if (find_hwe_strmatch(hwtable, dhwe))
307 if (!(hwe = alloc_hwe()))
310 if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
313 if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
316 if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
319 if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
322 if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
325 if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
328 if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
331 if (dhwe->checker_name && !(hwe->checker_name = set_param_str(dhwe->checker_name)))
334 if (dhwe->prio_name && !(hwe->prio_name = set_param_str(dhwe->prio_name)))
337 if (dhwe->prio_args && !(hwe->prio_args = set_param_str(dhwe->prio_args)))
340 if (dhwe->alias_prefix && !(hwe->alias_prefix = set_param_str(dhwe->alias_prefix)))
343 hwe->pgpolicy = dhwe->pgpolicy;
344 hwe->pgfailback = dhwe->pgfailback;
345 hwe->rr_weight = dhwe->rr_weight;
346 hwe->no_path_retry = dhwe->no_path_retry;
347 hwe->minio = dhwe->minio;
349 if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
352 if (!vector_alloc_slot(hwtable))
355 vector_set_slot(hwtable, hwe);
363 factorize_hwtable (vector hw)
365 struct hwentry *hwe1, *hwe2;
368 vector_foreach_slot(hw, hwe1, i) {
370 vector_foreach_slot_after(hw, hwe2, j) {
371 if (hwe_strmatch(hwe1, hwe2))
374 merge_hwe(hwe1, hwe2);
376 vector_del_slot(hw, j);
386 return (struct config *)MALLOC(sizeof(struct config));
390 free_config (struct config * conf)
399 FREE(conf->udev_dir);
401 if (conf->multipath_dir)
402 FREE(conf->multipath_dir);
405 FREE(conf->selector);
411 FREE(conf->features);
414 FREE(conf->hwhandler);
417 FREE(conf->prio_name);
419 if (conf->alias_prefix)
420 FREE(conf->alias_prefix);
423 FREE(conf->prio_args);
425 if (conf->checker_name)
426 FREE(conf->checker_name);
428 free_blacklist(conf->blist_devnode);
429 free_blacklist(conf->blist_wwid);
430 free_blacklist_device(conf->blist_device);
432 free_blacklist(conf->elist_devnode);
433 free_blacklist(conf->elist_wwid);
434 free_blacklist_device(conf->elist_device);
436 free_mptable(conf->mptable);
437 free_hwtable(conf->hwtable);
438 free_keywords(conf->keywords);
443 load_config (char * file)
446 conf = alloc_config();
454 if (!conf->verbosity)
455 conf->verbosity = DEFAULT_VERBOSITY;
457 conf->dev_type = DEV_NONE;
460 conf->bindings_file = DEFAULT_BINDINGS_FILE;
461 conf->bindings_read_only = 0;
462 conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
463 conf->flush_on_last_del = 0;
464 conf->attribute_flags = 0;
467 * preload default hwtable
469 if (conf->hwtable == NULL) {
470 conf->hwtable = vector_alloc();
475 if (setup_default_hwtable(conf->hwtable))
479 * read the config file
481 if (filepresent(file)) {
482 set_current_keywords(&conf->keywords);
483 if (init_data(file, init_keywords)) {
484 condlog(0, "error parsing config file");
490 * remove duplica in hwtable. config file takes precedence
491 * over build-in hwtable
493 factorize_hwtable(conf->hwtable);
496 * fill the voids left in the config file
498 if (conf->blist_devnode == NULL) {
499 conf->blist_devnode = vector_alloc();
501 if (!conf->blist_devnode)
504 if (conf->blist_wwid == NULL) {
505 conf->blist_wwid = vector_alloc();
507 if (!conf->blist_wwid)
510 if (conf->blist_device == NULL) {
511 conf->blist_device = vector_alloc();
513 if (!conf->blist_device)
516 if (setup_default_blist(conf))
519 if (conf->elist_devnode == NULL) {
520 conf->elist_devnode = vector_alloc();
522 if (!conf->elist_devnode)
525 if (conf->elist_wwid == NULL) {
526 conf->elist_wwid = vector_alloc();
528 if (!conf->elist_wwid)
532 if (conf->elist_device == NULL) {
533 conf->elist_device = vector_alloc();
535 if (!conf->elist_device)
539 if (conf->mptable == NULL) {
540 conf->mptable = vector_alloc();
544 if (conf->udev_dir == NULL)
545 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
547 if (!conf->udev_dir || !conf->multipath_dir)