From patchwork Fri Sep 12 17:44:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 4896891 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 097C7BEEA5 for ; Fri, 12 Sep 2014 17:49:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA24A20266 for ; Fri, 12 Sep 2014 17:49:16 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id E091D20225 for ; Fri, 12 Sep 2014 17:49:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s8CHj5CD026568; Fri, 12 Sep 2014 13:45:06 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s8CHj4Uv029269 for ; Fri, 12 Sep 2014 13:45:04 -0400 Received: from dhcp80-209.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8CHj3tR022032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 12 Sep 2014 13:45:04 -0400 Received: from dhcp80-209.msp.redhat.com (localhost [127.0.0.1]) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7) with ESMTP id s8CHj110029865; Fri, 12 Sep 2014 12:45:01 -0500 Received: (from bmarzins@localhost) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7/Submit) id s8CHj1Qb029864; Fri, 12 Sep 2014 12:45:01 -0500 From: Benjamin Marzinski To: device-mapper development Date: Fri, 12 Sep 2014 12:44:47 -0500 Message-Id: <1410543892-29826-2-git-send-email-bmarzins@redhat.com> In-Reply-To: <1410543892-29826-1-git-send-email-bmarzins@redhat.com> References: <1410543892-29826-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 1/6] libmultipath: cleanup rlookup_binding 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 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before the use_existing_alias() code was added, the scan_device() call in rlookup_binding always failed, complicated the function and was completely pointless. Now it has a use, but only when called by use_existing_alias(). Instead of doing this extra work in rlookup_binding() this patch makes use_existing_alias call scan_device() itself when necessary. Signed-off-by: Benjamin Marzinski --- libmultipath/alias.c | 29 ++++++++++++++--------------- libmultipath/propsel.c | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index f1879c9..f2859b0 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -149,13 +149,11 @@ rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix) { char line[LINE_MAX]; unsigned int line_nr = 0; - int id = 0; buff[0] = '\0'; while (fgets(line, LINE_MAX, f)) { char *c, *alias, *wwid; - int curr_id; line_nr++; c = strpbrk(line, "#\n\r"); @@ -164,9 +162,6 @@ rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix) alias = strtok(line, " \t"); if (!alias) /* blank line */ continue; - curr_id = scan_devname(alias, prefix); - if (curr_id >= id) - id = curr_id + 1; wwid = strtok(NULL, " \t"); if (!wwid){ condlog(3, @@ -184,16 +179,12 @@ rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix) "\nSetting wwid to %s", alias, wwid); strncpy(buff, wwid, WWID_SIZE); buff[WWID_SIZE - 1] = '\0'; - return id; + return 0; } } condlog(3, "No matching alias [%s] in bindings file.", map_alias); - /* Get the theoretical id for this map alias. - * Used by use_existing_alias - */ - id = scan_devname(map_alias, prefix); - return id; + return -1; } static char * @@ -264,9 +255,7 @@ use_existing_alias (char *wwid, char *file, char *alias_old, /* lookup the binding. if it exsists, the wwid will be in buff * either way, id contains the id for the alias */ - id = rlookup_binding(f , buff, alias_old, prefix); - if (id < 0) - goto out; + rlookup_binding(f, buff, alias_old, prefix); if (strlen(buff) > 0) { /* if buff is our wwid, it's already @@ -283,7 +272,17 @@ use_existing_alias (char *wwid, char *file, char *alias_old, } /* allocate the existing alias in the bindings file */ - if (can_write && id && !bindings_read_only) { + id = scan_devname(alias_old, prefix); + if (id <= 0) + goto out; + + if (fflush(f) != 0) { + condlog(0, "cannot fflush bindings file stream : %s", + strerror(errno)); + goto out; + } + + if (can_write && !bindings_read_only) { alias = allocate_binding(fd, wwid, id, prefix); condlog(0, "Allocated existing binding [%s] for WWID [%s]", alias, wwid); diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index e23d65c..7a966bb 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -269,7 +269,7 @@ select_alias (struct multipath * mp) mp->alias_old, mp->alias_prefix, conf->bindings_read_only); memset (mp->alias_old, 0, WWID_SIZE); - } + } if (mp->alias == NULL) mp->alias = get_user_friendly_alias(mp->wwid,