mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: Make virResctrlGetCacheControlType() behave like other functions
That means that returning negative values means error and non-negative values differ in meaning, but are all successful. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
af4270400a
commit
7c4b4f8905
@ -1647,15 +1647,17 @@ virCapabilitiesInitCaches(virCapsPtr caps)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
typeret = virResctrlGetCacheControlType(bank->level);
|
typeret = virResctrlGetCacheControlType(bank->level);
|
||||||
|
if (typeret < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (typeret == 0) {
|
if (typeret == 1) {
|
||||||
if (virResctrlGetCacheInfo(bank->level,
|
if (virResctrlGetCacheInfo(bank->level,
|
||||||
bank->size,
|
bank->size,
|
||||||
VIR_CACHE_TYPE_BOTH,
|
VIR_CACHE_TYPE_BOTH,
|
||||||
&bank->controls,
|
&bank->controls,
|
||||||
&bank->ncontrols) < 0)
|
&bank->ncontrols) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else if (typeret == 1) {
|
} else if (typeret == 2) {
|
||||||
if (virResctrlGetCacheInfo(bank->level,
|
if (virResctrlGetCacheInfo(bank->level,
|
||||||
bank->size,
|
bank->size,
|
||||||
VIR_CACHE_TYPE_CODE,
|
VIR_CACHE_TYPE_CODE,
|
||||||
|
@ -45,6 +45,16 @@ VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST,
|
|||||||
"code",
|
"code",
|
||||||
"data")
|
"data")
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the same enum, but for the resctrl naming
|
||||||
|
* of the type (L<level><type>)
|
||||||
|
*/
|
||||||
|
VIR_ENUM_DECL(virResctrl)
|
||||||
|
VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST,
|
||||||
|
"",
|
||||||
|
"CODE",
|
||||||
|
"DATA")
|
||||||
|
|
||||||
int
|
int
|
||||||
virResctrlGetCacheInfo(unsigned int level,
|
virResctrlGetCacheInfo(unsigned int level,
|
||||||
unsigned long long size,
|
unsigned long long size,
|
||||||
@ -114,40 +124,64 @@ virResctrlGetCacheInfo(unsigned int level,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
virResctrlGetCacheDir(char **path,
|
||||||
|
const char *prefix,
|
||||||
|
unsigned int level,
|
||||||
|
virCacheType type)
|
||||||
|
{
|
||||||
|
return virAsprintf(path,
|
||||||
|
SYSFS_RESCTRL_PATH "%s/L%u%s",
|
||||||
|
prefix ? prefix : "",
|
||||||
|
level,
|
||||||
|
virResctrlTypeToString(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function tests which TYPE of cache control is supported
|
* This function tests whether TYPE of cache control is supported or not.
|
||||||
* Return values are:
|
*
|
||||||
* -1: not supported
|
* Returns 0 if not, 1 if yes and negative value on error.
|
||||||
* 0: CAT
|
|
||||||
* 1: CDP
|
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
virResctrlGetCacheControlType(unsigned int level)
|
virResctrlGetCacheSupport(unsigned int level, virCacheType type)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
|
|
||||||
if (virAsprintf(&path,
|
if (virResctrlGetCacheDir(&path, "/info", level, type) < 0)
|
||||||
SYSFS_RESCTRL_PATH "/info/L%u",
|
|
||||||
level) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virFileExists(path)) {
|
ret = virFileExists(path);
|
||||||
ret = 0;
|
|
||||||
} else {
|
|
||||||
VIR_FREE(path);
|
|
||||||
/*
|
|
||||||
* If CDP is enabled, there will be both CODE and DATA, but it's enough
|
|
||||||
* to check one of those only.
|
|
||||||
*/
|
|
||||||
if (virAsprintf(&path,
|
|
||||||
SYSFS_RESCTRL_PATH "/info/L%uCODE",
|
|
||||||
level) < 0)
|
|
||||||
return -1;
|
|
||||||
if (virFileExists(path))
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function tests which TYPE of cache control is supported
|
||||||
|
* Return values are:
|
||||||
|
* -1: error
|
||||||
|
* 0: none
|
||||||
|
* 1: CAT
|
||||||
|
* 2: CDP
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virResctrlGetCacheControlType(unsigned int level)
|
||||||
|
{
|
||||||
|
int rv = -1;
|
||||||
|
|
||||||
|
rv = virResctrlGetCacheSupport(level, VIR_CACHE_TYPE_BOTH);
|
||||||
|
if (rv < 0)
|
||||||
|
return -1;
|
||||||
|
if (rv)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
rv = virResctrlGetCacheSupport(level, VIR_CACHE_TYPE_CODE);
|
||||||
|
if (rv < 0)
|
||||||
|
return -1;
|
||||||
|
if (rv)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user