[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/4] make virNetInterfaceStats silent



virNetInterfaceStats is now used in the bulk stats path, and
in this path errors must be silenced unless critical
(e.g. memory allocation failure).

To address this need, this patch adds an argument to disable error reporting.
---
 src/lxc/lxc_driver.c       |  2 +-
 src/openvz/openvz_driver.c |  2 +-
 src/qemu/qemu_driver.c     |  6 ++----
 src/util/virstats.c        | 21 +++++++++++++--------
 src/util/virstats.h        |  3 ++-
 src/xen/xen_hypervisor.c   |  2 +-
 6 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index c3cd62c..2eaeb22 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3112,7 +3112,7 @@ lxcDomainInterfaceStats(virDomainPtr dom,
     }
 
     if (ret == 0)
-        ret = virNetInterfaceStats(path, stats);
+        ret = virNetInterfaceStats(path, stats, true);
     else
         virReportError(VIR_ERR_INVALID_ARG,
                        _("Invalid path, '%s' is not a known interface"), path);
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b62273a..2b39f36 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -2010,7 +2010,7 @@ openvzDomainInterfaceStats(virDomainPtr dom,
     }
 
     if (ret == 0)
-        ret = virNetInterfaceStats(path, stats);
+        ret = virNetInterfaceStats(path, stats, true);
     else
         virReportError(VIR_ERR_INVALID_ARG,
                        _("invalid path, '%s' is not a known interface"), path);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dc8d6c3..3ff226f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9884,7 +9884,7 @@ qemuDomainInterfaceStats(virDomainPtr dom,
     }
 
     if (ret == 0)
-        ret = virNetInterfaceStats(path, stats);
+        ret = virNetInterfaceStats(path, stats, true);
     else
         virReportError(VIR_ERR_INVALID_ARG,
                        _("invalid path, '%s' is not a known interface"), path);
@@ -17634,10 +17634,8 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
         QEMU_ADD_NAME_PARAM(record, maxparams,
                             "net", i, dom->def->nets[i]->ifname);
 
-        if (virNetInterfaceStats(dom->def->nets[i]->ifname, &tmp) < 0) {
-            virResetLastError();
+        if (virNetInterfaceStats(dom->def->nets[i]->ifname, &tmp, false) < 0)
             continue;
-        }
 
         QEMU_ADD_NET_PARAM(record, maxparams, i,
                            "rx.bytes", tmp.rx_bytes);
diff --git a/src/util/virstats.c b/src/util/virstats.c
index c4725ed..496393b 100644
--- a/src/util/virstats.c
+++ b/src/util/virstats.c
@@ -51,7 +51,8 @@
 #ifdef __linux__
 int
 virNetInterfaceStats(const char *path,
-                     virDomainInterfaceStatsPtr stats)
+                     virDomainInterfaceStatsPtr stats,
+                     bool report)
 {
     int path_len;
     FILE *fp;
@@ -115,14 +116,16 @@ virNetInterfaceStats(const char *path,
     }
     VIR_FORCE_FCLOSE(fp);
 
-    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                   _("/proc/net/dev: Interface not found"));
+    if (report)
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("/proc/net/dev: Interface not found"));
     return -1;
 }
 #elif defined(HAVE_GETIFADDRS) && defined(AF_LINK)
 int
 virNetInterfaceStats(const char *path,
-                     virDomainInterfaceStatsPtr stats)
+                     virDomainInterfaceStatsPtr stats,
+                     bool report)
 {
     struct ifaddrs *ifap, *ifa;
     struct if_data *ifd;
@@ -158,7 +161,7 @@ virNetInterfaceStats(const char *path,
         }
     }
 
-    if (ret < 0)
+    if (ret < 0 && report)
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Interface not found"));
 
@@ -168,10 +171,12 @@ virNetInterfaceStats(const char *path,
 #else
 int
 virNetInterfaceStats(const char *path ATTRIBUTE_UNUSED,
-                     virDomainInterfaceStatsPtr stats ATTRIBUTE_UNUSED)
+                     virDomainInterfaceStatsPtr stats ATTRIBUTE_UNUSED,
+                     bool report)
 {
-    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                   _("interface stats not implemented on this platform"));
+    if (report)
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("interface stats not implemented on this platform"));
     return -1;
 }
 
diff --git a/src/util/virstats.h b/src/util/virstats.h
index d2c6b64..df993cd 100644
--- a/src/util/virstats.h
+++ b/src/util/virstats.h
@@ -26,6 +26,7 @@
 # include "internal.h"
 
 extern int virNetInterfaceStats(const char *path,
-                                virDomainInterfaceStatsPtr stats);
+                                virDomainInterfaceStatsPtr stats,
+                                bool report);
 
 #endif /* __STATS_LINUX_H__ */
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index d3d4aea..8b257f7 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -1470,7 +1470,7 @@ xenHypervisorDomainInterfaceStats(virDomainDefPtr def,
         return -1;
     }
 
-    return virNetInterfaceStats(path, stats);
+    return virNetInterfaceStats(path, stats, true);
 #else
     virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                    _("/proc/net/dev: Interface not found"));
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]