From: "Daniel P. Berrange" <berrange(a)redhat.com>
---
po/POTFILES.in | 2 +-
src/Makefile.am | 2 +-
src/lxc/lxc_driver.c | 2 +-
src/openvz/openvz_driver.c | 2 +-
src/qemu/qemu_driver.c | 2 +-
src/uml/uml_driver.c | 2 +-
src/util/stats_linux.c | 122 ---------------------------------------------
src/util/stats_linux.h | 35 -------------
src/util/virstatslinux.c | 122 +++++++++++++++++++++++++++++++++++++++++++++
src/util/virstatslinux.h | 35 +++++++++++++
src/xen/xen_hypervisor.c | 2 +-
tests/statstest.c | 2 +-
12 files changed, 165 insertions(+), 165 deletions(-)
delete mode 100644 src/util/stats_linux.c
delete mode 100644 src/util/stats_linux.h
create mode 100644 src/util/virstatslinux.c
create mode 100644 src/util/virstatslinux.h
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2b09531..ecb4498 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -138,7 +138,6 @@ src/test/test_driver.c
src/uml/uml_conf.c
src/uml/uml_driver.c
src/util/iohelper.c
-src/util/stats_linux.c
src/util/storage_file.c
src/util/sysinfo.c
src/util/util.c
@@ -174,6 +173,7 @@ src/util/virprocess.c
src/util/virrandom.c
src/util/virsexpr.c
src/util/virsocketaddr.c
+src/util/virstatslinux.c
src/util/virterror.c
src/util/virterror_internal.h
src/util/virtime.c
diff --git a/src/Makefile.am b/src/Makefile.am
index c0dfd38..feb4b77 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,7 +53,6 @@ augeastest_DATA =
# These files are not related to driver APIs. Simply generic
# helper APIs for various purposes
UTIL_SOURCES = \
- util/stats_linux.c util/stats_linux.h \
util/storage_file.c util/storage_file.h \
util/sysinfo.c util/sysinfo.h \
util/threads.c util/threads.h \
@@ -86,6 +85,7 @@ UTIL_SOURCES = \
util/virpidfile.c util/virpidfile.h \
util/virprocess.c util/virprocess.h \
util/virsexpr.c util/virsexpr.h \
+ util/virstatslinux.c util/virstatslinux.h \
util/virtypedparam.c util/virtypedparam.h \
util/xml.c util/xml.h \
util/virterror.c util/virterror_internal.h \
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 35e8ac9..57c1767 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -49,7 +49,7 @@
#include "virnetdevveth.h"
#include "nodeinfo.h"
#include "uuid.h"
-#include "stats_linux.h"
+#include "virstatslinux.h"
#include "virhooks.h"
#include "virfile.h"
#include "virpidfile.h"
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f6327fd..a35a6b1 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -59,7 +59,7 @@
#include "virlog.h"
#include "vircommand.h"
#include "viruri.h"
-#include "stats_linux.h"
+#include "virstatslinux.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 488c814..c5bd054 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -65,7 +65,7 @@
#include "virbuffer.h"
#include "util.h"
#include "nodeinfo.h"
-#include "stats_linux.h"
+#include "virstatslinux.h"
#include "capabilities.h"
#include "viralloc.h"
#include "uuid.h"
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index cece114..b20998f 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -49,7 +49,7 @@
#include "virbuffer.h"
#include "util.h"
#include "nodeinfo.h"
-#include "stats_linux.h"
+#include "virstatslinux.h"
#include "capabilities.h"
#include "viralloc.h"
#include "uuid.h"
diff --git a/src/util/stats_linux.c b/src/util/stats_linux.c
deleted file mode 100644
index 67ef82e..0000000
--- a/src/util/stats_linux.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Linux block and network stats.
- *
- * Copyright (C) 2007-2010 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <
http://www.gnu.org/licenses/>.
- *
- * Richard W.M. Jones <rjones(a)redhat.com>
- */
-
-#include <config.h>
-
-/* This file only applies on Linux. */
-#ifdef __linux__
-
-# include <stdio.h>
-# include <stdlib.h>
-# include <fcntl.h>
-# include <string.h>
-# include <unistd.h>
-# include <regex.h>
-
-# include "virterror_internal.h"
-# include "datatypes.h"
-# include "util.h"
-# include "stats_linux.h"
-# include "viralloc.h"
-# include "virfile.h"
-
-# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
-
-
-/*-------------------- interface stats --------------------*/
-/* Just reads the named interface, so not Xen or QEMU-specific.
- * NB. Caller must check that libvirt user is trying to query
- * the interface of a domain they own. We do no such checking.
- */
-
-int
-linuxDomainInterfaceStats(const char *path,
- struct _virDomainInterfaceStats *stats)
-{
- int path_len;
- FILE *fp;
- char line[256], *colon;
-
- fp = fopen("/proc/net/dev", "r");
- if (!fp) {
- virReportSystemError(errno, "%s",
- _("Could not open /proc/net/dev"));
- return -1;
- }
-
- path_len = strlen(path);
-
- while (fgets(line, sizeof(line), fp)) {
- long long dummy;
- long long rx_bytes;
- long long rx_packets;
- long long rx_errs;
- long long rx_drop;
- long long tx_bytes;
- long long tx_packets;
- long long tx_errs;
- long long tx_drop;
-
- /* The line looks like:
- * " eth0:..."
- * Split it at the colon.
- */
- colon = strchr(line, ':');
- if (!colon) continue;
- *colon = '\0';
- if (colon-path_len >= line &&
- STREQ(colon-path_len, path)) {
- /* IMPORTANT NOTE!
- * /proc/net/dev vif<domid>.nn sees the network from the point
- * of view of dom0 / hypervisor. So bytes TRANSMITTED by dom0
- * are bytes RECEIVED by the domain. That's why the TX/RX fields
- * appear to be swapped here.
- */
- if (sscanf(colon+1,
- "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld
%lld %lld %lld %lld",
- &tx_bytes, &tx_packets, &tx_errs, &tx_drop,
- &dummy, &dummy, &dummy, &dummy,
- &rx_bytes, &rx_packets, &rx_errs, &rx_drop,
- &dummy, &dummy, &dummy, &dummy) != 16)
- continue;
-
- stats->rx_bytes = rx_bytes;
- stats->rx_packets = rx_packets;
- stats->rx_errs = rx_errs;
- stats->rx_drop = rx_drop;
- stats->tx_bytes = tx_bytes;
- stats->tx_packets = tx_packets;
- stats->tx_errs = tx_errs;
- stats->tx_drop = tx_drop;
- VIR_FORCE_FCLOSE(fp);
-
- return 0;
- }
- }
- VIR_FORCE_FCLOSE(fp);
-
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("/proc/net/dev: Interface not found"));
- return -1;
-}
-
-#endif /* __linux__ */
diff --git a/src/util/stats_linux.h b/src/util/stats_linux.h
deleted file mode 100644
index 5847177..0000000
--- a/src/util/stats_linux.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Linux block and network stats.
- *
- * Copyright (C) 2007 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <
http://www.gnu.org/licenses/>.
- *
- * Richard W.M. Jones <rjones(a)redhat.com>
- */
-
-#ifndef __STATS_LINUX_H__
-# define __STATS_LINUX_H__
-
-# ifdef __linux__
-
-# include "internal.h"
-
-extern int linuxDomainInterfaceStats(const char *path,
- struct _virDomainInterfaceStats *stats);
-
-# endif /* __linux__ */
-
-#endif /* __STATS_LINUX_H__ */
diff --git a/src/util/virstatslinux.c b/src/util/virstatslinux.c
new file mode 100644
index 0000000..9359db9
--- /dev/null
+++ b/src/util/virstatslinux.c
@@ -0,0 +1,122 @@
+/*
+ * Linux block and network stats.
+ *
+ * Copyright (C) 2007-2010 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ *
+ * Richard W.M. Jones <rjones(a)redhat.com>
+ */
+
+#include <config.h>
+
+/* This file only applies on Linux. */
+#ifdef __linux__
+
+# include <stdio.h>
+# include <stdlib.h>
+# include <fcntl.h>
+# include <string.h>
+# include <unistd.h>
+# include <regex.h>
+
+# include "virterror_internal.h"
+# include "datatypes.h"
+# include "util.h"
+# include "virstatslinux.h"
+# include "viralloc.h"
+# include "virfile.h"
+
+# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
+
+
+/*-------------------- interface stats --------------------*/
+/* Just reads the named interface, so not Xen or QEMU-specific.
+ * NB. Caller must check that libvirt user is trying to query
+ * the interface of a domain they own. We do no such checking.
+ */
+
+int
+linuxDomainInterfaceStats(const char *path,
+ struct _virDomainInterfaceStats *stats)
+{
+ int path_len;
+ FILE *fp;
+ char line[256], *colon;
+
+ fp = fopen("/proc/net/dev", "r");
+ if (!fp) {
+ virReportSystemError(errno, "%s",
+ _("Could not open /proc/net/dev"));
+ return -1;
+ }
+
+ path_len = strlen(path);
+
+ while (fgets(line, sizeof(line), fp)) {
+ long long dummy;
+ long long rx_bytes;
+ long long rx_packets;
+ long long rx_errs;
+ long long rx_drop;
+ long long tx_bytes;
+ long long tx_packets;
+ long long tx_errs;
+ long long tx_drop;
+
+ /* The line looks like:
+ * " eth0:..."
+ * Split it at the colon.
+ */
+ colon = strchr(line, ':');
+ if (!colon) continue;
+ *colon = '\0';
+ if (colon-path_len >= line &&
+ STREQ(colon-path_len, path)) {
+ /* IMPORTANT NOTE!
+ * /proc/net/dev vif<domid>.nn sees the network from the point
+ * of view of dom0 / hypervisor. So bytes TRANSMITTED by dom0
+ * are bytes RECEIVED by the domain. That's why the TX/RX fields
+ * appear to be swapped here.
+ */
+ if (sscanf(colon+1,
+ "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld
%lld %lld %lld %lld",
+ &tx_bytes, &tx_packets, &tx_errs, &tx_drop,
+ &dummy, &dummy, &dummy, &dummy,
+ &rx_bytes, &rx_packets, &rx_errs, &rx_drop,
+ &dummy, &dummy, &dummy, &dummy) != 16)
+ continue;
+
+ stats->rx_bytes = rx_bytes;
+ stats->rx_packets = rx_packets;
+ stats->rx_errs = rx_errs;
+ stats->rx_drop = rx_drop;
+ stats->tx_bytes = tx_bytes;
+ stats->tx_packets = tx_packets;
+ stats->tx_errs = tx_errs;
+ stats->tx_drop = tx_drop;
+ VIR_FORCE_FCLOSE(fp);
+
+ return 0;
+ }
+ }
+ VIR_FORCE_FCLOSE(fp);
+
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("/proc/net/dev: Interface not found"));
+ return -1;
+}
+
+#endif /* __linux__ */
diff --git a/src/util/virstatslinux.h b/src/util/virstatslinux.h
new file mode 100644
index 0000000..5847177
--- /dev/null
+++ b/src/util/virstatslinux.h
@@ -0,0 +1,35 @@
+/*
+ * Linux block and network stats.
+ *
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ *
+ * Richard W.M. Jones <rjones(a)redhat.com>
+ */
+
+#ifndef __STATS_LINUX_H__
+# define __STATS_LINUX_H__
+
+# ifdef __linux__
+
+# include "internal.h"
+
+extern int linuxDomainInterfaceStats(const char *path,
+ struct _virDomainInterfaceStats *stats);
+
+# endif /* __linux__ */
+
+#endif /* __STATS_LINUX_H__ */
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 598ec5e..b308605 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -71,7 +71,7 @@
#include "xen_driver.h"
#include "xen_hypervisor.h"
#include "xs_internal.h"
-#include "stats_linux.h"
+#include "virstatslinux.h"
#include "block_stats.h"
#include "xend_internal.h"
#include "virbuffer.h"
diff --git a/tests/statstest.c b/tests/statstest.c
index ad71bf9..30f9ab0 100644
--- a/tests/statstest.c
+++ b/tests/statstest.c
@@ -5,7 +5,7 @@
#include <string.h>
#include <sys/utsname.h>
-#include "stats_linux.h"
+#include "virstatslinux.h"
#include "internal.h"
#include "xen/block_stats.h"
#include "testutils.h"
--
1.7.11.7