[libvirt] [PATCH 23/75] storage: Drop virAsprintf() and virAsprintfQuiet() retval checking

Michal Privoznik mprivozn at redhat.com
Tue Oct 22 13:57:27 UTC 2019


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

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/storage/storage_backend_disk.c         |  7 +-
 src/storage/storage_backend_gluster.c      | 16 +---
 src/storage/storage_backend_iscsi.c        | 17 ++---
 src/storage/storage_backend_iscsi_direct.c | 31 ++++----
 src/storage/storage_backend_logical.c      | 16 ++--
 src/storage/storage_backend_mpath.c        |  9 +--
 src/storage/storage_backend_rbd.c          | 16 +---
 src/storage/storage_backend_scsi.c         | 11 +--
 src/storage/storage_backend_sheepdog.c     |  7 +-
 src/storage/storage_backend_vstorage.c     |  6 +-
 src/storage/storage_backend_zfs.c          | 13 +---
 src/storage/storage_driver.c               | 17 ++---
 src/storage/storage_file_gluster.c         | 10 +--
 src/storage/storage_util.c                 | 87 +++++++---------------
 14 files changed, 90 insertions(+), 173 deletions(-)

diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index f37bcd2b15..d4bd526c14 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -605,17 +605,14 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
             /* XXX Only support one extended partition */
             switch (virStorageBackendDiskPartTypeToCreate(pool)) {
             case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY:
-                if (virAsprintf(partFormat, "primary %s", partedFormat) < 0)
-                    return -1;
+                virAsprintf(partFormat, "primary %s", partedFormat);
                 break;
             case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL:
                 /* make sure we have an extended partition */
                 if (virStoragePoolObjSearchVolume(pool,
                                                   virStorageVolPartFindExtended,
                                                   NULL)) {
-                    if (virAsprintf(partFormat, "logical %s",
-                                    partedFormat) < 0)
-                        return -1;
+                    virAsprintf(partFormat, "logical %s", partedFormat);
                 } else {
                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                    _("no extended partition found and no "
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 69de95a9ed..0022ed2f21 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -101,9 +101,7 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool)
         return NULL;
 
     ret->volname = g_strdup(name);
-    if (virAsprintf(&ret->dir, "%s%s", dir ? dir : "/",
-                    trailing_slash ? "" : "/") < 0)
-        goto error;
+    virAsprintf(&ret->dir, "%s%s", dir ? dir : "/", trailing_slash ? "" : "/");
 
     /* FIXME: Currently hard-coded to tcp transport; XML needs to be
      * extended to allow alternate transport */
@@ -111,8 +109,7 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool)
         goto error;
     ret->uri->scheme = g_strdup("gluster");
     ret->uri->server = g_strdup(def->source.hosts[0].name);
-    if (virAsprintf(&ret->uri->path, "/%s%s", ret->volname, ret->dir) < 0)
-        goto error;
+    virAsprintf(&ret->uri->path, "/%s%s", ret->volname, ret->dir);
     ret->uri->port = def->source.hosts[0].port;
 
     /* Actually connect to glfs */
@@ -196,15 +193,10 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
         vol->name = g_strdup(name);
     }
 
-    if (virAsprintf(&path, "%s%s%s", state->volname, state->dir,
-                    vol->name) < 0)
-        return -1;
+    virAsprintf(&path, "%s%s%s", state->volname, state->dir, vol->name);
 
     tmp = state->uri->path;
-    if (virAsprintf(&state->uri->path, "/%s", path) < 0) {
-        state->uri->path = tmp;
-        return -1;
-    }
+    virAsprintf(&state->uri->path, "/%s", path);
     if (!(vol->target.path = virURIFormat(state->uri))) {
         VIR_FREE(state->uri->path);
         state->uri->path = tmp;
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index b11d1d6622..b61abb7cbd 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -63,13 +63,13 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
         source->hosts[0].port = ISCSI_DEFAULT_TARGET_PORT;
 
     if (strchr(source->hosts[0].name, ':')) {
-        ignore_value(virAsprintf(&portal, "[%s]:%d,1",
-                                 source->hosts[0].name,
-                                 source->hosts[0].port));
+        virAsprintf(&portal, "[%s]:%d,1",
+                    source->hosts[0].name,
+                    source->hosts[0].port);
     } else {
-        ignore_value(virAsprintf(&portal, "%s:%d,1",
-                                 source->hosts[0].name,
-                                 source->hosts[0].port));
+        virAsprintf(&portal, "%s:%d,1",
+                    source->hosts[0].name,
+                    source->hosts[0].port);
     }
 
     return portal;
@@ -133,9 +133,8 @@ virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool,
     uint32_t host;
     g_autofree char *sysfs_path = NULL;
 
-    if (virAsprintf(&sysfs_path,
-                    "/sys/class/iscsi_session/session%s/device", session) < 0)
-        return -1;
+    virAsprintf(&sysfs_path, "/sys/class/iscsi_session/session%s/device",
+                session);
 
     if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0)
         return -1;
diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index e8bf42d0d0..f0b27451f0 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -68,17 +68,17 @@ virStorageBackendISCSIDirectPortal(virStoragePoolSourcePtr source)
         return NULL;
     }
     if (source->hosts[0].port == 0) {
-        ignore_value(virAsprintf(&portal, "%s:%d",
-                                 source->hosts[0].name,
-                                 ISCSI_DEFAULT_TARGET_PORT));
+        virAsprintf(&portal, "%s:%d",
+                    source->hosts[0].name,
+                    ISCSI_DEFAULT_TARGET_PORT);
     } else if (strchr(source->hosts[0].name, ':')) {
-        ignore_value(virAsprintf(&portal, "[%s]:%d",
-                                 source->hosts[0].name,
-                                 source->hosts[0].port));
+        virAsprintf(&portal, "[%s]:%d",
+                    source->hosts[0].name,
+                    source->hosts[0].port);
     } else {
-        ignore_value(virAsprintf(&portal, "%s:%d",
-                                 source->hosts[0].name,
-                                 source->hosts[0].port));
+        virAsprintf(&portal, "%s:%d",
+                    source->hosts[0].name,
+                    source->hosts[0].port);
     }
     return portal;
 }
@@ -230,14 +230,11 @@ virISCSIDirectSetVolumeAttributes(virStoragePoolObjPtr pool,
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
 
-    if (virAsprintf(&vol->name, "%s%u", VOL_NAME_PREFIX, lun) < 0)
-        return -1;
-    if (virAsprintf(&vol->key, "ip-%s-iscsi-%s-lun-%u", portal,
-                    def->source.devices[0].path, lun) < 0)
-        return -1;
-    if (virAsprintf(&vol->target.path, "ip-%s-iscsi-%s-lun-%u", portal,
-                    def->source.devices[0].path, lun) < 0)
-        return -1;
+    virAsprintf(&vol->name, "%s%u", VOL_NAME_PREFIX, lun);
+    virAsprintf(&vol->key, "ip-%s-iscsi-%s-lun-%u", portal,
+                def->source.devices[0].path, lun);
+    virAsprintf(&vol->target.path, "ip-%s-iscsi-%s-lun-%u", portal,
+                def->source.devices[0].path, lun);
     return 0;
 }
 
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 208ca0792f..4a5d61e57d 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -290,11 +290,8 @@ virStorageBackendLogicalMakeVol(char **const groups,
 
     }
 
-    if (vol->target.path == NULL) {
-        if (virAsprintf(&vol->target.path, "%s/%s",
-                        def->target.path, vol->name) < 0)
-            goto cleanup;
-    }
+    if (vol->target.path == NULL)
+        virAsprintf(&vol->target.path, "%s/%s", def->target.path, vol->name);
 
     /* Mark the (s) sparse/snapshot lv, e.g. the lv created using
      * the --virtualsize/-V option. We've already ignored the (t)hin
@@ -316,9 +313,8 @@ virStorageBackendLogicalMakeVol(char **const groups,
         if (!(vol->target.backingStore = virStorageSourceNew()))
             goto cleanup;
 
-        if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
-                        def->target.path, groups[1]) < 0)
-            goto cleanup;
+        virAsprintf(&vol->target.backingStore->path, "%s/%s",
+                    def->target.path, groups[1]);
 
         vol->target.backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
         vol->target.backingStore->type = VIR_STORAGE_TYPE_BLOCK;
@@ -916,9 +912,7 @@ virStorageBackendLogicalCreateVol(virStoragePoolObjPtr pool,
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->target.path, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->target.path, "%s/%s", def->target.path, vol->name);
 
     if (virStorageBackendLogicalLVCreate(vol, def) < 0)
         return -1;
diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c
index fd3ee76371..6912977657 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -53,11 +53,9 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
 
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
-    if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0)
-        return -1;
+    virAsprintf(&(vol->name), "dm-%u", devnum);
 
-    if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
-        return -1;
+    virAsprintf(&vol->target.path, "/dev/%s", dev);
 
     if (virStorageBackendUpdateVolInfo(vol, true,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < 0) {
@@ -165,8 +163,7 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool,
 
         if (is_mpath == 1) {
 
-            if (virAsprintf(&map_device, "mapper/%s", names->name) < 0)
-                return -1;
+            virAsprintf(&map_device, "mapper/%s", names->name);
 
             if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 1c59c18b0d..491b85e0e0 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -570,14 +570,10 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
               vol->target.allocation, info.obj_size, info.num_objs);
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->source.name, vol->name) < 0)
-        goto cleanup;
+    virAsprintf(&vol->target.path, "%s/%s", def->source.name, vol->name);
 
     VIR_FREE(vol->key);
-    if (virAsprintf(&vol->key, "%s/%s",
-                    def->source.name, vol->name) < 0)
-        goto cleanup;
+    virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name);
 
     ret = 0;
 
@@ -895,14 +891,10 @@ virStorageBackendRBDCreateVol(virStoragePoolObjPtr pool,
     }
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->source.name, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->target.path, "%s/%s", def->source.name, vol->name);
 
     VIR_FREE(vol->key);
-    if (virAsprintf(&vol->key, "%s/%s",
-                    def->source.name, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name);
 
     return 0;
 }
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index 98d9d92ac5..80965bc349 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -60,9 +60,7 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
 
     VIR_DEBUG("Triggering rescan of host %d", host);
 
-    if (virAsprintf(&path, "%s/host%u/scan",
-                    LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0)
-        return -1;
+    virAsprintf(&path, "%s/host%u/scan", LINUX_SYSFS_SCSI_HOST_PREFIX, host);
 
     VIR_DEBUG("Scan trigger path is '%s'", path);
 
@@ -261,8 +259,7 @@ checkParent(const char *name,
         goto cleanup;
     }
 
-    if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
-        goto cleanup;
+    virAsprintf(&scsi_host_name, "scsi_%s", name);
 
     if (!(vhba_parent = virNodeDeviceGetParentName(conn, scsi_host_name)))
         goto cleanup;
@@ -376,9 +373,7 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr pool,
     if (virSCSIHostGetNumber(name, &host) < 0)
         return -1;
 
-    if (virAsprintf(&path, "%s/host%d",
-                    LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0)
-        return -1;
+    virAsprintf(&path, "%s/host%d", LINUX_SYSFS_SCSI_HOST_PREFIX, host);
 
     *isActive = virFileExists(path);
 
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index e481eea816..ff13d2d9bd 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -226,9 +226,7 @@ virStorageBackendSheepdogCreateVol(virStoragePoolObjPtr pool,
     vol->type = VIR_STORAGE_VOL_NETWORK;
 
     VIR_FREE(vol->key);
-    if (virAsprintf(&vol->key, "%s/%s",
-                    def->source.name, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name);
 
     VIR_FREE(vol->target.path);
     vol->target.path = g_strdup(vol->name);
@@ -340,8 +338,7 @@ virStorageBackendSheepdogRefreshVol(virStoragePoolObjPtr pool,
     vol->type = VIR_STORAGE_VOL_NETWORK;
 
     VIR_FREE(vol->key);
-    if (virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name);
 
     VIR_FREE(vol->target.path);
     vol->target.path = g_strdup(vol->name);
diff --git a/src/storage/storage_backend_vstorage.c b/src/storage/storage_backend_vstorage.c
index 8a4023014d..9a34d87ec3 100644
--- a/src/storage/storage_backend_vstorage.c
+++ b/src/storage/storage_backend_vstorage.c
@@ -61,8 +61,7 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool)
     if (!(usr_name = virGetUserName(def->target.perms.uid)))
         return -1;
 
-    if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0)
-        return -1;
+    virAsprintf(&mode, "%o", def->target.perms.mode);
 
     cmd = virCommandNewArgList(VSTORAGE_MOUNT,
                                "-c", def->source.name,
@@ -91,8 +90,7 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool)
     char buf[1024];
     g_autofree char *cluster = NULL;
 
-    if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0)
-        return -1;
+    virAsprintf(&cluster, "vstorage://%s", def->source.name);
 
     if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
         virReportSystemError(errno,
diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c
index c3057fede6..793eb06f5c 100644
--- a/src/storage/storage_backend_zfs.c
+++ b/src/storage/storage_backend_zfs.c
@@ -87,9 +87,7 @@ virStorageBackendZFSCheckPool(virStoragePoolObjPtr pool G_GNUC_UNUSED,
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
     g_autofree char *devpath = NULL;
 
-    if (virAsprintf(&devpath, "/dev/zvol/%s",
-                    def->source.name) < 0)
-        return -1;
+    virAsprintf(&devpath, "/dev/zvol/%s", def->source.name);
     *isActive = virFileIsDir(devpath);
 
     return 0;
@@ -139,9 +137,8 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
         volume->key = g_strdup(tokens[0]);
 
     if (volume->target.path == NULL) {
-        if (virAsprintf(&volume->target.path, "%s/%s",
-                        def->target.path, volume->name) < 0)
-            goto cleanup;
+        virAsprintf(&volume->target.path, "%s/%s", def->target.path,
+                    volume->name);
     }
 
     if (virStrToLong_ull(tokens[1], NULL, 10, &volume->target.capacity) < 0) {
@@ -308,9 +305,7 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool,
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->target.path, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->target.path, "%s/%s", def->target.path, vol->name);
 
     vol->key = g_strdup(vol->target.path);
 
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 3b8332af01..dfe3dd1354 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -281,13 +281,9 @@ storageStateInitialize(bool privileged,
         if (!(configdir && rundir))
             goto error;
 
-        if ((virAsprintf(&driver->configDir,
-                        "%s/storage", configdir) < 0) ||
-            (virAsprintf(&driver->autostartDir,
-                        "%s/storage/autostart", configdir) < 0) ||
-            (virAsprintf(&driver->stateDir,
-                         "%s/storage/run", rundir) < 0))
-            goto error;
+        virAsprintf(&driver->configDir, "%s/storage", configdir);
+        virAsprintf(&driver->autostartDir, "%s/storage/autostart", configdir);
+        virAsprintf(&driver->stateDir, "%s/storage/run", rundir);
     }
     driver->privileged = privileged;
 
@@ -2293,8 +2289,7 @@ virStorageBackendPloopRestoreDesc(char *path)
     g_autofree char *refresh_tool = NULL;
     g_autofree char *desc = NULL;
 
-    if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0)
-        return -1;
+    virAsprintf(&desc, "%s/DiskDescriptor.xml", path);
 
     if (virFileRemove(desc, 0, 0) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2856,8 +2851,8 @@ virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr obj,
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
     char *tmp = NULL;
 
-    ignore_value(virAsprintf(&tmp, "%s/%s.%s.secret.XXXXXX",
-                             driver->stateDir, def->name, voldef->name));
+    virAsprintf(&tmp, "%s/%s.%s.secret.XXXXXX",
+                driver->stateDir, def->name, voldef->name);
     return tmp;
 }
 
diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_gluster.c
index 28f9962c0c..1577239431 100644
--- a/src/storage/storage_file_gluster.c
+++ b/src/storage/storage_file_gluster.c
@@ -311,11 +311,11 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
                                                     priv)))
         return NULL;
 
-    ignore_value(virAsprintf(&priv->canonpath, "gluster://%s:%u/%s/%s",
-                             src->hosts->name,
-                             src->hosts->port,
-                             src->volume,
-                             filePath));
+    virAsprintf(&priv->canonpath, "gluster://%s:%u/%s/%s",
+                src->hosts->name,
+                src->hosts->port,
+                src->volume,
+                filePath);
 
     return priv->canonpath;
 }
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 7b934b61e0..88fb8b5223 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -897,10 +897,8 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool,
     /* Convert relative backing store paths to absolute paths for access
      * validation.
      */
-    if ('/' != *(info->backingPath) &&
-        virAsprintf(&absolutePath, "%s/%s", def->target.path,
-                    info->backingPath) < 0)
-        return -1;
+    if (*(info->backingPath) != '/')
+        virAsprintf(&absolutePath, "%s/%s", def->target.path, info->backingPath);
     accessRetCode = access(absolutePath ? absolutePath :
                            info->backingPath, R_OK);
     if (accessRetCode != 0) {
@@ -1142,8 +1140,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
                            _("path to secret data file is required"));
             goto error;
         }
-        if (virAsprintf(&info.secretAlias, "%s_encrypt0", vol->name) < 0)
-            goto error;
+        virAsprintf(&info.secretAlias, "%s_encrypt0", vol->name);
         if (storageBackendCreateQemuImgSecretObject(cmd, secretPath,
                                                     info.secretAlias) < 0)
             goto error;
@@ -1156,9 +1153,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
                            _("path to inputvol secret data file is required"));
             goto error;
         }
-        if (virAsprintf(&inputSecretAlias, "%s_encrypt0",
-                        inputvol->name) < 0)
-            goto error;
+        virAsprintf(&inputSecretAlias, "%s_encrypt0", inputvol->name);
         if (storageBackendCreateQemuImgSecretObject(cmd, inputSecretPath,
                                                     inputSecretAlias) < 0)
             goto error;
@@ -1683,12 +1678,10 @@ storageBackendIsPloopDir(char *path)
     g_autofree char *root = NULL;
     g_autofree char *desc = NULL;
 
-    if (virAsprintf(&root, "%s/root.hds", path) < 0)
-        return false;
+    virAsprintf(&root, "%s/root.hds", path);
     if (!virFileExists(root))
         return false;
-    if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0)
-        return false;
+    virAsprintf(&desc, "%s/DiskDescriptor.xml", path);
     if (!virFileExists(desc))
         return false;
 
@@ -1706,8 +1699,7 @@ storageBackendRedoPloopUpdate(virStorageSourcePtr target, struct stat *sb,
 {
     g_autofree char *path = NULL;
 
-    if (virAsprintf(&path, "%s/root.hds", target->path) < 0)
-        return -1;
+    virAsprintf(&path, "%s/root.hds", target->path);
     VIR_FORCE_CLOSE(*fd);
     if ((*fd = virStorageBackendVolOpen(path, sb, flags)) < 0)
         return -1;
@@ -1957,11 +1949,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
      */
  retry:
     while ((direrr = virDirRead(dh, &dent, NULL)) > 0) {
-        if (virAsprintf(&stablepath, "%s/%s",
-                        def->target.path, dent->d_name) < 0) {
-            VIR_DIR_CLOSE(dh);
-            return NULL;
-        }
+        virAsprintf(&stablepath, "%s/%s", def->target.path, dent->d_name);
 
         if (virFileLinkPointsTo(stablepath, devpath)) {
             VIR_DIR_CLOSE(dh);
@@ -2057,9 +2045,7 @@ virStorageBackendVolCreateLocal(virStoragePoolObjPtr pool,
     }
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->target.path, vol->name) < 0)
-        return -1;
+    virAsprintf(&vol->target.path, "%s/%s", def->target.path, vol->name);
 
     if (virFileExists(vol->target.path)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -2296,8 +2282,7 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
               storageBackendCreateQemuImgSecretPath(pool, vol)))
             goto cleanup;
 
-        if (virAsprintf(&secretAlias, "%s_encrypt0", vol->name) < 0)
-            goto cleanup;
+        virAsprintf(&secretAlias, "%s_encrypt0", vol->name);
     }
 
     /* Round capacity as qemu-img resize errors out on sizes which are not
@@ -2434,8 +2419,7 @@ virStorageBackendVolUploadLocal(virStoragePoolObjPtr pool G_GNUC_UNUSED,
             return -1;
         }
 
-        if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
-            return -1;
+        virAsprintf(&path, "%s/root.hds", vol->target.path);
         target_path = path;
     }
 
@@ -2469,8 +2453,7 @@ virStorageBackendVolDownloadLocal(virStoragePoolObjPtr pool G_GNUC_UNUSED,
                              " will be lost"));
             return -1;
         }
-        if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
-            return -1;
+        virAsprintf(&path, "%s/root.hds", vol->target.path);
         target_path = path;
     }
 
@@ -2682,11 +2665,9 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol,
         return -1;
     }
 
-    if (virAsprintf(&target_path, "%s/root.hds", vol->target.path) < 0)
-        return -1;
+    virAsprintf(&target_path, "%s/root.hds", vol->target.path);
 
-    if (virAsprintf(&disk_desc, "%s/DiskDescriptor.xml", vol->target.path) < 0)
-        return -1;
+    virAsprintf(&disk_desc, "%s/DiskDescriptor.xml", vol->target.path);
 
     if (storageBackendVolWipeLocalFile(target_path, algorithm,
                                        vol->target.allocation, false) < 0)
@@ -3544,9 +3525,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
         vol->name = g_strdup(ent->d_name);
 
         vol->type = VIR_STORAGE_VOL_FILE;
-        if (virAsprintf(&vol->target.path, "%s/%s",
-                        def->target.path, vol->name) < 0)
-            goto cleanup;
+        virAsprintf(&vol->target.path, "%s/%s", def->target.path, vol->name);
 
         vol->key = g_strdup(vol->target.path);
 
@@ -3687,11 +3666,9 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
      * in the volume name. We only need uniqueness per-pool, so
      * just leave 'host' out
      */
-    if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0)
-        return -1;
+    virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun);
 
-    if (virAsprintf(&devpath, "/dev/%s", dev) < 0)
-        return -1;
+    virAsprintf(&devpath, "/dev/%s", dev);
 
     VIR_DEBUG("Trying to create volume for '%s'", devpath);
 
@@ -3751,8 +3728,7 @@ getNewStyleBlockDevice(const char *lun_path,
     int direrr;
     g_autofree char *block_path = NULL;
 
-    if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
-        goto cleanup;
+    virAsprintf(&block_path, "%s/block", lun_path);
 
     VIR_DEBUG("Looking for block device in '%s'", block_path);
 
@@ -3830,9 +3806,8 @@ getBlockDevice(uint32_t host,
 
     *block_device = NULL;
 
-    if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
-                    host, bus, target, lun) < 0)
-        goto cleanup;
+    virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u", host, bus,
+                target, lun);
 
     if (virDirOpen(&lun_dir, lun_path) < 0)
         goto cleanup;
@@ -3884,9 +3859,8 @@ getDeviceType(uint32_t host,
     FILE *typefile;
     g_autofree char *type_path = NULL;
 
-    if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type",
-                    host, bus, target, lun) < 0)
-        return -1;
+    virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type", host,
+                bus, target, lun);
 
     typefile = fopen(type_path, "r");
     if (typefile == NULL) {
@@ -4074,15 +4048,11 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool)
 
     if (def->type == VIR_STORAGE_POOL_NETFS) {
         if (def->source.format == VIR_STORAGE_POOL_NETFS_CIFS) {
-            if (virAsprintf(&src, "//%s/%s",
-                            def->source.hosts[0].name,
-                            def->source.dir) < 0)
-                return NULL;
+            virAsprintf(&src, "//%s/%s", def->source.hosts[0].name,
+                        def->source.dir);
         } else {
-            if (virAsprintf(&src, "%s:%s",
-                            def->source.hosts[0].name,
-                            def->source.dir) < 0)
-                return NULL;
+            virAsprintf(&src, "%s:%s", def->source.hosts[0].name,
+                        def->source.dir);
         }
     } else {
         src = g_strdup(def->source.devices[0].path);
@@ -4197,9 +4167,8 @@ virStorageBackendFileSystemMountCmd(const char *cmdstr,
     virCommandPtr cmd = NULL;
     g_autofree char *nfsVers = NULL;
 
-    if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0 &&
-        virAsprintf(&nfsVers, "nfsvers=%u", def->source.protocolVer) < 0)
-        return NULL;
+    if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0)
+        virAsprintf(&nfsVers, "nfsvers=%u", def->source.protocolVer);
 
     cmd = virCommandNew(cmdstr);
     if (netauto)
-- 
2.21.0




More information about the libvir-list mailing list