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"
23 static struct hwentry *
24 find_hwe_strmatch (vector hwtable, char * vendor, char * product, char * revision)
27 struct hwentry *hwe, *ret = NULL;
29 vector_foreach_slot (hwtable, hwe, i) {
30 if (hwe->vendor && vendor && strcmp(hwe->vendor, vendor))
33 if (hwe->product && product && strcmp(hwe->product, product))
36 if (hwe->revision && revision && strcmp(hwe->revision, revision))
46 find_hwe (vector hwtable, char * vendor, char * product, char * revision)
49 struct hwentry *hwe, *ret = NULL;
50 regex_t vre, pre, rre;
52 vector_foreach_slot (hwtable, hwe, i) {
54 regcomp(&vre, hwe->vendor, REG_EXTENDED|REG_NOSUB))
57 regcomp(&pre, hwe->product, REG_EXTENDED|REG_NOSUB)) {
62 regcomp(&rre, hwe->revision, REG_EXTENDED|REG_NOSUB)) {
67 if ((!hwe->vendor || !regexec(&vre, vendor, 0, NULL, 0)) &&
68 (!hwe->product || !regexec(&pre, product, 0, NULL, 0)) &&
69 (!hwe->revision || !regexec(&rre, revision, 0, NULL, 0)))
85 extern struct mpentry *
86 find_mpe (char * wwid)
94 vector_foreach_slot (conf->mptable, mpe, i)
95 if (mpe->wwid && !strcmp(mpe->wwid, wwid))
102 get_mpe_wwid (char * alias)
105 struct mpentry * mpe;
110 vector_foreach_slot (conf->mptable, mpe, i)
111 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
118 free_hwe (struct hwentry * hwe)
142 FREE(hwe->hwhandler);
145 FREE(hwe->bl_product);
151 free_hwtable (vector hwtable)
154 struct hwentry * hwe;
159 vector_foreach_slot (hwtable, hwe, i)
162 vector_free(hwtable);
166 free_mpe (struct mpentry * mpe)
187 free_mptable (vector mptable)
190 struct mpentry * mpe;
195 vector_foreach_slot (mptable, mpe, i)
198 vector_free(mptable);
204 struct mpentry * mpe = (struct mpentry *)
205 MALLOC(sizeof(struct mpentry));
210 static struct hwentry *
213 struct hwentry * hwe = (struct hwentry *)
214 MALLOC(sizeof(struct hwentry));
220 set_param_str(char * str)
233 dst = (char *)MALLOC(len + 1);
243 store_hwe (vector hwtable, struct hwentry * dhwe)
245 struct hwentry * hwe;
247 if (find_hwe_strmatch(hwtable, dhwe->vendor, dhwe->product, dhwe->revision))
250 if (!(hwe = alloc_hwe()))
253 if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
256 if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
259 if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
262 if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
265 if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
268 if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
271 if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
274 hwe->pgpolicy = dhwe->pgpolicy;
275 hwe->pgfailback = dhwe->pgfailback;
276 hwe->rr_weight = dhwe->rr_weight;
277 hwe->no_path_retry = dhwe->no_path_retry;
278 hwe->minio = dhwe->minio;
279 hwe->checker = dhwe->checker;
280 hwe->prio = dhwe->prio;
282 if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
285 if (!vector_alloc_slot(hwtable))
288 vector_set_slot(hwtable, hwe);
298 return (struct config *)MALLOC(sizeof(struct config));
302 free_config (struct config * conf)
311 FREE(conf->udev_dir);
313 if (conf->multipath_dir)
314 FREE(conf->multipath_dir);
317 FREE(conf->selector);
323 FREE(conf->features);
326 FREE(conf->hwhandler);
328 free_blacklist(conf->blist_devnode);
329 free_blacklist(conf->blist_wwid);
330 free_blacklist_device(conf->blist_device);
332 free_blacklist(conf->elist_devnode);
333 free_blacklist(conf->elist_wwid);
334 free_blacklist_device(conf->elist_device);
336 free_mptable(conf->mptable);
337 free_hwtable(conf->hwtable);
338 free_keywords(conf->keywords);
343 load_config (char * file)
346 conf = alloc_config();
354 if (!conf->verbosity)
357 conf->dev_type = DEV_NONE;
360 conf->bindings_file = DEFAULT_BINDINGS_FILE;
363 * read the config file
365 if (filepresent(file)) {
366 set_current_keywords(&conf->keywords);
367 if (init_data(file, init_keywords)) {
368 condlog(0, "error parsing config file");
374 * fill the voids left in the config file
376 if (conf->multipath_dir == NULL)
377 conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
379 if (conf->hwtable == NULL) {
380 conf->hwtable = vector_alloc();
385 if (setup_default_hwtable(conf->hwtable))
388 if (conf->blist_devnode == NULL) {
389 conf->blist_devnode = vector_alloc();
391 if (!conf->blist_devnode)
394 if (conf->blist_wwid == NULL) {
395 conf->blist_wwid = vector_alloc();
397 if (!conf->blist_wwid)
400 if (conf->blist_device == NULL) {
401 conf->blist_device = vector_alloc();
403 if (!conf->blist_device)
406 if (setup_default_blist(conf))
409 if (conf->elist_devnode == NULL) {
410 conf->elist_devnode = vector_alloc();
412 if (!conf->elist_devnode)
415 if (conf->elist_wwid == NULL) {
416 conf->elist_wwid = vector_alloc();
418 if (!conf->elist_wwid)
422 if (conf->elist_device == NULL) {
423 conf->elist_device = vector_alloc();
425 if (!conf->elist_device)
429 if (conf->mptable == NULL) {
430 conf->mptable = vector_alloc();
435 if (conf->selector == NULL)
436 conf->selector = set_default(DEFAULT_SELECTOR);
438 if (conf->udev_dir == NULL)
439 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
441 if (conf->getuid == NULL)
442 conf->getuid = set_default(DEFAULT_GETUID);
444 if (conf->features == NULL)
445 conf->features = set_default(DEFAULT_FEATURES);
447 if (conf->hwhandler == NULL)
448 conf->hwhandler = set_default(DEFAULT_HWHANDLER);
450 if (!conf->selector || !conf->udev_dir || !conf->multipath_dir ||
451 !conf->getuid || !conf->features ||
456 conf->prio = prio_default();
459 conf->checker = checker_lookup(DEFAULT_CHECKER);