2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2005 Benjamin Marzinski, Redhat
4 * Copyright (c) 2005 Edward Goggin, EMC
21 #include "blacklist.h"
24 static struct hwentry *
25 find_hwe_strmatch (vector hwtable, char * vendor, char * product, char * revision)
28 struct hwentry *hwe, *ret = NULL;
30 vector_foreach_slot (hwtable, hwe, i) {
31 if (hwe->vendor && vendor && strcmp(hwe->vendor, vendor))
34 if (hwe->product && product && strcmp(hwe->product, product))
37 if (hwe->revision && revision && strcmp(hwe->revision, revision))
47 find_hwe (vector hwtable, char * vendor, char * product, char * revision)
50 struct hwentry *hwe, *ret = NULL;
51 regex_t vre, pre, rre;
53 vector_foreach_slot (hwtable, hwe, i) {
55 regcomp(&vre, hwe->vendor, REG_EXTENDED|REG_NOSUB))
58 regcomp(&pre, hwe->product, REG_EXTENDED|REG_NOSUB)) {
63 regcomp(&rre, hwe->revision, REG_EXTENDED|REG_NOSUB)) {
68 if ((!hwe->vendor || !regexec(&vre, vendor, 0, NULL, 0)) &&
69 (!hwe->product || !regexec(&pre, product, 0, NULL, 0)) &&
70 (!hwe->revision || !regexec(&rre, revision, 0, NULL, 0)))
86 extern struct mpentry *
87 find_mpe (char * wwid)
95 vector_foreach_slot (conf->mptable, mpe, i)
96 if (mpe->wwid && !strcmp(mpe->wwid, wwid))
103 get_mpe_wwid (char * alias)
106 struct mpentry * mpe;
111 vector_foreach_slot (conf->mptable, mpe, i)
112 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
119 free_hwe (struct hwentry * hwe)
143 FREE(hwe->hwhandler);
146 FREE(hwe->bl_product);
152 free_hwtable (vector hwtable)
155 struct hwentry * hwe;
160 vector_foreach_slot (hwtable, hwe, i)
163 vector_free(hwtable);
167 free_mpe (struct mpentry * mpe)
188 free_mptable (vector mptable)
191 struct mpentry * mpe;
196 vector_foreach_slot (mptable, mpe, i)
199 vector_free(mptable);
205 struct mpentry * mpe = (struct mpentry *)
206 MALLOC(sizeof(struct mpentry));
211 static struct hwentry *
214 struct hwentry * hwe = (struct hwentry *)
215 MALLOC(sizeof(struct hwentry));
221 set_param_str(char * str)
234 dst = (char *)MALLOC(len + 1);
244 store_hwe (vector hwtable, struct hwentry * dhwe)
246 struct hwentry * hwe;
248 if (find_hwe_strmatch(hwtable, dhwe->vendor, dhwe->product, dhwe->revision))
251 if (!(hwe = alloc_hwe()))
254 if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
257 if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
260 if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
263 if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
266 if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
269 if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
272 if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
275 hwe->pgpolicy = dhwe->pgpolicy;
276 hwe->pgfailback = dhwe->pgfailback;
277 hwe->rr_weight = dhwe->rr_weight;
278 hwe->no_path_retry = dhwe->no_path_retry;
279 hwe->minio = dhwe->minio;
280 hwe->checker = dhwe->checker;
281 hwe->prio = dhwe->prio;
283 if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
286 if (!vector_alloc_slot(hwtable))
289 vector_set_slot(hwtable, hwe);
299 return (struct config *)MALLOC(sizeof(struct config));
303 free_config (struct config * conf)
312 FREE(conf->udev_dir);
315 FREE(conf->selector);
321 FREE(conf->features);
324 FREE(conf->hwhandler);
326 free_blacklist(conf->blist_devnode);
327 free_blacklist(conf->blist_wwid);
328 free_blacklist_device(conf->blist_device);
330 free_blacklist(conf->elist_devnode);
331 free_blacklist(conf->elist_wwid);
332 free_blacklist_device(conf->elist_device);
334 free_mptable(conf->mptable);
335 free_hwtable(conf->hwtable);
336 free_keywords(conf->keywords);
341 load_config (char * file)
344 conf = alloc_config();
352 if (!conf->verbosity)
355 conf->dev_type = DEV_NONE;
357 conf->bindings_file = DEFAULT_BINDINGS_FILE;
360 * read the config file
362 if (filepresent(file)) {
363 set_current_keywords(&conf->keywords);
364 if (init_data(file, init_keywords)) {
365 condlog(0, "error parsing config file");
371 * fill the voids left in the config file
373 if (conf->hwtable == NULL) {
374 conf->hwtable = vector_alloc();
380 if (setup_default_hwtable(conf->hwtable))
383 if (conf->blist_devnode == NULL) {
384 conf->blist_devnode = vector_alloc();
386 if (!conf->blist_devnode)
389 if (conf->blist_wwid == NULL) {
390 conf->blist_wwid = vector_alloc();
392 if (!conf->blist_wwid)
395 if (conf->blist_device == NULL) {
396 conf->blist_device = vector_alloc();
398 if (!conf->blist_device)
401 if (setup_default_blist(conf))
404 if (conf->elist_devnode == NULL) {
405 conf->elist_devnode = vector_alloc();
407 if (!conf->elist_devnode)
410 if (conf->elist_wwid == NULL) {
411 conf->elist_wwid = vector_alloc();
413 if (!conf->elist_wwid)
417 if (conf->elist_device == NULL) {
418 conf->elist_device = vector_alloc();
420 if (!conf->elist_device)
424 if (conf->mptable == NULL) {
425 conf->mptable = vector_alloc();
430 if (conf->selector == NULL)
431 conf->selector = set_default(DEFAULT_SELECTOR);
433 if (conf->udev_dir == NULL)
434 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
436 if (conf->getuid == NULL)
437 conf->getuid = set_default(DEFAULT_GETUID);
439 if (conf->features == NULL)
440 conf->features = set_default(DEFAULT_FEATURES);
442 if (conf->hwhandler == NULL)
443 conf->hwhandler = set_default(DEFAULT_HWHANDLER);
445 if (!conf->selector || !conf->udev_dir ||
446 !conf->getuid || !conf->features ||
451 conf->prio = prio_default();
454 conf->checker = checker_lookup(DEFAULT_CHECKER);