From nobody Fri May 3 07:30:35 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 1516872262104610.4436606221515; Thu, 25 Jan 2018 01:24:22 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45F5648E82; Thu, 25 Jan 2018 09:24:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E0FF5C8B7; Thu, 25 Jan 2018 09:24:21 +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 D6BA718033D9; Thu, 25 Jan 2018 09:24:20 +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 w0P9OI22032658 for ; Thu, 25 Jan 2018 04:24:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 38EC82C313; Thu, 25 Jan 2018 09:24:18 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 682A665608; Thu, 25 Jan 2018 09:24:17 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:48 +0100 Message-Id: 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] [PATCH 01/15] conf: nodedev: Rename virNodeDevObjHasCap to virNodeDevObjHasCapStr 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 25 Jan 2018 09:24:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We currently have 2 methods that do the capability matching. This should be condensed to a single function and all the derivates should just call into that using a proper type conversion. Signed-off-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index c4e3a40d3..a4d38b3a1 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -53,6 +53,8 @@ static virClassPtr virNodeDeviceObjClass; static virClassPtr virNodeDeviceObjListClass; static void virNodeDeviceObjDispose(void *opaque); static void virNodeDeviceObjListDispose(void *opaque); +static bool virNodeDeviceObjHasCapStr(const virNodeDeviceObj *obj, + const char *cap); =20 static int virNodeDeviceObjOnceInit(void) @@ -121,8 +123,8 @@ virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj) =20 =20 static bool -virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, - const char *cap) +virNodeDeviceObjHasCapStr(const virNodeDeviceObj *obj, + const char *cap) { virNodeDevCapsDefPtr caps =3D obj->def->caps; const char *fc_host_cap =3D @@ -375,7 +377,7 @@ virNodeDeviceObjListFindByCapCallback(const void *paylo= ad, int want =3D 0; =20 virObjectLock(obj); - if (virNodeDeviceObjHasCap(obj, matchstr)) + if (virNodeDeviceObjHasCapStr(obj, matchstr)) want =3D 1; virObjectUnlock(obj); return want; @@ -750,7 +752,7 @@ virNodeDeviceObjListNumOfDevicesCallback(void *payload, virObjectLock(obj); def =3D obj->def; if ((!filter || filter(data->conn, def)) && - (!data->matchstr || virNodeDeviceObjHasCap(obj, data->matchstr))) + (!data->matchstr || virNodeDeviceObjHasCapStr(obj, data->matchstr)= )) data->count++; =20 virObjectUnlock(obj); @@ -805,7 +807,7 @@ virNodeDeviceObjListGetNamesCallback(void *payload, def =3D obj->def; =20 if ((!filter || filter(data->conn, def)) && - (!data->matchstr || virNodeDeviceObjHasCap(obj, data->matchstr))) { + (!data->matchstr || virNodeDeviceObjHasCapStr(obj, data->matchstr)= )) { if (VIR_STRDUP(data->names[data->nnames], def->name) < 0) { data->error =3D true; goto cleanup; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872266820134.48900970479065; Thu, 25 Jan 2018 01:24:26 -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 CA5B178558; Thu, 25 Jan 2018 09:24:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0DFA4F0EE; Thu, 25 Jan 2018 09:24:25 +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 6494D18033DD; Thu, 25 Jan 2018 09:24:25 +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 w0P9OJhu032669 for ; Thu, 25 Jan 2018 04:24:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69ED02C315; Thu, 25 Jan 2018 09:24:19 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8833565635; Thu, 25 Jan 2018 09:24:18 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:49 +0100 Message-Id: <19bd57fa981637a78d13aa377170e779d43b5d64.1516872173.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] [PATCH 02/15] conf: nodedev: Rename virNodeDeviceCapMatch to virNodeDevObjHasCap 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 25 Jan 2018 09:24:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We currently have 2 methods that do the capability matching. This should be condensed to a single function and all the derivates should just call into that using a proper type conversion. Signed-off-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index a4d38b3a1..ccad59a4b 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -55,6 +55,8 @@ static void virNodeDeviceObjDispose(void *opaque); static void virNodeDeviceObjListDispose(void *opaque); static bool virNodeDeviceObjHasCapStr(const virNodeDeviceObj *obj, const char *cap); +static bool virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, + int type); =20 static int virNodeDeviceObjOnceInit(void) @@ -683,8 +685,8 @@ virNodeDeviceObjListGetParentHost(virNodeDeviceObjListP= tr devs, =20 =20 static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, - int type) +virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, + int type) { virNodeDevCapsDefPtr cap =3D NULL; =20 @@ -850,7 +852,7 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr de= vs, =20 =20 #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)= ) && \ - virNodeDeviceCapMatch(obj, VIR_NODE_DEV_CAP_ ## FLAG)) + virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG= )) static bool virNodeDeviceMatch(virNodeDeviceObjPtr obj, unsigned int flags) --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872268978742.4803988061071; Thu, 25 Jan 2018 01:24:28 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 260DBC070E24; Thu, 25 Jan 2018 09:24:28 +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 E8F9B2D331; Thu, 25 Jan 2018 09:24:27 +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 924DD4EE50; Thu, 25 Jan 2018 09:24:27 +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 w0P9OQDc032685 for ; Thu, 25 Jan 2018 04:24:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 072535D6A8; Thu, 25 Jan 2018 09:24:26 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 585BE2C30F; Thu, 25 Jan 2018 09:24:19 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:50 +0100 Message-Id: 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] [PATCH 03/15] conf: nodedev: Convert virNodeDevObjHasCapStr to a simple wrapper 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 25 Jan 2018 09:24:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch drops the capability matching redundancy by simply converting the string input to our internal types which are then in turn used for the actual capability matching. Signed-off-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 50 +----------------------------------------= ---- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index ccad59a4b..5360df805 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -128,55 +128,7 @@ static bool virNodeDeviceObjHasCapStr(const virNodeDeviceObj *obj, const char *cap) { - virNodeDevCapsDefPtr caps =3D obj->def->caps; - const char *fc_host_cap =3D - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); - const char *vports_cap =3D - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); - const char *mdev_types =3D - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_MDEV_TYPES); - - while (caps) { - if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) { - return true; - } else { - switch (caps->data.type) { - case VIR_NODE_DEV_CAP_PCI_DEV: - if ((STREQ(cap, mdev_types)) && - (caps->data.pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_= MDEV)) - return true; - break; - - case VIR_NODE_DEV_CAP_SCSI_HOST: - if ((STREQ(cap, fc_host_cap) && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HB= A_FC_HOST)) || - (STREQ(cap, vports_cap) && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HB= A_VPORT_OPS))) - return true; - break; - - case VIR_NODE_DEV_CAP_SYSTEM: - case VIR_NODE_DEV_CAP_USB_DEV: - case VIR_NODE_DEV_CAP_USB_INTERFACE: - case VIR_NODE_DEV_CAP_NET: - case VIR_NODE_DEV_CAP_SCSI_TARGET: - case VIR_NODE_DEV_CAP_SCSI: - case VIR_NODE_DEV_CAP_STORAGE: - case VIR_NODE_DEV_CAP_FC_HOST: - case VIR_NODE_DEV_CAP_VPORTS: - case VIR_NODE_DEV_CAP_SCSI_GENERIC: - case VIR_NODE_DEV_CAP_DRM: - case VIR_NODE_DEV_CAP_MDEV_TYPES: - case VIR_NODE_DEV_CAP_MDEV: - case VIR_NODE_DEV_CAP_CCW_DEV: - case VIR_NODE_DEV_CAP_LAST: - break; - } - } - - caps =3D caps->next; - } - return false; + return virNodeDeviceObjHasCap(obj, virNodeDevCapTypeFromString(cap)); } =20 =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872272070669.9576017523063; Thu, 25 Jan 2018 01:24:32 -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 219F9A8AA; Thu, 25 Jan 2018 09:24:31 +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 D66A62A2C4; Thu, 25 Jan 2018 09:24:30 +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 8B6CD410B7; Thu, 25 Jan 2018 09:24:30 +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 w0P9ORqM032691 for ; Thu, 25 Jan 2018 04:24:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 03D102C30F; Thu, 25 Jan 2018 09:24:27 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55FCD5D6A8; Thu, 25 Jan 2018 09:24:26 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:51 +0100 Message-Id: <8d84acd27ae698b2ea8bc2516f3a46d60a472e67.1516872173.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] [PATCH 04/15] nodedev: Drop the nodeDeviceSysfsGetSCSIHostCaps wrapper 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 25 Jan 2018 09:24:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We can call directly the virNodeDeviceGetSCSIHostCaps helper instead. Signed-off-by: Erik Skultety --- src/conf/node_device_conf.c | 12 ++++++++++++ src/node_device/node_device_driver.c | 2 +- src/node_device/node_device_hal.c | 4 ++-- src/node_device/node_device_linux_sysfs.c | 12 ------------ src/node_device/node_device_linux_sysfs.h | 1 - src/node_device/node_device_udev.c | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bf84fd2b3..70a753ebf 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2431,6 +2431,8 @@ virNodeDeviceDeleteVport(virConnectPtr conn, } =20 =20 +#ifdef __linux__ + int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host) { @@ -2511,3 +2513,13 @@ virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPt= r scsi_host) VIR_FREE(tmp); return ret; } + +#else + +int +virNodeDeviceGetSCSIHostCaps(virNodeDevCap) +{ + return -1; +} + +#endif /* __linux__ */ diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 6216a6977..a2f687942 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -56,7 +56,7 @@ nodeDeviceUpdateCaps(virNodeDeviceDefPtr def) while (cap) { switch (cap->data.type) { case VIR_NODE_DEV_CAP_SCSI_HOST: - nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host); + virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: nodeDeviceSysfsGetSCSITargetCaps(def->sysfs_path, diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index c19e327c9..4c50f4613 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -151,7 +151,7 @@ gather_pci_cap(LibHalContext *ctx, const char *udi, ignore_value(virStrToLong_ui(p+1, &p, 16, &d->pci_dev.function= )); } =20 - if (nodeDeviceSysfsGetPCIRelatedDevCaps(sysfs_path, &d->pci_dev) <= 0) { + if (virNodeDeviceGetPCIDynamicCaps(sysfs_path, &d->pci_dev) < 0) { VIR_FREE(sysfs_path); return -1; } @@ -237,7 +237,7 @@ gather_scsi_host_cap(LibHalContext *ctx, const char *ud= i, =20 (void)get_int_prop(ctx, udi, "scsi_host.host", (int *)&d->scsi_host.ho= st); =20 - retval =3D nodeDeviceSysfsGetSCSIHostCaps(&d->scsi_host); + retval =3D virNodeDeviceGetSCSIHostCaps(&d->scsi_host); =20 if (retval =3D=3D -1) goto out; diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c index 6f438e5f3..b3f80a555 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -45,12 +45,6 @@ =20 VIR_LOG_INIT("node_device.node_device_linux_sysfs"); =20 -int -nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host) -{ - return virNodeDeviceGetSCSIHostCaps(scsi_host); -} - =20 int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath, @@ -196,12 +190,6 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsP= ath, =20 #else =20 -int -nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host ATTRIBUT= E_UNUSED) -{ - return -1; -} - int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath ATTRIBUTE_UNUSE= D, virNodeDevCapSCSITargetPtr scsi_targe= t ATTRIBUTE_UNUSED) { diff --git a/src/node_device/node_device_linux_sysfs.h b/src/node_device/no= de_device_linux_sysfs.h index 12cfe6341..9392d6934 100644 --- a/src/node_device/node_device_linux_sysfs.h +++ b/src/node_device/node_device_linux_sysfs.h @@ -25,7 +25,6 @@ =20 # include "node_device_conf.h" =20 -int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath, virNodeDevCapSCSITargetPtr scsi_targe= t); int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e0fca6159..4cc531d2c 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -781,7 +781,7 @@ udevProcessSCSIHost(struct udev_device *device ATTRIBUT= E_UNUSED, return -1; } =20 - nodeDeviceSysfsGetSCSIHostCaps(&def->caps->data.scsi_host); + virNodeDeviceGetSCSIHostCaps(&def->caps->data.scsi_host); =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) return -1; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872276205449.80765835846194; Thu, 25 Jan 2018 01:24:36 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50677780EE; Thu, 25 Jan 2018 09:24:35 +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 204A35C8B7; Thu, 25 Jan 2018 09:24:35 +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 D54C53FC73; Thu, 25 Jan 2018 09:24:34 +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 w0P9OX0i032712 for ; Thu, 25 Jan 2018 04:24:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1D92F2C315; Thu, 25 Jan 2018 09:24:33 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03DB12C314; Thu, 25 Jan 2018 09:24:27 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:52 +0100 Message-Id: <72172317b8e0bd9df4dad457b542f2d290530a4b.1516872173.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] [PATCH 05/15] nodedev: Move the sysfs-related cap handling to node_device_conf.c 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 25 Jan 2018 09:24:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The capabilities are defined/parsed/formatted/queried from this module, no reason for 'update' not being part of the module as well. This also involves some module-specific prefix changes. This patch also drops the node_device_linux_sysfs module from the repo since: a) it only contained the capability handlers we just moved b) it's only linked with the driver (by design) and thus unreachable to other modules c) we touch sysfs across all the src/util modules so the module being deleted hasn't been serving its original intention for some time already. Signed-off-by: Erik Skultety --- src/Makefile.am | 4 +- src/conf/node_device_conf.c | 154 +++++++++++++++++++++- src/conf/node_device_conf.h | 7 + src/libvirt_private.syms | 2 + src/node_device/node_device_driver.c | 7 +- src/node_device/node_device_hal.c | 1 - src/node_device/node_device_linux_sysfs.c | 206 --------------------------= ---- src/node_device/node_device_linux_sysfs.h | 33 ----- src/node_device/node_device_udev.c | 5 +- 9 files changed, 168 insertions(+), 251 deletions(-) delete mode 100644 src/node_device/node_device_linux_sysfs.c delete mode 100644 src/node_device/node_device_linux_sysfs.h diff --git a/src/Makefile.am b/src/Makefile.am index 166c9a8e9..b8ecd8df8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1168,9 +1168,7 @@ ACCESS_DRIVER_POLKIT_POLICY =3D \ =20 NODE_DEVICE_DRIVER_SOURCES =3D \ node_device/node_device_driver.c \ - node_device/node_device_driver.h \ - node_device/node_device_linux_sysfs.c \ - node_device/node_device_linux_sysfs.h + node_device/node_device_driver.h =20 NODE_DEVICE_DRIVER_HAL_SOURCES =3D \ node_device/node_device_hal.c \ diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 70a753ebf..5b0af559a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -33,11 +33,13 @@ #include "virstring.h" #include "node_device_conf.h" #include "device_conf.h" +#include "dirname.h" #include "virxml.h" #include "virbuffer.h" #include "viruuid.h" #include "virrandom.h" #include "virlog.h" +#include "virfcp.h" =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 @@ -2514,10 +2516,160 @@ virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHost= Ptr scsi_host) return ret; } =20 + +int +virNodeDeviceGetSCSITargetCaps(const char *sysfsPath, + virNodeDevCapSCSITargetPtr scsi_target) +{ + int ret =3D -1; + char *dir =3D NULL, *rport =3D NULL; + + VIR_DEBUG("Checking if '%s' is an FC remote port", scsi_target->name); + + /* /sys/devices/[...]/host0/rport-0:0-0/target0:0:0 -> rport-0:0-0 */ + if (!(dir =3D mdir_name(sysfsPath))) + return -1; + + if (VIR_STRDUP(rport, last_component(dir)) < 0) + goto cleanup; + + if (!virFCIsCapableRport(rport)) + goto cleanup; + + VIR_FREE(scsi_target->rport); + VIR_STEAL_PTR(scsi_target->rport, rport); + + if (virFCReadRportValue(scsi_target->rport, "port_name", + &scsi_target->wwpn) < 0) { + VIR_WARN("Failed to read port_name for '%s'", scsi_target->rport); + goto cleanup; + } + + scsi_target->flags |=3D VIR_NODE_DEV_CAP_FLAG_FC_RPORT; + ret =3D 0; + + cleanup: + if (ret < 0) { + VIR_FREE(scsi_target->rport); + VIR_FREE(scsi_target->wwpn); + scsi_target->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_FC_RPORT; + } + VIR_FREE(rport); + VIR_FREE(dir); + + return ret; +} + + +static int +virNodeDeviceGetPCISRIOVCaps(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev) +{ + size_t i; + int ret; + + /* this could be a refresh, so clear out the old data */ + for (i =3D 0; i < pci_dev->num_virtual_functions; i++) + VIR_FREE(pci_dev->virtual_functions[i]); + VIR_FREE(pci_dev->virtual_functions); + pci_dev->num_virtual_functions =3D 0; + pci_dev->max_virtual_functions =3D 0; + pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; + + ret =3D virPCIGetPhysicalFunction(sysfsPath, + &pci_dev->physical_function); + if (ret < 0) + goto cleanup; + + if (pci_dev->physical_function) + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; + + ret =3D virPCIGetVirtualFunctions(sysfsPath, &pci_dev->virtual_functio= ns, + &pci_dev->num_virtual_functions, + &pci_dev->max_virtual_functions); + if (ret < 0) + goto cleanup; + + if (pci_dev->num_virtual_functions > 0 || + pci_dev->max_virtual_functions > 0) + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + + cleanup: + return ret; +} + + +static int +virNodeDeviceGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr pci_dev) +{ + size_t i; + int tmpGroup, ret =3D -1; + virPCIDeviceAddress addr; + + /* this could be a refresh, so clear out the old data */ + for (i =3D 0; i < pci_dev->nIommuGroupDevices; i++) + VIR_FREE(pci_dev->iommuGroupDevices[i]); + VIR_FREE(pci_dev->iommuGroupDevices); + pci_dev->nIommuGroupDevices =3D 0; + pci_dev->iommuGroupNumber =3D 0; + + addr.domain =3D pci_dev->domain; + addr.bus =3D pci_dev->bus; + addr.slot =3D pci_dev->slot; + addr.function =3D pci_dev->function; + tmpGroup =3D virPCIDeviceAddressGetIOMMUGroupNum(&addr); + if (tmpGroup =3D=3D -1) { + /* error was already reported */ + goto cleanup; + } + if (tmpGroup =3D=3D -2) { + /* -2 return means there is no iommu_group data */ + ret =3D 0; + goto cleanup; + } + if (tmpGroup >=3D 0) { + if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &pci_dev->iom= muGroupDevices, + &pci_dev->nIommuGrou= pDevices) < 0) + goto cleanup; + pci_dev->iommuGroupNumber =3D tmpGroup; + } + + ret =3D 0; + cleanup: + return ret; +} + + +/* virNodeDeviceGetPCIDynamicCaps() get info that is stored in sysfs + * about devices related to this device, i.e. things that can change + * without this device itself changing. These must be refreshed + * anytime full XML of the device is requested, because they can + * change with no corresponding notification from the kernel/udev. + */ +int +virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev) +{ + if (virNodeDeviceGetPCISRIOVCaps(sysfsPath, pci_dev) < 0) + return -1; + if (virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0) + return -1; + return 0; +} + #else =20 int -virNodeDeviceGetSCSIHostCaps(virNodeDevCap) +virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev) +{ + return -1; +} + + +int virNodeDeviceGetSCSITargetCaps(const char *sysfsPath ATTRIBUTE_UNUSED, + virNodeDevCapSCSITargetPtr scsi_target = ATTRIBUTE_UNUSED) { return -1; } diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index cf79773aa..4e3154875 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -393,4 +393,11 @@ virNodeDeviceDeleteVport(virConnectPtr conn, int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); =20 +int +virNodeDeviceGetSCSITargetCaps(const char *sysfsPath, + virNodeDevCapSCSITargetPtr scsi_target); + +int +virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, + virNodeDevCapPCIDevPtr pci_dev); #endif /* __VIR_NODE_DEVICE_CONF_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bc8cc1fba..0cd8086a6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -707,7 +707,9 @@ virNodeDeviceDefParseNode; virNodeDeviceDefParseString; virNodeDeviceDeleteVport; virNodeDeviceGetParentName; +virNodeDeviceGetPCIDynamicCaps; virNodeDeviceGetSCSIHostCaps; +virNodeDeviceGetSCSITargetCaps; virNodeDeviceGetWWNs; =20 =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index a2f687942..2e42d3527 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -38,7 +38,6 @@ #include "node_device_event.h" #include "node_device_driver.h" #include "node_device_hal.h" -#include "node_device_linux_sysfs.h" #include "virvhba.h" #include "viraccessapicheck.h" #include "virnetdev.h" @@ -59,7 +58,7 @@ nodeDeviceUpdateCaps(virNodeDeviceDefPtr def) virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: - nodeDeviceSysfsGetSCSITargetCaps(def->sysfs_path, + virNodeDeviceGetSCSITargetCaps(def->sysfs_path, &cap->data.scsi_target); break; case VIR_NODE_DEV_CAP_NET: @@ -70,8 +69,8 @@ nodeDeviceUpdateCaps(virNodeDeviceDefPtr def) return -1; break; case VIR_NODE_DEV_CAP_PCI_DEV: - if (nodeDeviceSysfsGetPCIRelatedDevCaps(def->sysfs_path, - &cap->data.pci_dev) < 0) + if (virNodeDeviceGetPCIDynamicCaps(def->sysfs_path, + &cap->data.pci_dev) < 0) return -1; break; =20 diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index 4c50f4613..f98fd0856 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -31,7 +31,6 @@ #include "node_device_conf.h" #include "node_device_driver.h" #include "node_device_hal.h" -#include "node_device_linux_sysfs.h" #include "virerror.h" #include "driver.h" #include "datatypes.h" diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c deleted file mode 100644 index b3f80a555..000000000 --- a/src/node_device/node_device_linux_sysfs.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * node_device_linux_sysfs.c: Linux specific code to gather device data - * that is available from sysfs (but not from UDEV or HAL). - * - * Copyright (C) 2009-2015 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * . - * - */ - -#include - -#include -#include -#include - -#include "dirname.h" -#include "node_device_driver.h" -#include "node_device_hal.h" -#include "node_device_linux_sysfs.h" -#include "virerror.h" -#include "viralloc.h" -#include "virfcp.h" -#include "virlog.h" -#include "virfile.h" -#include "virscsihost.h" -#include "virstring.h" -#include "virvhba.h" - -#define VIR_FROM_THIS VIR_FROM_NODEDEV - -#ifdef __linux__ - -VIR_LOG_INIT("node_device.node_device_linux_sysfs"); - - -int -nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath, - virNodeDevCapSCSITargetPtr scsi_target) -{ - int ret =3D -1; - char *dir =3D NULL, *rport =3D NULL; - - VIR_DEBUG("Checking if '%s' is an FC remote port", scsi_target->name); - - /* /sys/devices/[...]/host0/rport-0:0-0/target0:0:0 -> rport-0:0-0 */ - if (!(dir =3D mdir_name(sysfsPath))) - return -1; - - if (VIR_STRDUP(rport, last_component(dir)) < 0) - goto cleanup; - - if (!virFCIsCapableRport(rport)) - goto cleanup; - - VIR_FREE(scsi_target->rport); - VIR_STEAL_PTR(scsi_target->rport, rport); - - if (virFCReadRportValue(scsi_target->rport, "port_name", - &scsi_target->wwpn) < 0) { - VIR_WARN("Failed to read port_name for '%s'", scsi_target->rport); - goto cleanup; - } - - scsi_target->flags |=3D VIR_NODE_DEV_CAP_FLAG_FC_RPORT; - ret =3D 0; - - cleanup: - if (ret < 0) { - VIR_FREE(scsi_target->rport); - VIR_FREE(scsi_target->wwpn); - scsi_target->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_FC_RPORT; - } - VIR_FREE(rport); - VIR_FREE(dir); - - return ret; -} - - -static int -nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath, - virNodeDevCapPCIDevPtr pci_dev) -{ - size_t i; - int ret; - - /* this could be a refresh, so clear out the old data */ - for (i =3D 0; i < pci_dev->num_virtual_functions; i++) - VIR_FREE(pci_dev->virtual_functions[i]); - VIR_FREE(pci_dev->virtual_functions); - pci_dev->num_virtual_functions =3D 0; - pci_dev->max_virtual_functions =3D 0; - pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; - pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; - - ret =3D virPCIGetPhysicalFunction(sysfsPath, - &pci_dev->physical_function); - if (ret < 0) - goto cleanup; - - if (pci_dev->physical_function) - pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; - - ret =3D virPCIGetVirtualFunctions(sysfsPath, &pci_dev->virtual_functio= ns, - &pci_dev->num_virtual_functions, - &pci_dev->max_virtual_functions); - if (ret < 0) - goto cleanup; - - if (pci_dev->num_virtual_functions > 0 || - pci_dev->max_virtual_functions > 0) - pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; - - cleanup: - return ret; -} - - -static int -nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr pci_dev) -{ - size_t i; - int tmpGroup, ret =3D -1; - virPCIDeviceAddress addr; - - /* this could be a refresh, so clear out the old data */ - for (i =3D 0; i < pci_dev->nIommuGroupDevices; i++) - VIR_FREE(pci_dev->iommuGroupDevices[i]); - VIR_FREE(pci_dev->iommuGroupDevices); - pci_dev->nIommuGroupDevices =3D 0; - pci_dev->iommuGroupNumber =3D 0; - - addr.domain =3D pci_dev->domain; - addr.bus =3D pci_dev->bus; - addr.slot =3D pci_dev->slot; - addr.function =3D pci_dev->function; - tmpGroup =3D virPCIDeviceAddressGetIOMMUGroupNum(&addr); - if (tmpGroup =3D=3D -1) { - /* error was already reported */ - goto cleanup; - } - if (tmpGroup =3D=3D -2) { - /* -2 return means there is no iommu_group data */ - ret =3D 0; - goto cleanup; - } - if (tmpGroup >=3D 0) { - if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &pci_dev->iom= muGroupDevices, - &pci_dev->nIommuGrou= pDevices) < 0) - goto cleanup; - pci_dev->iommuGroupNumber =3D tmpGroup; - } - - ret =3D 0; - cleanup: - return ret; -} - - -/* nodeDeviceSysfsGetPCIRelatedCaps() get info that is stored in sysfs - * about devices related to this device, i.e. things that can change - * without this device itself changing. These must be refreshed - * anytime full XML of the device is requested, because they can - * change with no corresponding notification from the kernel/udev. - */ -int -nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, - virNodeDevCapPCIDevPtr pci_dev) -{ - if (nodeDeviceSysfsGetPCISRIOVCaps(sysfsPath, pci_dev) < 0) - return -1; - if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0) - return -1; - return 0; -} - - -#else - -int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath ATTRIBUTE_UNUSE= D, - virNodeDevCapSCSITargetPtr scsi_targe= t ATTRIBUTE_UNUSED) -{ - return -1; -} - -int -nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath ATTRIBUTE_UNUSED, - virNodeDevCapPCIDevPtr pci_dev ATTRIBU= TE_UNUSED) -{ - return -1; -} - -#endif /* __linux__ */ diff --git a/src/node_device/node_device_linux_sysfs.h b/src/node_device/no= de_device_linux_sysfs.h deleted file mode 100644 index 9392d6934..000000000 --- a/src/node_device/node_device_linux_sysfs.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * node_device_linux_sysfs.h: Linux specific code to gather device data - * that is available from sysfs (but not from UDEV or HAL). - * - * Copyright (C) 2015 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * . - * - */ - -#ifndef __VIR_NODE_DEVICE_LINUX_SYSFS_H__ -# define __VIR_NODE_DEVICE_LINUX_SYSFS_H__ - -# include "node_device_conf.h" - -int nodeDeviceSysfsGetSCSITargetCaps(const char *sysfsPath, - virNodeDevCapSCSITargetPtr scsi_targe= t); -int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, - virNodeDevCapPCIDevPtr pci_dev); - -#endif /* __VIR_NODE_DEVICE_LINUX_SYSFS_H__ */ diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 4cc531d2c..519b0bf6f 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -30,7 +30,6 @@ #include "node_device_conf.h" #include "node_device_event.h" #include "node_device_driver.h" -#include "node_device_linux_sysfs.h" #include "node_device_udev.h" #include "virerror.h" #include "driver.h" @@ -558,7 +557,7 @@ udevProcessPCI(struct udev_device *device, &pci_dev->numa_node, 10) < 0) goto cleanup; =20 - if (nodeDeviceSysfsGetPCIRelatedDevCaps(def->sysfs_path, pci_dev) < 0) + if (virNodeDeviceGetPCIDynamicCaps(def->sysfs_path, pci_dev) < 0) goto cleanup; =20 if (!(pciDev =3D virPCIDeviceNew(pci_dev->domain, @@ -802,7 +801,7 @@ udevProcessSCSITarget(struct udev_device *device, if (VIR_STRDUP(scsi_target->name, sysname) < 0) return -1; =20 - nodeDeviceSysfsGetSCSITargetCaps(def->sysfs_path, &def->caps->data.scs= i_target); + virNodeDeviceGetSCSITargetCaps(def->sysfs_path, &def->caps->data.scsi_= target); =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) return -1; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872289643384.5765461064193; Thu, 25 Jan 2018 01:24:49 -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 CF5B7DB958; Thu, 25 Jan 2018 09:24:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E68A65608; Thu, 25 Jan 2018 09:24: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 5A28918033DB; Thu, 25 Jan 2018 09:24:48 +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 w0P9OlMV032748 for ; Thu, 25 Jan 2018 04:24:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id CB7985D6A8; Thu, 25 Jan 2018 09:24:47 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAC2D46E63; Thu, 25 Jan 2018 09:24:33 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:53 +0100 Message-Id: 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] [PATCH 06/15] nodedev: Export nodeDeviceUpdateCaps from node_device_conf.c 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 25 Jan 2018 09:24:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since we moved the helpers from nodedev driver to src/conf, the actual 'update' function using those helpers should be moved as well so that we don't need to call back into the driver. Signed-off-by: Erik Skultety --- src/conf/node_device_conf.c | 54 ++++++++++++++++++++++++++++++++= ++++ src/conf/node_device_conf.h | 3 ++ src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 54 +-------------------------------= ---- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 5b0af559a..217673a56 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2433,6 +2433,60 @@ virNodeDeviceDeleteVport(virConnectPtr conn, } =20 =20 +int +virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def) +{ + virNodeDevCapsDefPtr cap =3D def->caps; + + while (cap) { + switch (cap->data.type) { + case VIR_NODE_DEV_CAP_SCSI_HOST: + virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host); + break; + case VIR_NODE_DEV_CAP_SCSI_TARGET: + virNodeDeviceGetSCSITargetCaps(def->sysfs_path, + &cap->data.scsi_target); + break; + case VIR_NODE_DEV_CAP_NET: + if (virNetDevGetLinkInfo(cap->data.net.ifname, + &cap->data.net.lnk) < 0) + return -1; + virBitmapFree(cap->data.net.features); + if (virNetDevGetFeatures(cap->data.net.ifname, + &cap->data.net.features) < 0) + return -1; + break; + case VIR_NODE_DEV_CAP_PCI_DEV: + if (virNodeDeviceGetPCIDynamicCaps(def->sysfs_path, + &cap->data.pci_dev) < 0) + return -1; + break; + + /* all types that (supposedly) don't require any updates + * relative to what's in the cache. + */ + case VIR_NODE_DEV_CAP_DRM: + case VIR_NODE_DEV_CAP_SYSTEM: + case VIR_NODE_DEV_CAP_USB_DEV: + case VIR_NODE_DEV_CAP_USB_INTERFACE: + case VIR_NODE_DEV_CAP_SCSI: + case VIR_NODE_DEV_CAP_STORAGE: + case VIR_NODE_DEV_CAP_FC_HOST: + case VIR_NODE_DEV_CAP_VPORTS: + case VIR_NODE_DEV_CAP_SCSI_GENERIC: + case VIR_NODE_DEV_CAP_MDEV_TYPES: + case VIR_NODE_DEV_CAP_MDEV: + case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_LAST: + break; + } + cap =3D cap->next; + } + + return 0; +} + + #ifdef __linux__ =20 int diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 4e3154875..7e32f5c05 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -400,4 +400,7 @@ virNodeDeviceGetSCSITargetCaps(const char *sysfsPath, int virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, virNodeDevCapPCIDevPtr pci_dev); + +int +virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def); #endif /* __VIR_NODE_DEVICE_CONF_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0cd8086a6..6098cf121 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -711,6 +711,7 @@ virNodeDeviceGetPCIDynamicCaps; virNodeDeviceGetSCSIHostCaps; virNodeDeviceGetSCSITargetCaps; virNodeDeviceGetWWNs; +virNodeDeviceUpdateCaps; =20 =20 # conf/node_device_event.h diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 2e42d3527..48f45474c 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -47,58 +47,6 @@ virNodeDeviceDriverStatePtr driver; =20 =20 -static int -nodeDeviceUpdateCaps(virNodeDeviceDefPtr def) -{ - virNodeDevCapsDefPtr cap =3D def->caps; - - while (cap) { - switch (cap->data.type) { - case VIR_NODE_DEV_CAP_SCSI_HOST: - virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host); - break; - case VIR_NODE_DEV_CAP_SCSI_TARGET: - virNodeDeviceGetSCSITargetCaps(def->sysfs_path, - &cap->data.scsi_target); - break; - case VIR_NODE_DEV_CAP_NET: - if (virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.= lnk) < 0) - return -1; - virBitmapFree(cap->data.net.features); - if (virNetDevGetFeatures(cap->data.net.ifname, &cap->data.net.= features) < 0) - return -1; - break; - case VIR_NODE_DEV_CAP_PCI_DEV: - if (virNodeDeviceGetPCIDynamicCaps(def->sysfs_path, - &cap->data.pci_dev) < 0) - return -1; - break; - - /* all types that (supposedly) don't require any updates - * relative to what's in the cache. - */ - case VIR_NODE_DEV_CAP_DRM: - case VIR_NODE_DEV_CAP_SYSTEM: - case VIR_NODE_DEV_CAP_USB_DEV: - case VIR_NODE_DEV_CAP_USB_INTERFACE: - case VIR_NODE_DEV_CAP_SCSI: - case VIR_NODE_DEV_CAP_STORAGE: - case VIR_NODE_DEV_CAP_FC_HOST: - case VIR_NODE_DEV_CAP_VPORTS: - case VIR_NODE_DEV_CAP_SCSI_GENERIC: - case VIR_NODE_DEV_CAP_MDEV_TYPES: - case VIR_NODE_DEV_CAP_MDEV: - case VIR_NODE_DEV_CAP_CCW_DEV: - case VIR_NODE_DEV_CAP_LAST: - break; - } - cap =3D cap->next; - } - - return 0; -} - - #if defined (__linux__) && ( defined (WITH_HAL) || defined(WITH_UDEV)) /* NB: It was previously believed that changes in driver name were * relayed to libvirt as "change" events by udev, and the udev event @@ -314,7 +262,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, if (nodeDeviceUpdateDriverName(def) < 0) goto cleanup; =20 - if (nodeDeviceUpdateCaps(def) < 0) + if (virNodeDeviceUpdateCaps(def) < 0) goto cleanup; =20 ret =3D virNodeDeviceDefFormat(def); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872300040369.0572402287455; Thu, 25 Jan 2018 01:25:00 -0800 (PST) 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 39BA2C058ECC; Thu, 25 Jan 2018 09:24:59 +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 18BC06056B; Thu, 25 Jan 2018 09:24:59 +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 D68F23FB18; Thu, 25 Jan 2018 09:24:58 +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 w0P9OvJB000333 for ; Thu, 25 Jan 2018 04:24:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1B0872C316; Thu, 25 Jan 2018 09:24:57 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CAC065608; Thu, 25 Jan 2018 09:24:47 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:54 +0100 Message-Id: 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] [PATCH 07/15] nodedev: Introduce virNodeDeviceCapsListExport 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.32]); Thu, 25 Jan 2018 09:24:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Whether asking for a number of capabilities supported by a device or listing them, it's handled essentially by a copy-paste code, so extract the common stuff into this new helper which also updates all capabilities just before touching them. Signed-off-by: Erik Skultety --- src/conf/node_device_conf.c | 73 ++++++++++++++++++++++++++++++++= +++ src/conf/node_device_conf.h | 5 +++ src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 75 +++++++++-----------------------= ---- 4 files changed, 97 insertions(+), 57 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 217673a56..9467bb415 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2487,6 +2487,79 @@ virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def) } =20 =20 +/** + * virNodeDeviceCapsListExport: + * @def: node device definition + * @list: pointer to an array to store all supported capabilities by a dev= ice + * + * Takes the definition, scans through all the capabilities that the device + * supports (including the nested caps) and populates a newly allocated li= st + * with them. Caller is responsible for freeing the list. + * If NULL is passed to @list, only the number of caps will be returned. + * + * Returns the number of capabilities the device supports, -1 on error. + */ +int +virNodeDeviceCapsListExport(virNodeDeviceDefPtr def, + virNodeDevCapType **list) +{ + virNodeDevCapsDefPtr caps =3D NULL; + virNodeDevCapType *tmp =3D NULL; + bool want_list =3D !!list; + int ncaps =3D 0; + int ret =3D -1; + +#define MAYBE_ADD_CAP(cap) \ + do { \ + if (want_list) \ + tmp[ncaps] =3D cap; \ + } while (0) + + if (want_list && VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST - 1) < 0) + goto cleanup; + + for (caps =3D def->caps; caps; caps =3D caps->next) { + unsigned int flags; + + MAYBE_ADD_CAP(caps->data.type); + ncaps++; + + /* check nested caps for a given type as well */ + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { + flags =3D caps->data.scsi_host.flags; + + if (flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { + MAYBE_ADD_CAP(VIR_NODE_DEV_CAP_FC_HOST); + ncaps++; + } + + if (flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) { + MAYBE_ADD_CAP(VIR_NODE_DEV_CAP_VPORTS); + ncaps++; + } + } + + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { + flags =3D caps->data.pci_dev.flags; + + if (flags & VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) { + MAYBE_ADD_CAP(VIR_NODE_DEV_CAP_MDEV_TYPES); + ncaps++; + } + } + } + +#undef MAYBE_ADD_CAP + + if (want_list) + VIR_STEAL_PTR(*list, tmp); + ret =3D ncaps; + cleanup: + VIR_FREE(tmp); + return ret; +} + + #ifdef __linux__ =20 int diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 7e32f5c05..53cdfdb01 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -403,4 +403,9 @@ virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, =20 int virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def); + +int +virNodeDeviceCapsListExport(virNodeDeviceDefPtr def, + virNodeDevCapType **list); + #endif /* __VIR_NODE_DEVICE_CONF_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6098cf121..1698e6227 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -699,6 +699,7 @@ virNodeDevCapMdevTypeFree; virNodeDevCapsDefFree; virNodeDevCapTypeFromString; virNodeDevCapTypeToString; +virNodeDeviceCapsListExport; virNodeDeviceCreateVport; virNodeDeviceDefFormat; virNodeDeviceDefFree; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 48f45474c..8fb08742b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -306,8 +306,6 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device) { virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; - virNodeDevCapsDefPtr caps; - int ncaps =3D 0; int ret =3D -1; =20 if (!(obj =3D nodeDeviceObjFindByName(device->name))) @@ -317,27 +315,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device) if (virNodeDeviceNumOfCapsEnsureACL(device->conn, def) < 0) goto cleanup; =20 - for (caps =3D def->caps; caps; caps =3D caps->next) { - ++ncaps; - - if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { - if (caps->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) - ncaps++; - - if (caps->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) - ncaps++; - } - if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { - if (caps->data.pci_dev.flags & - VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) - ncaps++; - } - - } - - ret =3D ncaps; + ret =3D virNodeDeviceCapsListExport(def, NULL); =20 cleanup: virNodeDeviceObjEndAPI(&obj); @@ -353,9 +331,10 @@ nodeDeviceListCaps(virNodeDevicePtr device, { virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; - virNodeDevCapsDefPtr caps; + virNodeDevCapType *list =3D NULL; int ncaps =3D 0; int ret =3D -1; + size_t i; =20 if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; @@ -364,46 +343,28 @@ nodeDeviceListCaps(virNodeDevicePtr device, if (virNodeDeviceListCapsEnsureACL(device->conn, def) < 0) goto cleanup; =20 - for (caps =3D def->caps; caps && ncaps < maxnames; caps =3D caps->next= ) { - if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->dat= a.type)) < 0) + if ((ncaps =3D virNodeDeviceCapsListExport(def, &list)) < 0) + goto cleanup; + + if (ncaps > maxnames) + ncaps =3D maxnames; + + for (i =3D 0; i < ncaps; i++) { + if (VIR_STRDUP(names[i], virNodeDevCapTypeToString(list[i])) < 0) goto cleanup; - - if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { - if (ncaps < maxnames && - caps->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { - if (VIR_STRDUP(names[ncaps++], - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_= FC_HOST)) < 0) - goto cleanup; - } - - if (ncaps < maxnames && - caps->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) { - if (VIR_STRDUP(names[ncaps++], - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_= VPORTS)) < 0) - goto cleanup; - } - } - if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { - if (ncaps < maxnames && - caps->data.pci_dev.flags & - VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) { - if (VIR_STRDUP(names[ncaps++], - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_= MDEV_TYPES)) < 0) - goto cleanup; - } - } } + ret =3D ncaps; =20 cleanup: virNodeDeviceObjEndAPI(&obj); - if (ret =3D=3D -1) { - --ncaps; - while (--ncaps >=3D 0) - VIR_FREE(names[ncaps]); + if (ret < 0) { + size_t j; + for (j =3D 0; j < i; j++) + VIR_FREE(names[j]); } + + VIR_FREE(list); return ret; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872314322836.5355877804474; Thu, 25 Jan 2018 01:25:14 -0800 (PST) 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 51C405589A; Thu, 25 Jan 2018 09:25:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CA866056B; Thu, 25 Jan 2018 09:25:13 +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 E5B5618033DE; Thu, 25 Jan 2018 09:25:12 +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 w0P9PB9e000377 for ; Thu, 25 Jan 2018 04:25:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3CFB86268B; Thu, 25 Jan 2018 09:25:11 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E07365608; Thu, 25 Jan 2018 09:24:57 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:55 +0100 Message-Id: <68f2cf03e23b7cec988effd5103d48c1570068a3.1516872173.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] [PATCH 08/15] conf: nodedev: Refresh capabilities before touching them 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.30]); Thu, 25 Jan 2018 09:25:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Most of them are static, however in case of PCI and SCSI_HOST devices, the nested capabilities can change dynamically, e.g. due to a driver change (from host_pci_driver -> vfio_pci). Signed-off-by: Erik Skultety Suggested-by: Wu Zongyong --- src/conf/node_device_conf.c | 3 +++ src/conf/virnodedeviceobj.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 9467bb415..3aefc9e5b 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2515,6 +2515,9 @@ virNodeDeviceCapsListExport(virNodeDeviceDefPtr def, tmp[ncaps] =3D cap; \ } while (0) =20 + if (virNodeDeviceUpdateCaps(def) < 0) + goto cleanup; + if (want_list && VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST - 1) < 0) goto cleanup; =20 diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 5360df805..34f754454 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -809,6 +809,10 @@ static bool virNodeDeviceMatch(virNodeDeviceObjPtr obj, unsigned int flags) { + /* Refresh the capabilities first, e.g. due to a driver change */ + if (virNodeDeviceUpdateCaps(obj->def) < 0) + return false; + /* filter by cap type */ if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { if (!(MATCH(SYSTEM) || --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872327869772.2270218169391; Thu, 25 Jan 2018 01:25:27 -0800 (PST) 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 EA2FDAB096; Thu, 25 Jan 2018 09:25:26 +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 C0DFF609C0; Thu, 25 Jan 2018 09:25:26 +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 84A973FB1A; Thu, 25 Jan 2018 09:25:26 +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 w0P9POhn000452 for ; Thu, 25 Jan 2018 04:25:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id D65586268B; Thu, 25 Jan 2018 09:25:24 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14A152C31D; Thu, 25 Jan 2018 09:25:11 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:56 +0100 Message-Id: <9443ed4af0006a26aebc15ee9f783aaff700b07e.1516872173.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] [PATCH 09/15] util: mdev: Drop some unused symbols/includes from the header 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.39]); Thu, 25 Jan 2018 09:25:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There were some leftovers from early development which never got used. Signed-off-by: Erik Skultety --- src/util/virmdev.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 0b8e830f4..84cbb1f2a 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -22,7 +22,6 @@ # include "internal.h" # include "virobject.h" # include "virutil.h" -# include "virpci.h" =20 typedef enum { VIR_MDEV_MODEL_TYPE_VFIO_PCI =3D 0, @@ -35,8 +34,6 @@ VIR_ENUM_DECL(virMediatedDeviceModel) =20 typedef struct _virMediatedDevice virMediatedDevice; typedef virMediatedDevice *virMediatedDevicePtr; -typedef struct _virMediatedDeviceAddress virMediatedDeviceAddress; -typedef virMediatedDeviceAddress *virMediatedDeviceAddressPtr; typedef struct _virMediatedDeviceList virMediatedDeviceList; typedef virMediatedDeviceList *virMediatedDeviceListPtr; =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872340290680.0614504644795; Thu, 25 Jan 2018 01:25:40 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F0DE5C9CE; Thu, 25 Jan 2018 09:25:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBDD96A96D; Thu, 25 Jan 2018 09:25:38 +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 AA1A818033DF; Thu, 25 Jan 2018 09:25:38 +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 w0P9Pb4j000488 for ; Thu, 25 Jan 2018 04:25:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id C8ABB6268B; Thu, 25 Jan 2018 09:25:37 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD32A2C31F; Thu, 25 Jan 2018 09:25:25 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:57 +0100 Message-Id: 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] [PATCH 10/15] util: mdev: Introduce virMediatedDeviceType structure 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 25 Jan 2018 09:25:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is later going to replace the existing virNodeDevCapMdevType, since: 1) it's going to couple related stuff in a single module 2) util is supposed to contain helpers that are widely accessible across the whole repository. Signed-off-by: Erik Skultety --- src/libvirt_private.syms | 1 + src/util/virmdev.c | 13 +++++++++++++ src/util/virmdev.h | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1698e6227..75eaf1d4c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2181,6 +2181,7 @@ virMediatedDeviceModelTypeFromString; virMediatedDeviceModelTypeToString; virMediatedDeviceNew; virMediatedDeviceSetUsedBy; +virMediatedDeviceTypeFree; =20 =20 =20 diff --git a/src/util/virmdev.c b/src/util/virmdev.c index a5f52d10f..db679b8a6 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -483,3 +483,16 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceList= Ptr dst, } goto cleanup; } + + +void +virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type) +{ + if (!type) + return; + + VIR_FREE(type->id); + VIR_FREE(type->name); + VIR_FREE(type->device_api); + VIR_FREE(type); +} diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 84cbb1f2a..320610ab9 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -37,6 +37,15 @@ typedef virMediatedDevice *virMediatedDevicePtr; typedef struct _virMediatedDeviceList virMediatedDeviceList; typedef virMediatedDeviceList *virMediatedDeviceListPtr; =20 +typedef struct _virMediatedDeviceType virMediatedDeviceType; +typedef virMediatedDeviceType *virMediatedDeviceTypePtr; +struct _virMediatedDeviceType { + char *id; + char *name; + char *device_api; + unsigned int available_instances; +}; + typedef int (*virMediatedDeviceCallback)(virMediatedDevicePtr dev, const char *path, void *opaque); =20 @@ -117,4 +126,7 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListP= tr dst, virMediatedDeviceListPtr src, const char *drvname, const char *domname); + +void +virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type); #endif /* __VIR_MDEV_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872349184259.49344268007326; Thu, 25 Jan 2018 01:25:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4030876540; Thu, 25 Jan 2018 09:25: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 1B71F5C89F; Thu, 25 Jan 2018 09:25: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 D72DC3FB1D; Thu, 25 Jan 2018 09:25:47 +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 w0P9Pk0S000519 for ; Thu, 25 Jan 2018 04:25:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46C1D2C316; Thu, 25 Jan 2018 09:25:46 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB3CE2C325; Thu, 25 Jan 2018 09:25:37 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:58 +0100 Message-Id: <1772f4644bcee90619f959ac087b8cd7196cc368.1516872173.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] [PATCH 11/15] util: mdev: Introduce virMediatedDeviceTypeReadAttrs getter 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 25 Jan 2018 09:25:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This should serve as a replacement for the existing udevFillMdevType which is responsible for fetching the device type's attributes from the sysfs interface. The problem with the existing solution is that it's tied to the udev backend. Signed-off-by: Erik Skultety --- src/util/virmdev.c | 34 ++++++++++++++++++++++++++++++++++ src/util/virmdev.h | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index db679b8a6..b57cc3ed9 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -496,3 +496,37 @@ virMediatedDeviceTypeFree(virMediatedDeviceTypePtr typ= e) VIR_FREE(type->device_api); VIR_FREE(type); } + + +int +virMediatedDeviceTypeReadAttrs(const char *sysfspath, + virMediatedDeviceTypePtr *type) +{ + int ret =3D -1; + virMediatedDeviceTypePtr tmp =3D NULL; + +#define MDEV_GET_SYSFS_ATTR(attr, dst, cb) \ + do { \ + if (cb(dst, "%s/%s", sysfspath, attr) < 0) \ + goto cleanup; \ + } while (0) \ + + if (VIR_ALLOC(tmp) < 0) + goto cleanup; + + if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0) + goto cleanup; + + MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString); + MDEV_GET_SYSFS_ATTR("device_api", &tmp->device_api, virFileReadValueSt= ring); + MDEV_GET_SYSFS_ATTR("available_instances", &tmp->available_instances, + virFileReadValueUint); + +#undef MDEV_GET_SYSFS_ATTR + + VIR_STEAL_PTR(*type, tmp); + ret =3D 0; + cleanup: + virMediatedDeviceTypeFree(tmp); + return ret; +} diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 320610ab9..01ab02e75 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -129,4 +129,9 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListP= tr dst, =20 void virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type); + +int +virMediatedDeviceTypeReadAttrs(const char *sysfspath, + virMediatedDeviceTypePtr *type); + #endif /* __VIR_MDEV_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872392911638.6594110456113; Thu, 25 Jan 2018 01:26:32 -0800 (PST) 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 11E0881DF4; Thu, 25 Jan 2018 09:26:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7FC7609A5; Thu, 25 Jan 2018 09:26:31 +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 81A3118033D9; Thu, 25 Jan 2018 09:26:31 +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 w0P9QTk1000980 for ; Thu, 25 Jan 2018 04:26:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id C53CB2C317; Thu, 25 Jan 2018 09:26:29 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64B3A2C7A2; Thu, 25 Jan 2018 09:25:46 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:59 +0100 Message-Id: <3bead6533469e008107b2f1d5586030d6a819b0a.1516872173.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] [PATCH 12/15] util: pci: Introduce virPCIGetMdevTypes helper 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.25]); Thu, 25 Jan 2018 09:26:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a replacement for the existing udevPCIGetMdevTypesCap which is static to the udev backend. This simple helper constructs the sysfs path from the device's base path for each mdev type and queries the corresponding attributes of that type. Signed-off-by: Erik Skultety --- src/libvirt_private.syms | 1 + src/util/virpci.c | 58 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virpci.h | 4 ++++ 3 files changed, 63 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 75eaf1d4c..8d4c8dd3f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2456,6 +2456,7 @@ virPCIDeviceWaitForCleanup; virPCIEDeviceInfoFree; virPCIGetDeviceAddressFromSysfsLink; virPCIGetHeaderType; +virPCIGetMdevTypes; virPCIGetNetName; virPCIGetPhysicalFunction; virPCIGetVirtualFunctionIndex; diff --git a/src/util/virpci.c b/src/util/virpci.c index fe57bef32..12d7ef0e4 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3027,6 +3027,64 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_de= vice_path, return ret; } =20 + +int +virPCIGetMdevTypes(const char *sysfspath, + virMediatedDeviceTypePtr **types) +{ + int ret =3D -1; + int dirret =3D -1; + DIR *dir =3D NULL; + struct dirent *entry; + char *types_path =3D NULL; + char *tmppath =3D NULL; + virMediatedDeviceTypePtr mdev_type =3D NULL; + virMediatedDeviceTypePtr *mdev_types =3D NULL; + size_t ntypes =3D 0; + size_t i; + + if (virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath) < 0) + return -1; + + if ((dirret =3D virDirOpenIfExists(&dir, types_path)) < 0) + goto cleanup; + + if (dirret =3D=3D 0) { + ret =3D 0; + goto cleanup; + } + + while ((dirret =3D virDirRead(dir, &entry, types_path)) > 0) { + /* append the type id to the path and read the attributes from the= re */ + if (virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name) < 0) + goto cleanup; + + if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(mdev_types, ntypes, mdev_type) < 0) + goto cleanup; + + VIR_FREE(tmppath); + } + + if (dirret < 0) + goto cleanup; + + VIR_STEAL_PTR(*types, mdev_types); + ret =3D ntypes; + ntypes =3D 0; + cleanup: + virMediatedDeviceTypeFree(mdev_type); + for (i =3D 0; i < ntypes; i++) + virMediatedDeviceTypeFree(mdev_types[i]); + VIR_FREE(mdev_types); + VIR_FREE(types_path); + VIR_FREE(tmppath); + VIR_DIR_CLOSE(dir); + return ret; +} + #else static const char *unsupported =3D N_("not supported on non-linux platform= s"); =20 diff --git a/src/util/virpci.h b/src/util/virpci.h index f1fbe39e6..a0bc0a474 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -25,6 +25,7 @@ # define __VIR_PCI_H__ =20 # include "internal.h" +# include "virmdev.h" # include "virobject.h" # include "virutil.h" =20 @@ -249,4 +250,7 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrTy= pe); =20 void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev); =20 +int virPCIGetMdevTypes(const char *sysfspath, + virMediatedDeviceType ***types); + #endif /* __VIR_PCI_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872399550499.22018543259276; Thu, 25 Jan 2018 01:26:39 -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 9BA4DC0567A2; Thu, 25 Jan 2018 09:26:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 712D05D728; Thu, 25 Jan 2018 09:26:38 +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 30A4718033DD; Thu, 25 Jan 2018 09:26:38 +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 w0P9QaAC000997 for ; Thu, 25 Jan 2018 04:26:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 866092C318; Thu, 25 Jan 2018 09:26:36 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 575BA6268B; Thu, 25 Jan 2018 09:26:29 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:24:00 +0100 Message-Id: <25cdef9772fa52a769dfecacf8c113f23c1c6e56.1516872173.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] [PATCH 13/15] nodedev: udev: Drop the unused mdev type helpers 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 25 Jan 2018 09:26:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" These are not necessary anymore, since these are going to be shadowed by the helpers provided by util/virmdev.c module. Signed-off-by: Erik Skultety --- src/node_device/node_device_udev.c | 119 ---------------------------------= ---- 1 file changed, 119 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 519b0bf6f..1ccf1f8b4 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -393,119 +393,6 @@ udevTranslatePCIIds(unsigned int vendor, =20 =20 static int -udevFillMdevType(struct udev_device *device, - const char *dir, - virNodeDevCapMdevTypePtr type) -{ - int ret =3D -1; - char *attrpath =3D NULL; - -#define MDEV_GET_SYSFS_ATTR(attr_name, cb, ...) \ - do { \ - if (virAsprintf(&attrpath, "%s/%s", dir, #attr_name) < 0) \ - goto cleanup; \ - \ - if (cb(device, attrpath, __VA_ARGS__) < 0) \ - goto cleanup; \ - \ - VIR_FREE(attrpath); \ - } while (0) \ - - if (VIR_STRDUP(type->id, last_component(dir)) < 0) - goto cleanup; - - /* query udev for the attributes under subdirectories using the relati= ve - * path stored in @dir, i.e. 'mdev_supported_types/' - */ - MDEV_GET_SYSFS_ATTR(name, udevGetStringSysfsAttr, &type->name); - MDEV_GET_SYSFS_ATTR(device_api, udevGetStringSysfsAttr, &type->device_= api); - MDEV_GET_SYSFS_ATTR(available_instances, udevGetUintSysfsAttr, - &type->available_instances, 10); - -#undef MDEV_GET_SYSFS_ATTR - - ret =3D 0; - cleanup: - VIR_FREE(attrpath); - return ret; -} - - -static int -udevPCIGetMdevTypesCap(struct udev_device *device, - virNodeDevCapPCIDevPtr pcidata) -{ - int ret =3D -1; - int dirret =3D -1; - DIR *dir =3D NULL; - struct dirent *entry; - char *path =3D NULL; - char *tmppath =3D NULL; - virNodeDevCapMdevTypePtr type =3D NULL; - virNodeDevCapMdevTypePtr *types =3D NULL; - size_t ntypes =3D 0; - size_t i; - - if (virAsprintf(&path, "%s/mdev_supported_types", - udev_device_get_syspath(device)) < 0) - return -1; - - if ((dirret =3D virDirOpenIfExists(&dir, path)) < 0) - goto cleanup; - - if (dirret =3D=3D 0) { - ret =3D 0; - goto cleanup; - } - - if (VIR_ALLOC(types) < 0) - goto cleanup; - - /* UDEV doesn't report attributes under subdirectories by default but = is - * able to query them if the path to the attribute is relative to 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, we n= eed to - * scan the subdirectories ourselves. - */ - while ((dirret =3D virDirRead(dir, &entry, path)) > 0) { - if (VIR_ALLOC(type) < 0) - goto cleanup; - - /* construct the relative mdev type path bit for udev */ - if (virAsprintf(&tmppath, "mdev_supported_types/%s", entry->d_name= ) < 0) - goto cleanup; - - if (udevFillMdevType(device, tmppath, type) < 0) - goto cleanup; - - if (VIR_APPEND_ELEMENT(types, ntypes, type) < 0) - goto cleanup; - - VIR_FREE(tmppath); - } - - if (dirret < 0) - goto cleanup; - - VIR_STEAL_PTR(pcidata->mdev_types, types); - pcidata->nmdev_types =3D ntypes; - pcidata->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; - ntypes =3D 0; - ret =3D 0; - cleanup: - virNodeDevCapMdevTypeFree(type); - for (i =3D 0; i < ntypes; i++) - virNodeDevCapMdevTypeFree(types[i]); - VIR_FREE(types); - VIR_FREE(path); - VIR_FREE(tmppath); - VIR_DIR_CLOSE(dir); - return ret; -} - - -static int udevProcessPCI(struct udev_device *device, virNodeDeviceDefPtr def) { @@ -596,12 +483,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: --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872623022432.2997866076014; Thu, 25 Jan 2018 01:30:23 -0800 (PST) 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 72AE9A452D; Thu, 25 Jan 2018 09:30:21 +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 1F2B0600D1; Thu, 25 Jan 2018 09:30:21 +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 1BB503FB19; Thu, 25 Jan 2018 09:30:20 +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 w0P9QpXq001037 for ; Thu, 25 Jan 2018 04:26:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 508092C317; Thu, 25 Jan 2018 09:26:51 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 548152C31E; Thu, 25 Jan 2018 09:26:36 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:24:01 +0100 Message-Id: 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] [PATCH 14/15] conf: Replace usage of virNodeDevCapMdevType with virMediatedDeviceType 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.25]); Thu, 25 Jan 2018 09:30:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have all the building blocks in place, switch the nodedev driver to use the "new" virMediatedDeviceType type instead of the "old" virNodeDevCapMdevType one. Signed-off-by: Erik Skultety --- src/conf/node_device_conf.c | 21 ++++----------------- src/conf/node_device_conf.h | 14 +------------- src/libvirt_private.syms | 1 - 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 3aefc9e5b..5fc5f6708 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -92,19 +92,6 @@ virNodeDevCapsDefParseString(const char *xpath, =20 =20 void -virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type) -{ - if (!type) - return; - - VIR_FREE(type->id); - VIR_FREE(type->name); - VIR_FREE(type->device_api); - VIR_FREE(type); -} - - -void virNodeDeviceDefFree(virNodeDeviceDefPtr def) { virNodeDevCapsDefPtr caps; @@ -285,7 +272,7 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); for (i =3D 0; i < data->pci_dev.nmdev_types; i++) { - virNodeDevCapMdevTypePtr type =3D data->pci_dev.mdev_types[i]; + virMediatedDeviceTypePtr type =3D data->pci_dev.mdev_types[i]; virBufferEscapeString(buf, "\n", type->id); virBufferAdjustIndent(buf, 2); if (type->name) @@ -1546,7 +1533,7 @@ virNodeDevPCICapMdevTypesParseXML(xmlXPathContextPtr = ctxt, xmlNodePtr orignode =3D NULL; xmlNodePtr *nodes =3D NULL; int nmdev_types =3D -1; - virNodeDevCapMdevTypePtr type =3D NULL; + virMediatedDeviceTypePtr type =3D NULL; size_t i; =20 if ((nmdev_types =3D virXPathNodeSet("./type", ctxt, &nodes)) < 0) @@ -1593,7 +1580,7 @@ virNodeDevPCICapMdevTypesParseXML(xmlXPathContextPtr = ctxt, ret =3D 0; cleanup: VIR_FREE(nodes); - virNodeDevCapMdevTypeFree(type); + virMediatedDeviceTypeFree(type); ctxt->node =3D orignode; return ret; } @@ -2176,7 +2163,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) VIR_FREE(data->pci_dev.iommuGroupDevices); virPCIEDeviceInfoFree(data->pci_dev.pci_express); for (i =3D 0; i < data->pci_dev.nmdev_types; i++) - virNodeDevCapMdevTypeFree(data->pci_dev.mdev_types[i]); + virMediatedDeviceTypeFree(data->pci_dev.mdev_types[i]); VIR_FREE(data->pci_dev.mdev_types); break; case VIR_NODE_DEV_CAP_USB_DEV: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 53cdfdb01..685ae3034 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -139,15 +139,6 @@ struct _virNodeDevCapSystem { virNodeDevCapSystemFirmware firmware; }; =20 -typedef struct _virNodeDevCapMdevType virNodeDevCapMdevType; -typedef virNodeDevCapMdevType *virNodeDevCapMdevTypePtr; -struct _virNodeDevCapMdevType { - char *id; - char *name; - char *device_api; - unsigned int available_instances; -}; - typedef struct _virNodeDevCapMdev virNodeDevCapMdev; typedef virNodeDevCapMdev *virNodeDevCapMdevPtr; struct _virNodeDevCapMdev { @@ -178,7 +169,7 @@ struct _virNodeDevCapPCIDev { int numa_node; virPCIEDeviceInfoPtr pci_express; int hdrType; /* enum virPCIHeaderType or -1 */ - virNodeDevCapMdevTypePtr *mdev_types; + virMediatedDeviceTypePtr *mdev_types; size_t nmdev_types; }; =20 @@ -358,9 +349,6 @@ virNodeDeviceDefFree(virNodeDeviceDefPtr def); void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); =20 -void -virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type); - # define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP \ (VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV | \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8d4c8dd3f..2e20304ad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -695,7 +695,6 @@ virNetDevIPRouteParseXML; =20 =20 # conf/node_device_conf.h -virNodeDevCapMdevTypeFree; virNodeDevCapsDefFree; virNodeDevCapTypeFromString; virNodeDevCapTypeToString; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:30:35 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 1516872723244427.4780636545255; Thu, 25 Jan 2018 01:32:03 -0800 (PST) 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 CEF7378553; Thu, 25 Jan 2018 09:32:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F265605D8; Thu, 25 Jan 2018 09:32:01 +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 3EFD918033DC; Thu, 25 Jan 2018 09:32:01 +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 w0P9QvhI001065 for ; Thu, 25 Jan 2018 04:26:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 285092C322; Thu, 25 Jan 2018 09:26:57 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0721D65608; Thu, 25 Jan 2018 09:26:51 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:24:02 +0100 Message-Id: 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] [PATCH 15/15] conf: nodedev: Update PCI mdev capabilities dynamically 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.28]); Thu, 25 Jan 2018 09:32:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Just like SRIOV, a PCI device is only capable of the mediated devices framework when it's bound to the vendor native driver, thus if a driver change occurs, e.g. vendor_native->vfio, we need to refresh some of the device's capabilities to reflect the reality, mdev included. Signed-off-by: Erik Skultety Suggested-by: Wu Zongyong --- src/conf/node_device_conf.c | 34 +++++++++++++++++++++++++++++++--- src/node_device/node_device_udev.c | 1 - 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 5fc5f6708..9e4273855 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2758,6 +2758,34 @@ virNodeDeviceGetPCIIOMMUGroupCaps(virNodeDevCapPCIDe= vPtr pci_dev) } =20 =20 +static int +virNodeDeviceGetPCIMdevTypesCaps(const char *sysfspath, + virNodeDevCapPCIDevPtr pci_dev) +{ + virMediatedDeviceTypePtr *types =3D NULL; + int rc =3D 0; + size_t i; + + /* this could be a refresh, so clear out the old data */ + for (i =3D 0; i < pci_dev->nmdev_types; i++) + virMediatedDeviceTypeFree(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; + + rc =3D virPCIGetMdevTypes(sysfspath, &types); + + if (rc <=3D 0) + return rc; + + VIR_STEAL_PTR(pci_dev->mdev_types, types); + pci_dev->nmdev_types =3D rc; + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; + + return 0; +} + + /* virNodeDeviceGetPCIDynamicCaps() get info that is stored in sysfs * about devices related to this device, i.e. things that can change * without this device itself changing. These must be refreshed @@ -2768,9 +2796,9 @@ int virNodeDeviceGetPCIDynamicCaps(const char *sysfsPath, virNodeDevCapPCIDevPtr pci_dev) { - if (virNodeDeviceGetPCISRIOVCaps(sysfsPath, pci_dev) < 0) - return -1; - if (virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0) + if (virNodeDeviceGetPCISRIOVCaps(sysfsPath, pci_dev) < 0 || + virNodeDeviceGetPCIIOMMUGroupCaps(pci_dev) < 0 || + virNodeDeviceGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0) return -1; return 0; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 1ccf1f8b4..e10660ba0 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -484,7 +484,6 @@ udevProcessPCI(struct udev_device *device, } =20 ret =3D 0; - cleanup: virPCIDeviceFree(pciDev); virPCIEDeviceInfoFree(pci_express); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list