#include "util.h"
#include "debug.h"
#include "regex.h"
+#include "structs.h"
+#include "config.h"
#include "blacklist.h"
-static int
+struct blentry {
+ char * str;
+ regex_t regex;
+};
+
+struct blentry_device {
+ char * vendor;
+ char * product;
+ regex_t vendor_reg;
+ regex_t product_reg;
+};
+
+extern int
store_ble (vector blist, char * str)
{
- regex_t * ble;
+ struct blentry * ble;
if (!str)
return 0;
- ble = MALLOC(sizeof(regex_t));
+ if (!blist)
+ goto out;
+
+ ble = MALLOC(sizeof(struct blentry));
if (!ble)
goto out;
- if (regcomp(ble, str, REG_EXTENDED|REG_NOSUB))
+ if (regcomp(&ble->regex, str, REG_EXTENDED|REG_NOSUB))
goto out1;
if (!vector_alloc_slot(blist))
goto out1;
+ ble->str = str;
vector_set_slot(blist, ble);
return 0;
out1:
FREE(ble);
out:
+ FREE(str);
return 1;
}
+
+extern int
+alloc_ble_device (vector blist)
+{
+ struct blentry_device * ble = MALLOC(sizeof(struct blentry_device));
+
+ if (!ble || !blist)
+ return 1;
+
+ if (!vector_alloc_slot(blist)) {
+ FREE(ble);
+ return 1;
+ }
+ vector_set_slot(blist, ble);
+ return 0;
+}
+
+extern int
+set_ble_device (vector blist, char * vendor, char * product)
+{
+ struct blentry_device * ble;
+
+ if (!blist)
+ return 1;
+
+ ble = VECTOR_SLOT(blist, VECTOR_SIZE(blist) - 1);
+
+ if (!ble)
+ return 1;
+
+ if (vendor) {
+ if (regcomp(&ble->vendor_reg, vendor,
+ REG_EXTENDED|REG_NOSUB)) {
+ FREE(vendor);
+ return 1;
+ }
+ ble->vendor = vendor;
+ }
+ if (product) {
+ if (regcomp(&ble->product_reg, product,
+ REG_EXTENDED|REG_NOSUB)) {
+ FREE(product);
+ return 1;
+ }
+ ble->product = product;
+ }
+ return 0;
+}
+
int
setup_default_blist (vector blist)
{
}
int
-blacklist (vector blist, char * dev)
+blacklist (vector blist, char * str)
{
int i;
- regex_t * ble;
+ struct blentry * ble;
vector_foreach_slot (blist, ble, i) {
- if (!regexec(ble, dev, 0, NULL, 0)) {
- condlog(3, "%s blacklisted", dev);
+ if (!regexec(&ble->regex, str, 0, NULL, 0)) {
+ condlog(3, "%s blacklisted", str);
return 1;
}
}
}
int
-store_regex (vector blist, char * regex)
+blacklist_device (vector blist, char * vendor, char * product)
{
- if (!blist)
+ int i;
+ struct blentry_device * ble;
+
+ vector_foreach_slot (blist, ble, i) {
+ if (!regexec(&ble->vendor_reg, vendor, 0, NULL, 0) &&
+ !regexec(&ble->product_reg, product, 0, NULL, 0)) {
+ condlog(3, "%s:%s blacklisted", vendor, product);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int
+blacklist_path (struct config * conf, struct path * pp)
+{
+ if (blacklist(conf->blist_devnode, pp->dev))
+ return 1;
+
+ if (blacklist(conf->blist_wwid, pp->wwid))
return 1;
- if (!regex)
+ if (pp->vendor_id && pp->product_id &&
+ blacklist_device(conf->blist_device, pp->vendor_id, pp->product_id))
return 1;
- return store_ble(blist, regex);
-}
+ return 0;
+}
void
free_blacklist (vector blist)
{
- regex_t * ble;
+ struct blentry * ble;
int i;
if (!blist)
vector_foreach_slot (blist, ble, i) {
if (ble) {
- regfree(ble);
+ //regfree(ble->regex);
+ FREE(ble->str);
FREE(ble);
}
}
+ vector_free(blist);
+}
+
+void
+free_blacklist_device (vector blist)
+{
+ struct blentry_device * ble;
+ int i;
+ if (!blist)
+ return;
+
+ vector_foreach_slot (blist, ble, i) {
+ if (ble) {
+ FREE(ble->vendor);
+ FREE(ble->product);
+ FREE(ble);
+ }
+ }
vector_free(blist);
}
#ifndef _BLACKLIST_H
#define _BLACKLIST_H
-#define BLIST_ENTRY_SIZE 255
-
-int setup_default_blist (vector blist);
-int blacklist (vector blist, char * dev);
-int store_regex (vector blist, char * regex);
-void free_blacklist (vector blist);
+int setup_default_blist (vector);
+int alloc_ble_device (vector);
+int blacklist (vector, char *);
+int blacklist_device (vector, char *, char *);
+int blacklist_path (struct config *, struct path *);
+int store_ble (vector, char *);
+int set_ble_device (vector, char *, char *);
+void free_blacklist (vector);
+void free_blacklist_device (vector);
#endif /* _BLACKLIST_H */
#include "dict.h"
#include "hwtable.h"
#include "vector.h"
+#include "structs.h"
+#include "config.h"
#include "blacklist.h"
#include "defaults.h"
-#include "config.h"
#include "../libcheckers/checkers.h"
if (conf->default_hwhandler)
FREE(conf->default_hwhandler);
- free_blacklist(conf->blist);
+ free_blacklist(conf->blist_devnode);
+ free_blacklist(conf->blist_wwid);
+ free_blacklist_device(conf->blist_device);
free_mptable(conf->mptable);
free_hwtable(conf->hwtable);
if (setup_default_hwtable(conf->hwtable))
goto out;
- if (conf->blist == NULL) {
- conf->blist = vector_alloc();
+ if (conf->blist_devnode == NULL) {
+ conf->blist_devnode = vector_alloc();
+
+ if (!conf->blist_devnode)
+ goto out;
- if (!conf->blist)
+ if (setup_default_blist(conf->blist_devnode))
goto out;
+ }
+ if (conf->blist_wwid == NULL) {
+ conf->blist_wwid = vector_alloc();
+
+ if (!conf->blist_wwid)
+ goto out;
+ }
+ if (conf->blist_device == NULL) {
+ conf->blist_device = vector_alloc();
- if (setup_default_blist(conf->blist))
+ if (!conf->blist_device)
goto out;
}
if (conf->mptable == NULL) {
vector mptable;
vector hwtable;
- vector blist;
+
+ vector blist_devnode;
+ vector blist_wwid;
+ vector blist_device;
};
struct config * conf;
#include "vector.h"
#include "memory.h"
#include "devmapper.h"
-#include "blacklist.h"
#include "defaults.h"
#include "structs.h"
#include "structs_vec.h"
#include "dmparser.h"
#include "config.h"
+#include "blacklist.h"
#include "propsel.h"
#include "discovery.h"
#include "debug.h"
/* 1. if path has no unique id or wwid blacklisted */
if (memcmp(empty_buff, pp1->wwid, WWID_SIZE) == 0 ||
- blacklist(conf->blist, pp1->wwid))
+ blacklist_path(conf, pp1))
continue;
/* 2. if path already coalesced */
static int
blacklist_handler(vector strvec)
{
- conf->blist = vector_alloc();
+ conf->blist_devnode = vector_alloc();
+ conf->blist_wwid = vector_alloc();
+ conf->blist_device = vector_alloc();
- if (!conf->blist)
+ if (!conf->blist_devnode || !conf->blist_wwid || !conf->blist_device)
return 1;
return 0;
}
static int
-ble_handler(vector strvec)
+ble_devnode_handler(vector strvec)
{
char * buff;
- int ret;
buff = set_value(strvec);
if (!buff)
return 1;
- ret = store_regex(conf->blist, buff);
- FREE(buff);
+ return store_ble(conf->blist_devnode, buff);
+}
+
+static int
+ble_wwid_handler(vector strvec)
+{
+ char * buff;
+
+ buff = set_value(strvec);
+
+ if (!buff)
+ return 1;
+
+ return store_ble(conf->blist_wwid, buff);
+}
- return ret;
+static int
+ble_device_handler(vector strvec)
+{
+ return alloc_ble_device(conf->blist_device);
+}
+
+static int
+ble_vendor_handler(vector strvec)
+{
+ char * buff;
+
+ buff = set_value(strvec);
+
+ if (!buff)
+ return 1;
+
+ return set_ble_device(conf->blist_device, buff, NULL);
+}
+
+static int
+ble_product_handler(vector strvec)
+{
+ char * buff;
+
+ buff = set_value(strvec);
+
+ if (!buff)
+ return 1;
+
+ return set_ble_device(conf->blist_device, NULL, buff);
}
/*
install_keyword("default_path_checker", &def_path_checker_handler, NULL);
install_keyword_root("devnode_blacklist", &blacklist_handler);
- install_keyword("devnode", &ble_handler, NULL);
- install_keyword("wwid", &ble_handler, NULL);
+ install_keyword("devnode", &ble_devnode_handler, NULL);
+ install_keyword("wwid", &ble_wwid_handler, NULL);
+ install_keyword("device", &ble_device_handler, NULL);
+ install_sublevel();
+ install_keyword("vendor", &ble_vendor_handler, NULL);
+ install_keyword("product", &ble_product_handler, NULL);
+ install_sublevel_end();
install_keyword_root("devices", &devices_handler);
install_keyword("device", &device_handler, NULL);
#include "vector.h"
#include "memory.h"
-#include "blacklist.h"
#include "util.h"
#include "structs.h"
-#include "callout.h"
#include "config.h"
+#include "blacklist.h"
+#include "callout.h"
#include "debug.h"
#include "propsel.h"
#include "sg_include.h"
if (!devp)
continue;
- if (blacklist(conf->blist, devp->name))
+ if (blacklist(conf->blist_devnode, devp->name))
continue;
if(safe_sprintf(path, "%s/block/%s/device", sysfs_path,
#include "config.h"
#include "debug.h"
#include "structs_vec.h"
+#include "blacklist.h"
struct path *
alloc_path (void)
return count;
}
-
dev = conf->dev;
}
- if (dev && blacklist(conf->blist, dev))
+ if (dev && blacklist(conf->blist_devnode, dev))
goto out;
/*
goto out;
}
condlog(3, "scope limited to %s", refwwid);
+
+ if (blacklist(conf->blist_wwid, refwwid))
+ goto out;
}
/*
condlog(2, "%s: add path (operator)", param);
- if (blacklist(conf->blist, param)) {
+ if (blacklist(conf->blist_devnode, param)) {
*reply = strdup("blacklisted");
*len = strlen(*reply) + 1;
condlog(2, "%s: path blacklisted", param);
condlog(2, "%s: add map (operator)", param);
+ if (blacklist(conf->blist_wwid, param)) {
+ *reply = strdup("blacklisted");
+ *len = strlen(*reply) + 1;
+ condlog(2, "%s: map blacklisted", param);
+ return 0;
+ }
return ev_add_map(param, vecs);
}
#include <config.h>
#include <callout.h>
#include <util.h>
-#include <blacklist.h>
#include <hwtable.h>
#include <defaults.h>
#include <structs.h>
+#include <blacklist.h>
#include <structs_vec.h>
#include <dmparser.h>
#include <devmapper.h>
/*
* path add/remove event
*/
- if (blacklist(conf->blist, devname))
+ if (blacklist(conf->blist_devnode, devname))
goto out;
if (!strncmp(uev->action, "add", 3)) {