From nobody Sun Feb 8 05:53:27 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 1490792444527798.6595857749527; Wed, 29 Mar 2017 06:00:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BED8C065126; Wed, 29 Mar 2017 13:00:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA3F483867; Wed, 29 Mar 2017 13:00:41 +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 80CAC5EC62; Wed, 29 Mar 2017 13:00:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2TCpbR3010117 for ; Wed, 29 Mar 2017 08:51:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF4629629F; Wed, 29 Mar 2017 12:51:37 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F19C962B8; Wed, 29 Mar 2017 12:51:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2BED8C065126 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 2BED8C065126 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 29 Mar 2017 14:51:18 +0200 Message-Id: <9be3caba1f901ff52ed0ece3e34becb8ef27e95a.1490791809.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [RFC PATCH 08/11] nodedev: Introduce udevProcessMediatedDevice 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 29 Mar 2017 13:00:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Start discovering the mediated devices on the host system and format the attributes for the child device into the XML. Compared to the parent device which reports generic information about the abstract mediated devices types, a child device only reports the type name it has been instantiated from and the iommu group number, since that's device specific compared to the rest of the info that can be gathered about mdevs at the moment. The resulting mdev child device XML: mdev_4b20d080_1b54_4048_85b3_a6a62d165c01 /sys/devices/.../4b20d080-1b54-4048-85b3-a6a62d165c01 pci_0000_06_00_0 vfio_mdev Signed-off-by: Erik Skultety --- src/conf/node_device_conf.c | 6 ++- src/node_device/node_device_udev.c | 87 +++++++++++++++++++++++++++++-----= ---- 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 03d7993ab1..1f13484d9b 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -541,9 +541,13 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) case VIR_NODE_DEV_CAP_DRM: virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; + case VIR_NODE_DEV_CAP_MDEV: + virBufferEscapeString(&buf, "\n", data->mdev.= type); + virBufferAsprintf(&buf, "\n", + data->mdev.iommuGroupNumber); + break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: - case VIR_NODE_DEV_CAP_MDEV: case VIR_NODE_DEV_CAP_LAST: break; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index be031fa5a8..092d9456b2 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -324,9 +324,9 @@ udevTranslatePCIIds(unsigned int vendor, return 0; } =20 -#define MDEV_GET_SYSFS_ATTR(attr, cb, ...) = \ +#define MDEV_GET_SYSFS_ATTR(attr_name, dir, cb, ...) = \ do { = \ - if (virAsprintf(&attrpath, "%s/%s", relpath, #attr) < 0) = \ + if (virAsprintf(&attrpath, "%s/%s", dir, #attr_name) < 0) = \ goto cleanup; = \ = \ if (cb(device, attrpath, __VA_ARGS__) < 0) = \ @@ -345,17 +345,6 @@ udevGetMdevCaps(struct udev_device *device, const char *relpath =3D NULL; /* diff between @sysfspath and @devpat= h */ char *tmp =3D NULL; =20 - - /* UDEV doesn't report attributes under subdirectories but can query t= hem - * if specified as relative paths to the device's base path, - * e.g. /sys/devices/../0000:00:01.0/ is the device's base path as udev - * reports it, but we're interested in attributes under - * /sys/devices/../0000:00:01.0/mdev_supported_types//. So, let's - * strip the common part of the path and let udev chew the relative bi= t. - */ - devpath =3D udev_device_get_syspath(device); - relpath =3D sysfspath + strlen(devpath); - /* When calling from the mdev child device, @sysfspath is a symbolic l= ink * to the actual mdev type (rather than a physical path), so we need to * resolve it in order to get the type's name. @@ -366,14 +355,24 @@ udevGetMdevCaps(struct udev_device *device, if (VIR_STRDUP(mdev->type, last_component(tmp)) < 0) goto cleanup; =20 - MDEV_GET_SYSFS_ATTR(name, udevGetStringSysfsAttr, - &mdev->name); - MDEV_GET_SYSFS_ATTR(description, udevGetStringSysfsAttr, - &mdev->description); - MDEV_GET_SYSFS_ATTR(device_api, udevGetStringSysfsAttr, - &mdev->device_api); - MDEV_GET_SYSFS_ATTR(available_instances, udevGetUintSysfsAttr, - &mdev->available_instances, 10); + /* UDEV doesn't report attributes under subdirectories by default but = is + * able to query them if the path to the attribute is relative paths t= o the + * device's base path, e.g. /sys/devices/../0000:00:01.0/ is the devic= e's + * base path as udev reports it, but we're interested in attributes un= der + * /sys/devices/../0000:00:01.0/mdev_supported_types//. So, let's + * strip the common part of the path and let udev chew the relative bi= t. + */ + devpath =3D udev_device_get_syspath(device); + relpath =3D sysfspath + strlen(devpath); + + MDEV_GET_SYSFS_ATTR(name, relpath, + udevGetStringSysfsAttr, &mdev->name); + MDEV_GET_SYSFS_ATTR(description, relpath, + udevGetStringSysfsAttr, &mdev->description); + MDEV_GET_SYSFS_ATTR(device_api, relpath, + udevGetStringSysfsAttr, &mdev->device_api); + MDEV_GET_SYSFS_ATTR(available_instances, relpath, + udevGetUintSysfsAttr, &mdev->available_instances, = 10); =20 ret =3D 0; cleanup: @@ -1099,6 +1098,51 @@ udevProcessSCSIGeneric(struct udev_device *dev, =20 =20 static int +udevProcessMediatedDevice(struct udev_device *dev, + virNodeDeviceDefPtr def) +{ + int ret =3D -1; + const char *uuidstr =3D NULL; + int iommugrp =3D -1; + int model =3D -1; + char *path =3D NULL; + virMediatedDevicePtr mdev =3D NULL; + virNodeDevCapMdevPtr data =3D &def->caps->data.mdev; + + if (virAsprintf(&path, "%s/mdev_type", udev_device_get_syspath(dev)) <= 0) + goto cleanup; + + if (udevGetMdevCaps(dev, path, data) < 0) + goto cleanup; + + if ((model =3D virMediatedDeviceModelTypeFromString(data->device_api))= < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Device API '%s' not supported yet"), + data->device_api); + goto cleanup; + } + + uuidstr =3D udev_device_get_sysname(dev); + if (!(mdev =3D virMediatedDeviceNew(uuidstr, model))) + goto cleanup; + + if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(mdev)) < 0) + goto cleanup; + + if (udevGenerateDeviceName(dev, def, NULL) !=3D 0) + goto cleanup; + + data->iommuGroupNumber =3D iommugrp; + + ret =3D 0; + cleanup: + VIR_FREE(path); + virMediatedDeviceFree(mdev); + return ret; + +} + +static int udevGetDeviceNodes(struct udev_device *device, virNodeDeviceDefPtr def) { @@ -1217,6 +1261,7 @@ udevGetDeviceDetails(struct udev_device *device, case VIR_NODE_DEV_CAP_DRM: return udevProcessDRMDevice(device, def); case VIR_NODE_DEV_CAP_MDEV: + return udevProcessMediatedDevice(device, def); case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list