From patchwork Sat Jan 12 06:04:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 1968711 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork2.kernel.org (Postfix) with ESMTP id 152F4DF230 for ; Sat, 12 Jan 2013 06:09:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0C66F6u018096; Sat, 12 Jan 2013 01:06:15 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0C651JN006151 for ; Sat, 12 Jan 2013 01:05:01 -0500 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0C6501b004852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 12 Jan 2013 01:05:00 -0500 Received: from ether.msp.redhat.com (localhost.localdomain [127.0.0.1]) by ether.msp.redhat.com (8.14.1/8.14.1) with ESMTP id r0C64xZU003432; Sat, 12 Jan 2013 00:05:00 -0600 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r0C64xdc003431; Sat, 12 Jan 2013 00:04:59 -0600 From: Benjamin Marzinski To: device-mapper development Date: Sat, 12 Jan 2013 00:04:43 -0600 Message-Id: <1357970695-3396-6-git-send-email-bmarzins@redhat.com> In-Reply-To: <1357970695-3396-1-git-send-email-bmarzins@redhat.com> References: <1357970695-3396-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH V3 06/18] multipath: remove duplicates from multipath X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Added code to remove duplcate entries in the devices section, and the blacklist devices section of the builtin configuration table. The only change to setup_default_blist is the addition of _blacklist_device() to check if the device's bl_product entry already exists. Signed-off-by: Benjamin Marzinski --- libmultipath/blacklist.c | 91 +++++++++++++++++++++++++----------------------- libmultipath/config.c | 19 ++++++++-- 2 files changed, 63 insertions(+), 47 deletions(-) diff --git a/libmultipath/blacklist.c b/libmultipath/blacklist.c index f369517..49a40f9 100644 --- a/libmultipath/blacklist.c +++ b/libmultipath/blacklist.c @@ -96,50 +96,6 @@ set_ble_device (vector blist, char * vendor, char * product, int origin) } int -setup_default_blist (struct config * conf) -{ - struct blentry * ble; - struct hwentry *hwe; - char * str; - int i; - - str = STRDUP("^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"); - if (!str) - return 1; - if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT)) - return 1; - - str = STRDUP("^hd[a-z]"); - if (!str) - return 1; - if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT)) - return 1; - - str = STRDUP("^dcssblk[0-9]*"); - if (!str) - return 1; - if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT)) - return 1; - - vector_foreach_slot (conf->hwtable, hwe, i) { - if (hwe->bl_product) { - if (alloc_ble_device(conf->blist_device)) - return 1; - ble = VECTOR_SLOT(conf->blist_device, - VECTOR_SIZE(conf->blist_device) -1); - if (set_ble_device(conf->blist_device, - STRDUP(hwe->vendor), - STRDUP(hwe->bl_product), - ORIGIN_DEFAULT)) { - FREE(ble); - return 1; - } - } - } - return 0; -} - -int _blacklist_exceptions (vector elist, char * str) { int i; @@ -193,6 +149,53 @@ _blacklist_device (vector blist, char * vendor, char * product) return 0; } +int +setup_default_blist (struct config * conf) +{ + struct blentry * ble; + struct hwentry *hwe; + char * str; + int i; + + str = STRDUP("^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"); + if (!str) + return 1; + if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT)) + return 1; + + str = STRDUP("^hd[a-z]"); + if (!str) + return 1; + if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT)) + return 1; + + str = STRDUP("^dcssblk[0-9]*"); + if (!str) + return 1; + if (store_ble(conf->blist_devnode, str, ORIGIN_DEFAULT)) + return 1; + + vector_foreach_slot (conf->hwtable, hwe, i) { + if (hwe->bl_product) { + if (_blacklist_device(conf->blist_device, hwe->vendor, + hwe->bl_product)) + continue; + if (alloc_ble_device(conf->blist_device)) + return 1; + ble = VECTOR_SLOT(conf->blist_device, + VECTOR_SIZE(conf->blist_device) -1); + if (set_ble_device(conf->blist_device, + STRDUP(hwe->vendor), + STRDUP(hwe->bl_product), + ORIGIN_DEFAULT)) { + FREE(ble); + return 1; + } + } + } + return 0; +} + #define LOG_BLIST(M) \ if (vendor && product) \ condlog(3, "%s: (%s:%s) %s", dev, vendor, product, (M)); \ diff --git a/libmultipath/config.c b/libmultipath/config.c index 5b26298..50863b2 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -25,13 +25,19 @@ static int hwe_strmatch (struct hwentry *hwe1, struct hwentry *hwe2) { - if (hwe1->vendor && hwe2->vendor && strcmp(hwe1->vendor, hwe2->vendor)) + if ((hwe2->vendor && !hwe1->vendor) || + (hwe1->vendor && (!hwe2->vendor || + strcmp(hwe1->vendor, hwe2->vendor)))) return 1; - if (hwe1->product && hwe2->product && strcmp(hwe1->product, hwe2->product)) + if ((hwe2->product && !hwe1->product) || + (hwe1->product && (!hwe2->product || + strcmp(hwe1->product, hwe2->product)))) return 1; - if (hwe1->revision && hwe2->revision && strcmp(hwe1->revision, hwe2->revision)) + if ((hwe2->revision && !hwe1->revision) || + (hwe1->revision && (!hwe2->revision || + strcmp(hwe1->revision, hwe2->revision)))) return 1; return 0; @@ -416,6 +422,13 @@ factorize_hwtable (vector hw, int n) continue; /* dup */ merge_hwe(hwe2, hwe1); + if (hwe_strmatch(hwe2, hwe1) == 0) { + vector_del_slot(hw, i); + free_hwe(hwe1); + n -= 1; + i -= 1; + break; + } } } return 0;