[libvirt] [PATCH 1/2] virsh: Accept iface alias for domifstats too

Michal Privoznik posted 2 patches 7 years, 11 months ago
[libvirt] [PATCH 1/2] virsh: Accept iface alias for domifstats too
Posted by Michal Privoznik 7 years, 11 months ago
https://bugzilla.redhat.com/show_bug.cgi?id=1459091

Not every interface has a name (for instance, vhostuser
interfaces might not have one). However, all interfaces have
aliases. We can accept those to uniquely identify interfaces.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_driver.c       | 6 ++++--
 tools/virsh-domain-monitor.c | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f0cdea659..0634d9e5a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10753,8 +10753,10 @@ qemuDomainInterfaceStats(virDomainPtr dom,
 
     /* Check the path is one of the domain's network interfaces. */
     for (i = 0; i < vm->def->nnets; i++) {
-        if (STREQ_NULLABLE(vm->def->nets[i]->ifname, path)) {
-            net = vm->def->nets[i];
+        virDomainNetDefPtr tmp = vm->def->nets[i];
+        if (STREQ_NULLABLE(tmp->ifname, path) ||
+            STREQ(tmp->info.alias, path)) {
+            net = tmp;
             break;
         }
     }
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 0ca53e438..313a6d2f0 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -614,7 +614,8 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
                                 "|./source/@network"
                                 "|./source/@name)", ctxt);
 
-        target = virXPathString("string(./target/@dev)", ctxt);
+        target = virXPathString("string(./target/@dev"
+                                "|./alias/@name)", ctxt);
         model = virXPathString("string(./model/@type)", ctxt);
         mac = virXPathString("string(./mac/@address)", ctxt);
 
-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] virsh: Accept iface alias for domifstats too
Posted by Ján Tomko 7 years, 11 months ago
On Wed, Jun 07, 2017 at 05:41:29PM +0200, Michal Privoznik wrote:
>https://bugzilla.redhat.com/show_bug.cgi?id=1459091
>
>Not every interface has a name (for instance, vhostuser
>interfaces might not have one). However, all interfaces have
>aliases. We can accept those to uniquely identify interfaces.
>

The documentation of virDomainInterfaceStats says:
The path parameter is the name of the network interface.

Overloading it to include alias introduces ambiguity.
APIs should be unambiguous if possible. Maybe it's time for a new one?

Jan

>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/qemu/qemu_driver.c       | 6 ++++--
> tools/virsh-domain-monitor.c | 3 ++-
> 2 files changed, 6 insertions(+), 3 deletions(-)
>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list