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 <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2015-03-04 15:08:09 +01:00
parent c2020b08ce
commit a73395ae66
3 changed files with 29 additions and 0 deletions

View File

@ -2270,6 +2270,8 @@ virIsCapableVport;
virIsDevMapperDevice;
virIsSUID;
virManageVport;
virMemoryLimitIsSet;
virMemoryLimitTruncate;
virParseNumber;
virParseOwnershipIds;
virParseVersionString;

View File

@ -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;
}

View File

@ -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__ */