Replace all occurrences of
if (VIR_STRDUP(a, b) < 0)
/* effectively dead code */
with:
a = g_strdup(b);
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/storage/parthelper.c | 3 +-
src/storage/storage_backend_disk.c | 19 ++++---------
src/storage/storage_backend_fs.c | 5 ++--
src/storage/storage_backend_gluster.c | 15 ++++------
src/storage/storage_backend_iscsi_direct.c | 3 +-
src/storage/storage_backend_logical.c | 8 ++----
src/storage/storage_backend_mpath.c | 3 +-
src/storage/storage_backend_rbd.c | 3 +-
src/storage/storage_backend_sheepdog.c | 7 +++--
src/storage/storage_backend_zfs.c | 6 ++--
src/storage/storage_driver.c | 19 +++++--------
src/storage/storage_util.c | 32 +++++++---------------
12 files changed, 43 insertions(+), 80 deletions(-)
diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c
index 4a404ddfa6..f1a8cc01ea 100644
--- a/src/storage/parthelper.c
+++ b/src/storage/parthelper.c
@@ -91,8 +91,7 @@ int main(int argc, char **argv)
partsep = "p";
else
partsep = "";
- if (VIR_STRDUP_QUIET(canonical_path, path) < 0)
- return 2;
+ canonical_path = g_strdup(path);
} else {
if (virFileResolveLink(path, &canonical_path) != 0)
return 2;
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 49590019c5..f37bcd2b15 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -75,13 +75,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
addVol = true;
if (VIR_ALLOC(vol) < 0)
return -1;
- if (VIR_STRDUP(vol->name, partname) < 0)
- goto error;
+ vol->name = g_strdup(partname);
}
if (vol->target.path == NULL) {
- if (VIR_STRDUP(devpath, groups[0]) < 0)
- goto error;
+ devpath = g_strdup(groups[0]);
/* Now figure out the stable path
*
@@ -129,8 +127,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
if (vol->key == NULL) {
/* XXX base off a unique key of the underlying disk */
- if (VIR_STRDUP(vol->key, vol->target.path) < 0)
- goto error;
+ vol->key = g_strdup(vol->target.path);
}
if (vol->source.extents == NULL) {
@@ -152,9 +149,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
goto error;
}
- if (VIR_STRDUP(vol->source.extents[0].path,
- def->source.devices[0].path) < 0)
- goto error;
+ vol->source.extents[0].path = g_strdup(def->source.devices[0].path);
}
/* set partition type */
@@ -602,8 +597,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
_("extended partition already exists"));
return -1;
}
- if (VIR_STRDUP(*partFormat, partedFormat) < 0)
- return -1;
+ *partFormat = g_strdup(partedFormat);
} else {
/* create primary partition as long as it is possible
and after that check if an extended partition exists
@@ -636,8 +630,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
}
}
} else {
- if (VIR_STRDUP(*partFormat, "primary") < 0)
- return -1;
+ *partFormat = g_strdup("primary");
}
return 0;
}
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index ad993c656f..02b824867a 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -81,9 +81,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(char **const groups,
goto cleanup;
src->nhost = 1;
- if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 ||
- VIR_STRDUP(src->dir, path) < 0)
- goto cleanup;
+ src->hosts[0].name = g_strdup(state->host);
+ src->dir = g_strdup(path);
src->format = VIR_STORAGE_POOL_NETFS_NFS;
ret = 0;
diff --git a/src/storage/storage_backend_gluster.c
b/src/storage/storage_backend_gluster.c
index 23fe0dc226..69de95a9ed 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -100,8 +100,7 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool)
if (VIR_ALLOC(ret) < 0)
return NULL;
- if (VIR_STRDUP(ret->volname, name) < 0)
- goto error;
+ ret->volname = g_strdup(name);
if (virAsprintf(&ret->dir, "%s%s", dir ? dir : "/",
trailing_slash ? "" : "/") < 0)
goto error;
@@ -110,10 +109,8 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool)
* extended to allow alternate transport */
if (VIR_ALLOC(ret->uri) < 0)
goto error;
- if (VIR_STRDUP(ret->uri->scheme, "gluster") < 0)
- goto error;
- if (VIR_STRDUP(ret->uri->server, def->source.hosts[0].name) < 0)
- 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->port = def->source.hosts[0].port;
@@ -196,8 +193,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr
state,
if (name) {
VIR_FREE(vol->name);
- if (VIR_STRDUP(vol->name, name) < 0)
- return -1;
+ vol->name = g_strdup(name);
}
if (virAsprintf(&path, "%s%s%s", state->volname, state->dir,
@@ -218,8 +214,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr
state,
state->uri->path = tmp;
/* the path is unique enough to serve as a volume key */
- if (VIR_STRDUP(vol->key, vol->target.path) < 0)
- return -1;
+ vol->key = g_strdup(vol->target.path);
return 0;
}
diff --git a/src/storage/storage_backend_iscsi_direct.c
b/src/storage/storage_backend_iscsi_direct.c
index 7492566099..e8bf42d0d0 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -425,8 +425,7 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi,
for (tmp_addr = addr; tmp_addr; tmp_addr = tmp_addr->next) {
g_autofree char *target = NULL;
- if (VIR_STRDUP(target, tmp_addr->target_name) < 0)
- goto cleanup;
+ target = g_strdup(tmp_addr->target_name);
if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0)
goto cleanup;
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index 80d2dfd0b4..208ca0792f 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -286,8 +286,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
is_new_vol = true;
vol->type = VIR_STORAGE_VOL_BLOCK;
- if (VIR_STRDUP(vol->name, groups[0]) < 0)
- goto cleanup;
+ vol->name = g_strdup(groups[0]);
}
@@ -466,9 +465,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **const groups,
g_autofree char *pvname = NULL;
g_autofree char *vgname = NULL;
- if (VIR_STRDUP(pvname, groups[0]) < 0 ||
- VIR_STRDUP(vgname, groups[1]) < 0)
- return -1;
+ pvname = g_strdup(groups[0]);
+ vgname = g_strdup(groups[1]);
thisSource = NULL;
for (i = 0; i < sourceList->nsources; i++) {
diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c
index 2d9ebf3ba3..fd3ee76371 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -65,8 +65,7 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
}
/* XXX should use logical unit's UUID instead */
- if (VIR_STRDUP(vol->key, vol->target.path) < 0)
- return -1;
+ vol->key = g_strdup(vol->target.path);
if (virStoragePoolObjAddVol(pool, vol) < 0)
return -1;
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index e4154479c2..1c59c18b0d 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -660,8 +660,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
if (STREQ(name, ""))
break;
- if (VIR_STRDUP(namedup, name) < 0)
- goto error;
+ namedup = g_strdup(name);
if (VIR_APPEND_ELEMENT(names, nnames, namedup) < 0)
goto error;
diff --git a/src/storage/storage_backend_sheepdog.c
b/src/storage/storage_backend_sheepdog.c
index 443c224222..e481eea816 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -118,9 +118,11 @@ virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr pool, const
char *diskIn
return -1;
}
- if (VIR_ALLOC(vol) < 0 || VIR_STRDUP(vol->name, diskInfo) < 0)
+ if (VIR_ALLOC(vol) < 0)
return -1;
+ vol->name = g_strdup(diskInfo);
+
vol->type = VIR_STORAGE_VOL_NETWORK;
if (virStorageBackendSheepdogRefreshVol(pool, vol) < 0)
@@ -229,8 +231,7 @@ virStorageBackendSheepdogCreateVol(virStoragePoolObjPtr pool,
return -1;
VIR_FREE(vol->target.path);
- if (VIR_STRDUP(vol->target.path, vol->name) < 0)
- return -1;
+ vol->target.path = g_strdup(vol->name);
return 0;
}
diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c
index 75edab4b26..c3057fede6 100644
--- a/src/storage/storage_backend_zfs.c
+++ b/src/storage/storage_backend_zfs.c
@@ -132,8 +132,7 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
is_new_vol = true;
volume->type = VIR_STORAGE_VOL_BLOCK;
- if (VIR_STRDUP(volume->name, vol_name) < 0)
- goto cleanup;
+ volume->name = g_strdup(vol_name);
}
if (!volume->key)
@@ -313,8 +312,7 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool,
def->target.path, vol->name) < 0)
return -1;
- if (VIR_STRDUP(vol->key, vol->target.path) < 0)
- goto cleanup;
+ vol->key = g_strdup(vol->target.path);
volmode_needed = virStorageBackendZFSVolModeNeeded();
if (volmode_needed < 0)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index ac215c7036..3b8332af01 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -272,13 +272,9 @@ storageStateInitialize(bool privileged,
goto error;
if (privileged) {
- if (VIR_STRDUP(driver->configDir,
- SYSCONFDIR "/libvirt/storage") < 0 ||
- VIR_STRDUP(driver->autostartDir,
- SYSCONFDIR "/libvirt/storage/autostart") < 0 ||
- VIR_STRDUP(driver->stateDir,
- RUNSTATEDIR "/libvirt/storage") < 0)
- goto error;
+ driver->configDir = g_strdup(SYSCONFDIR "/libvirt/storage");
+ driver->autostartDir = g_strdup(SYSCONFDIR
"/libvirt/storage/autostart");
+ driver->stateDir = g_strdup(RUNSTATEDIR "/libvirt/storage");
} else {
configdir = virGetUserConfigDirectory();
rundir = virGetUserRuntimeDirectory();
@@ -2442,12 +2438,11 @@ storageVolUpload(virStorageVolPtr vol,
* interaction and we can just lookup the backend in the callback
* routine in order to call the refresh API.
*/
- if (VIR_ALLOC(cbdata) < 0 ||
- VIR_STRDUP(cbdata->pool_name, def->name) < 0)
- goto cleanup;
- if (voldef->type == VIR_STORAGE_VOL_PLOOP &&
- VIR_STRDUP(cbdata->vol_path, voldef->target.path) < 0)
+ if (VIR_ALLOC(cbdata) < 0)
goto cleanup;
+ cbdata->pool_name = g_strdup(def->name);
+ if (voldef->type == VIR_STORAGE_VOL_PLOOP)
+ cbdata->vol_path = g_strdup(voldef->target.path);
virStoragePoolObjIncrAsyncjobs(obj);
voldef->in_use++;
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 692b3e7a9d..7b934b61e0 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1874,10 +1874,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
return -1;
}
} else {
- if (VIR_STRDUP(target->perms->label, filecon) < 0) {
- freecon(filecon);
- return -1;
- }
+ target->perms->label = g_strdup(filecon);
freecon(filecon);
}
}
@@ -2758,8 +2755,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool)
unsigned int dir_create_flags;
g_autofree char *parent = NULL;
- if (VIR_STRDUP(parent, def->target.path) < 0)
- return -1;
+ parent = g_strdup(def->target.path);
if (!(p = strrchr(parent, '/'))) {
virReportError(VIR_ERR_INVALID_ARG,
_("path '%s' is not absolute"),
@@ -2865,8 +2861,7 @@ virStorageUtilGlusterExtractPoolSources(const char *host,
src->format = VIR_STORAGE_POOL_NETFS_GLUSTERFS;
src->dir = g_steal_pointer(&volname);
} else if (pooltype == VIR_STORAGE_POOL_GLUSTER) {
- if (VIR_STRDUP(src->dir, "/") < 0)
- goto cleanup;
+ src->dir = g_strdup("/");
src->name = g_steal_pointer(&volname);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2878,8 +2873,7 @@ virStorageUtilGlusterExtractPoolSources(const char *host,
goto cleanup;
src->nhost = 1;
- if (VIR_STRDUP(src->hosts[0].name, host) < 0)
- goto cleanup;
+ src->hosts[0].name = g_strdup(host);
}
ret = nnodes;
@@ -3547,16 +3541,14 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
if (VIR_ALLOC(vol) < 0)
goto cleanup;
- if (VIR_STRDUP(vol->name, ent->d_name) < 0)
- goto cleanup;
+ 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;
- if (VIR_STRDUP(vol->key, vol->target.path) < 0)
- goto cleanup;
+ vol->key = g_strdup(vol->target.path);
if ((err = virStorageBackendRefreshVolTargetUpdate(vol)) < 0) {
if (err == -2) {
@@ -3615,8 +3607,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
def->target.perms.uid = target->perms->uid;
def->target.perms.gid = target->perms->gid;
VIR_FREE(def->target.perms.label);
- if (VIR_STRDUP(def->target.perms.label, target->perms->label) < 0)
- goto cleanup;
+ def->target.perms.label = g_strdup(target->perms->label);
ret = 0;
cleanup:
@@ -3769,8 +3760,7 @@ getNewStyleBlockDevice(const char *lun_path,
goto cleanup;
while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
- if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0)
- goto cleanup;
+ *block_device = g_strdup(block_dirent->d_name);
VIR_DEBUG("Block device is '%s'", *block_device);
@@ -3805,8 +3795,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UNUSED,
goto cleanup;
} else {
blockp++;
- if (VIR_STRDUP(*block_device, blockp) < 0)
- goto cleanup;
+ *block_device = g_strdup(blockp);
VIR_DEBUG("Block device is '%s'", *block_device);
}
@@ -4096,8 +4085,7 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool)
return NULL;
}
} else {
- if (VIR_STRDUP(src, def->source.devices[0].path) < 0)
- return NULL;
+ src = g_strdup(def->source.devices[0].path);
}
return src;
}
--
2.21.0