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->bl_product);
165 free_hwtable (vector hwtable)
168 struct hwentry * hwe;
173 vector_foreach_slot (hwtable, hwe, i)
176 vector_free(hwtable);
180 free_mpe (struct mpentry * mpe)
201 free_mptable (vector mptable)
204 struct mpentry * mpe;
209 vector_foreach_slot (mptable, mpe, i)
212 vector_free(mptable);
218 struct mpentry * mpe = (struct mpentry *)
219 MALLOC(sizeof(struct mpentry));
227 struct hwentry * hwe = (struct hwentry *)
228 MALLOC(sizeof(struct hwentry));
234 set_param_str(char * str)
247 dst = (char *)MALLOC(len + 1);
256 #define merge_str(s) \
260 if (!(hwe1->s = set_param_str(hwe2->s))) \
264 #define merge_num(s) \
270 merge_hwe (struct hwentry * hwe1, struct hwentry * hwe2)
277 merge_str(hwhandler);
279 merge_str(checker_name);
280 merge_str(prio_name);
281 merge_str(bl_product);
283 merge_num(pgfailback);
284 merge_num(rr_weight);
285 merge_num(no_path_retry);
292 store_hwe (vector hwtable, struct hwentry * dhwe)
294 struct hwentry * hwe;
296 if (find_hwe_strmatch(hwtable, dhwe))
299 if (!(hwe = alloc_hwe()))
302 if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
305 if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
308 if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
311 if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
314 if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
317 if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
320 if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
323 if (dhwe->checker_name && !(hwe->checker_name = set_param_str(dhwe->checker_name)))
326 if (dhwe->prio_name && !(hwe->prio_name = set_param_str(dhwe->prio_name)))
329 hwe->pgpolicy = dhwe->pgpolicy;
330 hwe->pgfailback = dhwe->pgfailback;
331 hwe->rr_weight = dhwe->rr_weight;
332 hwe->no_path_retry = dhwe->no_path_retry;
333 hwe->minio = dhwe->minio;
335 if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
338 if (!vector_alloc_slot(hwtable))
341 vector_set_slot(hwtable, hwe);
349 factorize_hwtable (vector hw)
351 struct hwentry *hwe1, *hwe2;
354 vector_foreach_slot(hw, hwe1, i) {
356 vector_foreach_slot_after(hw, hwe2, j) {
357 if (hwe_strmatch(hwe1, hwe2))
360 merge_hwe(hwe1, hwe2);
362 vector_del_slot(hw, j);
372 return (struct config *)MALLOC(sizeof(struct config));
376 free_config (struct config * conf)
385 FREE(conf->udev_dir);
387 if (conf->multipath_dir)
388 FREE(conf->multipath_dir);
391 FREE(conf->selector);
397 FREE(conf->features);
400 FREE(conf->hwhandler);
403 FREE(conf->prio_name);
405 if (conf->checker_name)
406 FREE(conf->checker_name);
408 free_blacklist(conf->blist_devnode);
409 free_blacklist(conf->blist_wwid);
410 free_blacklist_device(conf->blist_device);
412 free_blacklist(conf->elist_devnode);
413 free_blacklist(conf->elist_wwid);
414 free_blacklist_device(conf->elist_device);
416 free_mptable(conf->mptable);
417 free_hwtable(conf->hwtable);
418 free_keywords(conf->keywords);
423 load_config (char * file)
426 conf = alloc_config();
434 if (!conf->verbosity)
435 conf->verbosity = DEFAULT_VERBOSITY;
437 conf->dev_type = DEV_NONE;
440 conf->bindings_file = DEFAULT_BINDINGS_FILE;
441 conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
442 conf->flush_on_last_del = 0;
445 * preload default hwtable
447 if (conf->hwtable == NULL) {
448 conf->hwtable = vector_alloc();
453 if (setup_default_hwtable(conf->hwtable))
457 * read the config file
459 if (filepresent(file)) {
460 set_current_keywords(&conf->keywords);
461 if (init_data(file, init_keywords)) {
462 condlog(0, "error parsing config file");
468 * remove duplica in hwtable. config file takes precedence
469 * over build-in hwtable
471 factorize_hwtable(conf->hwtable);
474 * fill the voids left in the config file
476 if (conf->blist_devnode == NULL) {
477 conf->blist_devnode = vector_alloc();
479 if (!conf->blist_devnode)
482 if (conf->blist_wwid == NULL) {
483 conf->blist_wwid = vector_alloc();
485 if (!conf->blist_wwid)
488 if (conf->blist_device == NULL) {
489 conf->blist_device = vector_alloc();
491 if (!conf->blist_device)
494 if (setup_default_blist(conf))
497 if (conf->elist_devnode == NULL) {
498 conf->elist_devnode = vector_alloc();
500 if (!conf->elist_devnode)
503 if (conf->elist_wwid == NULL) {
504 conf->elist_wwid = vector_alloc();
506 if (!conf->elist_wwid)
510 if (conf->elist_device == NULL) {
511 conf->elist_device = vector_alloc();
513 if (!conf->elist_device)
517 if (conf->mptable == NULL) {
518 conf->mptable = vector_alloc();
522 if (conf->selector == NULL)
523 conf->selector = set_default(DEFAULT_SELECTOR);
525 if (conf->udev_dir == NULL)
526 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
528 if (conf->getuid == NULL)
529 conf->getuid = set_default(DEFAULT_GETUID);
531 if (conf->features == NULL)
532 conf->features = set_default(DEFAULT_FEATURES);
534 if (conf->hwhandler == NULL)
535 conf->hwhandler = set_default(DEFAULT_HWHANDLER);
537 if (!conf->selector || !conf->udev_dir || !conf->multipath_dir ||
538 !conf->getuid || !conf->features ||
542 if (!conf->prio_name)
543 conf->prio_name = set_default(DEFAULT_PRIO);
545 if (!conf->checker_name)
546 conf->checker_name = set_default(DEFAULT_CHECKER);