From c3658ab54348e863e31e0f1c0e98e69ee9c73da3 Mon Sep 17 00:00:00 2001 From: Gui Jianfeng Date: Tue, 8 Feb 2011 14:56:39 +0800 Subject: [PATCH] cgroup: Implement blkio.weight tuning API. Implement blkio.weight tuning API. Acked-by: Daniel P. Berrange Signed-off-by: Gui Jianfeng --- src/libvirt_private.syms | 2 ++ src/util/cgroup.c | 41 +++++++++++++++++++++++++++++++++++++++- src/util/cgroup.h | 4 ++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 88e270c276..1bbd44e8dd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -66,6 +66,7 @@ virCgroupDenyDevicePath; virCgroupForDomain; virCgroupForDriver; virCgroupFree; +virCgroupGetBlkioWeight; virCgroupGetCpuShares; virCgroupGetCpuacctUsage; virCgroupGetFreezerState; @@ -75,6 +76,7 @@ virCgroupGetMemoryUsage; virCgroupGetSwapHardLimit; virCgroupMounted; virCgroupRemove; +virCgroupSetBlkioWeight; virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; diff --git a/src/util/cgroup.c b/src/util/cgroup.c index 309f4e9b58..de1fd8e24b 100644 --- a/src/util/cgroup.c +++ b/src/util/cgroup.c @@ -1,7 +1,7 @@ /* * cgroup.c: Tools for managing cgroups * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright IBM Corp. 2008 * * See COPYING.LIB for the License of this software @@ -850,6 +850,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 int 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 int *weight) +{ + unsigned long long tmp; + int ret; + ret = virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", &tmp); + if (ret == 0) + *weight = tmp; + return ret; +} + /** * virCgroupSetMemory: * diff --git a/src/util/cgroup.h b/src/util/cgroup.h index 67b1299023..f1bdd0f3da 100644 --- a/src/util/cgroup.h +++ b/src/util/cgroup.h @@ -1,6 +1,7 @@ /* * cgroup.h: Interface to tools for managing cgroups * + * Copyright (C) 2011 Red Hat, Inc. * Copyright IBM Corp. 2008 * * See COPYING.LIB for the License of this software @@ -41,6 +42,9 @@ int virCgroupForDomain(virCgroupPtr driver, int virCgroupAddTask(virCgroupPtr group, pid_t pid); +int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight); +int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight); + int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb); -- GitLab