From nobody Sun Feb 8 15:08:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571576295; cv=none; d=zoho.com; s=zohoarc; b=ZoA0JhhbZ8ByPyOdQ/QSOWbMfrN+7nb82FyIywynXt0I/s5nlEpmexkhDwrrmH6GECWa9MFDhebacouPpVVctGwgHSO3yejrXXqyal/qLxqLRWVs6o+33IB6rDb55Ct8WGBNev9dKqcy9dSzDUdFMEaQgd6/myZkukepG+NXG7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571576295; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CLms3YXn0rOfZ2yL3H8gJ5RysvaCg8ZrPff9QzslBdc=; b=n/l0DkIB9vPx2U8dxB8tFIpxtAKHa4kh1eKPXIT52/Uuwdo63E0MD0O1QDN0bC+zQKfKmnrIvGK6KkcNzpHASwBAzkdQ8HHUGFmJekXprDPmpCk9RUUXa6trvPyh29slq6bWGiNxCvFculJoqWCs1BDFIcdF5qglbn+Bsm+LteQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571576294998689.9231989477624; Sun, 20 Oct 2019 05:58:14 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-dujeko8rNcuEDw3Y0cSbLQ-1; Sun, 20 Oct 2019 08:56:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D36C1800E18; Sun, 20 Oct 2019 12:56:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 340A46060D; Sun, 20 Oct 2019 12:56:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C31FC1804760; Sun, 20 Oct 2019 12:56:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9KCu73c023586 for ; Sun, 20 Oct 2019 08:56:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7BCCD3CC8; Sun, 20 Oct 2019 12:56:07 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-23.brq.redhat.com [10.40.200.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id D77D69446 for ; Sun, 20 Oct 2019 12:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571576293; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CLms3YXn0rOfZ2yL3H8gJ5RysvaCg8ZrPff9QzslBdc=; b=KLHq9iFU/8rca95gzw+1PRnJyr8kfJDLJdUXRTkd2aLglXg1w/OEtEI4lEizxXbEAopte8 AJsXY3gB6zgWcf/Ykb8ywDf/NBaiBS23e7eYmw/chZgfnCYSnMhIfdHPaIDrCNQLBpVFy+ Xyy2lcxpX5n61SjoVd4OcX4KRi94/r0= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Sun, 20 Oct 2019 14:55:44 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 26/34] storage: use g_strdup instead of VIR_STRDUP X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: dujeko8rNcuEDw3Y0cSbLQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a =3D g_strdup(b); Signed-off-by: J=C3=A1n Tomko --- 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 =3D "p"; else partsep =3D ""; - if (VIR_STRDUP_QUIET(canonical_path, path) < 0) - return 2; + canonical_path =3D g_strdup(path); } else { if (virFileResolveLink(path, &canonical_path) !=3D 0) return 2; diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_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 p= ool, addVol =3D true; if (VIR_ALLOC(vol) < 0) return -1; - if (VIR_STRDUP(vol->name, partname) < 0) - goto error; + vol->name =3D g_strdup(partname); } =20 if (vol->target.path =3D=3D NULL) { - if (VIR_STRDUP(devpath, groups[0]) < 0) - goto error; + devpath =3D g_strdup(groups[0]); =20 /* Now figure out the stable path * @@ -129,8 +127,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr p= ool, =20 if (vol->key =3D=3D NULL) { /* XXX base off a unique key of the underlying disk */ - if (VIR_STRDUP(vol->key, vol->target.path) < 0) - goto error; + vol->key =3D g_strdup(vol->target.path); } =20 if (vol->source.extents =3D=3D NULL) { @@ -152,9 +149,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr p= ool, goto error; } =20 - if (VIR_STRDUP(vol->source.extents[0].path, - def->source.devices[0].path) < 0) - goto error; + vol->source.extents[0].path =3D g_strdup(def->source.devices[0].pa= th); } =20 /* set partition type */ @@ -602,8 +597,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr po= ol, _("extended partition already exists")); return -1; } - if (VIR_STRDUP(*partFormat, partedFormat) < 0) - return -1; + *partFormat =3D 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 po= ol, } } } else { - if (VIR_STRDUP(*partFormat, "primary") < 0) - return -1; + *partFormat =3D 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 =3D 1; =20 - if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 || - VIR_STRDUP(src->dir, path) < 0) - goto cleanup; + src->hosts[0].name =3D g_strdup(state->host); + src->dir =3D g_strdup(path); src->format =3D VIR_STORAGE_POOL_NETFS_NFS; =20 ret =3D 0; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_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; =20 - if (VIR_STRDUP(ret->volname, name) < 0) - goto error; + ret->volname =3D 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 =3D g_strdup("gluster"); + ret->uri->server =3D g_strdup(def->source.hosts[0].name); if (virAsprintf(&ret->uri->path, "/%s%s", ret->volname, ret->dir) < 0) goto error; ret->uri->port =3D def->source.hosts[0].port; @@ -196,8 +193,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGl= usterStatePtr state, =20 if (name) { VIR_FREE(vol->name); - if (VIR_STRDUP(vol->name, name) < 0) - return -1; + vol->name =3D g_strdup(name); } =20 if (virAsprintf(&path, "%s%s%s", state->volname, state->dir, @@ -218,8 +214,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGl= usterStatePtr state, state->uri->path =3D tmp; =20 /* the path is unique enough to serve as a volume key */ - if (VIR_STRDUP(vol->key, vol->target.path) < 0) - return -1; + vol->key =3D g_strdup(vol->target.path); =20 return 0; } diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_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 =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) { g_autofree char *target =3D NULL; =20 - if (VIR_STRDUP(target, tmp_addr->target_name) < 0) - goto cleanup; + target =3D g_strdup(tmp_addr->target_name); =20 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_ba= ckend_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 =3D true; vol->type =3D VIR_STORAGE_VOL_BLOCK; =20 - if (VIR_STRDUP(vol->name, groups[0]) < 0) - goto cleanup; + vol->name =3D g_strdup(groups[0]); =20 } =20 @@ -466,9 +465,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **cons= t groups, g_autofree char *pvname =3D NULL; g_autofree char *vgname =3D NULL; =20 - if (VIR_STRDUP(pvname, groups[0]) < 0 || - VIR_STRDUP(vgname, groups[1]) < 0) - return -1; + pvname =3D g_strdup(groups[0]); + vgname =3D g_strdup(groups[1]); =20 thisSource =3D NULL; for (i =3D 0; i < sourceList->nsources; i++) { diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_back= end_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, } =20 /* XXX should use logical unit's UUID instead */ - if (VIR_STRDUP(vol->key, vol->target.path) < 0) - return -1; + vol->key =3D g_strdup(vol->target.path); =20 if (virStoragePoolObjAddVol(pool, vol) < 0) return -1; diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_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(virStorageBackendRBDSta= tePtr ptr) if (STREQ(name, "")) break; =20 - if (VIR_STRDUP(namedup, name) < 0) - goto error; + namedup =3D g_strdup(name); =20 if (VIR_APPEND_ELEMENT(names, nnames, namedup) < 0) goto error; diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_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(virStoragePoolObjPt= r pool, const char *diskIn return -1; } =20 - if (VIR_ALLOC(vol) < 0 || VIR_STRDUP(vol->name, diskInfo) < 0) + if (VIR_ALLOC(vol) < 0) return -1; =20 + vol->name =3D g_strdup(diskInfo); + vol->type =3D VIR_STORAGE_VOL_NETWORK; =20 if (virStorageBackendSheepdogRefreshVol(pool, vol) < 0) @@ -229,8 +231,7 @@ virStorageBackendSheepdogCreateVol(virStoragePoolObjPtr= pool, return -1; =20 VIR_FREE(vol->target.path); - if (VIR_STRDUP(vol->target.path, vol->name) < 0) - return -1; + vol->target.path =3D g_strdup(vol->name); =20 return 0; } diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_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 =3D true; volume->type =3D VIR_STORAGE_VOL_BLOCK; =20 - if (VIR_STRDUP(volume->name, vol_name) < 0) - goto cleanup; + volume->name =3D g_strdup(vol_name); } =20 if (!volume->key) @@ -313,8 +312,7 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool, def->target.path, vol->name) < 0) return -1; =20 - if (VIR_STRDUP(vol->key, vol->target.path) < 0) - goto cleanup; + vol->key =3D g_strdup(vol->target.path); =20 volmode_needed =3D 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; =20 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 =3D g_strdup(SYSCONFDIR "/libvirt/storage"); + driver->autostartDir =3D g_strdup(SYSCONFDIR "/libvirt/storage/aut= ostart"); + driver->stateDir =3D g_strdup(RUNSTATEDIR "/libvirt/storage"); } else { configdir =3D virGetUserConfigDirectory(); rundir =3D 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 =3D=3D VIR_STORAGE_VOL_PLOOP && - VIR_STRDUP(cbdata->vol_path, voldef->target.path) < 0) + if (VIR_ALLOC(cbdata) < 0) goto cleanup; + cbdata->pool_name =3D g_strdup(def->name); + if (voldef->type =3D=3D VIR_STORAGE_VOL_PLOOP) + cbdata->vol_path =3D g_strdup(voldef->target.path); =20 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(virStorageSou= rcePtr target, return -1; } } else { - if (VIR_STRDUP(target->perms->label, filecon) < 0) { - freecon(filecon); - return -1; - } + target->perms->label =3D g_strdup(filecon); freecon(filecon); } } @@ -2758,8 +2755,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) unsigned int dir_create_flags; g_autofree char *parent =3D NULL; =20 - if (VIR_STRDUP(parent, def->target.path) < 0) - return -1; + parent =3D g_strdup(def->target.path); if (!(p =3D strrchr(parent, '/'))) { virReportError(VIR_ERR_INVALID_ARG, _("path '%s' is not absolute"), @@ -2865,8 +2861,7 @@ virStorageUtilGlusterExtractPoolSources(const char *h= ost, src->format =3D VIR_STORAGE_POOL_NETFS_GLUSTERFS; src->dir =3D g_steal_pointer(&volname); } else if (pooltype =3D=3D VIR_STORAGE_POOL_GLUSTER) { - if (VIR_STRDUP(src->dir, "/") < 0) - goto cleanup; + src->dir =3D g_strdup("/"); src->name =3D g_steal_pointer(&volname); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2878,8 +2873,7 @@ virStorageUtilGlusterExtractPoolSources(const char *h= ost, goto cleanup; src->nhost =3D 1; =20 - if (VIR_STRDUP(src->hosts[0].name, host) < 0) - goto cleanup; + src->hosts[0].name =3D g_strdup(host); } =20 ret =3D nnodes; @@ -3547,16 +3541,14 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) if (VIR_ALLOC(vol) < 0) goto cleanup; =20 - if (VIR_STRDUP(vol->name, ent->d_name) < 0) - goto cleanup; + vol->name =3D g_strdup(ent->d_name); =20 vol->type =3D VIR_STORAGE_VOL_FILE; if (virAsprintf(&vol->target.path, "%s/%s", def->target.path, vol->name) < 0) goto cleanup; =20 - if (VIR_STRDUP(vol->key, vol->target.path) < 0) - goto cleanup; + vol->key =3D g_strdup(vol->target.path); =20 if ((err =3D virStorageBackendRefreshVolTargetUpdate(vol)) < 0) { if (err =3D=3D -2) { @@ -3615,8 +3607,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) def->target.perms.uid =3D target->perms->uid; def->target.perms.gid =3D 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 =3D g_strdup(target->perms->label); =20 ret =3D 0; cleanup: @@ -3769,8 +3760,7 @@ getNewStyleBlockDevice(const char *lun_path, goto cleanup; =20 while ((direrr =3D virDirRead(block_dir, &block_dirent, block_path)) >= 0) { - if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0) - goto cleanup; + *block_device =3D g_strdup(block_dirent->d_name); =20 VIR_DEBUG("Block device is '%s'", *block_device); =20 @@ -3805,8 +3795,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UN= USED, goto cleanup; } else { blockp++; - if (VIR_STRDUP(*block_device, blockp) < 0) - goto cleanup; + *block_device =3D g_strdup(blockp); =20 VIR_DEBUG("Block device is '%s'", *block_device); } @@ -4096,8 +4085,7 @@ virStorageBackendFileSystemGetPoolSource(virStoragePo= olObjPtr pool) return NULL; } } else { - if (VIR_STRDUP(src, def->source.devices[0].path) < 0) - return NULL; + src =3D g_strdup(def->source.devices[0].path); } return src; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list