From nobody Wed Feb 11 01:27:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1487106503661427.8804253816264; Tue, 14 Feb 2017 13:08:23 -0800 (PST) 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 v1EL4cIP029237; Tue, 14 Feb 2017 16:04:38 -0500 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 v1EL4QQf005037 for ; Tue, 14 Feb 2017 16:04:26 -0500 Received: from localhost (ovpn-116-118.phx2.redhat.com [10.3.116.118]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1EL4NQw029418; Tue, 14 Feb 2017 16:04:25 -0500 From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Date: Wed, 15 Feb 2017 01:04:10 +0400 Message-Id: <20170214210413.23142-3-marcandre.lureau@redhat.com> In-Reply-To: <20170214210413.23142-1-marcandre.lureau@redhat.com> References: <20170214210413.23142-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [libvirt] [PATCH 2/5] nodedev: add paths 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Marc-Andr=C3=A9 Lureau Add new top-level element, that list the associated /dev files. Distinguish the main /dev name from symlinks with a 'type' attribute of value 'dev' or 'symlink'. Update a test to check XML schema, and actually add it to the test list since it was missing. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/formatnode.html.in | 6 +++ docs/schemas/nodedev.rng | 16 +++++++ src/conf/node_device_conf.c | 54 ++++++++++++++++++= +++- src/conf/node_device_conf.h | 12 +++++ src/node_device/node_device_udev.c | 31 +++++++++++++ ...ge_serial_3600c0ff000d7a2a5d463ff4902000000.xml | 4 ++ tests/nodedevxml2xmltest.c | 1 + 7 files changed, 123 insertions(+), 1 deletion(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index f8d0e1234..ecdd1dbcb 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -37,6 +37,12 @@
If this element is present, it names the parent device (that is, a controller to which this node belongs).
+
devnode
+
This node appears for each associated /dev + special file. A mandatory attribute type specify + the kind of file path, which may be either dev for + the main name, or link for additional symlinks. +
capability
This node appears for each capability that libvirt associates with a node. A mandatory diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index b100a6e16..62e29b6cc 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -16,6 +16,22 @@ + + + dev + + + + + + + + link + + + + + =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 6163fd5ed..49ecc8897 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -40,6 +40,10 @@ =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 +VIR_ENUM_IMPL(virNodeDevDevnode, VIR_NODE_DEV_DEVNODE_LAST, + "dev", + "link") + VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST, "system", "pci", @@ -252,6 +256,8 @@ void virNodeDeviceDefFree(virNodeDeviceDefPtr def) VIR_FREE(def->driver); VIR_FREE(def->sysfs_path); VIR_FREE(def->parent_sysfs_path); + VIR_FREE(def->devnode); + virStringListFree(def->devlinks); =20 caps =3D def->caps; while (caps) { @@ -387,6 +393,14 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *d= ef) virBufferAdjustIndent(&buf, 2); virBufferEscapeString(&buf, "%s\n", def->name); virBufferEscapeString(&buf, "%s\n", def->sysfs_path); + if (def->devnode) + virBufferEscapeString(&buf, "%s\n", + def->devnode); + if (def->devlinks) { + for (i =3D 0; def->devlinks[i]; i++) + virBufferEscapeString(&buf, "%s\n", + def->devlinks[i]); + } if (def->parent) virBufferEscapeString(&buf, "%s\n", def->parent); if (def->driver) { @@ -1703,7 +1717,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def; virNodeDevCapsDefPtr *next_cap; xmlNodePtr *nodes; - int n; + int n, m; size_t i; =20 if (VIR_ALLOC(def) < 0) @@ -1722,6 +1736,44 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, goto error; } =20 + /* Parse devnodes */ + nodes =3D NULL; + if ((n =3D virXPathNodeSet("./devnode", ctxt, &nodes)) < 0) + goto error; + + if (VIR_ALLOC_N(def->devlinks, n + 1) < 0) + goto error; + + for (i =3D 0, m =3D 0; i < n; i++) { + xmlNodePtr node =3D nodes[i]; + char *tmp =3D virXMLPropString(node, "type"); + virNodeDevDevnodeType type; + + if (!tmp) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing devnode type")); + goto error; + } + + if ((type =3D virNodeDevDevnodeTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown devnode type '%s'"), tmp); + VIR_FREE(tmp); + goto error; + } + + switch (type) { + case VIR_NODE_DEV_DEVNODE_DEV: + def->devnode =3D (char*)xmlNodeGetContent(node); + break; + case VIR_NODE_DEV_DEVNODE_LINK: + def->devlinks[m++] =3D (char*)xmlNodeGetContent(node); + break; + case VIR_NODE_DEV_DEVNODE_LAST: + break; + } + } + /* Extract device parent, if any */ def->parent =3D virXPathString("string(./parent[1])", ctxt); def->parent_wwnn =3D virXPathString("string(./parent[1]/@wwnn)", ctxt); diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 163448333..f46e9841a 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -40,6 +40,16 @@ =20 typedef enum { /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */ + VIR_NODE_DEV_DEVNODE_DEV, + VIR_NODE_DEV_DEVNODE_LINK, + + VIR_NODE_DEV_DEVNODE_LAST +} virNodeDevDevnodeType; + +VIR_ENUM_DECL(virNodeDevDevnode) + +typedef enum { + /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */ VIR_NODE_DEV_CAP_SYSTEM, /* System capability */ VIR_NODE_DEV_CAP_PCI_DEV, /* PCI device */ VIR_NODE_DEV_CAP_USB_DEV, /* USB device */ @@ -204,6 +214,8 @@ struct _virNodeDeviceDef { char *parent_wwpn; /* optional parent wwpn */ char *parent_fabric_wwn; /* optional parent fabric_wwn */ char *driver; /* optional driver name */ + char *devnode; /* /dev path */ + char **devlinks; /* /dev links */ virNodeDevCapsDefPtr caps; /* optional device capabilities */ }; =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 4b813127c..d7658410a 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -918,6 +918,34 @@ udevProcessSCSIGeneric(struct udev_device *dev, } =20 static int +udevGetDeviceNodes(struct udev_device *device, + virNodeDeviceDefPtr def) +{ + const char *devnode =3D NULL; + struct udev_list_entry *list_entry =3D NULL; + int n =3D 0; + + devnode =3D udev_device_get_devnode(device); + + if (VIR_STRDUP(def->devnode, devnode) < 0) + return -1; + + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entr= y(device)) + n++; + + if (VIR_ALLOC_N(def->devlinks, n + 1) < 0) + return -1; + + n =3D 0; + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entr= y(device)) { + if (VIR_STRDUP(def->devlinks[n++], udev_list_entry_get_name(list_e= ntry)) < 0) + return -1; + } + + return 0; +} + +static int udevGetDeviceType(struct udev_device *device, virNodeDevCapType *type) { @@ -1125,6 +1153,9 @@ static int udevAddOneDevice(struct udev_device *devic= e) if (udevGetDeviceType(device, &def->caps->data.type) !=3D 0) goto cleanup; =20 + if (udevGetDeviceNodes(device, def) !=3D 0) + goto cleanup; + if (udevGetDeviceDetails(device, def) !=3D 0) goto cleanup; =20 diff --git a/tests/nodedevschemadata/storage_serial_3600c0ff000d7a2a5d463ff= 4902000000.xml b/tests/nodedevschemadata/storage_serial_3600c0ff000d7a2a5d4= 63ff4902000000.xml index d9d61da44..d225dca8f 100644 --- a/tests/nodedevschemadata/storage_serial_3600c0ff000d7a2a5d463ff4902000= 000.xml +++ b/tests/nodedevschemadata/storage_serial_3600c0ff000d7a2a5d463ff4902000= 000.xml @@ -1,5 +1,9 @@ storage_serial_3600c0ff000d7a2a5d463ff4902000000 + /dev/sdb + /dev/disk/by-id/usb-SanDisk_Ultra_Fit_4C530001051= 009112405-0:0 + /dev/disk/by-path/pci-0000:00:14.0-usb-0:1:1.0-sc= si-0:0:0:0 + /dev/disk/by-uuid/661A1A460111DA18 pci_10df_fe00_scsi_host_scsi_device_lun8 /dev/sdj diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index eb32dd31d..ec96943cb 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -87,6 +87,7 @@ mymain(void) DO_TEST("pci_8086_27c5_scsi_host_scsi_host"); DO_TEST("pci_8086_27c5_scsi_host"); DO_TEST("storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE"); + DO_TEST("storage_serial_3600c0ff000d7a2a5d463ff4902000000"); DO_TEST("usb_device_1d6b_1_0000_00_1d_0_if0"); DO_TEST("usb_device_1d6b_1_0000_00_1d_0"); DO_TEST("pci_8086_4238_pcie_wireless"); --=20 2.11.0.295.gd7dffce1c.dirty -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list