Re: [PATCHv3 02/10] Implement domainMemoryStats API slot for LXC driver.

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

 



On 03.02.2014 18:44, Thorsten Behrens wrote:
---
  src/lxc/lxc_driver.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 50 insertions(+)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 138c706..02b5cc3 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -5169,6 +5169,55 @@ lxcNodeGetInfo(virConnectPtr conn,


  static int
+lxcDomainMemoryStats(virDomainPtr dom,
+                     struct _virDomainMemoryStat *stats,
+                     unsigned int nr_stats,
+                     unsigned int flags)
+{
+    virDomainObjPtr vm;
+    int ret = -1;
+    virLXCDomainObjPrivatePtr priv;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = lxcDomObjFromDomain(dom)))
+        goto cleanup;
+
+    priv = vm->privateData;
+
+    if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    ret = 0;
+    if (!virDomainObjIsActive(vm))
+        goto cleanup;
+
+    if (ret < nr_stats) {
+        stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON;
+        stats[ret].val = vm->def->mem.cur_balloon;
+        ret++;
+    }
+    if (ret < nr_stats) {
+        stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_SWAP_IN;
+        virCgroupGetMemSwapUsage(priv->cgroup, &stats[ret].val);
+        ret++;
+    }
+    if (ret < nr_stats) {
+        unsigned long kb;
+        stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_RSS;
+        virCgroupGetMemoryUsage(priv->cgroup, &kb);
+        stats[ret].val = kb;
+        ret++;
+    }

Both these virCgroupGetMem* may fail, in which case the return pointer is untouched hence we will return bogus value.

Just a side note - all of our virCgroupGet* handling functions take unsigned long long (if they take integer at all). Except the virCgroupGetMemoryUsage(). I wonder why. In fact quick git grep over the function reveals another places where a UL local variable is introduced just so it can be later casted to ULL .. If you decide to do something with this, it can be a follow up/separate patch to this series.

Michal

--
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]