2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2005 Benjamin Marzinski, Redhat
4 * Copyright (c) 2005 Edward Goggin, EMC
20 #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)
145 FREE(hwe->hwhandler);
148 FREE(hwe->bl_product);
154 free_hwtable (vector hwtable)
157 struct hwentry * hwe;
162 vector_foreach_slot (hwtable, hwe, i)
165 vector_free(hwtable);
169 free_mpe (struct mpentry * mpe)
190 free_mptable (vector mptable)
193 struct mpentry * mpe;
198 vector_foreach_slot (mptable, mpe, i)
201 vector_free(mptable);
207 struct mpentry * mpe = (struct mpentry *)
208 MALLOC(sizeof(struct mpentry));
213 static struct hwentry *
216 struct hwentry * hwe = (struct hwentry *)
217 MALLOC(sizeof(struct hwentry));
223 set_param_str(char * str)
236 dst = (char *)MALLOC(len + 1);
246 store_hwe (vector hwtable, struct hwentry * dhwe)
248 struct hwentry * hwe;
250 if (find_hwe_strmatch(hwtable, dhwe->vendor, dhwe->product, dhwe->revision))
253 if (!(hwe = alloc_hwe()))
256 if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor)))
259 if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product)))
262 if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
265 if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
268 if (dhwe->getprio && !(hwe->getprio = set_param_str(dhwe->getprio)))
271 if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
274 if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler)))
277 if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector)))
280 hwe->pgpolicy = dhwe->pgpolicy;
281 hwe->pgfailback = dhwe->pgfailback;
282 hwe->rr_weight = dhwe->rr_weight;
283 hwe->no_path_retry = dhwe->no_path_retry;
284 hwe->minio = dhwe->minio;
285 hwe->checker = dhwe->checker;
287 if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
290 if (!vector_alloc_slot(hwtable))
293 vector_set_slot(hwtable, hwe);
303 return (struct config *)MALLOC(sizeof(struct config));
307 free_config (struct config * conf)
316 FREE(conf->udev_dir);
319 FREE(conf->selector);
328 FREE(conf->features);
331 FREE(conf->hwhandler);
333 free_blacklist(conf->blist_devnode);
334 free_blacklist(conf->blist_wwid);
335 free_blacklist_device(conf->blist_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;
359 conf->bindings_file = DEFAULT_BINDINGS_FILE;
362 * read the config file
364 if (filepresent(file)) {
365 set_current_keywords(&conf->keywords);
366 if (init_data(file, init_keywords)) {
367 condlog(0, "error parsing config file");
373 * fill the voids left in the config file
375 if (conf->hwtable == NULL) {
376 conf->hwtable = vector_alloc();
382 if (setup_default_hwtable(conf->hwtable))
385 if (conf->blist_devnode == NULL) {
386 conf->blist_devnode = vector_alloc();
388 if (!conf->blist_devnode)
391 if (conf->blist_wwid == NULL) {
392 conf->blist_wwid = vector_alloc();
394 if (!conf->blist_wwid)
397 if (conf->blist_device == NULL) {
398 conf->blist_device = vector_alloc();
400 if (!conf->blist_device)
403 if (setup_default_blist(conf))
406 if (conf->mptable == NULL) {
407 conf->mptable = vector_alloc();
412 if (conf->selector == NULL)
413 conf->selector = set_default(DEFAULT_SELECTOR);
415 if (conf->udev_dir == NULL)
416 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
418 if (conf->getuid == NULL)
419 conf->getuid = set_default(DEFAULT_GETUID);
421 if (conf->features == NULL)
422 conf->features = set_default(DEFAULT_FEATURES);
424 if (conf->hwhandler == NULL)
425 conf->hwhandler = set_default(DEFAULT_HWHANDLER);
427 if (!conf->selector || !conf->udev_dir ||
428 !conf->getuid || !conf->features ||
433 conf->checker = checker_lookup(DEFAULT_CHECKER);