Implement blkio.weight tuning API.
Acked-by: Daniel P. Berrange <berrange(a)redhat.com>
Signed-off-by: Gui Jianfeng <guijianfeng(a)cn.fujitsu.com>
---
src/libvirt_private.syms | 2 ++
src/util/cgroup.c | 39 +++++++++++++++++++++++++++++++++++++++
src/util/cgroup.h | 3 +++
3 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 88e270c..490901e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -77,6 +77,8 @@ virCgroupMounted;
virCgroupRemove;
virCgroupSetCpuShares;
virCgroupSetFreezerState;
+virCgroupSetBlkioWeight;
+virCgroupGetBlkioWeight;
virCgroupSetMemory;
virCgroupSetMemoryHardLimit;
virCgroupSetMemorySoftLimit;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 309f4e9..bb3f334 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -851,6 +851,45 @@ int virCgroupForDomain(virCgroupPtr driver ATTRIBUTE_UNUSED,
#endif
/**
+ * virCgroupSetBlkioWeight:
+ *
+ * @group: The cgroup to change io weight for
+ * @weight: The Weight for this cgroup
+ *
+ * Returns: 0 on success
+ */
+int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned long weight)
+{
+ if (weight > 1000 || weight < 100)
+ return -EINVAL;
+
+ return virCgroupSetValueU64(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "blkio.weight",
+ weight);
+}
+
+/**
+ * virCgroupGetBlkioWeight:
+ *
+ * @group: The cgroup to get weight for
+ * @Weight: Pointer to returned weight
+ *
+ * Returns: 0 on success
+ */
+int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned long *weight)
+{
+ long long unsigned int __weight;
+ int ret;
+ ret = virCgroupGetValueU64(group,
+ VIR_CGROUP_CONTROLLER_BLKIO,
+ "blkio.weight", &__weight);
+ if (ret == 0)
+ *weight = (unsigned long) __weight;
+ return ret;
+}
+
+/**
* virCgroupSetMemory:
*
* @group: The cgroup to change memory for
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 67b1299..f1a47dc 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -41,6 +41,9 @@ int virCgroupForDomain(virCgroupPtr driver,
int virCgroupAddTask(virCgroupPtr group, pid_t pid);
+int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned long weight);
+int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned long *weight);
+
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
--
1.7.1