From nobody Thu May 15 13:42:44 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 1507214838248850.1315291496563; Thu, 5 Oct 2017 07:47:18 -0700 (PDT) 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 2C94E25B99; Thu, 5 Oct 2017 14:47:17 +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 DA45762690; Thu, 5 Oct 2017 14:47: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 8079A18355CA; Thu, 5 Oct 2017 14:47:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v95EIjin013999 for ; Thu, 5 Oct 2017 10:18:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id BFB4C60468; Thu, 5 Oct 2017 14:18:45 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41A9C600C0 for ; Thu, 5 Oct 2017 14:18:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2C94E25B99 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 5 Oct 2017 16:18:30 +0200 Message-Id: <2572ced3c755ea0314157ebbc33c411b739d3518.1507213037.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] virDomainNetFind: Report error if no device found 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.39]); Thu, 05 Oct 2017 14:47:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Every caller reports the error themselves. Might as well move it into the function and thus unify it. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 18 ++++++++++-------- src/libxl/libxl_driver.c | 5 +---- src/lxc/lxc_driver.c | 5 +---- src/openvz/openvz_driver.c | 5 +---- src/qemu/qemu_driver.c | 21 ++++----------------- src/test/test_driver.c | 5 +---- src/xen/xen_driver.c | 5 +---- 7 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 54be9028d..caffa896d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26983,13 +26983,12 @@ virDomainGraphicsListenAppendSocket(virDomainGrap= hicsDefPtr def, * * Finds a domain's net def, given the interface name or MAC address * - * Returns a pointer to the net def or NULL if not found. + * Returns a pointer to the net def or NULL if not found (error is reporte= d). */ virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device) { bool isMac =3D false; - virDomainNetDefPtr net =3D NULL; virMacAddr mac; size_t i; =20 @@ -26998,16 +26997,19 @@ virDomainNetFind(virDomainDefPtr def, const char = *device) =20 if (isMac) { for (i =3D 0; i < def->nnets; i++) { - if (virMacAddrCmp(&mac, &def->nets[i]->mac) =3D=3D 0) { - net =3D def->nets[i]; - break; - } + if (virMacAddrCmp(&mac, &def->nets[i]->mac) =3D=3D 0) + return def->nets[i]; } } else { /* ifname */ - net =3D virDomainNetFindByName(def, device); + virDomainNetDefPtr net =3D NULL; + + if ((net =3D virDomainNetFindByName(def, device))) + return net; } =20 - return net; + virReportError(VIR_ERR_INVALID_ARG, + _("'%s' is not a known interface"), device); + return NULL; } =20 =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9db6f3503..08b0f0317 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4979,11 +4979,8 @@ libxlDomainInterfaceStats(virDomainPtr dom, goto endjob; } =20 - if (!(net =3D virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net =3D virDomainNetFind(vm->def, device))) goto endjob; - } =20 if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) <= 0) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4ab05a7ff..6cf499367 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2872,11 +2872,8 @@ lxcDomainInterfaceStats(virDomainPtr dom, goto endjob; } =20 - if (!(net =3D virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net =3D virDomainNetFind(vm->def, device))) goto endjob; - } =20 if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) <= 0) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 05ed2bcae..ffd64da04 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2006,11 +2006,8 @@ openvzDomainInterfaceStats(virDomainPtr dom, goto cleanup; } =20 - if (!(net =3D virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net =3D virDomainNetFind(vm->def, device))) goto cleanup; - } =20 if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) <= 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f2cc0f0a5..7b79c0950 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11040,11 +11040,8 @@ qemuDomainInterfaceStats(virDomainPtr dom, goto cleanup; } =20 - if (!(net =3D virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net =3D virDomainNetFind(vm->def, device))) goto cleanup; - } =20 if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSE= R) { if (virNetDevOpenvswitchInterfaceStats(device, stats) < 0) @@ -11114,18 +11111,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, goto endjob; =20 if (def && - !(net =3D virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("Can't find device %s"), device); + !(net =3D virDomainNetFind(vm->def, device))) goto endjob; - } =20 if (persistentDef && - !(persistentNet =3D virDomainNetFind(persistentDef, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("Can't find device %s"), device); + !(persistentNet =3D virDomainNetFind(persistentDef, device))) goto endjob; - } =20 if ((VIR_ALLOC(bandwidth) < 0) || (VIR_ALLOC(bandwidth->in) < 0) || @@ -11291,12 +11282,8 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom, goto cleanup; } =20 - net =3D virDomainNetFind(def, device); - if (!net) { - virReportError(VIR_ERR_INVALID_ARG, - _("Can't find device %s"), device); + if (!(net =3D virDomainNetFind(def, device))) goto cleanup; - } =20 for (i =3D 0; i < *nparams && i < QEMU_NB_BANDWIDTH_PARAM; i++) { switch (i) { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3e286635e..be9e8a7aa 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3181,11 +3181,8 @@ testDomainInterfaceStats(virDomainPtr domain, goto error; } =20 - if (!(net =3D virDomainNetFind(privdom->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net =3D virDomainNetFind(privdom->def, device))) goto error; - } =20 if (gettimeofday(&tv, NULL) < 0) { virReportSystemError(errno, diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 4235ca0ce..901b6ba4b 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2122,11 +2122,8 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, con= st char *device, if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0) goto cleanup; =20 - if (!(net =3D virDomainNetFind(def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net =3D virDomainNetFind(def, device))) goto cleanup; - } =20 ret =3D xenHypervisorDomainInterfaceStats(def, net->ifname, stats); =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list