[libvirt PATCH v2 2/2] conf: skip resource cache init if sysfs files are missing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/conf/capabilities.c | 56 ++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 15 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index d693d38f3c..a79547f6ca 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -2183,6 +2183,7 @@ virCapabilitiesInitCaches(virCaps *caps)
             g_autofree char *type = NULL;
             int kernel_type;
             unsigned int level;
+            int ret;
 
             if (!STRPREFIX(ent->d_name, "index"))
                 continue;
@@ -2198,29 +2199,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);
-- 
2.37.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux