]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainNetFind: Report error if no device found
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 13 Oct 2017 20:40:47 +0000 (13:40 -0700)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 13 Oct 2017 20:46:36 +0000 (13:46 -0700)
Every caller reports the error themselves. Might as well move it
into the function and thus unify it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/conf/domain_conf.c
src/libxl/libxl_driver.c
src/lxc/lxc_driver.c
src/openvz/openvz_driver.c
src/qemu/qemu_driver.c
src/test/test_driver.c
src/xen/xen_driver.c

index 54be9028d72b03f740fb93991df00e79093b47d0..caffa896d25150194e815e2329933fa731d561be 100644 (file)
@@ -26983,13 +26983,12 @@ virDomainGraphicsListenAppendSocket(virDomainGraphicsDefPtr 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 reported).
  */
 virDomainNetDefPtr
 virDomainNetFind(virDomainDefPtr def, const char *device)
 {
     bool isMac = false;
-    virDomainNetDefPtr net = NULL;
     virMacAddr mac;
     size_t i;
 
@@ -26998,16 +26997,19 @@ virDomainNetFind(virDomainDefPtr def, const char *device)
 
     if (isMac) {
         for (i = 0; i < def->nnets; i++) {
-            if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0) {
-                net = def->nets[i];
-                break;
-            }
+            if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0)
+                return def->nets[i];
         }
     } else { /* ifname */
-        net = virDomainNetFindByName(def, device);
+        virDomainNetDefPtr net = NULL;
+
+        if ((net = virDomainNetFindByName(def, device)))
+            return net;
     }
 
-    return net;
+    virReportError(VIR_ERR_INVALID_ARG,
+                   _("'%s' is not a known interface"), device);
+    return NULL;
 }
 
 
index 8483d6ecf78eba08647ac1a85de2ae7b0b0de47f..1c4abb6d36e8719c2f1fb36d34de6f54676c0092 100644 (file)
@@ -4979,11 +4979,8 @@ libxlDomainInterfaceStats(virDomainPtr dom,
         goto endjob;
     }
 
-    if (!(net = virDomainNetFindByName(vm->def, path))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("'%s' is not a known interface"), path);
+    if (!(net = virDomainNetFindByName(vm->def, path)))
         goto endjob;
-    }
 
     if (virNetDevTapInterfaceStats(path, stats,
                                    !virDomainNetTypeSharesHostView(net)) < 0)
index 6ad61bdb767027d62abc829ebfbc54064a37a921..95a2d8a78a0f1b3c75629f6cdecc0c69d8f99e60 100644 (file)
@@ -2872,11 +2872,8 @@ lxcDomainInterfaceStats(virDomainPtr dom,
         goto endjob;
     }
 
-    if (!(net = virDomainNetFindByName(vm->def, path))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("Invalid path, '%s' is not a known interface"), path);
+    if (!(net = virDomainNetFindByName(vm->def, path)))
         goto endjob;
-    }
 
     if (virNetDevTapInterfaceStats(path, stats,
                                    !virDomainNetTypeSharesHostView(net)) < 0)
index 11173898dca134d18088292625711fe43679b4da..8d1af7d7c75361e852512190c7d1a1917e09b53d 100644 (file)
@@ -2006,11 +2006,8 @@ openvzDomainInterfaceStats(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (!(net = virDomainNetFindByName(vm->def, path))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("invalid path, '%s' is not a known interface"), path);
+    if (!(net = virDomainNetFindByName(vm->def, path)))
         goto cleanup;
-    }
 
     if (virNetDevTapInterfaceStats(path, stats,
                                    !virDomainNetTypeSharesHostView(net)) < 0)
index 7c6f1674a9d372aad9a5d175cb66dbe351f37b2e..00de5150c87ca7c1b2d0ecfde625044925b748c5 100644 (file)
@@ -11040,11 +11040,8 @@ qemuDomainInterfaceStats(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (!(net = virDomainNetFindByName(vm->def, path))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("invalid path, '%s' is not a known interface"), path);
+    if (!(net = virDomainNetFindByName(vm->def, path)))
         goto cleanup;
-    }
 
     if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
         if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0)
@@ -11114,18 +11111,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
         goto endjob;
 
     if (def &&
-        !(net = virDomainNetFind(vm->def, device))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("Can't find device %s"), device);
+        !(net = virDomainNetFind(vm->def, device)))
         goto endjob;
-    }
 
     if (persistentDef &&
-        !(persistentNet = virDomainNetFind(persistentDef, device))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("Can't find device %s"), device);
+        !(persistentNet = virDomainNetFind(persistentDef, device)))
         goto endjob;
-    }
 
     if ((VIR_ALLOC(bandwidth) < 0) ||
         (VIR_ALLOC(bandwidth->in) < 0) ||
@@ -11291,12 +11282,8 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom,
         goto cleanup;
     }
 
-    net = virDomainNetFind(def, device);
-    if (!net) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("Can't find device %s"), device);
+    if (!(net = virDomainNetFind(def, device)))
         goto cleanup;
-    }
 
     for (i = 0; i < *nparams && i < QEMU_NB_BANDWIDTH_PARAM; i++) {
         switch (i) {
index 1c483479949093c7d72b1a940335141b425f46cd..d572edf21b6023d9f0c5b06280285d9df3d69240 100644 (file)
@@ -3180,11 +3180,8 @@ static int testDomainInterfaceStats(virDomainPtr domain,
         goto error;
     }
 
-    if (!(net = virDomainNetFindByName(privdom->def, path))) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("invalid path, '%s' is not a known interface"), path);
+    if (!(net = virDomainNetFindByName(privdom->def, path)))
         goto error;
-    }
 
     if (gettimeofday(&tv, NULL) < 0) {
         virReportSystemError(errno,
index dae0f4f28959855abcce254899d521c3d3fb8e65..8a624818686cdd34a5b5c13f195c549af89f00a2 100644 (file)
@@ -2113,6 +2113,7 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
                                virDomainInterfaceStatsPtr stats)
 {
     virDomainDefPtr def = NULL;
+    virDomainNetDefPtr net = NULL;
     int ret = -1;
 
     if (!(def = xenGetDomainDefForDom(dom)))
@@ -2121,7 +2122,10 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
     if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
         goto cleanup;
 
-    ret = xenHypervisorDomainInterfaceStats(def, path, stats);
+    if (!(net = virDomainNetFind(def, path)))
+        goto cleanup;
+
+    ret = xenHypervisorDomainInterfaceStats(def, net->ifname, stats);
 
  cleanup:
     virDomainDefFree(def);