Blame libmultipath/blacklist.c

Packit Service 0af388
/*
Packit Service 0af388
 * Copyright (c) 2004, 2005 Christophe Varoqui
Packit Service 0af388
 */
Packit Service 0af388
#include <stdio.h>
Packit Service 0af388
#include <libudev.h>
Packit Service 0af388
Packit Service 0af388
#include "checkers.h"
Packit Service 0af388
#include "memory.h"
Packit Service 0af388
#include "vector.h"
Packit Service 0af388
#include "util.h"
Packit Service 0af388
#include "debug.h"
Packit Service 0af388
#include "structs.h"
Packit Service 0af388
#include "config.h"
Packit Service 0af388
#include "blacklist.h"
Packit Service 0af388
#include "structs_vec.h"
Packit Service 0af388
#include "print.h"
Packit Service 0af388
Packit Service 0af388
int store_ble(vector blist, char * str, int origin)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry * ble;
Packit Service 0af388
Packit Service 0af388
	if (!str)
Packit Service 0af388
		return 0;
Packit Service 0af388
Packit Service 0af388
	if (!blist)
Packit Service 0af388
		goto out;
Packit Service 0af388
Packit Service 0af388
	ble = MALLOC(sizeof(struct blentry));
Packit Service 0af388
Packit Service 0af388
	if (!ble)
Packit Service 0af388
		goto out;
Packit Service 0af388
Packit Service 0af388
	if (regcomp(&ble->regex, str, REG_EXTENDED|REG_NOSUB))
Packit Service 0af388
		goto out1;
Packit Service 0af388
Packit Service 0af388
	if (!vector_alloc_slot(blist))
Packit Service 0af388
		goto out1;
Packit Service 0af388
Packit Service 0af388
	ble->str = str;
Packit Service 0af388
	ble->origin = origin;
Packit Service 0af388
	vector_set_slot(blist, ble);
Packit Service 0af388
	return 0;
Packit Service 0af388
out1:
Packit Service 0af388
	FREE(ble);
Packit Service 0af388
out:
Packit Service 0af388
	FREE(str);
Packit Service 0af388
	return 1;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
Packit Service 0af388
int alloc_ble_device(vector blist)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry_device * ble = MALLOC(sizeof(struct blentry_device));
Packit Service 0af388
Packit Service 0af388
	if (!ble)
Packit Service 0af388
		return 1;
Packit Service 0af388
Packit Service 0af388
	if (!blist || !vector_alloc_slot(blist)) {
Packit Service 0af388
		FREE(ble);
Packit Service 0af388
		return 1;
Packit Service 0af388
	}
Packit Service 0af388
	vector_set_slot(blist, ble);
Packit Service 0af388
	return 0;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int set_ble_device(vector blist, char * vendor, char * product, int origin)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry_device * ble;
Packit Service 0af388
Packit Service 0af388
	if (!blist)
Packit Service 0af388
		return 1;
Packit Service 0af388
Packit Service 0af388
	ble = VECTOR_LAST_SLOT(blist);
Packit Service 0af388
Packit Service 0af388
	if (!ble)
Packit Service 0af388
		return 1;
Packit Service 0af388
Packit Service 0af388
	if (vendor) {
Packit Service 0af388
		if (regcomp(&ble->vendor_reg, vendor,
Packit Service 0af388
			    REG_EXTENDED|REG_NOSUB)) {
Packit Service 0af388
			FREE(vendor);
Packit Service 0af388
			if (product)
Packit Service 0af388
				FREE(product);
Packit Service 0af388
			return 1;
Packit Service 0af388
		}
Packit Service 0af388
		ble->vendor = vendor;
Packit Service 0af388
	}
Packit Service 0af388
	if (product) {
Packit Service 0af388
		if (regcomp(&ble->product_reg, product,
Packit Service 0af388
			    REG_EXTENDED|REG_NOSUB)) {
Packit Service 0af388
			FREE(product);
Packit Service 0af388
			if (vendor) {
Packit Service 0af388
				ble->vendor = NULL;
Packit Service 0af388
				FREE(vendor);
Packit Service 0af388
			}
Packit Service 0af388
			return 1;
Packit Service 0af388
		}
Packit Service 0af388
		ble->product = product;
Packit Service 0af388
	}
Packit Service 0af388
	ble->origin = origin;
Packit Service 0af388
	return 0;
Packit Service 0af388
}
Packit Service 0af388
Packit Service c6ddb4
static int
Packit Service c6ddb4
match_reglist (vector blist, const char * str)
Packit Service 0af388
{
Packit Service 0af388
	int i;
Packit Service 0af388
	struct blentry * ble;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot (blist, ble, i) {
Packit Service 0af388
		if (!regexec(&ble->regex, str, 0, NULL, 0))
Packit Service 0af388
			return 1;
Packit Service 0af388
	}
Packit Service 0af388
	return 0;
Packit Service 0af388
}
Packit Service 0af388
Packit Service c6ddb4
static int
Packit Service c6ddb4
match_reglist_device (const struct _vector *blist, const char * vendor,
Packit Service c6ddb4
		    const char * product)
Packit Service 0af388
{
Packit Service 0af388
	int i;
Packit Service 0af388
	struct blentry_device * ble;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot (blist, ble, i) {
Packit Service 0af388
		if (!ble->vendor && !ble->product)
Packit Service 0af388
			continue;
Packit Service 0af388
		if ((!ble->vendor ||
Packit Service 0af388
		     !regexec(&ble->vendor_reg, vendor, 0, NULL, 0)) &&
Packit Service 0af388
		    (!ble->product ||
Packit Service 0af388
		     !regexec(&ble->product_reg, product, 0, NULL, 0)))
Packit Service 0af388
			return 1;
Packit Service 0af388
	}
Packit Service 0af388
	return 0;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
static int
Packit Service 0af388
find_blacklist_device (const struct _vector *blist, const char * vendor,
Packit Service 0af388
		       const char * product)
Packit Service 0af388
{
Packit Service 0af388
	int i;
Packit Service 0af388
	struct blentry_device * ble;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot (blist, ble, i) {
Packit Service 0af388
		if (((!vendor && !ble->vendor) ||
Packit Service 0af388
		     (vendor && ble->vendor &&
Packit Service 0af388
		      !strcmp(vendor, ble->vendor))) &&
Packit Service 0af388
		    ((!product && !ble->product) ||
Packit Service 0af388
		     (product && ble->product &&
Packit Service 0af388
		      !strcmp(product, ble->product))))
Packit Service 0af388
			return 1;
Packit Service 0af388
	}
Packit Service 0af388
	return 0;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
setup_default_blist (struct config * conf)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry * ble;
Packit Service 0af388
	struct hwentry *hwe;
Packit Service 0af388
	char * str;
Packit Service 0af388
	int i;
Packit Service 0af388
Packit Service 0af388
	str = STRDUP("^(ram|zram|raw|loop|fd|md|dm-|sr|scd|st|dcssblk)[0-9]");
Packit Service 0af388
	if (!str)
Packit Service 0af388
		return 1;
Packit Service 0af388
	if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT))
Packit Service 0af388
		return 1;
Packit Service 0af388
Packit Service 0af388
	str = STRDUP("^(td|hd|vd)[a-z]");
Packit Service 0af388
	if (!str)
Packit Service 0af388
		return 1;
Packit Service 0af388
	if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT))
Packit Service 0af388
		return 1;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot (conf->hwtable, hwe, i) {
Packit Service 0af388
		if (hwe->bl_product) {
Packit Service 0af388
			if (find_blacklist_device(conf->blist_device,
Packit Service 0af388
						  hwe->vendor, hwe->bl_product))
Packit Service 0af388
				continue;
Packit Service 0af388
			if (alloc_ble_device(conf->blist_device))
Packit Service 0af388
				return 1;
Packit Service 0af388
			ble = VECTOR_SLOT(conf->blist_device,
Packit Service 0af388
					  VECTOR_SIZE(conf->blist_device) - 1);
Packit Service 0af388
			if (set_ble_device(conf->blist_device,
Packit Service 0af388
					   STRDUP(hwe->vendor),
Packit Service 0af388
					   STRDUP(hwe->bl_product),
Packit Service 0af388
					   ORIGIN_DEFAULT)) {
Packit Service 0af388
				FREE(ble);
Packit Service 0af388
				vector_del_slot(conf->blist_device, VECTOR_SIZE(conf->blist_device) - 1);
Packit Service 0af388
				return 1;
Packit Service 0af388
			}
Packit Service 0af388
		}
Packit Service 0af388
	}
Packit Service 0af388
	return 0;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
#define LOG_BLIST(M, S, lvl)						\
Packit Service 0af388
	if (vendor && product)						\
Packit Service 0af388
		condlog(lvl, "%s: (%s:%s) %s %s",			\
Packit Service 0af388
			dev, vendor, product, (M), (S));		\
Packit Service 0af388
	else if (wwid && !dev)						\
Packit Service 0af388
		condlog(lvl, "%s: %s %s", wwid, (M), (S));		\
Packit Service 0af388
	else if (wwid)							\
Packit Service 0af388
		condlog(lvl, "%s: %s %s %s", dev, (M), wwid, (S));	\
Packit Service 0af388
	else if (env)							\
Packit Service 0af388
		condlog(lvl, "%s: %s %s %s", dev, (M), env, (S));	\
Packit Service 0af388
	else if (protocol)						\
Packit Service 0af388
		condlog(lvl, "%s: %s %s %s", dev, (M), protocol, (S));	\
Packit Service 0af388
	else								\
Packit Service 0af388
		condlog(lvl, "%s: %s %s", dev, (M), (S))
Packit Service 0af388
Packit Service 0af388
static void
Packit Service 0af388
log_filter (const char *dev, char *vendor, char *product, char *wwid,
Packit Service 0af388
	    const char *env, const char *protocol, int r, int lvl)
Packit Service 0af388
{
Packit Service 0af388
	/*
Packit Service 0af388
	 * Try to sort from most likely to least.
Packit Service 0af388
	 */
Packit Service 0af388
	switch (r) {
Packit Service 0af388
	case MATCH_NOTHING:
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_DEVICE_BLIST:
Packit Service 0af388
		LOG_BLIST("vendor/product", "blacklisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_WWID_BLIST:
Packit Service 0af388
		LOG_BLIST("wwid", "blacklisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_DEVNODE_BLIST:
Packit Service 0af388
		LOG_BLIST("device node name", "blacklisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_PROPERTY_BLIST:
Packit Service 0af388
		LOG_BLIST("udev property", "blacklisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_PROTOCOL_BLIST:
Packit Service 0af388
		LOG_BLIST("protocol", "blacklisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_DEVICE_BLIST_EXCEPT:
Packit Service 0af388
		LOG_BLIST("vendor/product", "whitelisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_WWID_BLIST_EXCEPT:
Packit Service 0af388
		LOG_BLIST("wwid", "whitelisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_DEVNODE_BLIST_EXCEPT:
Packit Service 0af388
		LOG_BLIST("device node name", "whitelisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_PROPERTY_BLIST_EXCEPT:
Packit Service 0af388
		LOG_BLIST("udev property", "whitelisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_PROPERTY_BLIST_MISSING:
Packit Service 0af388
		LOG_BLIST("blacklisted,", "udev property missing", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	case MATCH_PROTOCOL_BLIST_EXCEPT:
Packit Service 0af388
		LOG_BLIST("protocol", "whitelisted", lvl);
Packit Service 0af388
		break;
Packit Service 0af388
	}
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
filter_device (vector blist, vector elist, char * vendor, char * product,
Packit Service 0af388
	       char * dev)
Packit Service 0af388
{
Packit Service 0af388
	int r = MATCH_NOTHING;
Packit Service 0af388
Packit Service 0af388
	if (vendor && product) {
Packit Service c6ddb4
		if (match_reglist_device(elist, vendor, product))
Packit Service 0af388
			r = MATCH_DEVICE_BLIST_EXCEPT;
Packit Service c6ddb4
		else if (match_reglist_device(blist, vendor, product))
Packit Service 0af388
			r = MATCH_DEVICE_BLIST;
Packit Service 0af388
	}
Packit Service 0af388
Packit Service 0af388
	log_filter(dev, vendor, product, NULL, NULL, NULL, r, 3);
Packit Service 0af388
	return r;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
filter_devnode (vector blist, vector elist, char * dev)
Packit Service 0af388
{
Packit Service 0af388
	int r = MATCH_NOTHING;
Packit Service 0af388
Packit Service 0af388
	if (dev) {
Packit Service c6ddb4
		if (match_reglist(elist, dev))
Packit Service 0af388
			r = MATCH_DEVNODE_BLIST_EXCEPT;
Packit Service c6ddb4
		else if (match_reglist(blist, dev))
Packit Service 0af388
			r = MATCH_DEVNODE_BLIST;
Packit Service 0af388
	}
Packit Service 0af388
Packit Service 0af388
	log_filter(dev, NULL, NULL, NULL, NULL, NULL, r, 3);
Packit Service 0af388
	return r;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
filter_wwid (vector blist, vector elist, char * wwid, char * dev)
Packit Service 0af388
{
Packit Service 0af388
	int r = MATCH_NOTHING;
Packit Service 0af388
Packit Service 0af388
	if (wwid) {
Packit Service c6ddb4
		if (match_reglist(elist, wwid))
Packit Service 0af388
			r = MATCH_WWID_BLIST_EXCEPT;
Packit Service c6ddb4
		else if (match_reglist(blist, wwid))
Packit Service 0af388
			r = MATCH_WWID_BLIST;
Packit Service 0af388
	}
Packit Service 0af388
Packit Service 0af388
	log_filter(dev, NULL, NULL, wwid, NULL, NULL, r, 3);
Packit Service 0af388
	return r;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
filter_protocol(vector blist, vector elist, struct path * pp)
Packit Service 0af388
{
Packit Service 0af388
	char buf[PROTOCOL_BUF_SIZE];
Packit Service 0af388
	int r = MATCH_NOTHING;
Packit Service 0af388
Packit Service 0af388
	if (pp) {
Packit Service 0af388
		snprint_path_protocol(buf, sizeof(buf), pp);
Packit Service 0af388
Packit Service c6ddb4
		if (match_reglist(elist, buf))
Packit Service 0af388
			r = MATCH_PROTOCOL_BLIST_EXCEPT;
Packit Service c6ddb4
		else if (match_reglist(blist, buf))
Packit Service 0af388
			r = MATCH_PROTOCOL_BLIST;
Packit Service 0af388
	}
Packit Service 0af388
Packit Service 0af388
	log_filter(pp->dev, NULL, NULL, NULL, NULL, buf, r, 3);
Packit Service 0af388
	return r;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
filter_path (struct config * conf, struct path * pp)
Packit Service 0af388
{
Packit Service 0af388
	int r;
Packit Service 0af388
Packit Service 0af388
	r = filter_property(conf, pp->udev, 3, pp->uid_attribute);
Packit Service 0af388
	if (r > 0)
Packit Service 0af388
		return r;
Packit Service 0af388
	r = filter_devnode(conf->blist_devnode, conf->elist_devnode, pp->dev);
Packit Service 0af388
	if (r > 0)
Packit Service 0af388
		return r;
Packit Service 0af388
	r = filter_device(conf->blist_device, conf->elist_device,
Packit Service 0af388
			   pp->vendor_id, pp->product_id, pp->dev);
Packit Service 0af388
	if (r > 0)
Packit Service 0af388
		return r;
Packit Service 0af388
	r = filter_protocol(conf->blist_protocol, conf->elist_protocol, pp);
Packit Service 0af388
	if (r > 0)
Packit Service 0af388
		return r;
Packit Service 0af388
	r = filter_wwid(conf->blist_wwid, conf->elist_wwid, pp->wwid, pp->dev);
Packit Service 0af388
	return r;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
filter_property(struct config *conf, struct udev_device *udev, int lvl,
Packit Service 0af388
		const char *uid_attribute)
Packit Service 0af388
{
Packit Service 0af388
	const char *devname = udev_device_get_sysname(udev);
Packit Service 0af388
	struct udev_list_entry *list_entry;
Packit Service 0af388
	const char *env = NULL;
Packit Service 0af388
	int r = MATCH_NOTHING;
Packit Service 0af388
Packit Service 0af388
	if (udev) {
Packit Service 0af388
		/*
Packit Service 0af388
		 * This is the inverse of the 'normal' matching;
Packit Service 0af388
		 * the environment variable _has_ to match.
Packit Service 0af388
		 * But only if the uid_attribute used for determining the WWID
Packit Service 0af388
		 * of the path is is present in the environment
Packit Service 0af388
		 * (uid_attr_seen). If this is not the case, udev probably
Packit Service 0af388
		 * just failed to access the device, which should not cause the
Packit Service 0af388
		 * device to be blacklisted (it won't be used by multipath
Packit Service 0af388
		 * anyway without WWID).
Packit Service 0af388
		 * Likewise, if no uid attribute is defined, udev-based WWID
Packit Service 0af388
		 * determination is effectively off, and devices shouldn't be
Packit Service 0af388
		 * blacklisted by missing properties (check_missing_prop).
Packit Service 0af388
		 */
Packit Service 0af388
Packit Service 0af388
		bool check_missing_prop = uid_attribute != NULL &&
Packit Service 0af388
			*uid_attribute != '\0';
Packit Service 0af388
		bool uid_attr_seen = false;
Packit Service 0af388
Packit Service 8aace1
		if (VECTOR_SIZE(conf->elist_property))
Packit Service 8aace1
			r = MATCH_PROPERTY_BLIST_MISSING;
Packit Service 0af388
		udev_list_entry_foreach(list_entry,
Packit Service 0af388
				udev_device_get_properties_list_entry(udev)) {
Packit Service 0af388
Packit Service 0af388
			env = udev_list_entry_get_name(list_entry);
Packit Service 0af388
			if (!env)
Packit Service 0af388
				continue;
Packit Service 0af388
Packit Service 0af388
			if (check_missing_prop && !strcmp(env, uid_attribute))
Packit Service 0af388
				uid_attr_seen = true;
Packit Service 0af388
Packit Service c6ddb4
			if (match_reglist(conf->elist_property, env)) {
Packit Service 0af388
				r = MATCH_PROPERTY_BLIST_EXCEPT;
Packit Service 0af388
				break;
Packit Service 0af388
			}
Packit Service c6ddb4
			if (match_reglist(conf->blist_property, env)) {
Packit Service 0af388
				r = MATCH_PROPERTY_BLIST;
Packit Service 0af388
				break;
Packit Service 0af388
			}
Packit Service 0af388
			env = NULL;
Packit Service 0af388
		}
Packit Service 0af388
		if (r == MATCH_PROPERTY_BLIST_MISSING &&
Packit Service 0af388
		    (!check_missing_prop || !uid_attr_seen))
Packit Service 0af388
			r = MATCH_NOTHING;
Packit Service 0af388
	}
Packit Service 0af388
Packit Service 0af388
	log_filter(devname, NULL, NULL, NULL, env, NULL, r, lvl);
Packit Service 0af388
	return r;
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
static void free_ble(struct blentry *ble)
Packit Service 0af388
{
Packit Service 0af388
	if (!ble)
Packit Service 0af388
		return;
Packit Service 0af388
	regfree(&ble->regex);
Packit Service 0af388
	FREE(ble->str);
Packit Service 0af388
	FREE(ble);
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
void
Packit Service 0af388
free_blacklist (vector blist)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry * ble;
Packit Service 0af388
	int i;
Packit Service 0af388
Packit Service 0af388
	if (!blist)
Packit Service 0af388
		return;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot (blist, ble, i) {
Packit Service 0af388
		free_ble(ble);
Packit Service 0af388
	}
Packit Service 0af388
	vector_free(blist);
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
void merge_blacklist(vector blist)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry *bl1, *bl2;
Packit Service 0af388
	int i, j;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot(blist, bl1, i) {
Packit Service 0af388
		j = i + 1;
Packit Service 0af388
		vector_foreach_slot_after(blist, bl2, j) {
Packit Service 0af388
			if (!bl1->str || !bl2->str || strcmp(bl1->str, bl2->str))
Packit Service 0af388
				continue;
Packit Service 0af388
			condlog(3, "%s: duplicate blist entry section for %s",
Packit Service 0af388
				__func__, bl1->str);
Packit Service 0af388
			free_ble(bl2);
Packit Service 0af388
			vector_del_slot(blist, j);
Packit Service 0af388
			j--;
Packit Service 0af388
		}
Packit Service 0af388
	}
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
static void free_ble_device(struct blentry_device *ble)
Packit Service 0af388
{
Packit Service 0af388
	if (ble) {
Packit Service 0af388
		if (ble->vendor) {
Packit Service 0af388
			regfree(&ble->vendor_reg);
Packit Service 0af388
			FREE(ble->vendor);
Packit Service 0af388
		}
Packit Service 0af388
		if (ble->product) {
Packit Service 0af388
			regfree(&ble->product_reg);
Packit Service 0af388
			FREE(ble->product);
Packit Service 0af388
		}
Packit Service 0af388
		FREE(ble);
Packit Service 0af388
	}
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
void
Packit Service 0af388
free_blacklist_device (vector blist)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry_device * ble;
Packit Service 0af388
	int i;
Packit Service 0af388
Packit Service 0af388
	if (!blist)
Packit Service 0af388
		return;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot (blist, ble, i) {
Packit Service 0af388
		free_ble_device(ble);
Packit Service 0af388
	}
Packit Service 0af388
	vector_free(blist);
Packit Service 0af388
}
Packit Service 0af388
Packit Service 0af388
void merge_blacklist_device(vector blist)
Packit Service 0af388
{
Packit Service 0af388
	struct blentry_device *bl1, *bl2;
Packit Service 0af388
	int i, j;
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot(blist, bl1, i) {
Packit Service 0af388
		if (!bl1->vendor && !bl1->product) {
Packit Service 0af388
			free_ble_device(bl1);
Packit Service 0af388
			vector_del_slot(blist, i);
Packit Service 0af388
			i--;
Packit Service 0af388
		}
Packit Service 0af388
	}
Packit Service 0af388
Packit Service 0af388
	vector_foreach_slot(blist, bl1, i) {
Packit Service 0af388
		j = i + 1;
Packit Service 0af388
		vector_foreach_slot_after(blist, bl2, j) {
Packit Service 0af388
			if ((!bl1->vendor && bl2->vendor) ||
Packit Service 0af388
			    (bl1->vendor && !bl2->vendor) ||
Packit Service 0af388
			    (bl1->vendor && bl2->vendor &&
Packit Service 0af388
			     strcmp(bl1->vendor, bl2->vendor)))
Packit Service 0af388
				continue;
Packit Service 0af388
			if ((!bl1->product && bl2->product) ||
Packit Service 0af388
			    (bl1->product && !bl2->product) ||
Packit Service 0af388
			    (bl1->product && bl2->product &&
Packit Service 0af388
			     strcmp(bl1->product, bl2->product)))
Packit Service 0af388
				continue;
Packit Service 0af388
			condlog(3, "%s: duplicate blist entry section for %s:%s",
Packit Service 0af388
				__func__, bl1->vendor, bl1->product);
Packit Service 0af388
			free_ble_device(bl2);
Packit Service 0af388
			vector_del_slot(blist, j);
Packit Service 0af388
			j--;
Packit Service 0af388
		}
Packit Service 0af388
	}
Packit Service 0af388
}