From nobody Mon Feb 9 19:43:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550234552124932.2870987016107; Fri, 15 Feb 2019 04:42:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C37C12455C; Fri, 15 Feb 2019 12:42:24 +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 3BCA55DD6B; Fri, 15 Feb 2019 12:42:23 +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 AE130181A00C; Fri, 15 Feb 2019 12:42:21 +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 x1FCgKbs012012 for ; Fri, 15 Feb 2019 07:42:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2844526350; Fri, 15 Feb 2019 12:42:20 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7809A16E20; Fri, 15 Feb 2019 12:42:19 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 15 Feb 2019 13:42:09 +0100 Message-Id: <7d93342030a87c3d3531e39b8746fd60d0839205.1550234476.git.pkrempa@redhat.com> 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 Cc: Peter Krempa Subject: [libvirt] [PATCH 1/5] util: Introduce function for allocating virStorageSource 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Feb 2019 12:42:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add virStorageSourceNew and refactor places allocating that structure to use the helper. Signed-off-by: Peter Krempa Reviewed-by: Erik Skultety --- src/conf/domain_conf.c | 10 +++++----- src/conf/snapshot_conf.c | 4 ++-- src/conf/storage_conf.c | 2 +- src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 4 ++-- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 4 ++-- src/storage/storage_backend_gluster.c | 2 +- src/storage/storage_backend_logical.c | 2 +- src/storage/storage_util.c | 4 ++-- src/util/virstoragefile.c | 20 ++++++++++++++++---- src/util/virstoragefile.h | 1 + tests/qemublocktest.c | 2 +- tests/virstoragetest.c | 2 +- 14 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d49f4388c..52cec5cd3d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1881,7 +1881,7 @@ virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt) if (VIR_ALLOC(ret) < 0) return NULL; - if (VIR_ALLOC(ret->src) < 0) + if (!(ret->src =3D virStorageSourceNew())) goto error; if (xmlopt && @@ -2099,7 +2099,7 @@ virDomainFSDefNew(void) if (VIR_ALLOC(ret) < 0) return NULL; - if (VIR_ALLOC(ret->src) < 0) + if (!(ret->src =3D virStorageSourceNew())) goto cleanup; return ret; @@ -7585,7 +7585,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr= sourcenode, /* For the purposes of command line creation, this needs to look * like a disk storage source */ - if (VIR_ALLOC(iscsisrc->src) < 0) + if (!(iscsisrc->src =3D virStorageSourceNew())) return -1; iscsisrc->src->type =3D VIR_STORAGE_TYPE_NETWORK; iscsisrc->src->protocol =3D VIR_STORAGE_NET_PROTOCOL_ISCSI; @@ -9078,7 +9078,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, goto cleanup; } - if (VIR_ALLOC(backingStore) < 0) + if (!(backingStore =3D virStorageSourceNew())) goto cleanup; /* backing store is always read-only */ @@ -9236,7 +9236,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, char *blockJob =3D NULL; int ret =3D -1; - if (VIR_ALLOC(def->mirror) < 0) + if (!(def->mirror =3D virStorageSourceNew())) goto cleanup; if ((blockJob =3D virXMLPropString(cur, "job"))) { diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index b16f450a01..5127ebbdfd 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -122,7 +122,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, ctxt->node =3D node; - if (VIR_ALLOC(def->src) < 0) + if (!(def->src =3D virStorageSourceNew())) goto cleanup; def->name =3D virXMLPropString(node, "name"); @@ -621,7 +621,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, if (virBitmapIsBitSet(map, i)) continue; disk =3D &def->disks[ndisks++]; - if (VIR_ALLOC(disk->src) < 0) + if (!(disk->src =3D virStorageSourceNew())) goto cleanup; if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0) goto cleanup; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index a2ddecf0f2..d7c17db669 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1200,7 +1200,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, } if ((backingStore =3D virXPathString("string(./backingStore/path)", ct= xt))) { - if (VIR_ALLOC(def->target.backingStore) < 0) + if (!(def->target.backingStore =3D virStorageSourceNew())) return NULL; def->target.backingStore->type =3D VIR_STORAGE_TYPE_FILE; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 67579742fd..0a959c4bf9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2925,6 +2925,7 @@ virStorageSourceIsLocalStorage; virStorageSourceIsRelative; virStorageSourceIsSameLocation; virStorageSourceNetworkAssignDefaultPorts; +virStorageSourceNew; virStorageSourceNewFromBacking; virStorageSourceNewFromBackingAbsolute; virStorageSourceParseRBDColonString; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ac01e861f7..0c8feb25be 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2742,7 +2742,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr n= ode, goto cleanup; } - if (VIR_ALLOC(migrSource) < 0) + if (!(migrSource =3D virStorageSourceNew())) goto cleanup; if (!(type =3D virXMLPropString(ctxt->node, "type"))) { @@ -9050,7 +9050,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, /* terminate the chain for such images as the code below would do = */ if (!disksrc->backingStore && - VIR_ALLOC(disksrc->backingStore) < 0) + !(disksrc->backingStore =3D virStorageSourceNew())) goto cleanup; /* host cdrom requires special treatment in qemu, so we need to ch= eck diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 971f915619..f94955a22f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17984,7 +17984,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char = *path, const char *base, return qemuDomainBlockPullCommon(driver, vm, path, base, bandwidth= , flags); /* If we got here, we are doing a block copy rebase. */ - if (VIR_ALLOC(dest) < 0) + if (!(dest =3D virStorageSourceNew())) goto cleanup; dest->type =3D (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) ? VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index c93ae33476..8a9dbb5e63 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -794,14 +794,14 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverP= tr driver, VIR_DEBUG("starting blockdev mirror for disk=3D%s to host=3D%s", diskA= lias, host); - if (VIR_ALLOC(copysrc) < 0) + if (!(copysrc =3D virStorageSourceNew())) goto cleanup; copysrc->type =3D VIR_STORAGE_TYPE_NETWORK; copysrc->protocol =3D VIR_STORAGE_NET_PROTOCOL_NBD; copysrc->format =3D VIR_STORAGE_FILE_RAW; - if (VIR_ALLOC(copysrc->backingStore) < 0) + if (!(copysrc->backingStore =3D virStorageSourceNew())) goto cleanup; if (VIR_STRDUP(copysrc->path, diskAlias) < 0) diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 846a647cb6..854ecf2b67 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -294,7 +294,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, goto cleanup; if (meta->backingStoreRaw) { - if (VIR_ALLOC(vol->target.backingStore) < 0) + if (!(vol->target.backingStore =3D virStorageSourceNew())) goto cleanup; vol->target.backingStore->type =3D VIR_STORAGE_TYPE_NETWORK; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index f153d23aec..77e4dfb8b1 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -308,7 +308,7 @@ virStorageBackendLogicalMakeVol(char **const groups, * lv is created with "--virtualsize"). */ if (groups[1] && STRNEQ(groups[1], "") && (groups[1][0] !=3D '[')) { - if (VIR_ALLOC(vol->target.backingStore) < 0) + if (!(vol->target.backingStore =3D virStorageSourceNew())) goto cleanup; if (virAsprintf(&vol->target.backingStore->path, "%s/%s", diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index f18e38733a..3a6cc34b68 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3402,7 +3402,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, if (!virStorageSourceIsLocalStorage(target->backingStore)) { virStorageSourceFree(target->backingStore); - if (VIR_ALLOC(target->backingStore) < 0) + if (!(target->backingStore =3D virStorageSourceNew())) return -1; target->backingStore->type =3D VIR_STORAGE_TYPE_NETWORK; @@ -3576,7 +3576,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) goto cleanup; VIR_DIR_CLOSE(dir); - if (VIR_ALLOC(target)) + if (!(target =3D virStorageSourceNew())) goto cleanup; if ((fd =3D open(def->target.path, O_RDONLY)) < 0) { diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index a6d44b64a4..7f52a5fdc7 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2245,7 +2245,7 @@ virStorageSourceCopy(const virStorageSource *src, { virStorageSourcePtr def =3D NULL; - if (VIR_ALLOC(def) < 0) + if (!(def =3D virStorageSourceNew())) return NULL; def->id =3D src->id; @@ -2562,6 +2562,18 @@ virStorageSourceClear(virStorageSourcePtr def) } +virStorageSourcePtr +virStorageSourceNew(void) +{ + virStorageSourcePtr ret =3D NULL; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + return ret; +} + + void virStorageSourceFree(virStorageSourcePtr def) { @@ -2580,7 +2592,7 @@ virStorageSourceNewFromBackingRelative(virStorageSour= cePtr parent, virStorageSourcePtr def; VIR_AUTOFREE(char *) dirname =3D NULL; - if (VIR_ALLOC(def) < 0) + if (!(def =3D virStorageSourceNew())) return NULL; /* store relative name */ @@ -3627,7 +3639,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) virStorageSourcePtr def; int rc; - if (VIR_ALLOC(def) < 0) + if (!(def =3D virStorageSourceNew())) return NULL; if (virStorageIsFile(path)) { @@ -4900,7 +4912,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, } } else { /* add terminator */ - if (VIR_ALLOC(backingStore) < 0) + if (!(backingStore =3D virStorageSourceNew())) goto cleanup; } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 8c3a36d473..48af06653e 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -431,6 +431,7 @@ int virStorageSourceGetActualType(const virStorageSourc= e *def); bool virStorageSourceIsLocalStorage(const virStorageSource *src); bool virStorageSourceIsEmpty(virStorageSourcePtr src); bool virStorageSourceIsBlockLocal(const virStorageSource *src); +virStorageSourcePtr virStorageSourceNew(void); void virStorageSourceFree(virStorageSourcePtr def); void virStorageSourceBackingStoreClear(virStorageSourcePtr def); int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src, diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index d7e5e72a0b..813b20a08d 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -55,7 +55,7 @@ testBackingXMLjsonXML(const void *args) VIR_AUTOPTR(virStorageSource) xmlsrc =3D NULL; VIR_AUTOPTR(virStorageSource) jsonsrc =3D NULL; - if (VIR_ALLOC(xmlsrc) < 0) + if (!(xmlsrc =3D virStorageSourceNew())) return -1; xmlsrc->type =3D data->type; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 646ae78ff0..da70beb1f7 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -98,7 +98,7 @@ testStorageFileGetMetadata(const char *path, virStorageSourcePtr ret =3D NULL; VIR_AUTOPTR(virStorageSource) def =3D NULL; - if (VIR_ALLOC(def) < 0) + if (!(def =3D virStorageSourceNew())) return NULL; def->type =3D VIR_STORAGE_TYPE_FILE; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list