From nobody Mon May 6 12:00:48 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 15072164349551014.9841901280429; Thu, 5 Oct 2017 08:13:54 -0700 (PDT) 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 7B0F55F297F; Thu, 5 Oct 2017 15:13:53 +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 2ED0561989; Thu, 5 Oct 2017 15:13:53 +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 17D0A410B3; Thu, 5 Oct 2017 15:13:52 +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 v95EIfog013966 for ; Thu, 5 Oct 2017 10:18:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 26ABB600C0; Thu, 5 Oct 2017 14:18:41 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FE1360470 for ; Thu, 5 Oct 2017 14:18:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7B0F55F297F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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:27 +0200 Message-Id: <765acaa33185e0e70585c24a7ab30e7c5b4ee493.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 1/4] virsh: Document limitation of domifstat 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.38]); Thu, 05 Oct 2017 15:13:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1497396 The current implementation reads the stats from the host. However, this doesn't work for all types of interfaces as not all of them have a representation in the host. For instance, interface type=3D'user' doesn't. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tools/virsh.pod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 00d93781a..632f202e8 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -775,7 +775,9 @@ the guest OS via an agent. If unspecified, 'lease' is t= he default. =20 =3Ditem B I I =20 -Get network interface stats for a running domain. +Get network interface stats for a running domain. This might be +unavailable for some types of interface which don't have +representation in the host, e.g. user. =20 =3Ditem B I I I [I<--confi= g>] =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 12:00:48 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 1507214162864400.5699988803109; Thu, 5 Oct 2017 07:36:02 -0700 (PDT) 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 322E88123E; Thu, 5 Oct 2017 14:36: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 73A596179E; Thu, 5 Oct 2017 14:36:00 +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 81DFF18355CA; Thu, 5 Oct 2017 14:35:59 +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 v95EIgVv013981 for ; Thu, 5 Oct 2017 10:18:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 86FF360480; Thu, 5 Oct 2017 14:18:42 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7FA7600C0 for ; Thu, 5 Oct 2017 14:18:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 322E88123E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:28 +0200 Message-Id: <410704a31fea779672b08fa273ff0ff6727aef70.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 2/4] virDomainInterfaceStats: Accept MAC address too 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, 05 Oct 2017 14:36:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1497396 The other APIs accept both, ifname and MAC address. There's no reason virDomainInterfaceStats can't do the same. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- include/libvirt/libvirt-domain.h | 2 +- src/driver-hypervisor.h | 2 +- src/libvirt-domain.c | 15 ++++++++------- src/libxl/libxl_driver.c | 8 ++++---- src/lxc/lxc_driver.c | 8 ++++---- src/openvz/openvz_driver.c | 8 ++++---- src/qemu/qemu_driver.c | 10 +++++----- src/remote/remote_protocol.x | 2 +- src/remote_protocol-structs | 2 +- src/test/test_driver.c | 11 ++++++----- src/vz/vz_driver.c | 4 ++-- src/vz/vz_sdk.c | 9 +++++++-- src/xen/xen_driver.c | 11 +++++++++-- tools/virsh.pod | 3 ++- 14 files changed, 55 insertions(+), 40 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 030a62c43..ebf47a9bb 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1571,7 +1571,7 @@ int virDomainBlockStatsFlags (vir= DomainPtr dom, int *nparams, unsigned int flags); int virDomainInterfaceStats (virDomainPtr dom, - const char *path, + const char *device, virDomainInterfaceStatsPt= r stats, size_t size); =20 diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 6c3f7d795..4de0581c3 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -486,7 +486,7 @@ typedef int =20 typedef int (*virDrvDomainInterfaceStats)(virDomainPtr domain, - const char *path, + const char *device, virDomainInterfaceStatsPtr stats); =20 typedef int diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index d2d022a66..34a91d683 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -5507,14 +5507,15 @@ virDomainBlockStatsFlags(virDomainPtr dom, /** * virDomainInterfaceStats: * @dom: pointer to the domain object - * @path: path to the interface + * @device: the interface name or MAC address * @stats: network interface stats (returned) * @size: size of stats structure * * This function returns network interface stats for interfaces * attached to the domain. * - * The path parameter is the name of the network interface. + * The @device parameter is the name of the network interface or + * its MAC address. * * Domains may have more than one network interface. To get stats for * each you should make multiple calls to this function. @@ -5528,20 +5529,20 @@ virDomainBlockStatsFlags(virDomainPtr dom, * Returns: 0 in case of success or -1 in case of failure. */ int -virDomainInterfaceStats(virDomainPtr dom, const char *path, +virDomainInterfaceStats(virDomainPtr dom, const char *device, virDomainInterfaceStatsPtr stats, size_t size) { virConnectPtr conn; virDomainInterfaceStatsStruct stats2 =3D { -1, -1, -1, -1, -1, -1, -1, -1 }; =20 - VIR_DOMAIN_DEBUG(dom, "path=3D%s, stats=3D%p, size=3D%zi", - path, stats, size); + VIR_DOMAIN_DEBUG(dom, "device=3D%s, stats=3D%p, size=3D%zi", + device, stats, size); =20 virResetLastError(); =20 virCheckDomainReturn(dom, -1); - virCheckNonNullArgGoto(path, error); + virCheckNonNullArgGoto(device, error); virCheckNonNullArgGoto(stats, error); if (size > sizeof(stats2)) { virReportInvalidArg(size, @@ -5553,7 +5554,7 @@ virDomainInterfaceStats(virDomainPtr dom, const char = *path, conn =3D dom->conn; =20 if (conn->driver->domainInterfaceStats) { - if (conn->driver->domainInterfaceStats(dom, path, &stats2) =3D=3D = -1) + if (conn->driver->domainInterfaceStats(dom, device, &stats2) =3D= =3D -1) goto error; =20 memcpy(stats, &stats2, size); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 8483d6ecf..9db6f3503 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4956,7 +4956,7 @@ libxlDomainIsUpdated(virDomainPtr dom) =20 static int libxlDomainInterfaceStats(virDomainPtr dom, - const char *path, + const char *device, virDomainInterfaceStatsPtr stats) { libxlDriverPrivatePtr driver =3D dom->conn->privateData; @@ -4979,13 +4979,13 @@ libxlDomainInterfaceStats(virDomainPtr dom, goto endjob; } =20 - if (!(net =3D virDomainNetFindByName(vm->def, path))) { + if (!(net =3D virDomainNetFind(vm->def, device))) { virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), path); + _("'%s' is not a known interface"), device); goto endjob; } =20 - if (virNetDevTapInterfaceStats(path, stats, + if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) <= 0) goto endjob; =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 6ad61bdb7..4ab05a7ff 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2849,7 +2849,7 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, =20 static int lxcDomainInterfaceStats(virDomainPtr dom, - const char *path, + const char *device, virDomainInterfaceStatsPtr stats) { virDomainObjPtr vm; @@ -2872,13 +2872,13 @@ lxcDomainInterfaceStats(virDomainPtr dom, goto endjob; } =20 - if (!(net =3D virDomainNetFindByName(vm->def, path))) { + if (!(net =3D virDomainNetFind(vm->def, device))) { virReportError(VIR_ERR_INVALID_ARG, - _("Invalid path, '%s' is not a known interface"), p= ath); + _("'%s' is not a known interface"), device); goto endjob; } =20 - if (virNetDevTapInterfaceStats(path, stats, + if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) <= 0) goto endjob; =20 diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 11173898d..05ed2bcae 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1980,7 +1980,7 @@ openvzGetVEStatus(virDomainObjPtr vm, int *status, in= t *reason) =20 static int openvzDomainInterfaceStats(virDomainPtr dom, - const char *path, + const char *device, virDomainInterfaceStatsPtr stats) { struct openvz_driver *driver =3D dom->conn->privateData; @@ -2006,13 +2006,13 @@ openvzDomainInterfaceStats(virDomainPtr dom, goto cleanup; } =20 - if (!(net =3D virDomainNetFindByName(vm->def, path))) { + if (!(net =3D virDomainNetFind(vm->def, device))) { virReportError(VIR_ERR_INVALID_ARG, - _("invalid path, '%s' is not a known interface"), p= ath); + _("'%s' is not a known interface"), device); goto cleanup; } =20 - if (virNetDevTapInterfaceStats(path, stats, + if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) <= 0) goto cleanup; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7c6f1674a..f2cc0f0a5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11021,7 +11021,7 @@ qemuDomainBlockStatsFlags(virDomainPtr dom, =20 static int qemuDomainInterfaceStats(virDomainPtr dom, - const char *path, + const char *device, virDomainInterfaceStatsPtr stats) { virDomainObjPtr vm; @@ -11040,17 +11040,17 @@ qemuDomainInterfaceStats(virDomainPtr dom, goto cleanup; } =20 - if (!(net =3D virDomainNetFindByName(vm->def, path))) { + if (!(net =3D virDomainNetFind(vm->def, device))) { virReportError(VIR_ERR_INVALID_ARG, - _("invalid path, '%s' is not a known interface"), p= ath); + _("'%s' is not a known interface"), device); goto cleanup; } =20 if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSE= R) { - if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0) + if (virNetDevOpenvswitchInterfaceStats(device, stats) < 0) goto cleanup; } else { - if (virNetDevTapInterfaceStats(path, stats, + if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net= )) < 0) goto cleanup; } diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 07463b781..e3014f66b 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -682,7 +682,7 @@ struct remote_domain_block_stats_flags_ret { =20 struct remote_domain_interface_stats_args { remote_nonnull_domain dom; - remote_nonnull_string path; + remote_nonnull_string device; }; =20 struct remote_domain_interface_stats_ret { /* insert@2 */ diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 6038bf138..dc78d51c4 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -348,7 +348,7 @@ struct remote_domain_block_stats_flags_ret { }; struct remote_domain_interface_stats_args { remote_nonnull_domain dom; - remote_nonnull_string path; + remote_nonnull_string device; }; struct remote_domain_interface_stats_ret { int64_t rx_bytes; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e92768a97..3e286635e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3160,9 +3160,10 @@ static int testDomainBlockStats(virDomainPtr domain, return ret; } =20 -static int testDomainInterfaceStats(virDomainPtr domain, - const char *path, - virDomainInterfaceStatsPtr stats) +static int +testDomainInterfaceStats(virDomainPtr domain, + const char *device, + virDomainInterfaceStatsPtr stats) { virDomainObjPtr privdom; struct timeval tv; @@ -3180,9 +3181,9 @@ static int testDomainInterfaceStats(virDomainPtr doma= in, goto error; } =20 - if (!(net =3D virDomainNetFindByName(privdom->def, path))) { + if (!(net =3D virDomainNetFind(privdom->def, device))) { virReportError(VIR_ERR_INVALID_ARG, - _("invalid path, '%s' is not a known interface"), p= ath); + _("'%s' is not a known interface"), device); goto error; } =20 diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 9ebb51d60..c33962229 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1873,7 +1873,7 @@ vzDomainBlockStatsFlags(virDomainPtr domain, =20 static int vzDomainInterfaceStats(virDomainPtr domain, - const char *path, + const char *device, virDomainInterfaceStatsPtr stats) { virDomainObjPtr dom =3D NULL; @@ -1888,7 +1888,7 @@ vzDomainInterfaceStats(virDomainPtr domain, =20 privdom =3D dom->privateData; =20 - ret =3D prlsdkGetNetStats(privdom->stats, privdom->sdkdom, path, stats= ); + ret =3D prlsdkGetNetStats(privdom->stats, privdom->sdkdom, device, sta= ts); =20 cleanup: virDomainObjEndAPI(&dom); diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 6ead47a0f..5f377147c 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4484,7 +4484,7 @@ prlsdkFindNetByPath(PRL_HANDLE sdkdom, const char *pa= th) } =20 int -prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *path, +prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *devi= ce, virDomainInterfaceStatsPtr stats) { int ret =3D -1; @@ -4492,8 +4492,13 @@ prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sd= kdom, const char *path, char *name =3D NULL; PRL_RESULT pret; PRL_HANDLE net =3D PRL_INVALID_HANDLE; + virMacAddr mac; + + if (virMacAddrParse(device, &mac) =3D=3D 0) + net =3D prlsdkFindNetByMAC(sdkdom, device); + else + net =3D prlsdkFindNetByPath(sdkdom, device); =20 - net =3D prlsdkFindNetByPath(sdkdom, path); if (net =3D=3D PRL_INVALID_HANDLE) goto cleanup; =20 diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index dae0f4f28..4235ca0ce 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2109,10 +2109,11 @@ xenUnifiedDomainBlockStats(virDomainPtr dom, const = char *path, } =20 static int -xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path, +xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *device, virDomainInterfaceStatsPtr stats) { virDomainDefPtr def =3D NULL; + virDomainNetDefPtr net =3D NULL; int ret =3D -1; =20 if (!(def =3D xenGetDomainDefForDom(dom))) @@ -2121,7 +2122,13 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, con= st char *path, if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0) goto cleanup; =20 - ret =3D xenHypervisorDomainInterfaceStats(def, path, stats); + if (!(net =3D virDomainNetFind(def, device))) { + virReportError(VIR_ERR_INVALID_ARG, + _("'%s' is not a known interface"), device); + goto cleanup; + } + + ret =3D xenHypervisorDomainInterfaceStats(def, net->ifname, stats); =20 cleanup: virDomainDefFree(def); diff --git a/tools/virsh.pod b/tools/virsh.pod index 632f202e8..d21c5df72 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -777,7 +777,8 @@ the guest OS via an agent. If unspecified, 'lease' is t= he default. =20 Get network interface stats for a running domain. This might be unavailable for some types of interface which don't have -representation in the host, e.g. user. +representation in the host, e.g. user. I can be +the interface's target name or the MAC address. =20 =3Ditem B I I I [I<--confi= g>] =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 12:00:48 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 1507216462710970.0267740817501; Thu, 5 Oct 2017 08:14:22 -0700 (PDT) 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 0F25D4D4A9; Thu, 5 Oct 2017 15:14: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 BDB4D60603; Thu, 5 Oct 2017 15:14:20 +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 32093410B7; Thu, 5 Oct 2017 15:14:20 +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 v95EIiVl013991 for ; Thu, 5 Oct 2017 10:18:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id E778D600C0; Thu, 5 Oct 2017 14:18:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B46B60480 for ; Thu, 5 Oct 2017 14:18:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F25D4D4A9 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:29 +0200 Message-Id: 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 3/4] virsh: Deal with multiple matching devices in domif-getlink 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.39]); Thu, 05 Oct 2017 15:14:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The command tries to match interface in domain definition by MAC address or interface name. However, since it's possible to configure two interfaces with the same MAC address, it may happen that the XPath returns two or more nodes. We should check for that. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tools/virsh-domain-monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0ca53e438..4c50155e1 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -707,13 +707,16 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (ninterfaces !=3D 1) { + if (ninterfaces < 1) { if (macstr[0]) vshError(ctl, _("Interface (mac: %s) not found."), macstr); else vshError(ctl, _("Interface (dev: %s) not found."), iface); =20 goto cleanup; + } else if (ninterfaces > 1) { + vshError(ctl, _("multiple matching interfaces found")); + goto cleanup; } =20 ctxt->node =3D interfaces[0]; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 12:00:48 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 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