From nobody Sat Feb 7 07:31:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1495435177790954.656743688766; Sun, 21 May 2017 23:39:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8AC53D955; Mon, 22 May 2017 06:39:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B14D677CBC; Mon, 22 May 2017 06:39:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 686AB180BAF4; Mon, 22 May 2017 06:39:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4M6col7010440 for ; Mon, 22 May 2017 02:38:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C89D9171E3; Mon, 22 May 2017 06:38:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFE4F5C881 for ; Mon, 22 May 2017 06:38:49 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E0C5BDD0 for ; Mon, 22 May 2017 06:38:47 +0000 (UTC) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4M6ShDY026573 for ; Mon, 22 May 2017 02:38:47 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2akmunatw0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 22 May 2017 02:38:46 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 May 2017 07:38:44 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 22 May 2017 07:38:42 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4M6cgNl34275362; Mon, 22 May 2017 06:38:42 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D320352043; Mon, 22 May 2017 06:35:52 +0100 (BST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id BE48052045; Mon, 22 May 2017 06:35:52 +0100 (BST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D8AC53D955 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D8AC53D955 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5E0C5BDD0 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=bwalk@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5E0C5BDD0 From: Bjoern Walk To: libvir-list@redhat.com Date: Mon, 22 May 2017 08:38:25 +0200 In-Reply-To: <20170522063826.15949-1-bwalk@linux.vnet.ibm.com> References: <20170522063826.15949-1-bwalk@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17052206-0016-0000-0000-000004A589CE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052206-0017-0000-0000-000027C21D1D Message-Id: <20170522063826.15949-7-bwalk@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-22_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705220034 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 22 May 2017 06:38:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 22 May 2017 06:38:47 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'bwalk@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -2.7 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Bjoern Walk Subject: [libvirt] [PATCH 6/7] node_device: introduce new capability FC_RPORT X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 22 May 2017 06:39:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similar to scsi_host and fc_host, there is a relation between a scsi_target and its transport specific fc_remote_port. Let's expose this relation and relevant information behind it. An example for a virsh nodedev-dumpxml: virsh # nodedev-dumpxml scsi_target0_0_0 scsi_target0_0_0 /sys/devices/[...]/host0/rport-0:0-0/target0:0:0 scsi_host0 target0:0:0 rport-0:0-0 0x9d73bc45f0e21a86 Reviewed-by: Boris Fiuczynski Signed-off-by: Bjoern Walk Reviewed-by: John Ferlan --- docs/schemas/nodedev.rng | 20 ++++++++ src/conf/node_device_conf.c | 75 ++++++++++++++++++++++++= +++- src/conf/node_device_conf.h | 7 +++ src/node_device/node_device_driver.c | 5 +- src/node_device/node_device_linux_sysfs.c | 56 +++++++++++++++++++++ src/node_device/node_device_linux_sysfs.h | 2 + src/node_device/node_device_udev.c | 4 +- tests/nodedevschemadata/scsi_target1_0_0.xml | 12 +++++ tests/nodedevxml2xmltest.c | 1 + 9 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 tests/nodedevschemadata/scsi_target1_0_0.xml diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 87bfb0c28..5bcf31787 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -458,6 +458,20 @@ =20 + + + fc_remote_port + + + + + + + + + + + scsi_target @@ -466,6 +480,12 @@ + + + + + + =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 28d4907f5..ed003d37b 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -563,6 +563,16 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) case VIR_NODE_DEV_CAP_SCSI_TARGET: virBufferEscapeString(&buf, "%s\n", data->scsi_target.name); + if (data->scsi_target.flags & VIR_NODE_DEV_CAP_FLAG_FC_RPORT) { + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "%s\n", + data->scsi_target.rport); + virBufferAsprintf(&buf, "0x%llx\n", + data->scsi_target.wwpn); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + } break; case VIR_NODE_DEV_CAP_SCSI: virNodeDeviceCapSCSIDefFormat(&buf, data); @@ -932,8 +942,10 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctx= t, xmlNodePtr node, virNodeDevCapSCSITargetPtr scsi_target) { - xmlNodePtr orignode; - int ret =3D -1; + xmlNodePtr orignode, *nodes =3D NULL; + int ret =3D -1, n =3D 0; + size_t i; + char *type =3D NULL, *wwpn =3D NULL; =20 orignode =3D ctxt->node; ctxt->node =3D node; @@ -946,10 +958,68 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ct= xt, goto out; } =20 + if ((n =3D virXPathNodeSet("./capability", ctxt, &nodes)) < 0) + goto out; + + for (i =3D 0; i < n; ++i) { + type =3D virXMLPropString(nodes[i], "type"); + + if (!type) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing type for SCSI target capability for = '%s'"), + def->name); + goto out; + } + + if (STREQ(type, "fc_remote_port")) { + xmlNodePtr orignode2; + + scsi_target->flags |=3D VIR_NODE_DEV_CAP_FLAG_FC_RPORT; + + orignode2 =3D ctxt->node; + ctxt->node =3D nodes[i]; + + if (virNodeDevCapsDefParseString("string(./rport[1])", + ctxt, + &scsi_target->rport) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing rport name for '%s'"), def->name= ); + goto out; + } + + if (virNodeDevCapsDefParseString("string(./wwpn[1])", + ctxt, &wwpn) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing wwpn identifier for '%s'"), + def->name); + goto out; + } + + if (virStrToLong_ullp(wwpn, NULL, 16, &scsi_target->wwpn) < 0)= { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid wwpn identifier '%s' for '%s'"), + wwpn, def->name); + goto out; + } + + ctxt->node =3D orignode2; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown SCSI target capability type '%s' for= '%s'"), + type, def->name); + goto out; + } + + VIR_FREE(type); + VIR_FREE(wwpn); + } + ret =3D 0; =20 out: ctxt->node =3D orignode; + VIR_FREE(type); + VIR_FREE(wwpn); return ret; } =20 @@ -2132,6 +2202,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) break; case VIR_NODE_DEV_CAP_SCSI_TARGET: VIR_FREE(data->scsi_target.name); + VIR_FREE(data->scsi_target.rport); break; case VIR_NODE_DEV_CAP_SCSI: VIR_FREE(data->scsi.type); diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 285841edc..f5267efda 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -93,6 +93,10 @@ typedef enum { } virNodeDevSCSIHostCapFlags; =20 typedef enum { + VIR_NODE_DEV_CAP_FLAG_FC_RPORT =3D (1 << 0), +} virNodeDevSCSITargetCapsFlags; + +typedef enum { VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION =3D (1 << 0), VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION =3D (1 << 1), VIR_NODE_DEV_CAP_FLAG_PCIE =3D (1 << 2), @@ -227,6 +231,9 @@ typedef struct _virNodeDevCapSCSITarget virNodeDevCapSC= SITarget; typedef virNodeDevCapSCSITarget *virNodeDevCapSCSITargetPtr; struct _virNodeDevCapSCSITarget { char *name; + unsigned int flags; /* enum virNodeDevSCSITargetCapsFlags */ + char *rport; + unsigned long long wwpn; }; =20 typedef struct _virNodeDevCapSCSI virNodeDevCapSCSI; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 286af26bc..acb8b89af 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -56,6 +56,10 @@ static int update_caps(virNodeDeviceObjPtr dev) case VIR_NODE_DEV_CAP_SCSI_HOST: nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host); break; + case VIR_NODE_DEV_CAP_SCSI_TARGET: + nodeDeviceSysfsGetSCSITargetCaps(dev->def->sysfs_path, + &cap->data.scsi_target); + break; case VIR_NODE_DEV_CAP_NET: if (virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.= lnk) < 0) return -1; @@ -76,7 +80,6 @@ static int update_caps(virNodeDeviceObjPtr dev) case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_USB_DEV: case VIR_NODE_DEV_CAP_USB_INTERFACE: - case VIR_NODE_DEV_CAP_SCSI_TARGET: case VIR_NODE_DEV_CAP_SCSI: case VIR_NODE_DEV_CAP_STORAGE: case VIR_NODE_DEV_CAP_FC_HOST: diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c index 1b7aa9435..90452fb29 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -26,11 +26,13 @@ #include #include =20 +#include "dirname.h" #include "node_device_driver.h" #include "node_device_hal.h" #include "node_device_linux_sysfs.h" #include "virerror.h" #include "viralloc.h" +#include "virfcp.h" #include "virlog.h" #include "virfile.h" #include "virscsihost.h" @@ -124,6 +126,54 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPt= r scsi_host) } =20 =20 +int +nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath, + virNodeDevCapSCSITargetPtr scsi_target) +{ + int ret =3D -1; + char *dir =3D NULL, *rport =3D NULL, *wwpn =3D NULL; + + VIR_DEBUG("Checking if '%s' is an FC remote port", scsi_target->name); + + /* /sys/devices/[...]/host0/rport-0:0-0/target0:0:0 -> rport-0:0-0 */ + if (!(dir =3D mdir_name(sysfsPath))) + return -1; + + if (VIR_STRDUP(rport, last_component(dir)) < 0) + goto cleanup; + + if (!virFCIsCapableRport(rport)) + goto cleanup; + + VIR_FREE(scsi_target->rport); + scsi_target->rport =3D rport; + + if (virFCReadRportValue(scsi_target->rport, "port_name", &wwpn) < 0) { + VIR_WARN("Failed to read port_name for '%s'", scsi_target->rport); + goto cleanup; + } + + if (virStrToLong_ullp(wwpn, NULL, 16, &scsi_target->wwpn) < 0) { + VIR_WARN("Failed to parse value of port_name '%s'", wwpn); + goto cleanup; + } + + scsi_target->flags |=3D VIR_NODE_DEV_CAP_FLAG_FC_RPORT; + ret =3D 0; + + cleanup: + if (ret < 0) { + VIR_FREE(scsi_target->rport); + scsi_target->wwpn =3D 0; + scsi_target->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_FC_RPORT; + } + VIR_FREE(dir); + VIR_FREE(wwpn); + + return ret; +} + + static int nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath, virNodeDevCapPCIDevPtr pci_dev) @@ -230,6 +280,12 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPt= r scsi_host ATTRIBUTE_UNUS return -1; } =20 +int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath ATTRIBUTE_UNUSE= D, + virNodeDevCapSCSITargetPtr scsi_targe= t ATTRIBUTE_UNUSED) +{ + return -1; +} + int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath ATTRIBUTE_UNUSED, virNodeDevCapPCIDevPtr pci_dev ATTRIBU= TE_UNUSED) diff --git a/src/node_device/node_device_linux_sysfs.h b/src/node_device/no= de_device_linux_sysfs.h index 8deea6699..12cfe6341 100644 --- a/src/node_device/node_device_linux_sysfs.h +++ b/src/node_device/node_device_linux_sysfs.h @@ -26,6 +26,8 @@ # include "node_device_conf.h" =20 int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); +int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath, + virNodeDevCapSCSITargetPtr scsi_targe= t); int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, virNodeDevCapPCIDevPtr pci_dev); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 7744c2637..49269b678 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -697,7 +697,7 @@ static int udevProcessSCSIHost(struct udev_device *devi= ce ATTRIBUTE_UNUSED, } =20 =20 -static int udevProcessSCSITarget(struct udev_device *device ATTRIBUTE_UNUS= ED, +static int udevProcessSCSITarget(struct udev_device *device, virNodeDeviceDefPtr def) { const char *sysname =3D NULL; @@ -708,6 +708,8 @@ static int udevProcessSCSITarget(struct udev_device *de= vice ATTRIBUTE_UNUSED, if (VIR_STRDUP(scsi_target->name, sysname) < 0) return -1; =20 + nodeDeviceSysfsGetSCSITargetCaps(def->sysfs_path, &def->caps->data.scs= i_target); + if (udevGenerateDeviceName(device, def, NULL) !=3D 0) return -1; =20 diff --git a/tests/nodedevschemadata/scsi_target1_0_0.xml b/tests/nodedevsc= hemadata/scsi_target1_0_0.xml new file mode 100644 index 000000000..b783c54fe --- /dev/null +++ b/tests/nodedevschemadata/scsi_target1_0_0.xml @@ -0,0 +1,12 @@ + + scsi_target1_0_0 + /sys/devices/css0/0.0.0000/0.0.0000/host1/rport-1:0-0/target1:0:0<= /path> + scsi_host0 + + target1:0:0 + + rport-1:0-0 + 0x9d73bc45f0e21a86 + + + diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index 805deef26..5d9f4724d 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -95,6 +95,7 @@ mymain(void) DO_TEST("pci_0000_00_02_0_header_type"); DO_TEST("pci_0000_00_1c_0_header_type"); DO_TEST("scsi_target0_0_0"); + DO_TEST("scsi_target1_0_0"); DO_TEST("pci_0000_02_10_7_sriov"); DO_TEST("pci_0000_02_10_7_sriov_vfs"); DO_TEST("pci_0000_02_10_7_sriov_zero_vfs_max_count"); --=20 2.11.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list