[libvirt] [PATCH v2 35/37] Adapt to VIR_ALLOC and virAsprintf in src/*

Michal Privoznik mprivozn at redhat.com
Tue Jul 9 15:10:25 UTC 2013


---
 src/fdstream.c |  4 +---
 src/libvirt.c  | 21 ++++++---------------
 src/nodeinfo.c | 58 ++++++++++++++--------------------------------------------
 3 files changed, 21 insertions(+), 62 deletions(-)

diff --git a/src/fdstream.c b/src/fdstream.c
index d5e5aaf..30f1729 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -488,10 +488,8 @@ static int virFDStreamOpenInternal(virStreamPtr st,
         virSetNonBlock(fd) < 0)
         return -1;
 
-    if (VIR_ALLOC(fdst) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC(fdst) < 0)
         return -1;
-    }
 
     fdst->fd = fd;
     fdst->cmd = cmd;
diff --git a/src/libvirt.c b/src/libvirt.c
index 8e19c64..4ab69d9 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -275,7 +275,7 @@ static int virTLSMutexInit(void **priv)
 {
     virMutexPtr lock = NULL;
 
-    if (VIR_ALLOC(lock) < 0)
+    if (VIR_ALLOC_QUIET(lock) < 0)
         return ENOMEM;
 
     if (virMutexInit(lock) < 0) {
@@ -947,26 +947,21 @@ virConnectGetConfigFilePath(void)
     if (geteuid() == 0) {
         if (virAsprintf(&path, "%s/libvirt/libvirt.conf",
                         SYSCONFDIR) < 0)
-            goto no_memory;
+            return NULL;
     } else {
         char *userdir = virGetUserConfigDirectory();
         if (!userdir)
-            goto error;
+            return NULL;
 
         if (virAsprintf(&path, "%s/libvirt.conf",
                         userdir) < 0) {
             VIR_FREE(userdir);
-            goto no_memory;
+            return NULL;
         }
         VIR_FREE(userdir);
     }
 
     return path;
-
-no_memory:
-    virReportOOMError();
-error:
-    return NULL;
 }
 
 static int
@@ -16978,10 +16973,8 @@ int virStreamSendAll(virStreamPtr stream,
         goto cleanup;
     }
 
-    if (VIR_ALLOC_N(bytes, want) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(bytes, want) < 0)
         goto cleanup;
-    }
 
     for (;;) {
         int got, offset = 0;
@@ -17078,10 +17071,8 @@ int virStreamRecvAll(virStreamPtr stream,
     }
 
 
-    if (VIR_ALLOC_N(bytes, want) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(bytes, want) < 0)
         goto cleanup;
-    }
 
     for (;;) {
         int got, offset = 0;
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 498adca..49c7ced 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -118,10 +118,8 @@ virNodeGetCpuValue(const char *dir, unsigned int cpu, const char *file,
     char value_str[INT_BUFSIZE_BOUND(value)];
     char *tmp;
 
-    if (virAsprintf(&path, "%s/cpu%u/%s", dir, cpu, file) < 0) {
-        virReportOOMError();
+    if (virAsprintf(&path, "%s/cpu%u/%s", dir, cpu, file) < 0)
         return -1;
-    }
 
     pathfp = fopen(path, "r");
     if (pathfp == NULL) {
@@ -160,10 +158,8 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
     int i;
 
     if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings",
-                    dir, cpu) < 0) {
-        virReportOOMError();
+                    dir, cpu) < 0)
         return 0;
-    }
 
     pathfp = fopen(path, "r");
     if (pathfp == NULL) {
@@ -297,10 +293,8 @@ virNodeParseNode(const char *node,
     sock_max++;
 
     /* allocate cpu maps for each socket */
-    if (VIR_ALLOC_N(core_maps, sock_max) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(core_maps, sock_max) < 0)
         goto cleanup;
-    }
 
     for (i = 0; i < sock_max; i++)
         CPU_ZERO(&core_maps[i]);
@@ -481,10 +475,8 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
     /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
      * core, node, socket, thread and topology information from /sys
      */
-    if (virAsprintf(&sysfs_nodedir, "%s/node", sysfs_dir) < 0) {
-        virReportOOMError();
+    if (virAsprintf(&sysfs_nodedir, "%s/node", sysfs_dir) < 0)
         goto cleanup;
-    }
 
     if (!(nodedir = opendir(sysfs_nodedir))) {
         /* the host isn't probably running a NUMA architecture */
@@ -499,10 +491,8 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
         nodeinfo->nodes++;
 
         if (virAsprintf(&sysfs_cpudir, "%s/node/%s",
-                        sysfs_dir, nodedirent->d_name) < 0) {
-            virReportOOMError();
+                        sysfs_dir, nodedirent->d_name) < 0)
             goto cleanup;
-        }
 
         if ((cpus = virNodeParseNode(sysfs_cpudir, &socks, &cores,
                                      &threads, &offline)) < 0)
@@ -535,10 +525,8 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
 fallback:
     VIR_FREE(sysfs_cpudir);
 
-    if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0) {
-        virReportOOMError();
+    if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0)
         goto cleanup;
-    }
 
     if ((cpus = virNodeParseNode(sysfs_cpudir, &socks, &cores,
                                  &threads, &offline)) < 0)
@@ -848,10 +836,8 @@ linuxParseCPUmap(int max_cpuid, const char *path)
     virBitmapPtr map = NULL;
     char *str = NULL;
 
-    if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0) {
-        virReportOOMError();
+    if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0)
         goto error;
-    }
 
     if (virBitmapParse(str, 0, &map, max_cpuid) < 0)
         goto error;
@@ -1005,10 +991,8 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED,
 # endif
 
             if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo",
-                            SYSFS_SYSTEM_PATH, cellNum) < 0) {
-                virReportOOMError();
+                            SYSFS_SYSTEM_PATH, cellNum) < 0)
                 return -1;
-            }
         }
         meminfo = fopen(meminfo_path, "r");
 
@@ -1050,10 +1034,8 @@ nodeGetCPUCount(void)
             i++;
             VIR_FREE(cpupath);
             if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
-                            SYSFS_SYSTEM_PATH, i) < 0) {
-                virReportOOMError();
+                            SYSFS_SYSTEM_PATH, i) < 0)
                 return -1;
-            }
         } while (virFileExists(cpupath));
     } else {
         /* no cpu/cpu0: we give up */
@@ -1090,10 +1072,8 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
         int i;
 
         cpumap = virBitmapNew(present);
-        if (!cpumap) {
-            virReportOOMError();
+        if (!cpumap)
             return NULL;
-        }
         for (i = 0; i < present; i++) {
             int online = virNodeGetCpuValue(SYSFS_SYSTEM_PATH, i, "online", 1);
             if (online < 0) {
@@ -1128,13 +1108,11 @@ nodeSetMemoryParameterValue(virTypedParameterPtr param)
     field++;
     if (virAsprintf(&path, "%s/%s",
                     SYSFS_MEMORY_SHARED_PATH, field) < 0) {
-        virReportOOMError();
         ret = -2;
         goto cleanup;
     }
 
     if (virAsprintf(&strval, "%u", param->value.ui) == -1) {
-        virReportOOMError();
         ret = -2;
         goto cleanup;
     }
@@ -1165,10 +1143,8 @@ nodeMemoryParametersIsAllSupported(virTypedParameterPtr params,
         sa_assert(field);
         field++;
         if (virAsprintf(&path, "%s/%s",
-                        SYSFS_MEMORY_SHARED_PATH, field) < 0) {
-            virReportOOMError();
+                        SYSFS_MEMORY_SHARED_PATH, field) < 0)
             return false;
-        }
 
         if (!virFileExists(path)) {
             virReportError(VIR_ERR_OPERATION_INVALID,
@@ -1238,10 +1214,8 @@ nodeGetMemoryParameterValue(const char *field,
     int rc = -1;
 
     if (virAsprintf(&path, "%s/%s",
-                    SYSFS_MEMORY_SHARED_PATH, field) < 0) {
-        virReportOOMError();
+                    SYSFS_MEMORY_SHARED_PATH, field) < 0)
         goto cleanup;
-    }
 
     if (!virFileExists(path)) {
         ret = -2;
@@ -1472,10 +1446,8 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
 
     ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
 
-    if (VIR_ALLOC_N(cpus, ncpus) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(cpus, ncpus) < 0)
         return -1;
-    }
 
     id = 0;
     for (s = 0; s < nodeinfo.sockets; s++) {
@@ -1568,10 +1540,8 @@ virNodeGetSiblingsList(const char *dir, int cpu_id)
     virBitmapPtr ret = NULL;
 
     if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings_list",
-                    dir, cpu_id) < 0) {
-        virReportOOMError();
+                    dir, cpu_id) < 0)
         goto cleanup;
-    }
 
     if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &buf) < 0)
         goto cleanup;
-- 
1.8.1.5




More information about the libvir-list mailing list