From patchwork Mon Mar 16 12:36:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6017581 X-Patchwork-Delegate: christophe.varoqui@free.fr 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 531CCBF90F for ; Mon, 16 Mar 2015 12:40:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8155D204D8 for ; Mon, 16 Mar 2015 12:40:40 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33C76204D5 for ; Mon, 16 Mar 2015 12:40:38 +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 t2GCcPar027983; Mon, 16 Mar 2015 08:38:25 -0400 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 t2GCbLWj028983 for ; Mon, 16 Mar 2015 08:37:21 -0400 Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCbKBl020341; Mon, 16 Mar 2015 08:37:20 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCbIgY019213 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=FAIL); Mon, 16 Mar 2015 08:37:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3C7D5ADFA; Mon, 16 Mar 2015 12:37:11 +0000 (UTC) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 16 Mar 2015 13:36:57 +0100 Message-Id: <1426509425-15978-71-git-send-email-hare@suse.de> In-Reply-To: <1426509425-15978-1-git-send-email-hare@suse.de> References: <1426509425-15978-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.309 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, URIBL_BLOCKED) 195.135.220.15 cantor2.suse.de 195.135.220.15 cantor2.suse.de X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.17 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 70/78] multipathd: use SG_IO as fallback to generate uid 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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 If both udev attribute and sysfs vpd fails to generate a valid WWID fallback to use SG_IO directly. Signed-off-by: Hannes Reinecke --- libmultipath/discovery.c | 61 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 50444db..009ef0c 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -998,7 +998,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, } static int -get_vpd (struct udev_device *parent, int fd, int pg, char * str, int maxlen) +get_vpd_sysfs (struct udev_device *parent, int pg, char * str, int maxlen) { int len, buff_len; unsigned char buff[4096]; @@ -1006,11 +1006,39 @@ get_vpd (struct udev_device *parent, int fd, int pg, char * str, int maxlen) memset(buff, 0x0, 4096); if (!parent || sysfs_get_vpd(parent, pg, buff, 4096) <= 0) { condlog(3, "failed to read sysfs vpd pg%02x", pg); - if (sgio_get_vpd(buff, 4096, fd) <= 0) { - condlog(3, "failed to issue vpd inquiry for pg%02x", - pg); - return -errno; - } + return -EINVAL; + } + + if (buff[1] != pg) { + condlog(3, "vpd pg%02x error, invalid vpd page %02x", + pg, buff[1]); + return -ENODATA; + } + buff_len = (buff[2] << 8) + buff[3] + 4; + if (buff_len > 4096) + condlog(3, "vpd pg%02x page truncated", pg); + + if (pg == 0x80) + len = parse_vpd_pg80(buff, str, maxlen); + else if (pg == 0x83) + len = parse_vpd_pg83(buff, buff_len, str, maxlen); + else + len = -ENOSYS; + + return len; +} + +static int +get_vpd_sgio (int fd, int pg, char * str, int maxlen) +{ + int len, buff_len; + unsigned char buff[4096]; + + memset(buff, 0x0, 4096); + if (sgio_get_vpd(buff, 4096, fd) <= 0) { + condlog(3, "failed to issue vpd inquiry for pg%02x", + pg); + return -errno; } if (buff[1] != pg) { @@ -1344,7 +1372,7 @@ scsi_ioctl_pathinfo (struct path * pp, int mask) if (!attr_path || pp->sg_id.host_no == -1) return -ENODEV; - if (get_vpd(parent, pp->fd, 0x80, pp->serial, SERIAL_SIZE) > 0) + if (get_vpd_sysfs(parent, 0x80, pp->serial, SERIAL_SIZE) > 0) condlog(3, "%s: serial = %s", pp->dev, pp->serial); @@ -1474,7 +1502,7 @@ get_vpd_uid(struct path * pp) parent = udev_device_get_parent(parent); } - return get_vpd(parent, pp->fd, 0x83, pp->wwid, WWID_SIZE); + return get_vpd_sysfs(parent, 0x83, pp->wwid, WWID_SIZE); } static int @@ -1513,19 +1541,30 @@ get_uid (struct path * pp) if (pp->uid_attribute) { len = get_udev_uid(pp, pp->uid_attribute); origin = "udev"; + if (len <= 0) + condlog(2, + "%s: failed to get UID attribute '%s'", + pp->dev, pp->uid_attribute); } if (len <= 0) { len = get_vpd_uid(pp); if (len > 0) { origin = "sysfs"; pp->uid_attribute = NULL; + } else { + condlog(2, "%s: failed to get sysfs vpd pg83", + pp->dev); } } if (len <= 0) { - len = get_udev_uid(pp, DEFAULT_UID_ATTRIBUTE); + len = get_vpd_sgio(pp->fd, 0x83, pp->wwid, + WWID_SIZE); if (len > 0) { - origin = "default"; - pp->uid_attribute = DEFAULT_UID_ATTRIBUTE; + origin = "sgio"; + pp->uid_attribute = NULL; + } else { + condlog(2, "%s: failed to get sgio vpd pg83", + pp->dev); } } }