From nobody Sun Feb 8 18:32:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628172988; cv=none; d=zohomail.com; s=zohoarc; b=gr87RuYXMU7xJQwLajmi6A+lulS7DlCNQB8XyDOx4QuvXdbgrQzaD7zTg1MWFvrcl0lOhKko7sHMjZrcbBDTZD5bXH+XHTR4eiekyq9HNNqaw88H1QluWBHO3Q3ROuqHCpPaGUcGfJH2W4wxugjRefM2NJzujeDJjHHlW5N76S4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628172988; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zQrS/25Lpv6afwzEbku89Cb1Qs/s2qkPAIttB0UI0eU=; b=d3OEVZrN6046q17WLkdf4VDUGDBA2HEZDGc/LfErGaSci+W7j0KpIzeLwRL+ov2mN1zfEOF9t9LyFIBriI1d61G/6E/9ypq4NciGcV0e6c6OxGdzyTaW+M4OuyLsRGQVc1zlVoxWdwlXd4lAkCKCtDPNVnb5DW+COzQNfvN+GWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628172988428179.53714745183993; Thu, 5 Aug 2021 07:16:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-oGjFshiWP12voKCUOk3o7w-1; Thu, 05 Aug 2021 10:16:25 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C20B5802C80; Thu, 5 Aug 2021 14:16:16 +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 A5B4A6E6E9; Thu, 5 Aug 2021 14:16:16 +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 6DD82180BAD2; Thu, 5 Aug 2021 14:16:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 175EDMkR016842 for ; Thu, 5 Aug 2021 10:13:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id CA9B45C1A1; Thu, 5 Aug 2021 14:13:22 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 343D35C25D for ; Thu, 5 Aug 2021 14:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628172987; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zQrS/25Lpv6afwzEbku89Cb1Qs/s2qkPAIttB0UI0eU=; b=HWfkXSc33EATA4QfXJ5jI0aMGBI9WYlpDM3HeIQhx5Gmh/G/KHBJxGHiQ/R5grOuCUX/NW rXBvP1Yiy/0v8oGl4HofW0nTxsr+Hu+ZC2Hoap8zBa5GWftj92xTE3wVZClBGUO121SWYO Fjz2RzorwCNCHK0b6QsY/SQFTsoq5+w= X-MC-Unique: oGjFshiWP12voKCUOk3o7w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] virNetDevGetVirtualFunctions: Directly return virPCIVirtualFunctionList Date: Thu, 5 Aug 2021 16:13:10 +0200 Message-Id: <7b0ebe1a2e3f3030d08ea13a135e9c0ef7c882b6.1628169131.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628172990622100001 Content-Type: text/plain; charset="utf-8" Remove the conversion from virPCIVirtualFunctionList which encapsulates the list of virtual functions to two disjunct arrays. This greatly simplifies the fetching of the parameters as well as cleanup in the caller. Signed-off-by: Peter Krempa --- src/network/bridge_driver.c | 22 ++++++---------------- src/util/virnetdev.c | 26 ++++---------------------- src/util/virnetdev.h | 7 ++----- 3 files changed, 12 insertions(+), 43 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4ffcecdf9f..2555119892 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2598,29 +2598,25 @@ networkShutdownNetworkBridge(virNetworkObj *obj G_G= NUC_UNUSED) static int networkCreateInterfacePool(virNetworkDef *netdef) { - size_t numVirtFns =3D 0; - char **vfNames =3D NULL; - virPCIDeviceAddress **virtFns; - + g_autoptr(virPCIVirtualFunctionList) vfs =3D NULL; int ret =3D -1; size_t i; if (netdef->forward.npfs =3D=3D 0 || netdef->forward.nifs > 0) return 0; - if ((virNetDevGetVirtualFunctions(netdef->forward.pfs->dev, &vfNames, - &virtFns, &numVirtFns)) < 0) { + if (virNetDevGetVirtualFunctions(netdef->forward.pfs->dev, &vfs) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not get Virtual functions on %s"), netdef->forward.pfs->dev); goto cleanup; } - netdef->forward.ifs =3D g_new0(virNetworkForwardIfDef, numVirtFns); + netdef->forward.ifs =3D g_new0(virNetworkForwardIfDef, vfs->nfunctions= ); - for (i =3D 0; i < numVirtFns; i++) { - virPCIDeviceAddress *thisVirtFn =3D virtFns[i]; - const char *thisName =3D vfNames[i]; + for (i =3D 0; i < vfs->nfunctions; i++) { + virPCIDeviceAddress *thisVirtFn =3D vfs->functions[i].addr; + const char *thisName =3D vfs->functions[i].ifname; virNetworkForwardIfDef *thisIf =3D &netdef->forward.ifs[netdef->forward.nifs]; @@ -2689,12 +2685,6 @@ networkCreateInterfacePool(virNetworkDef *netdef) if (netdef->forward.nifs =3D=3D 0) g_clear_pointer(&netdef->forward.ifs, g_free); - for (i =3D 0; i < numVirtFns; i++) { - g_free(vfNames[i]); - g_free(virtFns[i]); - } - g_free(vfNames); - g_free(virtFns); return ret; } diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 4db3b255f6..5b4c585716 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1213,24 +1213,17 @@ virNetDevGetPhysPortName(const char *ifname, /** * virNetDevGetVirtualFunctions: - * * @pfname : name of the physical function interface name - * @vfname: array that will hold the interface names of the virtual_functi= ons - * @n_vfname: pointer to the number of virtual functions + * @vfs: Filled with struct describing the virtual functions of @pfname * * Returns 0 on success and -1 on failure */ - int virNetDevGetVirtualFunctions(const char *pfname, - char ***vfname, - virPCIDeviceAddress ***virt_fns, - size_t *n_vfname) + virPCIVirtualFunctionList **vfs) { - size_t i; g_autofree char *pf_sysfs_device_link =3D NULL; g_autofree char *pfPhysPortID =3D NULL; - g_autoptr(virPCIVirtualFunctionList) vfs =3D NULL; if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) return -1; @@ -1238,18 +1231,9 @@ virNetDevGetVirtualFunctions(const char *pfname, if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) return -1; - if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, &vfs, pfPhysPo= rtID) < 0) + if (virPCIGetVirtualFunctionsFull(pf_sysfs_device_link, vfs, pfPhysPor= tID) < 0) return -1; - *vfname =3D g_new0(char *, vfs->nfunctions); - *virt_fns =3D g_new0(virPCIDeviceAddress *, vfs->nfunctions); - *n_vfname =3D vfs->nfunctions; - - for (i =3D 0; i < *n_vfname; i++) { - virt_fns[i] =3D g_steal_pointer(&vfs->functions[i].addr); - vfname[i] =3D g_steal_pointer(&vfs->functions[i].ifname); - } - return 0; } @@ -1448,9 +1432,7 @@ virNetDevGetPhysPortName(const char *ifname G_GNUC_UN= USED, int virNetDevGetVirtualFunctions(const char *pfname G_GNUC_UNUSED, - char ***vfname G_GNUC_UNUSED, - virPCIDeviceAddress ***virt_fns G_GNUC_UNUSED, - size_t *n_vfname G_GNUC_UNUSED) + virPCIVirtualFunctionList **vfs G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Unable to get virtual functions on this platfo= rm")); diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index de786c9789..790fae5f7a 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -252,11 +252,8 @@ int virNetDevGetPhysPortName(const char *ifname, G_GNUC_WARN_UNUSED_RESULT; int virNetDevGetVirtualFunctions(const char *pfname, - char ***vfname, - virPCIDeviceAddress ***virt_fns, - size_t *n_vfname) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) - ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT; + virPCIVirtualFunctionList **vfs) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; int virNetDevSaveNetConfig(const char *linkdev, int vf, const char *stateDir, --=20 2.31.1