From nobody Wed May 1 06:44:30 2024 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 1515425450791363.18293707149496; Mon, 8 Jan 2018 07:30:50 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C53D1C054C5F; Mon, 8 Jan 2018 15:30:48 +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 0AA275D964; Mon, 8 Jan 2018 15:30:48 +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 6F12D4EE4F; Mon, 8 Jan 2018 15:30:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w08FQoPB024059 for ; Mon, 8 Jan 2018 10:26:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED84E605FB; Mon, 8 Jan 2018 15:26:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34EC1600D3; Mon, 8 Jan 2018 15:26:49 +0000 (UTC) Received: from huawei.com (unknown [45.249.212.35]) (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 A4A13C02C01C; Mon, 8 Jan 2018 15:26:46 +0000 (UTC) Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1D33DD84E25B1; Mon, 8 Jan 2018 19:38:14 +0800 (CST) Received: from HSH1000044456.huawei.com (10.184.157.230) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Mon, 8 Jan 2018 19:38:08 +0800 From: Wu Zongyong To: Date: Mon, 8 Jan 2018 19:35:22 +0800 Message-ID: <1515411322-22846-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 03:48:27 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 08 Jan 2018 15:26:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 08 Jan 2018 15:26:48 +0000 (UTC) for IP:'45.249.212.35' DOMAIN:'[45.249.212.35]' 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.35 [45.249.212.35] 45.249.212.35 [45.249.212.35] X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: weijinfen@huawei.com, wanzongshun@huawei.com, eskultet@redhat.com Subject: [libvirt] [PATCH v2] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 08 Jan 2018 15:30:49 +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 --- v2: - fix mistakes pointed out by Erik src/node_device/node_device_linux_sysfs.c | 21 +++++++++++++++++++++ src/node_device/node_device_udev.c | 29 +++++++++++++++++++++++++++= ++ src/node_device/node_device_udev.h | 18 +++++++++++++----- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c index 6f438e5..8b00aff 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,24 @@ 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; + + 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 +209,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..781facf 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -506,6 +506,35 @@ udevPCIGetMdevTypesCap(struct udev_device *device, } =20 =20 +int +udevPCISysfsGetMdevTypesCap(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev) +{ + int ret =3D -1; + udevEventDataPtr priv =3D NULL; + struct udev *udev =3D NULL; + struct udev_device *device =3D NULL; + + priv =3D driver->privateData; + udev =3D udev_monitor_get_udev(priv->udev_monitor); + device =3D udev_device_new_from_syspath(udev, sysfsPath); + 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) diff --git a/src/node_device/node_device_udev.h b/src/node_device/node_devi= ce_udev.h index f15e520..bbdc70f 100644 --- a/src/node_device/node_device_udev.h +++ b/src/node_device/node_device_udev.h @@ -19,10 +19,18 @@ * * Author: Dave Allan */ +#ifndef __VIR_NODE_DEVICE_UDEV_H__ +# define __VIR_NODE_DEVICE_UDEV_H__ =20 -#include -#include +# include +# include =20 -#define SYSFS_DATA_SIZE 4096 -#define DMI_DEVPATH "/sys/devices/virtual/dmi/id" -#define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id" +# define SYSFS_DATA_SIZE 4096 +# define DMI_DEVPATH "/sys/devices/virtual/dmi/id" +# define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id" + +int +udevPCISysfsGetMdevTypesCap(const char *sysfsPath, virNodeDevCapPCIDevPtr = pci_dev); + + +#endif /* __VIR_NODE_DEVICE_UDEV_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list