mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-08-25 13:50:09 +03:00
conf: skip resource cache init if sysfs files are missing
On aarch64 the 'id' file is not present for CPU cache information in sysfs. This causes the local stateful hypervisor drivers to fail to initialize capabilities: virStateInitialize:657 : Initialisation of cloud-hypervisor state driver failed: no error The 'no error' is because the 'virFileReadValueNNN' methods return ret==-2, with no error raised, when the requeted file does not exist. None of the callers were checking for this scenario when populating capabilities. The most graceful way to handle this is to skip the cache bank in question. This fixes failure to launch libvirt drivers on certain aarch64 hardware. Fixes: https://gitlab.com/libvirt/libvirt/-/issues/389 Tested-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
@ -2191,6 +2191,7 @@ virCapabilitiesInitCaches(virCaps *caps)
|
||||
g_autofree char *type = NULL;
|
||||
int kernel_type;
|
||||
unsigned int level;
|
||||
int ret;
|
||||
|
||||
if (!STRPREFIX(ent->d_name, "index"))
|
||||
continue;
|
||||
@ -2206,29 +2207,54 @@ virCapabilitiesInitCaches(virCaps *caps)
|
||||
bank = g_new0(virCapsHostCacheBank, 1);
|
||||
bank->level = level;
|
||||
|
||||
if (virFileReadValueUint(&bank->id,
|
||||
"%s/cpu/cpu%zd/cache/%s/id",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
|
||||
ret = virFileReadValueUint(&bank->id,
|
||||
"%s/cpu/cpu%zd/cache/%s/id",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name);
|
||||
if (ret == -2) {
|
||||
VIR_DEBUG("CPU %zd cache %s 'id' missing", pos, ent->d_name);
|
||||
continue;
|
||||
}
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (virFileReadValueUint(&bank->level,
|
||||
"%s/cpu/cpu%zd/cache/%s/level",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
|
||||
ret = virFileReadValueUint(&bank->level,
|
||||
"%s/cpu/cpu%zd/cache/%s/level",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name);
|
||||
if (ret == -2) {
|
||||
VIR_DEBUG("CPU %zd cache %s 'level' missing", pos, ent->d_name);
|
||||
continue;
|
||||
}
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (virFileReadValueString(&type,
|
||||
"%s/cpu/cpu%zd/cache/%s/type",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
|
||||
ret = virFileReadValueString(&type,
|
||||
"%s/cpu/cpu%zd/cache/%s/type",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name);
|
||||
if (ret == -2) {
|
||||
VIR_DEBUG("CPU %zd cache %s 'type' missing", pos, ent->d_name);
|
||||
continue;
|
||||
}
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (virFileReadValueScaledInt(&bank->size,
|
||||
"%s/cpu/cpu%zd/cache/%s/size",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
|
||||
ret = virFileReadValueScaledInt(&bank->size,
|
||||
"%s/cpu/cpu%zd/cache/%s/size",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name);
|
||||
if (ret == -2) {
|
||||
VIR_DEBUG("CPU %zd cache %s 'size' missing", pos, ent->d_name);
|
||||
continue;
|
||||
}
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (virFileReadValueBitmap(&bank->cpus,
|
||||
"%s/cpu/cpu%zd/cache/%s/shared_cpu_list",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
|
||||
ret = virFileReadValueBitmap(&bank->cpus,
|
||||
"%s/cpu/cpu%zd/cache/%s/shared_cpu_list",
|
||||
SYSFS_SYSTEM_PATH, pos, ent->d_name);
|
||||
if (ret == -2) {
|
||||
VIR_DEBUG("CPU %zd cache %s 'shared_cpu_list' missing", pos, ent->d_name);
|
||||
continue;
|
||||
}
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
kernel_type = virCacheKernelTypeFromString(type);
|
||||
|
Reference in New Issue
Block a user