On Fri, Nov 06, 2009 at 08:33:37AM +0900, Ryota Ozaki wrote:
Most part of code is just copied from qemu_driver.c.
* src/lxc/lxc_driver.c: add lxcDomainInterfaceStats
---
src/lxc/lxc_driver.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 61 insertions(+), 1 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index a917a46..542b382 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -48,6 +48,7 @@
#include "event.h"
#include "nodeinfo.h"
#include "uuid.h"
+#include "stats_linux.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -1939,6 +1940,65 @@ cleanup:
return ret;
}
+#ifdef __linux__
+static int
+lxcDomainInterfaceStats(virDomainPtr dom,
+ const char *path,
+ struct _virDomainInterfaceStats *stats)
+{
+ lxc_driver_t *driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ int i;
+ int ret = -1;
+
+ lxcDriverLock(driver);
+ vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+ lxcDriverUnlock(driver);
+
+ if (!vm) {
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virUUIDFormat(dom->uuid, uuidstr);
+ lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN,
+ _("No domain with matching uuid '%s'"), uuidstr);
+ goto cleanup;
+ }
+
+ if (!virDomainObjIsActive(vm)) {
+ lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID,
+ "%s", _("Domain is not running"));
+ goto cleanup;
+ }
+
+ /* Check the path is one of the domain's network interfaces. */
+ for (i = 0 ; i < vm->def->nnets ; i++) {
+ if (vm->def->nets[i]->ifname &&
+ STREQ(vm->def->nets[i]->ifname, path)) {
+ ret = 0;
+ break;
+ }
+ }
+
+ if (ret == 0)
+ ret = linuxDomainInterfaceStats(dom->conn, path, stats);
+ else
+ lxcError(dom->conn, dom, VIR_ERR_INVALID_ARG,
+ _("Invalid path, '%s' is not a known interface"),
path);
+
+cleanup:
+ if (vm)
+ virDomainObjUnlock(vm);
+ return ret;
+}
+#else
+static int
+lxcDomainInterfaceStats(virDomainPtr dom,
+ const char *path ATTRIBUTE_UNUSED,
+ struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED)
+ lxcError(dom->conn, dom, VIR_ERR_NO_SUPPORT, "%s", __FUNCTION__);
+ return -1;
+}
+#endif
+
static int lxcDomainGetAutostart(virDomainPtr dom,
int *autostart) {
lxc_driver_t *driver = dom->conn->privateData;
@@ -2308,7 +2368,7 @@ static virDriver lxcDriver = {
NULL, /* domainMigratePerform */
NULL, /* domainMigrateFinish */
NULL, /* domainBlockStats */
- NULL, /* domainInterfaceStats */
+ lxcDomainInterfaceStats, /* domainInterfaceStats */
NULL, /* domainBlockPeek */
NULL, /* domainMemoryPeek */
nodeGetCellsFreeMemory, /* nodeGetCellsFreeMemory */
ACK, looks good
daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|