[libvirt] [PATCH 3/3] cmdDomIfAddr: Move domain lookup down a few lines

Michal Privoznik posted 3 patches 4 years, 10 months ago
[libvirt] [PATCH 3/3] cmdDomIfAddr: Move domain lookup down a few lines
Posted by Michal Privoznik 4 years, 10 months ago
The 'domifaddr' command accepts several arguments. Let's validate
them first and look up domain to work with only after to save
some RPC cycles should validation fail.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tools/virsh-domain-monitor.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 97301f71f9..e357635757 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -2377,20 +2377,20 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
     const char *sourcestr = NULL;
     int source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE;
 
-    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
-        return false;
-
     if (vshCommandOptStringReq(ctl, cmd, "interface", &ifacestr) < 0)
-        goto cleanup;
+        return false;
     if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0)
-        goto cleanup;
+        return false;
 
     if (sourcestr &&
         (source = virshDomainInterfaceAddressesSourceTypeFromString(sourcestr)) < 0) {
         vshError(ctl, _("Unknown data source '%s'"), sourcestr);
-        goto cleanup;
+        return false;
     }
 
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
     if ((ifaces_count = virDomainInterfaceAddresses(dom, &ifaces, source, 0)) < 0) {
         vshError(ctl, _("Failed to query for interfaces addresses"));
         goto cleanup;
-- 
2.24.1

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

Re: [libvirt] [PATCH 3/3] cmdDomIfAddr: Move domain lookup down a few lines
Posted by Daniel P. Berrangé 4 years, 10 months ago
On Tue, Jan 07, 2020 at 09:41:54AM +0100, Michal Privoznik wrote:
> The 'domifaddr' command accepts several arguments. Let's validate
> them first and look up domain to work with only after to save
> some RPC cycles should validation fail.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tools/virsh-domain-monitor.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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