[libvirt PATCH v2 1/2] conf: define autoptr func for virCapsHostCacheBankFree

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

 



This lets us simplify the cleanup paths when populating the host cache
bank information in capabilities XML.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/conf/capabilities.c | 34 ++++++++++++++--------------------
 src/conf/capabilities.h |  3 +++
 2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 1a7ebf4a13..d693d38f3c 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -2150,9 +2150,7 @@ virCapabilitiesInitCaches(virCaps *caps)
     size_t i = 0;
     g_autoptr(virBitmap) cpus = NULL;
     ssize_t pos = -1;
-    int ret = -1;
     struct dirent *ent = NULL;
-    virCapsHostCacheBank *bank = NULL;
     const virResctrlMonitorType montype = VIR_RESCTRL_MONITOR_TYPE_CACHE;
     const char *prefix = virResctrlMonitorPrefixTypeToString(montype);
 
@@ -2172,10 +2170,11 @@ virCapabilitiesInitCaches(virCaps *caps)
         int rv = -1;
         g_autoptr(DIR) dirp = NULL;
         g_autofree char *path = g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos);
+        g_autoptr(virCapsHostCacheBank) bank = NULL;
 
         rv = virDirOpenIfExists(&dirp, path);
         if (rv < 0)
-            goto cleanup;
+            return -1;
 
         if (!dirp)
             continue;
@@ -2191,7 +2190,7 @@ virCapabilitiesInitCaches(virCaps *caps)
             if (virFileReadValueUint(&level,
                                      "%s/cpu/cpu%zd/cache/%s/level",
                                      SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
-                goto cleanup;
+                return -1;
 
             if (level < cache_min_level)
                 continue;
@@ -2202,33 +2201,33 @@ virCapabilitiesInitCaches(virCaps *caps)
             if (virFileReadValueUint(&bank->id,
                                      "%s/cpu/cpu%zd/cache/%s/id",
                                      SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
-                goto cleanup;
+                return -1;
 
             if (virFileReadValueUint(&bank->level,
                                      "%s/cpu/cpu%zd/cache/%s/level",
                                      SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
-                goto cleanup;
+                return -1;
 
             if (virFileReadValueString(&type,
                                        "%s/cpu/cpu%zd/cache/%s/type",
                                        SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
-                goto cleanup;
+                return -1;
 
             if (virFileReadValueScaledInt(&bank->size,
                                           "%s/cpu/cpu%zd/cache/%s/size",
                                           SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
-                goto cleanup;
+                return -1;
 
             if (virFileReadValueBitmap(&bank->cpus,
                                        "%s/cpu/cpu%zd/cache/%s/shared_cpu_list",
                                        SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
-                goto cleanup;
+                return -1;
 
             kernel_type = virCacheKernelTypeFromString(type);
             if (kernel_type < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Unknown cache type '%s'"), type);
-                goto cleanup;
+                return -1;
             }
 
             bank->type = kernel_type;
@@ -2244,15 +2243,13 @@ virCapabilitiesInitCaches(virCaps *caps)
                                            bank->size,
                                            &bank->ncontrols,
                                            &bank->controls) < 0)
-                    goto cleanup;
+                    return -1;
 
                 VIR_APPEND_ELEMENT(caps->host.cache.banks, caps->host.cache.nbanks, bank);
             }
-
-            g_clear_pointer(&bank, virCapsHostCacheBankFree);
         }
         if (rv < 0)
-            goto cleanup;
+            return -1;
     }
 
     /* Sort the array in order for the tests to be predictable.  This way we can
@@ -2264,16 +2261,13 @@ virCapabilitiesInitCaches(virCaps *caps)
     }
 
     if (virCapabilitiesInitResctrlMemory(caps) < 0)
-        goto cleanup;
+        return -1;
 
     if (virResctrlInfoGetMonitorPrefix(caps->host.resctrl, prefix,
                                        &caps->host.cache.monitor) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    virCapsHostCacheBankFree(bank);
-    return ret;
+    return 0;
 }
 
 
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 6fe7818b2e..ef6e8ab685 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -137,6 +137,9 @@ struct _virCapsHostCacheBank {
     virResctrlInfoPerCache **controls;
 };
 
+void virCapsHostCacheBankFree(virCapsHostCacheBank *ptr);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCapsHostCacheBank, virCapsHostCacheBankFree);
+
 struct _virCapsHostCache {
     size_t nbanks;
     virCapsHostCacheBank **banks;
-- 
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