From nobody Thu May 15 02:23:21 2025 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.zohomail.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 1515586737516103.10260924539557; Wed, 10 Jan 2018 04:18:57 -0800 (PST) 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 BB6A8C01F296; Wed, 10 Jan 2018 12:18:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FF6C83283; Wed, 10 Jan 2018 12:18:29 +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 A8445410AD; Wed, 10 Jan 2018 12:18:20 +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 w0ACIHBH027141 for ; Wed, 10 Jan 2018 07:18:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 805867A2FD; Wed, 10 Jan 2018 12:18:17 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C76BA7A2E1; Wed, 10 Jan 2018 12:18:15 +0000 (UTC) Received: from huawei.com (unknown [45.249.212.32]) (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 5FCCA52120; Wed, 10 Jan 2018 12:18:07 +0000 (UTC) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5AF55BD715C7F; Wed, 10 Jan 2018 20:17:52 +0800 (CST) Received: from HSH1000044456.huawei.com (10.184.157.230) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Wed, 10 Jan 2018 20:17:43 +0800 From: Wu Zongyong To: Date: Wed, 10 Jan 2018 20:14:50 +0800 Message-ID: <1515586491-2808-3-git-send-email-cordius.wu@huawei.com> In-Reply-To: <1515586491-2808-1-git-send-email-cordius.wu@huawei.com> References: <1515586491-2808-1-git-send-email-cordius.wu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.184.157.230] X-CFilter-Loop: Reflected X-Greylist: Delayed for 48:39:48 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 10 Jan 2018 12:18:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 10 Jan 2018 12:18:08 +0000 (UTC) for IP:'45.249.212.32' DOMAIN:'[45.249.212.32]' HELO:'huawei.com' FROM:'cordius.wu@huawei.com' RCPT:'' X-RedHat-Spam-Score: 1.272 * (RDNS_NONE, SPF_HELO_PASS, SPF_PASS) 45.249.212.32 [45.249.212.32] 45.249.212.32 [45.249.212.32] X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: weijinfen@huawei.com, wanzongshun@huawei.com, eskultet@redhat.com Subject: [libvirt] [PATCH 2/3] nodedev: update mdev_types caps before dumpxml 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-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.31]); Wed, 10 Jan 2018 12:18:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In current implemention, mdev_types caps keep constant all the time. But, it is possible that a device capable of mdev_types sometime(for example:bind to proper driver) and incapable of mdev_types at other times(for example: unbind from its driver). We should keep the info of xml dumped out consistent with real status of the device. Signed-off-by: Wu Zongyong Reviewed-by: Erik Skultety --- src/node_device/node_device_linux_sysfs.c | 22 ++++++++++++++++++ src/node_device/node_device_udev.c | 37 ++++++++++++++++++++++++++-= ---- src/node_device/node_device_udev.h | 3 +++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c index 6f438e5..388ffb4 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -29,6 +29,7 @@ #include "dirname.h" #include "node_device_driver.h" #include "node_device_hal.h" +#include "node_device_udev.h" #include "node_device_linux_sysfs.h" #include "virerror.h" #include "viralloc.h" @@ -175,6 +176,25 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDe= vPtr pci_dev) return ret; } =20 +static int +nodeDeviceSysfsGetPCIMdevTypesCaps(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev) +{ + size_t i; + + /* this could be a refresh, so clear out the old data */ + for (i =3D 0; i < pci_dev->nmdev_types; i++) + virNodeDevCapMdevTypeFree(pci_dev->mdev_types[i]); + VIR_FREE(pci_dev->mdev_types); + pci_dev->nmdev_types =3D 0; + pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; + + if (udevPCISysfsGetMdevTypesCap(sysfsPath, pci_dev) < 0) + return -1; + + return 0; +} + =20 /* nodeDeviceSysfsGetPCIRelatedCaps() get info that is stored in sysfs * about devices related to this device, i.e. things that can change @@ -190,6 +210,8 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPa= th, return -1; if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0) return -1; + if (nodeDeviceSysfsGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0) + return -1; return 0; } =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e0fca61..7b0014e 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -506,6 +506,37 @@ udevPCIGetMdevTypesCap(struct udev_device *device, } =20 =20 +int +udevPCISysfsGetMdevTypesCap(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev) +{ + int ret =3D -1; + struct udev *udev =3D NULL; + struct udev_device *device =3D NULL; + udevEventDataPtr priv =3D driver->privateData; + + virObjectLock(priv); + udev =3D udev_monitor_get_udev(priv->udev_monitor); + device =3D udev_device_new_from_syspath(udev, sysfsPath); + virObjectUnlock(priv); + + if (!device) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to create udev device from path %s"), + sysfsPath); + goto cleanup; + } + + if (udevPCIGetMdevTypesCap(device, pci_dev) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + udev_device_unref(device); + return ret; +} + + static int udevProcessPCI(struct udev_device *device, virNodeDeviceDefPtr def) @@ -597,12 +628,6 @@ udevProcessPCI(struct udev_device *device, } } =20 - /* check whether the device is mediated devices framework capable, if = so, - * process it - */ - if (udevPCIGetMdevTypesCap(device, pci_dev) < 0) - goto cleanup; - ret =3D 0; =20 cleanup: diff --git a/src/node_device/node_device_udev.h b/src/node_device/node_devi= ce_udev.h index 300f57e..bbdc70f 100644 --- a/src/node_device/node_device_udev.h +++ b/src/node_device/node_device_udev.h @@ -29,5 +29,8 @@ # define DMI_DEVPATH "/sys/devices/virtual/dmi/id" # define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id" =20 +int +udevPCISysfsGetMdevTypesCap(const char *sysfsPath, virNodeDevCapPCIDevPtr = pci_dev); + =20 #endif /* __VIR_NODE_DEVICE_UDEV_H__ */ --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list