From patchwork Mon Mar 16 12:36:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6017931 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 AF0B9BF90F for ; Mon, 16 Mar 2015 12:41:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D498C200F4 for ; Mon, 16 Mar 2015 12:41:44 +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 DC850204D5 for ; Mon, 16 Mar 2015 12:41: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 t2GCcV2C028023; Mon, 16 Mar 2015 08:38:31 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t2GCbKDA028943 for ; Mon, 16 Mar 2015 08:37:20 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCbKUr021960; 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 t2GCbIfX003118 (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 relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EC2EEADF4; Mon, 16 Mar 2015 12:37:10 +0000 (UTC) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 16 Mar 2015 13:36:52 +0100 Message-Id: <1426509425-15978-66-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.26 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.21 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 65/78] Use sysfs attribute vpd_pg80 to read serial number 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 There is no need to issue an ioctl to read the serial number as it's already present in sysfs. And we should not print out the serial number unconditionally but rather check the discovery mask. Signed-off-by: Hannes Reinecke --- libmultipath/discovery.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index b1cd6a0..f8a0503 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1026,9 +1026,6 @@ scsi_sysfs_pathinfo (struct path * pp) condlog(3, "%s: rev = %s", pp->dev, pp->rev); - if (get_vpd(parent, 0x80, pp->serial, SERIAL_SIZE) >= 0) - condlog(3, "%s: serial = %s", pp->dev, pp->serial); - /* * set the hwe configlet pointer */ @@ -1276,13 +1273,36 @@ sysfs_pathinfo(struct path * pp) static int scsi_ioctl_pathinfo (struct path * pp, int mask) { - if (mask & DI_SERIAL) { - if (strlen(pp->serial) == 0) - get_serial(pp->serial, SERIAL_SIZE, pp->fd); - condlog(3, "%s: serial = %s", pp->dev, pp->serial); + struct udev_device *parent; + const char *attr_path = NULL; + + if (!(mask & DI_SERIAL)) + return 0; + + parent = pp->udev; + while (parent) { + const char *subsys = udev_device_get_subsystem(parent); + if (subsys && !strncmp(subsys, "scsi", 4)) { + attr_path = udev_device_get_sysname(parent); + if (!attr_path) + break; + if (sscanf(attr_path, "%i:%i:%i:%i", + &pp->sg_id.host_no, + &pp->sg_id.channel, + &pp->sg_id.scsi_id, + &pp->sg_id.lun) == 4) + break; + } + parent = udev_device_get_parent(parent); } + if (!attr_path || pp->sg_id.host_no == -1) + return -ENODEV; - return 0; + if (get_vpd(parent, 0x80, pp->serial, SERIAL_SIZE) > 0) + condlog(3, "%s: serial = %s", + pp->dev, pp->serial); + + return strlen(pp->serial) ? 0 : -EIO; } static int