From nobody Sun Feb 8 19:21:08 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 1490792215417805.4505184556152; Wed, 29 Mar 2017 05:56:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F11595A71; Wed, 29 Mar 2017 12:56:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6D47B23F5; Wed, 29 Mar 2017 12:56:53 +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 6649F5EC64; Wed, 29 Mar 2017 12:56:53 +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 v2TCpa2d010106 for ; Wed, 29 Mar 2017 08:51:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id A44D99629F; Wed, 29 Mar 2017 12:51:36 +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 042EA173A8; Wed, 29 Mar 2017 12:51:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F11595A71 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.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 F11595A71 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 29 Mar 2017 14:51:17 +0200 Message-Id: <0d53e0421890565561dd5624a09ff28f0a0da4a2.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 07/11] nodedev: Fill in the mdev info for the parent PCI device 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 29 Mar 2017 12:56:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The parent device needs to report the generic stuff about the supported mediated devices types, like device API, available instances, and description which might hold some useful data about supported resolutions for the type given, framebuffer size, etc. Unfortunately, these are not standardized yet to be considered for separate elements. Signed-off-by: Erik Skultety --- src/conf/node_device_conf.h | 2 + src/node_device/node_device_udev.c | 115 +++++++++++++++++++++++++++++++++= ++++ 2 files changed, 117 insertions(+) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index b7db35dd50..d521dd9a4c 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -166,6 +166,8 @@ struct _virNodeDevCapPCIDev { int numa_node; virPCIEDeviceInfoPtr pci_express; int hdrType; /* enum virPCIHeaderType or -1 */ + virNodeDevCapMdevPtr *mdevs; + size_t nmdevs; }; =20 typedef struct _virNodeDevCapUSBDev virNodeDevCapUSBDev; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index dbbd8e5d06..be031fa5a8 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -324,6 +324,115 @@ udevTranslatePCIIds(unsigned int vendor, return 0; } =20 +#define MDEV_GET_SYSFS_ATTR(attr, cb, ...) = \ + do { = \ + if (virAsprintf(&attrpath, "%s/%s", relpath, #attr) < 0) = \ + goto cleanup; = \ + = \ + if (cb(device, attrpath, __VA_ARGS__) < 0) = \ + goto cleanup; = \ + } while (0) = \ + + +static int +udevGetMdevCaps(struct udev_device *device, + const char *sysfspath, + virNodeDevCapMdevPtr mdev) +{ + int ret =3D -1; + char *attrpath =3D NULL; /* relative path to the actual sysfs attribu= te */ + const char *devpath =3D NULL; /* base sysfs path as reported by udev= */ + const char *relpath =3D NULL; /* diff between @sysfspath and @devpat= h */ + char *tmp =3D NULL; + + + /* 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. + */ + if (virFileResolveLink(sysfspath, &tmp) < 0) + goto cleanup; + + if (VIR_STRDUP(mdev->type, last_component(tmp)) < 0) + goto cleanup; + + 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); + + ret =3D 0; + cleanup: + VIR_FREE(attrpath); + VIR_FREE(tmp); + return ret; +} +#undef MDEV_GET_SYSFS_ATTR + + +static int +udevPCIGetMdevCaps(struct udev_device *device, + virNodeDevCapPCIDevPtr pcidata) +{ + int ret =3D -1; + DIR *dir =3D NULL; + struct dirent *entry; + char *path =3D NULL; + char *tmppath =3D NULL; + virNodeDevCapMdevPtr mdev =3D NULL; + + if (virAsprintf(&path, "%s/mdev_supported_types", + udev_device_get_syspath(device)) < 0) + return -1; + + if ((ret =3D virDirOpenIfExists(&dir, path)) <=3D 0) + goto cleanup; + + if (VIR_ALLOC(pcidata->mdevs) < 0) + goto cleanup; + + /* since udev doesn't provide means to list other than top-level + * attributes, we need to scan the subdirectories ourselves + */ + while ((ret =3D virDirRead(dir, &entry, path)) > 0) { + if (VIR_ALLOC(mdev) < 0) + goto cleanup; + + if (virAsprintf(&tmppath, "%s/%s", path, entry->d_name) < 0) + goto cleanup; + + if (udevGetMdevCaps(device, tmppath, mdev) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(pcidata->mdevs, pcidata->nmdevs, mdev) < 0) + goto cleanup; + + VIR_FREE(tmppath); + } + + ret =3D 0; + cleanup: + VIR_DIR_CLOSE(dir); + VIR_FREE(path); + VIR_FREE(tmppath); + virNodeDevCapMdevFree(mdev); + return ret; +} + =20 static int udevProcessPCI(struct udev_device *device, @@ -412,6 +521,12 @@ udevProcessPCI(struct udev_device *device, } } =20 + /* check whether the device is mediated devices framework capable, if = so, + * process it + */ + if (udevPCIGetMdevCaps(device, pci_dev) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list