From a73395ae66c163ba2fefb39c558ea36972ef6406 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Wed, 4 Mar 2015 15:08:09 +0100 Subject: [PATCH] virutil: introduce helper functions for memory limits The first one is to truncate the memory limit to VIR_DOMAIN_MEMORY_PARAM_UNLIMITED if the value is greater and the second one is to decide whether the memory limit is set or not, unlimited means that it's not set. Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 2 ++ src/util/virutil.c | 24 ++++++++++++++++++++++++ src/util/virutil.h | 3 +++ 3 files changed, 29 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3c6fd33a02..3590bd7371 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2270,6 +2270,8 @@ virIsCapableVport; virIsDevMapperDevice; virIsSUID; virManageVport; +virMemoryLimitIsSet; +virMemoryLimitTruncate; virParseNumber; virParseOwnershipIds; virParseVersionString; diff --git a/src/util/virutil.c b/src/util/virutil.c index 4a95292f5e..599d59c4d3 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2598,3 +2598,27 @@ long virGetSystemPageSizeKB(void) return val; return val / 1024; } + +/** + * virMemoryLimitTruncate + * + * Return truncated memory limit to VIR_DOMAIN_MEMORY_PARAM_UNLIMITED as maximum + * which means that the limit is not set => unlimited. + */ +unsigned long long +virMemoryLimitTruncate(unsigned long long value) +{ + return value < VIR_DOMAIN_MEMORY_PARAM_UNLIMITED ? value : + VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; +} + +/** + * virMemoryLimitIsSet + * + * Returns true if the limit is set and false for unlimited value. + */ +bool +virMemoryLimitIsSet(unsigned long long value) +{ + return value < VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index d1173c1a11..b8f503681e 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -247,4 +247,7 @@ unsigned int virGetListenFDs(void); long virGetSystemPageSize(void); long virGetSystemPageSizeKB(void); +unsigned long long virMemoryLimitTruncate(unsigned long long value); +bool virMemoryLimitIsSet(unsigned long long value); + #endif /* __VIR_UTIL_H__ */