From nobody Thu May 15 21:10:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506957892602820.8543699607548; Mon, 2 Oct 2017 08:24:52 -0700 (PDT) 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 83B70C04AC5E; Mon, 2 Oct 2017 15:24:51 +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 217E35D973; Mon, 2 Oct 2017 15:24:51 +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 D465A18355C5; Mon, 2 Oct 2017 15:24:50 +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 v92F5WL0017306 for ; Mon, 2 Oct 2017 11:05:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id DBD915C544; Mon, 2 Oct 2017 15:05:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 640E2171DB for ; Mon, 2 Oct 2017 15:05:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83B70C04AC5E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Oct 2017 17:05:14 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] src: Use virDomainNetFindByName 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.31]); Mon, 02 Oct 2017 15:24:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/libxl/libxl_driver.c | 22 +++++++++------------- src/lxc/lxc_driver.c | 22 +++++++++------------- src/openvz/openvz_driver.c | 22 +++++++++------------- src/qemu/qemu_driver.c | 11 +---------- src/test/test_driver.c | 28 ++++++---------------------- 5 files changed, 34 insertions(+), 71 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index bf3625e34..a174d892e 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4961,7 +4961,7 @@ libxlDomainInterfaceStats(virDomainPtr dom, { libxlDriverPrivatePtr driver =3D dom->conn->privateData; virDomainObjPtr vm; - size_t i; + virDomainNetDefPtr net =3D NULL; int ret =3D -1; =20 if (!(vm =3D libxlDomObjFromDomain(dom))) @@ -4979,20 +4979,16 @@ libxlDomainInterfaceStats(virDomainPtr dom, goto endjob; } =20 - /* Check the path is one of the domain's network interfaces. */ - for (i =3D 0; i < vm->def->nnets; i++) { - if (vm->def->nets[i]->ifname && - STREQ(vm->def->nets[i]->ifname, path)) { - ret =3D 0; - break; - } - } - - if (ret =3D=3D 0) - ret =3D virNetDevTapInterfaceStats(path, stats); - else + if (!(net =3D virDomainNetFindByName(vm->def, path))) { virReportError(VIR_ERR_INVALID_ARG, _("'%s' is not a known interface"), path); + goto endjob; + } + + if (virNetDevTapInterfaceStats(path, stats) < 0) + goto endjob; + + ret =3D 0; =20 endjob: libxlDomainObjEndJob(driver, vm); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4d24d2870..c0ef0c210 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2853,9 +2853,9 @@ lxcDomainInterfaceStats(virDomainPtr dom, virDomainInterfaceStatsPtr stats) { virDomainObjPtr vm; - size_t i; int ret =3D -1; virLXCDriverPtr driver =3D dom->conn->privateData; + virDomainNetDefPtr net =3D NULL; =20 if (!(vm =3D lxcDomObjFromDomain(dom))) goto cleanup; @@ -2872,20 +2872,16 @@ lxcDomainInterfaceStats(virDomainPtr dom, goto endjob; } =20 - /* Check the path is one of the domain's network interfaces. */ - for (i =3D 0; i < vm->def->nnets; i++) { - if (vm->def->nets[i]->ifname && - STREQ(vm->def->nets[i]->ifname, path)) { - ret =3D 0; - break; - } - } - - if (ret =3D=3D 0) - ret =3D virNetDevTapInterfaceStats(path, stats); - else + if (!(net =3D virDomainNetFindByName(vm->def, path))) { virReportError(VIR_ERR_INVALID_ARG, _("Invalid path, '%s' is not a known interface"), p= ath); + goto endjob; + } + + if (virNetDevTapInterfaceStats(path, stats) < 0) + goto endjob; + + ret =3D 0; =20 endjob: virLXCDomainObjEndJob(driver, vm); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index a1485fc88..3c24020ce 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1985,7 +1985,7 @@ openvzDomainInterfaceStats(virDomainPtr dom, { struct openvz_driver *driver =3D dom->conn->privateData; virDomainObjPtr vm; - size_t i; + virDomainNetDefPtr net =3D NULL; int ret =3D -1; =20 openvzDriverLock(driver); @@ -2006,20 +2006,16 @@ openvzDomainInterfaceStats(virDomainPtr dom, goto cleanup; } =20 - /* Check the path is one of the domain's network interfaces. */ - for (i =3D 0; i < vm->def->nnets; i++) { - if (vm->def->nets[i]->ifname && - STREQ(vm->def->nets[i]->ifname, path)) { - ret =3D 0; - break; - } - } - - if (ret =3D=3D 0) - ret =3D virNetDevTapInterfaceStats(path, stats); - else + if (!(net =3D virDomainNetFindByName(vm->def, path))) { virReportError(VIR_ERR_INVALID_ARG, _("invalid path, '%s' is not a known interface"), p= ath); + goto cleanup; + } + + if (virNetDevTapInterfaceStats(path, stats) < 0) + goto cleanup; + + ret =3D 0; =20 cleanup: if (vm) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2c8ea19e3..1ab16e57c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11016,7 +11016,6 @@ qemuDomainInterfaceStats(virDomainPtr dom, { virDomainObjPtr vm; virDomainNetDefPtr net =3D NULL; - size_t i; int ret =3D -1; =20 if (!(vm =3D qemuDomObjFromDomain(dom))) @@ -11031,15 +11030,7 @@ qemuDomainInterfaceStats(virDomainPtr dom, goto cleanup; } =20 - /* Check the path is one of the domain's network interfaces. */ - for (i =3D 0; i < vm->def->nnets; i++) { - if (STREQ_NULLABLE(vm->def->nets[i]->ifname, path)) { - net =3D vm->def->nets[i]; - break; - } - } - - if (!net) { + if (!(net =3D virDomainNetFindByName(vm->def, path))) { virReportError(VIR_ERR_INVALID_ARG, _("invalid path, '%s' is not a known interface"), p= ath); goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 9b434e9a0..e92768a97 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -593,25 +593,16 @@ testDomainGenerateIfname(virDomainDefPtr domdef) { int maxif =3D 1024; int ifctr; - size_t i; =20 for (ifctr =3D 0; ifctr < maxif; ++ifctr) { + virDomainNetDefPtr net =3D NULL; char *ifname; - int found =3D 0; =20 if (virAsprintf(&ifname, "testnet%d", ifctr) < 0) return NULL; =20 /* Generate network interface names */ - for (i =3D 0; i < domdef->nnets; i++) { - if (domdef->nets[i]->ifname && - STREQ(domdef->nets[i]->ifname, ifname)) { - found =3D 1; - break; - } - } - - if (!found) + if (!(net =3D virDomainNetFindByName(domdef, ifname))) return ifname; VIR_FREE(ifname); } @@ -3176,8 +3167,9 @@ static int testDomainInterfaceStats(virDomainPtr doma= in, virDomainObjPtr privdom; struct timeval tv; unsigned long long statbase; - size_t i; - int found =3D 0, ret =3D -1; + virDomainNetDefPtr net =3D NULL; + int ret =3D -1; + =20 if (!(privdom =3D testDomObjFromDomain(domain))) return -1; @@ -3188,15 +3180,7 @@ static int testDomainInterfaceStats(virDomainPtr dom= ain, goto error; } =20 - for (i =3D 0; i < privdom->def->nnets; i++) { - if (privdom->def->nets[i]->ifname && - STREQ(privdom->def->nets[i]->ifname, path)) { - found =3D 1; - break; - } - } - - if (!found) { + if (!(net =3D virDomainNetFindByName(privdom->def, path))) { virReportError(VIR_ERR_INVALID_ARG, _("invalid path, '%s' is not a known interface"), p= ath); goto error; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list