[libvirt] [PATCH 3/4] virsh: Deal with multiple matching devices in domif-getlink

Michal Privoznik posted 4 patches 8 years, 4 months ago
[libvirt] [PATCH 3/4] virsh: Deal with multiple matching devices in domif-getlink
Posted by Michal Privoznik 8 years, 4 months ago
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 <mprivozn@redhat.com>
---
 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;
     }
 
-    if (ninterfaces != 1) {
+    if (ninterfaces < 1) {
         if (macstr[0])
             vshError(ctl, _("Interface (mac: %s) not found."), macstr);
         else
             vshError(ctl, _("Interface (dev: %s) not found."), iface);
 
         goto cleanup;
+    } else if (ninterfaces > 1) {
+        vshError(ctl, _("multiple matching interfaces found"));
+        goto cleanup;
     }
 
     ctxt->node = interfaces[0];
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/4] virsh: Deal with multiple matching devices in domif-getlink
Posted by John Ferlan 8 years, 3 months ago

On 10/05/2017 10:18 AM, Michal Privoznik wrote:
> 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 <mprivozn@redhat.com>
> ---
>  tools/virsh-domain-monitor.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list