]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Use g_strdup_printf() instead of virAsprintf()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 22 Oct 2019 13:26:14 +0000 (15:26 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Nov 2019 15:15:58 +0000 (16:15 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
14 files changed:
src/storage/storage_backend_disk.c
src/storage/storage_backend_gluster.c
src/storage/storage_backend_iscsi.c
src/storage/storage_backend_iscsi_direct.c
src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c
src/storage/storage_backend_rbd.c
src/storage/storage_backend_scsi.c
src/storage/storage_backend_sheepdog.c
src/storage/storage_backend_vstorage.c
src/storage/storage_backend_zfs.c
src/storage/storage_driver.c
src/storage/storage_file_gluster.c
src/storage/storage_util.c

index f37bcd2b15c1546524615fa416d15b0d02f95256..d971530cd848feabccf740175f0afaa6ce8fc610 100644 (file)
@@ -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;
+                *partFormat = g_strdup_printf("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;
+                    *partFormat = g_strdup_printf("logical %s", partedFormat);
                 } else {
                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                    _("no extended partition found and no "
index 69de95a9edacb78ad960516e8eaec88fdd9c7f6a..4a8ee3870dc4f95f8cde0f198be8c9ead7e1a0dd 100644 (file)
@@ -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;
+    ret->dir = g_strdup_printf("%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;
+    ret->uri->path = g_strdup_printf("/%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;
+    path = g_strdup_printf("%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;
-    }
+    state->uri->path = g_strdup_printf("/%s", path);
     if (!(vol->target.path = virURIFormat(state->uri))) {
         VIR_FREE(state->uri->path);
         state->uri->path = tmp;
index c754b5958c7618d595108f3049a9bf5e9a1c4c89..ee39cbf88df2c7f828ebc932bb02ded44984f410 100644 (file)
@@ -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",
+        portal = g_strdup_printf("[%s]:%d,1",
                                  source->hosts[0].name,
-                                 source->hosts[0].port));
+                                 source->hosts[0].port);
     } else {
-        ignore_value(virAsprintf(&portal, "%s:%d,1",
+        portal = g_strdup_printf("%s:%d,1",
                                  source->hosts[0].name,
-                                 source->hosts[0].port));
+                                 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;
+    sysfs_path = g_strdup_printf("/sys/class/iscsi_session/session%s/device",
+                                 session);
 
     if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0)
         return -1;
index e8bf42d0d08e5ab8f60c923005be2475d02bad25..2afa617cc1e40ba058dc0c76095aeefe23d422ee 100644 (file)
@@ -68,17 +68,17 @@ virStorageBackendISCSIDirectPortal(virStoragePoolSourcePtr source)
         return NULL;
     }
     if (source->hosts[0].port == 0) {
-        ignore_value(virAsprintf(&portal, "%s:%d",
+        portal = g_strdup_printf("%s:%d",
                                  source->hosts[0].name,
-                                 ISCSI_DEFAULT_TARGET_PORT));
+                                 ISCSI_DEFAULT_TARGET_PORT);
     } else if (strchr(source->hosts[0].name, ':')) {
-        ignore_value(virAsprintf(&portal, "[%s]:%d",
+        portal = g_strdup_printf("[%s]:%d",
                                  source->hosts[0].name,
-                                 source->hosts[0].port));
+                                 source->hosts[0].port);
     } else {
-        ignore_value(virAsprintf(&portal, "%s:%d",
+        portal = g_strdup_printf("%s:%d",
                                  source->hosts[0].name,
-                                 source->hosts[0].port));
+                                 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;
+    vol->name = g_strdup_printf("%s%u", VOL_NAME_PREFIX, lun);
+    vol->key = g_strdup_printf("ip-%s-iscsi-%s-lun-%u", portal,
+                               def->source.devices[0].path, lun);
+    vol->target.path = g_strdup_printf("ip-%s-iscsi-%s-lun-%u", portal,
+                                       def->source.devices[0].path, lun);
     return 0;
 }
 
index 208ca0792f53ad43cddb1fcbc0f5d26725155433..48023abd1acfec88a941de1d5aa7b79cc00270b3 100644 (file)
@@ -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)
+        vol->target.path = g_strdup_printf("%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;
+        vol->target.backingStore->path = g_strdup_printf("%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;
+    vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
 
     if (virStorageBackendLogicalLVCreate(vol, def) < 0)
         return -1;
index fd3ee763713e7d6b90280f09b510b0bf1c7049dd..8843dffc30a2368b310d57b715bdf8cc06bb3335 100644 (file)
@@ -53,11 +53,9 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
 
     vol->type = VIR_STORAGE_VOL_BLOCK;
 
-    if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0)
-        return -1;
+    (vol->name) = g_strdup_printf("dm-%u", devnum);
 
-    if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
-        return -1;
+    vol->target.path = g_strdup_printf("/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;
+            map_device = g_strdup_printf("mapper/%s", names->name);
 
             if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
index 7ce26edab056d33fbd1b31e8cbc8a591b960b099..bd6a9fa4dfcbf97bf2f21eac6042b25369bcb6f9 100644 (file)
@@ -567,14 +567,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;
+    vol->target.path = g_strdup_printf("%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;
+    vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
 
     ret = 0;
 
@@ -892,14 +888,10 @@ virStorageBackendRBDCreateVol(virStoragePoolObjPtr pool,
     }
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->source.name, vol->name) < 0)
-        return -1;
+    vol->target.path = g_strdup_printf("%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;
+    vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
 
     return 0;
 }
index 98d9d92ac5989058166545d34b2568232f1c631b..9c0f041616af61e5fea36cadb8319ae55d2f3b64 100644 (file)
@@ -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;
+    path = g_strdup_printf("%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;
+    scsi_host_name = g_strdup_printf("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;
+    path = g_strdup_printf("%s/host%d", LINUX_SYSFS_SCSI_HOST_PREFIX, host);
 
     *isActive = virFileExists(path);
 
index e481eea81650358a99965719030e77f27337398f..853a53115ff944015c526c7748f169688f09585f 100644 (file)
@@ -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;
+    vol->key = g_strdup_printf("%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;
+    vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
 
     VIR_FREE(vol->target.path);
     vol->target.path = g_strdup(vol->name);
index 8a4023014d3041980abe4a18a9d809676341fcfd..85ab8325ceeb279d77f3091d40c99437a24b1322 100644 (file)
@@ -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;
+    mode = g_strdup_printf("%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;
+    cluster = g_strdup_printf("vstorage://%s", def->source.name);
 
     if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
         virReportSystemError(errno,
index c3057fede6f92267237b87a4e9a90e4374328061..b708c7fd4a32ae03d4706db7c36e9794e74937a5 100644 (file)
@@ -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;
+    devpath = g_strdup_printf("/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;
+        volume->target.path = g_strdup_printf("%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;
+    vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
 
     vol->key = g_strdup(vol->target.path);
 
index 3b8332af01417c509419ba93d0635ef12c778a8f..84d76eebd075df4deb739ae4c3addaf72b9299b5 100644 (file)
@@ -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;
+        driver->configDir = g_strdup_printf("%s/storage", configdir);
+        driver->autostartDir = g_strdup_printf("%s/storage/autostart", configdir);
+        driver->stateDir = g_strdup_printf("%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;
+    desc = g_strdup_printf("%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));
+    tmp = g_strdup_printf("%s/%s.%s.secret.XXXXXX",
+                          driver->stateDir, def->name, voldef->name);
     return tmp;
 }
 
index 28f9962c0c9dde7a0ad10ff93740fa00bdea7560..f389a944377b46eb2254fcf64c817688786b0ab1 100644 (file)
@@ -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));
+    priv->canonpath = g_strdup_printf("gluster://%s:%u/%s/%s",
+                                      src->hosts->name,
+                                      src->hosts->port,
+                                      src->volume,
+                                      filePath);
 
     return priv->canonpath;
 }
index a3447c453c735a5c65a28efc64a739fed1645c62..7ecb8b384a1f0e05d45f4b945c6ae563f10bb2e4 100644 (file)
@@ -894,10 +894,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) != '/')
+        absolutePath = g_strdup_printf("%s/%s", def->target.path, info->backingPath);
     accessRetCode = access(absolutePath ? absolutePath :
                            info->backingPath, R_OK);
     if (accessRetCode != 0) {
@@ -1129,8 +1127,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
                            _("path to secret data file is required"));
             goto error;
         }
-        if (virAsprintf(&info.secretAlias, "%s_encrypt0", vol->name) < 0)
-            goto error;
+        info.secretAlias = g_strdup_printf("%s_encrypt0", vol->name);
         if (storageBackendCreateQemuImgSecretObject(cmd, secretPath,
                                                     info.secretAlias) < 0)
             goto error;
@@ -1143,9 +1140,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
                            _("path to inputvol secret data file is required"));
             goto error;
         }
-        if (virAsprintf(&inputSecretAlias, "%s_encrypt0",
-                        inputvol->name) < 0)
-            goto error;
+        inputSecretAlias = g_strdup_printf("%s_encrypt0", inputvol->name);
         if (storageBackendCreateQemuImgSecretObject(cmd, inputSecretPath,
                                                     inputSecretAlias) < 0)
             goto error;
@@ -1670,12 +1665,10 @@ storageBackendIsPloopDir(char *path)
     g_autofree char *root = NULL;
     g_autofree char *desc = NULL;
 
-    if (virAsprintf(&root, "%s/root.hds", path) < 0)
-        return false;
+    root = g_strdup_printf("%s/root.hds", path);
     if (!virFileExists(root))
         return false;
-    if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0)
-        return false;
+    desc = g_strdup_printf("%s/DiskDescriptor.xml", path);
     if (!virFileExists(desc))
         return false;
 
@@ -1693,8 +1686,7 @@ storageBackendRedoPloopUpdate(virStorageSourcePtr target, struct stat *sb,
 {
     g_autofree char *path = NULL;
 
-    if (virAsprintf(&path, "%s/root.hds", target->path) < 0)
-        return -1;
+    path = g_strdup_printf("%s/root.hds", target->path);
     VIR_FORCE_CLOSE(*fd);
     if ((*fd = virStorageBackendVolOpen(path, sb, flags)) < 0)
         return -1;
@@ -1944,11 +1936,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;
-        }
+        stablepath = g_strdup_printf("%s/%s", def->target.path, dent->d_name);
 
         if (virFileLinkPointsTo(stablepath, devpath)) {
             VIR_DIR_CLOSE(dh);
@@ -2044,9 +2032,7 @@ virStorageBackendVolCreateLocal(virStoragePoolObjPtr pool,
     }
 
     VIR_FREE(vol->target.path);
-    if (virAsprintf(&vol->target.path, "%s/%s",
-                    def->target.path, vol->name) < 0)
-        return -1;
+    vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
 
     if (virFileExists(vol->target.path)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -2283,8 +2269,7 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
               storageBackendCreateQemuImgSecretPath(pool, vol)))
             goto cleanup;
 
-        if (virAsprintf(&secretAlias, "%s_encrypt0", vol->name) < 0)
-            goto cleanup;
+        secretAlias = g_strdup_printf("%s_encrypt0", vol->name);
     }
 
     /* Round capacity as qemu-img resize errors out on sizes which are not
@@ -2421,8 +2406,7 @@ virStorageBackendVolUploadLocal(virStoragePoolObjPtr pool G_GNUC_UNUSED,
             return -1;
         }
 
-        if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
-            return -1;
+        path = g_strdup_printf("%s/root.hds", vol->target.path);
         target_path = path;
     }
 
@@ -2456,8 +2440,7 @@ virStorageBackendVolDownloadLocal(virStoragePoolObjPtr pool G_GNUC_UNUSED,
                              " will be lost"));
             return -1;
         }
-        if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
-            return -1;
+        path = g_strdup_printf("%s/root.hds", vol->target.path);
         target_path = path;
     }
 
@@ -2669,11 +2652,9 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol,
         return -1;
     }
 
-    if (virAsprintf(&target_path, "%s/root.hds", vol->target.path) < 0)
-        return -1;
+    target_path = g_strdup_printf("%s/root.hds", vol->target.path);
 
-    if (virAsprintf(&disk_desc, "%s/DiskDescriptor.xml", vol->target.path) < 0)
-        return -1;
+    disk_desc = g_strdup_printf("%s/DiskDescriptor.xml", vol->target.path);
 
     if (storageBackendVolWipeLocalFile(target_path, algorithm,
                                        vol->target.allocation, false) < 0)
@@ -3531,9 +3512,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;
+        vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
 
         vol->key = g_strdup(vol->target.path);
 
@@ -3674,11 +3653,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;
+    vol->name = g_strdup_printf("unit:%u:%u:%u", bus, target, lun);
 
-    if (virAsprintf(&devpath, "/dev/%s", dev) < 0)
-        return -1;
+    devpath = g_strdup_printf("/dev/%s", dev);
 
     VIR_DEBUG("Trying to create volume for '%s'", devpath);
 
@@ -3738,8 +3715,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;
+    block_path = g_strdup_printf("%s/block", lun_path);
 
     VIR_DEBUG("Looking for block device in '%s'", block_path);
 
@@ -3817,9 +3793,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;
+    lun_path = g_strdup_printf("/sys/bus/scsi/devices/%u:%u:%u:%u", host, bus,
+                               target, lun);
 
     if (virDirOpen(&lun_dir, lun_path) < 0)
         goto cleanup;
@@ -3871,9 +3846,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;
+    type_path = g_strdup_printf("/sys/bus/scsi/devices/%u:%u:%u:%u/type", host,
+                                bus, target, lun);
 
     typefile = fopen(type_path, "r");
     if (typefile == NULL) {
@@ -4061,15 +4035,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;
+            src = g_strdup_printf("//%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;
+            src = g_strdup_printf("%s:%s", def->source.hosts[0].name,
+                                  def->source.dir);
         }
     } else {
         src = g_strdup(def->source.devices[0].path);
@@ -4184,9 +4154,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)
+        nfsVers = g_strdup_printf("nfsvers=%u", def->source.protocolVer);
 
     cmd = virCommandNew(cmdstr);
     if (netauto)