[PATCH 1/2] KVM network stats

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

 



Firstly there's a bug in how we parse /proc/net/dev. The format of each interface line turns out to be:

  %6s:...

so in other words network interface names smaller than 6 characters are right justified (padded on the left with spaces).

This isn't a problem for Xen because the shortest interface name (eg. 'vif1.0') is always 6 or more characters long. However it is a problem for QEMU and KVM because we have interface names such as 'vnet0'.

In any case, the following patch fixes this bug.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: src/stats_linux.c
===================================================================
RCS file: /data/cvs/libvirt/src/stats_linux.c,v
retrieving revision 1.2
diff -u -r1.2 stats_linux.c
--- src/stats_linux.c	15 Nov 2007 10:56:24 -0000	1.2
+++ src/stats_linux.c	15 Nov 2007 15:43:40 -0000
@@ -291,7 +291,7 @@
 {
     int path_len;
     FILE *fp;
-    char line[256];
+    char line[256], *colon;
 
     fp = fopen ("/proc/net/dev", "r");
     if (!fp) {
@@ -313,16 +313,22 @@
         long long tx_errs;
         long long tx_drop;
 
-        if (STREQLEN (line, path, path_len) &&
-            line[path_len] == ':' &&
-            line[path_len+1] == ' ') {
+        /* 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 (&line[path_len+2],
+            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,

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]