virCgroupGetMemSwapUsage is used to get container's swap usage,
with this interface,we can get swap usage in fuse filesystem.
Signed-off-by: Gao feng <gaofeng(a)cn.fujitsu.com>
---
src/libvirt_private.syms | 1 +
src/util/cgroup.c | 20 ++++++++++++++++++++
src/util/cgroup.h | 1 +
3 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6625fc6..5a1f20e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -79,6 +79,7 @@ virCgroupGetCpuacctStat;
virCgroupGetCpuacctUsage;
virCgroupGetCpusetMems;
virCgroupGetFreezerState;
+virCgroupGetMemSwapUsage;
virCgroupGetMemSwapHardLimit;
virCgroupGetMemoryHardLimit;
virCgroupGetMemorySoftLimit;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 5b32881..d6fcd61 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -1188,6 +1188,26 @@ int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long
long kb)
}
/**
+ * virCgroupGetMemSwapUsage:
+ *
+ * @group: The cgroup to get mem+swap usage for
+ * @kb: The mem+swap amount in kilobytes
+ *
+ * Returns: 0 on success
+ */
+int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb)
+{
+ long long unsigned int usage_in_bytes;
+ int ret;
+ ret = virCgroupGetValueU64(group,
+ VIR_CGROUP_CONTROLLER_MEMORY,
+ "memory.memsw.usage_in_bytes",
&usage_in_bytes);
+ if (ret == 0)
+ *kb = usage_in_bytes >> 10;
+ return ret;
+}
+
+/**
* virCgroupGetMemSwapHardLimit:
*
* @group: The cgroup to get mem+swap hard limit for
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 05325ae..caca362 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -70,6 +70,7 @@ int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long
kb);
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb);
int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
+int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
enum {
VIR_CGROUP_DEVICE_READ = 1,
--
1.7.7.6