From patchwork Mon Mar 16 12:36:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6017731 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 F04ABBF911 for ; Mon, 16 Mar 2015 12:41:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 24FED204E7 for ; Mon, 16 Mar 2015 12:41:04 +0000 (UTC) Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0F05D204D9 for ; Mon, 16 Mar 2015 12:41:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCcOYc005360; Mon, 16 Mar 2015 08:38:24 -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 t2GCbKrv028959 for ; Mon, 16 Mar 2015 08:37:20 -0400 Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCbK6Q020336 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 16 Mar 2015 08:37:20 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (Postfix) with ESMTPS id 791D1C79D7; Mon, 16 Mar 2015 12:37:19 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 351AEADF8; Mon, 16 Mar 2015 12:37:11 +0000 (UTC) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 16 Mar 2015 13:36:54 +0100 Message-Id: <1426509425-15978-68-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.75 on 10.5.110.25 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 67/78] libmultipath: Fall back to SG_IO if no UID could be assigned 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Relying on udev attributes or sysfs vpd pages might fail, in which case we're unable to assign an UID and multipath will fail to start up. Implement a fallback to read VPD page 0x83 directly in these cases. Signed-off-by: Hannes Reinecke --- libmultipath/discovery.c | 53 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index f8a0503..d5dda2c 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -770,6 +770,29 @@ get_serial (char * str, int maxlen, int fd) return 1; } +#define DEFAULT_SGIO_LEN 254 + +static int +sgio_get_vpd (unsigned char * buff, int maxlen, int fd) +{ + int len = DEFAULT_SGIO_LEN; + + if (fd < 0) { + errno = EBADF; + return -1; + } +retry: + if (0 == do_inq(fd, 0, 1, 0x83, buff, len)) { + len = buff[3] + (buff[2] << 8); + if (len >= maxlen) + return len; + if (len > DEFAULT_SGIO_LEN) + goto retry; + return 0; + } + return -1; +} + static int get_geometry(struct path *pp) { @@ -788,15 +811,19 @@ get_geometry(struct path *pp) } static int -get_vpd (struct udev_device *parent, int pg, char * str, int maxlen) +get_vpd (struct udev_device *parent, int fd, int pg, char * str, int maxlen) { int len = -ENODATA, buff_len; unsigned char buff[4096]; memset(buff, 0x0, 4096); - if (sysfs_get_vpd(parent, pg, buff, 4096) <= 0) { - condlog(3, "failed to get vpd pg%02x", pg); - return -EIO; + 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; + } } if (buff[1] != pg) { @@ -1298,7 +1325,7 @@ scsi_ioctl_pathinfo (struct path * pp, int mask) if (!attr_path || pp->sg_id.host_no == -1) return -ENODEV; - if (get_vpd(parent, 0x80, pp->serial, SERIAL_SIZE) > 0) + if (get_vpd(parent, pp->fd, 0x80, pp->serial, SERIAL_SIZE) > 0) condlog(3, "%s: serial = %s", pp->dev, pp->serial); @@ -1428,11 +1455,7 @@ get_vpd_uid(struct path * pp) parent = udev_device_get_parent(parent); } - if (!parent) { - condlog(3, "%s: no scsi device found in sysfs", pp->dev); - return -ENXIO; - } - return get_vpd(parent, 0x83, pp->wwid, WWID_SIZE); + return get_vpd(parent, pp->fd, 0x83, pp->wwid, WWID_SIZE); } static int @@ -1471,14 +1494,16 @@ get_uid (struct path * pp) if (pp->uid_attribute) { len = get_udev_uid(pp, pp->uid_attribute); origin = "udev"; - } else { + } + if (len <= 0) { len = get_vpd_uid(pp); if (len > 0) origin = "sysfs"; - else { - len = get_udev_uid(pp, DEFAULT_UID_ATTRIBUTE); + } + if (len <= 0) { + len = get_udev_uid(pp, DEFAULT_UID_ATTRIBUTE); + if (len > 0) origin = "udev"; - } } } if ( len < 0 ) {