[PATCH 07/75] esx: Drop virAsprintf() and virAsprintfQuiet() retval checking

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

 



These functions can't fail really. Drop checking of their retval
then.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/esx/esx_driver.c               | 54 +++++++++---------------
 src/esx/esx_storage_backend_vmfs.c | 67 +++++++++++-------------------
 src/esx/esx_stream.c               | 11 ++---
 src/esx/esx_vi.c                   | 32 ++++++--------
 4 files changed, 61 insertions(+), 103 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 8e39075701..117ac674d4 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -143,9 +143,8 @@ esxParseVMXFileName(const char *fileName, void *opaque)
 
     if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
         /* Plain file name, use same directory as for the .vmx file */
-        if (virAsprintf(&result, "%s/%s",
-                        data->datastorePathWithoutFileName, fileName) < 0)
-            goto cleanup;
+        virAsprintf(&result, "%s/%s", data->datastorePathWithoutFileName,
+                    fileName);
     } else {
         if (esxVI_String_AppendValueToList(&propertyNameList,
                                            "summary.name") < 0 ||
@@ -189,9 +188,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
                 ++tmp;
             }
 
-            if (virAsprintf(&result, "[%s] %s", datastoreName,
-                            strippedFileName) < 0)
-                goto cleanup;
+            virAsprintf(&result, "[%s] %s", datastoreName, strippedFileName);
 
             break;
         }
@@ -225,9 +222,8 @@ esxParseVMXFileName(const char *fileName, void *opaque)
                 goto cleanup;
             }
 
-            if (virAsprintf(&result, "[%s] %s", datastoreName,
-                            directoryAndFileName) < 0)
-                goto cleanup;
+            virAsprintf(&result, "[%s] %s", datastoreName,
+                        directoryAndFileName);
         }
 
         /* If it's an absolute path outside of a datastore just use it as is */
@@ -639,9 +635,8 @@ esxConnectToHost(esxPrivate *priv,
                                         conn->uri->server)))
         goto cleanup;
 
-    if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
-                    conn->uri->server, conn->uri->port) < 0)
-        goto cleanup;
+    virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
+                conn->uri->server, conn->uri->port);
 
     if (esxVI_Context_Alloc(&priv->host) < 0 ||
         esxVI_Context_Connect(priv->host, url, ipAddress, username, password,
@@ -728,9 +723,8 @@ esxConnectToVCenter(esxPrivate *priv,
     if (!(password = virAuthGetPassword(conn, auth, "esx", username, hostname)))
         goto cleanup;
 
-    if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
-                    hostname, conn->uri->port) < 0)
-        goto cleanup;
+    virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport, hostname,
+                conn->uri->port);
 
     if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
         esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
@@ -1164,8 +1158,7 @@ esxConnectGetHostname(virConnectPtr conn)
     if (!domainName || strlen(domainName) < 1) {
         complete = g_strdup(hostName);
     } else {
-        if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0)
-            goto cleanup;
+        virAsprintf(&complete, "%s.%s", hostName, domainName);
     }
 
  cleanup:
@@ -2645,13 +2638,10 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
     data.ctx = priv->primary;
 
     if (!directoryName) {
-        if (virAsprintf(&data.datastorePathWithoutFileName, "[%s]",
-                        datastoreName) < 0)
-            goto cleanup;
+        virAsprintf(&data.datastorePathWithoutFileName, "[%s]", datastoreName);
     } else {
-        if (virAsprintf(&data.datastorePathWithoutFileName, "[%s] %s",
-                        datastoreName, directoryName) < 0)
-            goto cleanup;
+        virAsprintf(&data.datastorePathWithoutFileName, "[%s] %s",
+                    datastoreName, directoryName);
     }
 
     ctx.opaque = &data;
@@ -3116,13 +3106,11 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
 
     /* Register the domain */
     if (directoryName) {
-        if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
-                        directoryName, escapedName) < 0)
-            goto cleanup;
+        virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
+                    directoryName, escapedName);
     } else {
-        if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
-                        escapedName) < 0)
-            goto cleanup;
+        virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
+                    escapedName);
     }
 
     if (esxVI_RegisterVM_Task(priv->primary, priv->primary->datacenter->vmFolder,
@@ -3734,11 +3722,9 @@ esxDomainMigratePrepare(virConnectPtr dconn,
     virCheckFlags(ESX_MIGRATION_FLAGS, -1);
 
     if (!uri_in) {
-        if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s",
-                        priv->vCenter->ipAddress,
-                        priv->vCenter->computeResource->resourcePool->value,
-                        priv->vCenter->hostSystem->_reference->value) < 0)
-            return -1;
+        virAsprintf(uri_out, "vpxmigr://%s/%s/%s", priv->vCenter->ipAddress,
+                    priv->vCenter->computeResource->resourcePool->value,
+                    priv->vCenter->hostSystem->_reference->value);
     }
 
     return 0;
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index dfb4b7be15..24deee7215 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -605,9 +605,9 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
              fileInfo = fileInfo->_next) {
             if (length < 1) {
                 names[count] = g_strdup(fileInfo->path);
-            } else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName,
-                                   fileInfo->path) < 0) {
-                goto cleanup;
+            } else {
+                virAsprintf(&names[count], "%s/%s",
+                            directoryAndFileName, fileInfo->path);
             }
 
             ++count;
@@ -641,8 +641,7 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
     char *datastorePath = NULL;
     char *key = NULL;
 
-    if (virAsprintf(&datastorePath, "[%s] %s", pool->name, name) < 0)
-        goto cleanup;
+    virAsprintf(&datastorePath, "[%s] %s", pool->name, name);
 
     if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary,
                                                     datastorePath, &key) < 0) {
@@ -773,15 +772,12 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
 
                 if (length < 1) {
                     volumeName = g_strdup(fileInfo->path);
-                } else if (virAsprintf(&volumeName, "%s/%s",
-                                       directoryAndFileName,
-                                       fileInfo->path) < 0) {
-                    goto cleanup;
+                } else {
+                    virAsprintf(&volumeName, "%s/%s",
+                                directoryAndFileName, fileInfo->path);
                 }
 
-                if (virAsprintf(&datastorePath, "[%s] %s", datastoreName,
-                                volumeName) < 0)
-                    goto cleanup;
+                virAsprintf(&datastorePath, "[%s] %s", datastoreName, volumeName);
 
                 if (!esxVI_VmDiskFileInfo_DynamicCast(fileInfo)) {
                     /* Only a VirtualDisk has a UUID */
@@ -888,9 +884,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name,
-                    def->name) < 0)
-        goto cleanup;
+    virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name, def->name);
 
     if (def->target.format == VIR_STORAGE_FILE_VMDK) {
         /* Parse and escape datastore path */
@@ -911,13 +905,11 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         if (!fileName)
             goto cleanup;
 
-        if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
-                        directoryName) < 0)
-            goto cleanup;
+        virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
+                    directoryName);
 
-        if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
-                        fileName) < 0)
-            goto cleanup;
+        virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
+                    fileName);
 
         /* Create directory, if it doesn't exist yet */
         if (esxVI_LookupFileInfoByDatastorePath
@@ -1074,9 +1066,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    if (virAsprintf(&sourceDatastorePath, "[%s] %s", sourceVolume->pool,
-                    sourceVolume->name) < 0)
-        goto cleanup;
+    virAsprintf(&sourceDatastorePath, "[%s] %s", sourceVolume->pool,
+                sourceVolume->name);
 
     /* Parse config */
     def = virStorageVolDefParseString(&poolDef, xmldesc, 0);
@@ -1107,9 +1098,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name,
-                    def->name) < 0)
-        goto cleanup;
+    virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name, def->name);
 
     if (def->target.format == VIR_STORAGE_FILE_VMDK) {
         /* Parse and escape datastore path */
@@ -1130,13 +1119,11 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
         if (!fileName)
             goto cleanup;
 
-        if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
-                        directoryName) < 0)
-            goto cleanup;
+        virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
+                    directoryName);
 
-        if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
-                        fileName) < 0)
-            goto cleanup;
+        virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
+                    fileName);
 
         /* Create directory, if it doesn't exist yet */
         if (esxVI_LookupFileInfoByDatastorePath
@@ -1231,8 +1218,7 @@ esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
-        goto cleanup;
+    virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name);
 
     if (esxVI_DeleteVirtualDisk_Task(priv->primary, datastorePath,
                                      priv->primary->datacenter->_reference,
@@ -1274,8 +1260,7 @@ esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags)
 
     virCheckFlags(0, -1);
 
-    if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
-        goto cleanup;
+    virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name);
 
     if (esxVI_ZeroFillVirtualDisk_Task(priv->primary, datastorePath,
                                        priv->primary->datacenter->_reference,
@@ -1317,8 +1302,7 @@ esxStorageVolGetInfo(virStorageVolPtr volume,
 
     memset(info, 0, sizeof(*info));
 
-    if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
-        goto cleanup;
+    virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name);
 
     if (esxVI_LookupFileInfoByDatastorePath(priv->primary, datastorePath,
                                             false, &fileInfo,
@@ -1375,8 +1359,7 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
     }
 
     /* Lookup file info */
-    if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
-        goto cleanup;
+    virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name);
 
     if (esxVI_LookupFileInfoByDatastorePath(priv->primary, datastorePath,
                                             false, &fileInfo,
@@ -1437,7 +1420,7 @@ esxStorageVolGetPath(virStorageVolPtr volume)
 {
     char *path;
 
-    ignore_value(virAsprintf(&path, "[%s] %s", volume->pool, volume->name));
+    virAsprintf(&path, "[%s] %s", volume->pool, volume->name);
     return path;
 }
 
diff --git a/src/esx/esx_stream.c b/src/esx/esx_stream.c
index b820b38ee2..1a779aa095 100644
--- a/src/esx/esx_stream.c
+++ b/src/esx/esx_stream.c
@@ -415,11 +415,9 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
     streamPriv->mode = mode;
 
     if (length > 0) {
-        if (virAsprintf(&range, "%llu-%llu", offset, offset + length - 1) < 0)
-            goto cleanup;
+        virAsprintf(&range, "%llu-%llu", offset, offset + length - 1);
     } else if (offset > 0) {
-        if (virAsprintf(&range, "%llu-", offset) < 0)
-            goto cleanup;
+        virAsprintf(&range, "%llu-", offset);
     }
 
     if (esxVI_CURL_Alloc(&streamPriv->curl) < 0 ||
@@ -448,9 +446,8 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
     curl_easy_setopt(streamPriv->curl->handle, CURLOPT_PASSWORD,
                      priv->primary->password);
 #else
-    if (virAsprintf(&userpwd, "%s:%s", priv->primary->username,
-                    priv->primary->password) < 0)
-        goto cleanup;
+    virAsprintf(&userpwd, "%s:%s", priv->primary->username,
+                priv->primary->password);
 
     curl_easy_setopt(streamPriv->curl->handle, CURLOPT_USERPWD, userpwd);
 #endif
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 78e61ecd24..61082c5113 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -387,11 +387,9 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
             return -1;
         }
 
-        if (virAsprintf(&range, "%llu-%llu", offset, offset + *length - 1) < 0)
-            goto cleanup;
+        virAsprintf(&range, "%llu-%llu", offset, offset + *length - 1);
     } else if (offset > 0) {
-        if (virAsprintf(&range, "%llu-", offset) < 0)
-            goto cleanup;
+        virAsprintf(&range, "%llu-", offset);
     }
 
     virMutexLock(&curl->lock);
@@ -1489,10 +1487,9 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
 
             goto cleanup;
         } else {
-            if (virAsprintf(&xpathExpression,
-                            "/soapenv:Envelope/soapenv:Body/vim:%sResponse",
-                            methodName) < 0)
-                goto cleanup;
+            virAsprintf(&xpathExpression,
+                        "/soapenv:Envelope/soapenv:Body/vim:%sResponse",
+                        methodName);
 
             responseNode = virXPathNode(xpathExpression, xpathContext);
 
@@ -3588,15 +3585,12 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
          * The <path> part of the datatore path didn't contain a '/', assume
          * that the <path> part is actually the file name.
          */
-        if (virAsprintf(&datastorePathWithoutFileName, "[%s]",
-                        datastoreName) < 0)
-            goto cleanup;
+        virAsprintf(&datastorePathWithoutFileName, "[%s]", datastoreName);
 
         fileName = g_strdup(directoryAndFileName);
     } else {
-        if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
-                        datastoreName, directoryName) < 0)
-            goto cleanup;
+        virAsprintf(&datastorePathWithoutFileName, "[%s] %s", datastoreName,
+                    directoryName);
 
         length = strlen(directoryName);
 
@@ -3822,8 +3816,7 @@ esxVI_LookupDatastoreContentByDatastoreName
     floppyImageFileQuery = NULL;
 
     /* Search datastore for files */
-    if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0)
-        goto cleanup;
+    virAsprintf(&datastorePath, "[%s]", datastoreName);
 
     if (esxVI_SearchDatastoreSubFolders_Task(ctx, hostDatastoreBrowser,
                                              datastorePath, searchSpec,
@@ -4541,10 +4534,9 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
         } else if (!taskInfo->error->localizedMessage) {
             *errorMessage = g_strdup(taskInfo->error->fault->_actualType);
         } else {
-            if (virAsprintf(errorMessage, "%s - %s",
-                            taskInfo->error->fault->_actualType,
-                            taskInfo->error->localizedMessage) < 0)
-                goto cleanup;
+            virAsprintf(errorMessage, "%s - %s",
+                        taskInfo->error->fault->_actualType,
+                        taskInfo->error->localizedMessage);
         }
     }
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[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