
On 01/10/2011 10:18 PM, Nikunj A. Dadhania wrote:
Display unlimited when the memory cgroup settings says so. Unlimited is represented by INT64_MAX in memory cgroup.
Signed-off-by: Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com> Reported-by: Justin Clift <jclift@redhat.com> --- include/libvirt/libvirt.h.in | 1 + src/lxc/lxc_driver.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/util/cgroup.c | 27 +++++++++++++++++++++------ src/util/cgroup.h | 6 +++--- tools/virsh.c | 9 +++++++-- 6 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 3c6a54a..cb53f6b 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -696,6 +696,7 @@ typedef enum { */
#define VIR_DOMAIN_MEMORY_FIELD_LENGTH 80 +#define VIR_DOMAIN_MEMORY_PARAM_UNLIMITED (UINT64_MAX)
() aren't strictly necessary here, but don't hurt, either.
@@ -907,7 +907,7 @@ int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb) * * Returns: 0 on success */ -int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb) +int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
So why is Get changed to ull, but Set remains with just unsigned long? This patch is still incomplete. I think you need to touch both functions, and also virCgroupSetMemory. Also, in virCgroupSetMemory, you need to check for overflow, and fail if someone requests an impossible amount of kb.
{ long long unsigned int limit_in_bytes; int ret; @@ -915,7 +915,12 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb) VIR_CGROUP_CONTROLLER_MEMORY, "memory.limit_in_bytes", &limit_in_bytes); if (ret == 0) - *kb = (unsigned long) limit_in_bytes >> 10; + { + if (limit_in_bytes != INT64_MAX) + *kb = (unsigned long long) limit_in_bytes >> 10;
This cast is not necessary, since limit_in_bytes is already ull. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org