[PATCH 2/2] KVM network stats

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

 



This patch adds the implementation of virDomainInterfaceStats for QEMU & KVM domains. The function simply verifies that the requested path (interface name) belongs to the domain, then calls the existing code in stats_linux.c.

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/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.34
diff -u -r1.34 qemu_driver.c
--- src/qemu_driver.c	14 Nov 2007 11:40:57 -0000	1.34
+++ src/qemu_driver.c	15 Nov 2007 15:43:52 -0000
@@ -55,6 +55,7 @@
 #include "qemu_driver.h"
 #include "qemu_conf.h"
 #include "nodeinfo.h"
+#include "stats_linux.h"
 
 static int qemudShutdown(void);
 
@@ -2479,6 +2480,65 @@
     return 0;
 }
 
+static int
+qemudDomainInterfaceStats (virDomainPtr dom,
+                           const char *path,
+                           struct _virDomainInterfaceStats *stats)
+{
+#ifdef __linux__
+    struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
+    struct qemud_vm *vm = qemudFindVMByID (driver, dom->id);
+    struct qemud_vm_net_def *net;
+
+    if (!vm) {
+        qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+                          "no domain with matching id %d", dom->id);
+        return -1;
+    }
+
+    if (!qemudIsActiveVM(vm)) {
+        qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                         "domain is not running");
+        return -1;
+    }
+
+    if (!path || path[0] == '\0') {
+        qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
+                         "NULL or empty path");
+        return -1;
+    }
+
+    /* Check the path is one of the domain's network interfaces. */
+    for (net = vm->def->nets; net; net = net->next) {
+        switch (net->type) {
+        case QEMUD_NET_NETWORK:
+            if (STREQ (net->dst.network.ifname, path))
+                goto ok;
+            break;
+        case QEMUD_NET_ETHERNET:
+            if (STREQ (net->dst.ethernet.ifname, path))
+                goto ok;
+            break;
+        case QEMUD_NET_BRIDGE:
+            if (STREQ (net->dst.bridge.ifname, path))
+                goto ok;
+            break;
+        }
+    }
+
+    qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
+                      "invalid path, '%s' is not a known interface", path);
+    return -1;
+ ok:
+
+    return linuxDomainInterfaceStats (dom->conn, path, stats);
+#else
+    qemudReportError (dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
+                      "%s", __FUNCTION__);
+    return -1;
+#endif
+}
+
 static virNetworkPtr qemudNetworkLookupByUUID(virConnectPtr conn ATTRIBUTE_UNUSED,
                                      const unsigned char *uuid) {
     struct qemud_driver *driver = (struct qemud_driver *)conn->networkPrivateData;
@@ -2822,7 +2882,7 @@
     NULL, /* domainMigratePerform */
     NULL, /* domainMigrateFinish */
     NULL, /* domainBlockStats */
-    NULL, /* domainInterfaceStats */
+    qemudDomainInterfaceStats, /* domainInterfaceStats */
     NULL, /* nodeGetCellsFreeMemory */
     NULL, /* getFreeMemory */
 };

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]