From nobody Sat May 4 06:59:54 2024 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 1549981164090188.04777785094564; Tue, 12 Feb 2019 06:19:24 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23483BDD0; Tue, 12 Feb 2019 14:19:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3CEC62988; Tue, 12 Feb 2019 14:19:20 +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 8A70A3F606; Tue, 12 Feb 2019 14:19:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJDLp012877 for ; Tue, 12 Feb 2019 09:19:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 554EA16938; Tue, 12 Feb 2019 14:19:13 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FD5C18972 for ; Tue, 12 Feb 2019 14:19:12 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:18:59 -0500 Message-Id: <20190212141906.28995-2-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 1/8] storage: Cleanup virStorageFileBackendGlusterReadlinkCallback 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 12 Feb 2019 14:19:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than having two exit paths, let's use a @retval value and VIR_STEAL_PTR in order to unite the exit path through the error label. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_file_gluster.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_= gluster.c index f8bbde8cfe..41c66c5a5d 100644 --- a/src/storage/storage_file_gluster.c +++ b/src/storage/storage_file_gluster.c @@ -262,6 +262,7 @@ virStorageFileBackendGlusterReadlinkCallback(const char= *path, size_t bufsiz =3D 0; ssize_t ret; struct stat st; + int retval =3D -1; =20 *linkpath =3D NULL; =20 @@ -291,13 +292,13 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, =20 buf[ret] =3D '\0'; =20 - *linkpath =3D buf; + VIR_STEAL_PTR(*linkpath, buf); =20 - return 0; + retval =3D 0; =20 error: VIR_FREE(buf); - return -1; + return retval; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 1549981165031858.7648009850155; Tue, 12 Feb 2019 06:19:25 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C133988E6F; Tue, 12 Feb 2019 14:19:22 +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 9218718784; Tue, 12 Feb 2019 14:19:22 +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 470641819AFD; Tue, 12 Feb 2019 14:19:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJJLH012894 for ; Tue, 12 Feb 2019 09:19:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 574BC18A49; Tue, 12 Feb 2019 14:19:19 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAF6D5C2E3 for ; Tue, 12 Feb 2019 14:19:13 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:00 -0500 Message-Id: <20190212141906.28995-3-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 2/8] storage: Use VIR_AUTOFREE for storage backends 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 12 Feb 2019 14:19:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities. This also allows for the cleanup of some goto paths. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend.c | 9 +-- src/storage/storage_backend_disk.c | 62 +++++++------------ src/storage/storage_backend_fs.c | 17 ++--- src/storage/storage_backend_gluster.c | 30 ++++----- src/storage/storage_backend_iscsi.c | 72 +++++++--------------- src/storage/storage_backend_iscsi_direct.c | 36 ++++------- src/storage/storage_backend_logical.c | 32 +++------- src/storage/storage_backend_mpath.c | 17 +++-- src/storage/storage_backend_rbd.c | 35 ++++------- src/storage/storage_backend_scsi.c | 64 +++++++------------ src/storage/storage_backend_sheepdog.c | 27 +++----- src/storage/storage_backend_vstorage.c | 25 +++----- src/storage/storage_backend_zfs.c | 15 ++--- src/storage/storage_file_gluster.c | 17 ++--- 14 files changed, 150 insertions(+), 308 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a54c338cf0..5c8275e978 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -87,8 +87,7 @@ virStorageDriverLoadBackendModule(const char *name, const char *regfunc, bool forceload) { - char *modfile =3D NULL; - int ret; + VIR_AUTOFREE(char *) modfile =3D NULL; =20 if (!(modfile =3D virFileFindResourceFull(name, "libvirt_storage_backend_", @@ -98,11 +97,7 @@ virStorageDriverLoadBackendModule(const char *name, "LIBVIRT_STORAGE_BACKEND_DIR")= )) return -1; =20 - ret =3D virModuleLoad(modfile, regfunc, forceload); - - VIR_FREE(modfile); - - return ret; + return virModuleLoad(modfile, regfunc, forceload); } =20 =20 diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_disk.c index cd2469320b..4c5b784ca7 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -56,8 +56,9 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *tmp, *devpath, *partname; + char *tmp, *partname; bool addVol =3D false; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 /* Prepended path will be same for all partitions, so we can * strip the path to form a reasonable pool-unique name @@ -89,7 +90,6 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, * way of doing this... */ vol->target.path =3D virStorageBackendStablePath(pool, devpath, tr= ue); - VIR_FREE(devpath); if (vol->target.path =3D=3D NULL) goto error; } @@ -355,12 +355,11 @@ virStorageBackendDiskReadPartitions(virStoragePoolObj= Ptr pool, */ =20 virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *parthelper_path; struct virStorageBackendDiskPoolVolData cbdata =3D { .pool =3D pool, .vol =3D vol, }; - int ret; + VIR_AUTOFREE(char *) parthelper_path =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", @@ -388,12 +387,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjP= tr pool, def->allocation =3D 0; def->capacity =3D def->available =3D 0; =20 - ret =3D virCommandRunNul(cmd, - 6, - virStorageBackendDiskMakeVol, - &cbdata); - VIR_FREE(parthelper_path); - return ret; + return virCommandRunNul(cmd, 6, virStorageBackendDiskMakeVol, &cbdata); } =20 static int @@ -419,8 +413,7 @@ static int virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *parthelper_path; - int ret; + VIR_AUTOFREE(char *) parthelper_path =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", @@ -433,12 +426,8 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr= pool) "-g", NULL); =20 - ret =3D virCommandRunNul(cmd, - 3, - virStorageBackendDiskMakePoolGeometry, - pool); - VIR_FREE(parthelper_path); - return ret; + return virCommandRunNul(cmd, 3, virStorageBackendDiskMakePoolGeometry, + pool); } =20 static int @@ -770,13 +759,12 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr p= ool, unsigned int flags) { char *part_num =3D NULL; - char *devpath =3D NULL; char *dev_name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src_path =3D def->source.devices[0].path; char *srcname =3D last_component(src_path); bool isDevMapperDevice; - int rc =3D -1; + VIR_AUTOFREE(char *) devpath =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); @@ -800,7 +788,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportSystemError(errno, _("Couldn't read volume target path '%s'"= ), vol->target.path); - goto cleanup; + return -1; } dev_name =3D last_component(devpath); } @@ -811,7 +799,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportError(VIR_ERR_INTERNAL_ERROR, _("Volume path '%s' did not start with parent " "pool source device name."), dev_name); - goto cleanup; + return -1; } =20 part_num =3D dev_name + strlen(srcname); @@ -825,7 +813,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse partition number from target " "'%s'"), dev_name); - goto cleanup; + return -1; } =20 /* eg parted /dev/sda rm 2 or /dev/mapper/mpathc rm 2 */ @@ -836,7 +824,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, part_num, NULL); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* Refreshing the pool is the easiest option as LOGICAL and EXTENDED * partition allocation/capacity management is handled within @@ -845,12 +833,9 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr po= ol, */ virStoragePoolObjClearVols(pool); if (virStorageBackendDiskRefreshPool(pool) < 0) - goto cleanup; + return -1; =20 - rc =3D 0; - cleanup: - VIR_FREE(devpath); - return rc; + return 0; } =20 =20 @@ -858,11 +843,10 @@ static int virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int res =3D -1; - char *partFormat =3D NULL; unsigned long long startOffset =3D 0, endOffset =3D 0; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr save_err; + VIR_AUTOFREE(char *)partFormat =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(PARTED, @@ -875,11 +859,11 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, vol->target.encryption->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_= LUKS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("storage pool only supports LUKS encrypted volume= s")); - goto cleanup; + return -1; } =20 if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) !=3D 0) - goto cleanup; + return -1; virCommandAddArg(cmd, partFormat); =20 /* If we're going to encrypt using LUKS, then we could need up to @@ -889,13 +873,13 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, =20 if (virStorageBackendDiskPartBoundaries(pool, &startOffset, &endOffset, vol->target.capacity) < 0) - goto cleanup; + return -1; =20 virCommandAddArgFormat(cmd, "%lluB", startOffset); virCommandAddArgFormat(cmd, "%lluB", endOffset); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* wait for device node to show up */ virWaitForDevices(); @@ -919,11 +903,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr po= ol, goto error; } =20 - res =3D 0; - - cleanup: - VIR_FREE(partFormat); - return res; + return 0; =20 error: /* Best effort to remove the partition. Ignore any errors @@ -933,7 +913,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr poo= l, ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0)); virSetError(save_err); virFreeError(save_err); - goto cleanup; + return -1; } =20 =20 diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index 0436c25af0..97148acebe 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -246,11 +246,11 @@ virStorageBackendFileSystemIsMounted(virStoragePoolOb= jPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *src =3D NULL; FILE *mtab; struct mntent ent; char buf[1024]; int rc1, rc2; + VIR_AUTOFREE(char *) src =3D NULL; =20 if ((mtab =3D fopen(_PATH_MOUNTED, "r")) =3D=3D NULL) { virReportSystemError(errno, @@ -282,7 +282,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjP= tr pool) =20 cleanup: VIR_FORCE_FCLOSE(mtab); - VIR_FREE(src); return ret; } =20 @@ -299,9 +298,8 @@ static int virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *src =3D NULL; - int ret =3D -1; int rc; + VIR_AUTOFREE(char *) src =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virStorageBackendFileSystemIsValid(pool) < 0) @@ -320,13 +318,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr = pool) return -1; =20 cmd =3D virStorageBackendFileSystemMountCmd(MOUNT, def, src); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - VIR_FREE(src); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -579,10 +571,10 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr = ctxt, void **data) { virStoragePoolFSMountOptionsDefPtr cmdopts =3D NULL; - xmlNodePtr *nodes =3D NULL; int nnodes; size_t i; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *)nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "fs", BAD_CAST STORAGE_POOL_FS_NAMESPACE_HREF) < 0) { @@ -617,7 +609,6 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr ct= xt, ret =3D 0; =20 cleanup: - VIR_FREE(nodes); virStoragePoolDefFSNamespaceFree(cmdopts); return ret; } diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 5428bb92ba..1888314d95 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -127,11 +127,9 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool) if (glfs_set_volfile_server(ret->vol, "tcp", ret->uri->server, ret->uri->port) < 0 || glfs_init(ret->vol) < 0) { - char *uri =3D virURIFormat(ret->uri); - - virReportSystemError(errno, _("failed to connect to %s"), - NULLSTR(uri)); - VIR_FREE(uri); + VIR_AUTOFREE(char *) uri =3D NULL; + uri =3D virURIFormat(ret->uri); + virReportSystemError(errno, _("failed to connect to %s"), NULLSTR(= uri)); goto error; } =20 @@ -187,9 +185,8 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGl= usterStatePtr state, virStorageVolDefPtr vol, const char *name) { - int ret =3D -1; - char *path =3D NULL; char *tmp; + VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_FREE(vol->key); VIR_FREE(vol->target.path); @@ -200,35 +197,31 @@ virStorageBackendGlusterSetMetadata(virStorageBackend= GlusterStatePtr state, if (name) { VIR_FREE(vol->name); if (VIR_STRDUP(vol->name, name) < 0) - goto cleanup; + return -1; } =20 if (virAsprintf(&path, "%s%s%s", state->volname, state->dir, vol->name) < 0) - goto cleanup; + return -1; =20 tmp =3D state->uri->path; if (virAsprintf(&state->uri->path, "/%s", path) < 0) { state->uri->path =3D tmp; - goto cleanup; + return -1; } if (!(vol->target.path =3D virURIFormat(state->uri))) { VIR_FREE(state->uri->path); state->uri->path =3D tmp; - goto cleanup; + return -1; } VIR_FREE(state->uri->path); 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) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -244,10 +237,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterStatePtr state, int ret =3D -1; glfs_fd_t *fd =3D NULL; virStorageSourcePtr meta =3D NULL; - char *header =3D NULL; ssize_t len; int backingFormat; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOFREE(char *) header =3D NULL; =20 *volptr =3D NULL; =20 @@ -333,7 +326,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, virStorageSourceFree(meta); if (fd) glfs_close(fd); - VIR_FREE(header); return ret; } =20 diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index dc1a983b58..06f815625f 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -130,27 +130,20 @@ static int virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool, const char *session) { - char *sysfs_path; - int retval =3D -1; uint32_t host; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virAsprintf(&sysfs_path, "/sys/class/iscsi_session/session%s/device", session) = < 0) - goto cleanup; + return -1; =20 if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSCSIFindLUs(pool, host) < 0) - goto cleanup; - - retval =3D 0; - - cleanup: - - VIR_FREE(sysfs_path); + return -1; =20 - return retval; + return 0; } =20 =20 @@ -167,7 +160,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, .nsources =3D 0, .sources =3D NULL }; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); @@ -226,7 +219,6 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); - VIR_FREE(portal); return ret; } =20 @@ -235,8 +227,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr po= ol, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *session =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) session =3D NULL; =20 *isActive =3D false; =20 @@ -259,10 +251,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr p= ool, return -1; } =20 - if ((session =3D virStorageBackendISCSISession(pool, true)) !=3D NULL)= { + if ((session =3D virStorageBackendISCSISession(pool, true))) *isActive =3D true; - VIR_FREE(session); - } ret =3D 0; =20 return ret; @@ -330,9 +320,8 @@ static int virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *portal =3D NULL; - char *session =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) portal =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 if (def->source.nhost !=3D 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -355,50 +344,40 @@ virStorageBackendISCSIStartPool(virStoragePoolObjPtr = pool) =20 if ((session =3D virStorageBackendISCSISession(pool, true)) =3D=3D NUL= L) { if ((portal =3D virStorageBackendISCSIPortal(&def->source)) =3D=3D= NULL) - goto cleanup; + return -1; =20 /* Create a static node record for the IQN target. Must be done * in order for login to the target */ if (virISCSINodeNew(portal, def->source.devices[0].path) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendISCSISetAuth(portal, &def->source) < 0) - goto cleanup; + return -1; =20 if (virISCSIConnectionLogin(portal, def->source.initiator.iqn, def->source.devices[0].path) < 0) - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - VIR_FREE(portal); - VIR_FREE(session); - return ret; + return 0; } =20 static int virStorageBackendISCSIRefreshPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *session =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 def->allocation =3D def->capacity =3D def->available =3D 0; =20 if ((session =3D virStorageBackendISCSISession(pool, false)) =3D=3D NU= LL) - goto cleanup; + return -1; if (virISCSIRescanLUNs(session) < 0) - goto cleanup; + return -1; if (virStorageBackendISCSIFindLUs(pool, session) < 0) - goto cleanup; - VIR_FREE(session); + return -1; =20 return 0; - - cleanup: - VIR_FREE(session); - return -1; } =20 =20 @@ -406,13 +385,11 @@ static int virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *portal; - char *session; - int ret =3D -1; + VIR_AUTOFREE(char *) portal =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 if ((session =3D virStorageBackendISCSISession(pool, true)) =3D=3D NUL= L) return 0; - VIR_FREE(session); =20 if ((portal =3D virStorageBackendISCSIPortal(&def->source)) =3D=3D NUL= L) return -1; @@ -420,12 +397,9 @@ virStorageBackendISCSIStopPool(virStoragePoolObjPtr po= ol) if (virISCSIConnectionLogout(portal, def->source.initiator.iqn, def->source.devices[0].path) < 0) - goto cleanup; - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(portal); - return ret; + return 0; } =20 virStorageBackend virStorageBackendISCSI =3D { diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 42060dd758..4ac4ad471c 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -421,15 +421,13 @@ virISCSIDirectUpdateTargets(struct iscsi_context *isc= si, } =20 for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) { - char *target =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; =20 if (VIR_STRDUP(target, tmp_addr->target_name) < 0) goto cleanup; =20 - if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) { - VIR_FREE(target); + if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) goto cleanup; - } } =20 VIR_STEAL_PTR(*targets, tmp_targets); @@ -490,7 +488,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, .nsources =3D 0, .sources =3D NULL }; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); @@ -551,7 +549,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); - VIR_FREE(portal); return ret; } =20 @@ -561,7 +558,7 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoo= lObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); struct iscsi_context *iscsi =3D NULL; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; =20 if (!(iscsi =3D virISCSIDirectCreateContext(def->source.initiator.iqn)= )) goto error; @@ -578,7 +575,6 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoo= lObjPtr pool, VIR_STEAL_PTR(*portalRet, portal); =20 cleanup: - VIR_FREE(portal); return iscsi; =20 error: @@ -591,19 +587,14 @@ static int virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool) { struct iscsi_context *iscsi =3D NULL; - char *portal =3D NULL; int ret =3D -1; - if (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) - goto cleanup; - if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0) - goto disconect; + VIR_AUTOFREE(char *) portal =3D NULL; =20 - ret =3D 0; - disconect: + if (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) + return -1; + ret =3D virISCSIDirectReportLuns(pool, iscsi, portal); virISCSIDirectDisconnect(iscsi); iscsi_destroy_context(iscsi); - cleanup: - VIR_FREE(portal); return ret; } =20 @@ -639,7 +630,7 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDe= fPtr vol, struct scsi_task *task =3D NULL; int lun =3D 0; int ret =3D -1; - unsigned char *data; + VIR_AUTOFREE(unsigned char *) data =3D NULL; =20 if (virStorageBackendISCSIDirectGetLun(vol, &lun) < 0) return ret; @@ -656,22 +647,19 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVol= DefPtr vol, if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block_size * BLOCK_PER_PACKET, block_size, 0, 0, 0, 0, 0))) - goto cleanup; + return -1; scsi_free_scsi_task(task); lba +=3D BLOCK_PER_PACKET; } else { if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block= _size, block_size, 0, 0, 0, 0, 0))) - goto cleanup; + return -1; scsi_free_scsi_task(task); lba++; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(data); - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index b8da5c7efe..c61d03519f 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -117,14 +117,14 @@ virStorageBackendLogicalParseVolExtents(virStorageVol= DefPtr vol, { int nextents, ret =3D -1; const char *regex_unit =3D "(\\S+)\\((\\S+)\\)"; - char *regex =3D NULL; - regex_t *reg =3D NULL; - regmatch_t *vars =3D NULL; char *p =3D NULL; size_t i; int err, nvars; unsigned long long offset, size, length; virStorageVolSourceExtent extent; + VIR_AUTOFREE(char *) regex =3D NULL; + VIR_AUTOFREE(regex_t *) reg =3D NULL; + VIR_AUTOFREE(regmatch_t *) vars =3D NULL; =20 memset(&extent, 0, sizeof(extent)); =20 @@ -202,7 +202,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDe= fPtr vol, for (i =3D 0; i < nextents; i++) { size_t j; int len; - char *offset_str =3D NULL; + VIR_AUTOFREE(char *) offset_str =3D NULL; =20 j =3D (i * 2) + 1; len =3D vars[j].rm_eo - vars[j].rm_so; @@ -219,10 +219,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolD= efPtr vol, if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent offset value")); - VIR_FREE(offset_str); goto cleanup; } - VIR_FREE(offset_str); extent.start =3D offset * size; extent.end =3D (offset * size) + length; =20 @@ -234,9 +232,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDe= fPtr vol, ret =3D 0; =20 cleanup: - VIR_FREE(regex); - VIR_FREE(reg); - VIR_FREE(vars); VIR_FREE(extent.path); return ret; } @@ -459,16 +454,15 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **co= nst groups, void *data) { virStoragePoolSourceListPtr sourceList =3D data; - char *pvname =3D NULL; - char *vgname =3D NULL; - int retval =3D -1; size_t i; virStoragePoolSourceDevicePtr dev; virStoragePoolSource *thisSource; + VIR_AUTOFREE(char *) pvname =3D NULL; + VIR_AUTOFREE(char *) vgname =3D NULL; =20 if (VIR_STRDUP(pvname, groups[0]) < 0 || VIR_STRDUP(vgname, groups[1]) < 0) - goto error; + return -1; =20 thisSource =3D NULL; for (i =3D 0; i < sourceList->nsources; i++) { @@ -480,13 +474,13 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **co= nst groups, =20 if (thisSource =3D=3D NULL) { if (!(thisSource =3D virStoragePoolSourceListNewSource(sourceList)= )) - goto error; + return -1; =20 VIR_STEAL_PTR(thisSource->name, vgname); } =20 if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) !=3D 0) - goto error; + return -1; =20 dev =3D &thisSource->devices[thisSource->ndevice]; thisSource->ndevice++; @@ -495,13 +489,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **con= st groups, memset(dev, 0, sizeof(*dev)); VIR_STEAL_PTR(dev->path, pvname); =20 - retval =3D 0; - - error: - VIR_FREE(pvname); - VIR_FREE(vgname); - - return retval; + return 0; } =20 /* diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_back= end_mpath.c index 423f945fbc..cb1b23288a 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -153,31 +153,31 @@ static int virStorageBackendCreateVols(virStoragePoolObjPtr pool, struct dm_names *names) { - int retval =3D -1, is_mpath =3D 0; - char *map_device =3D NULL; + int is_mpath =3D 0; uint32_t minor =3D -1; uint32_t next; + VIR_AUTOFREE(char *) map_device =3D NULL; =20 do { is_mpath =3D virStorageBackendIsMultipath(names->name); =20 if (is_mpath < 0) - goto out; + return -1; =20 if (is_mpath =3D=3D 1) { =20 if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) - goto out; + return -1; =20 if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to get %s minor number"), names->name); - goto out; + return -1; } =20 if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0) - goto out; + return -1; =20 VIR_FREE(map_device); } @@ -191,10 +191,7 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, =20 } while (next); =20 - retval =3D 0; - out: - VIR_FREE(map_device); - return retval; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index ece04f0f2d..2b7af1db23 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -86,10 +86,10 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr c= txt, void **data) { virStoragePoolRBDConfigOptionsDefPtr cmdopts =3D NULL; - xmlNodePtr *nodes =3D NULL; int nnodes; size_t i; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *)nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd", BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) { @@ -145,7 +145,6 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr c= txt, ret =3D 0; =20 cleanup: - VIR_FREE(nodes); virStoragePoolDefRBDNamespaceFree(cmdopts); return ret; } @@ -213,12 +212,12 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRB= DStatePtr ptr, char *rados_key =3D NULL; virBuffer mon_host =3D VIR_BUFFER_INITIALIZER; size_t i; - char *mon_buff =3D NULL; const char *client_mount_timeout =3D "30"; const char *mon_op_timeout =3D "30"; const char *osd_op_timeout =3D "30"; const char *rbd_default_format =3D "2"; virConnectPtr conn =3D NULL; + VIR_AUTOFREE(char *) mon_buff =3D NULL; =20 if (authdef) { VIR_DEBUG("Using cephx authorization, username: %s", authdef->user= name); @@ -348,7 +347,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDS= tatePtr ptr, =20 virObjectUnref(conn); virBufferFreeAndReset(&mon_host); - VIR_FREE(mon_buff); return ret; } =20 @@ -574,11 +572,12 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr = pool) int ret =3D -1; int len =3D -1; int r =3D 0; - char *name, *names =3D NULL; + char *name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virStorageBackendRBDStatePtr ptr =3D NULL; struct rados_cluster_stat_t clusterstat; struct rados_pool_stat_t poolstat; + VIR_AUTOFREE(char *) names =3D NULL; =20 if (!(ptr =3D virStorageBackendRBDNewState(pool))) goto cleanup; @@ -662,7 +661,6 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr po= ol) ret =3D 0; =20 cleanup: - VIR_FREE(names); virStorageBackendRBDFreeState(&ptr); return ret; } @@ -677,8 +675,8 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioct= x, int max_snaps =3D 128; int snap_count, protected; size_t i; - rbd_snap_info_t *snaps =3D NULL; rbd_image_t image =3D NULL; + VIR_AUTOFREE(rbd_snap_info_t *) snaps =3D NULL; =20 if ((r =3D rbd_open(ioctx, vol->name, &image, NULL)) < 0) { virReportSystemError(-r, _("failed to open the RBD image '%s'"), @@ -737,8 +735,6 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioct= x, if (snaps) rbd_snap_list_end(snaps); =20 - VIR_FREE(snaps); - if (image) rbd_close(image); =20 @@ -949,8 +945,8 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t imag= e, int max_snaps =3D 128; size_t i; int diff; - rbd_snap_info_t *snaps =3D NULL; rbd_image_info_t info; + VIR_AUTOFREE(rbd_snap_info_t *) snaps =3D NULL; =20 if ((r =3D rbd_stat(image, &info, sizeof(info))) < 0) { virReportSystemError(-r, _("failed to stat the RBD image %s"), @@ -1023,8 +1019,6 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t im= age, if (snaps) rbd_snap_list_end(snaps); =20 - VIR_FREE(snaps); - return ret; } =20 @@ -1098,8 +1092,8 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, uint64_t stripe_count; uint64_t stripe_unit; virBuffer snapname =3D VIR_BUFFER_INITIALIZER; - char *snapname_buff =3D NULL; rbd_image_t image =3D NULL; + VIR_AUTOFREE(char *) snapname_buff =3D NULL; =20 if ((r =3D rbd_open(io, origvol, &image, NULL)) < 0) { virReportSystemError(-r, _("failed to open the RBD image %s"), @@ -1170,7 +1164,6 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, =20 cleanup: virBufferFreeAndReset(&snapname); - VIR_FREE(snapname_buff); =20 if (image) rbd_close(image); @@ -1271,13 +1264,12 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, uint64_t stripe_count) { int r =3D -1; - int ret =3D -1; unsigned long long offset =3D 0; unsigned long long length; - char *writebuf; + VIR_AUTOFREE(char *) writebuf =3D NULL; =20 if (VIR_ALLOC_N(writebuf, info->obj_size * stripe_count) < 0) - goto cleanup; + return -1; =20 while (offset < info->size) { length =3D MIN((info->size - offset), (info->obj_size * stripe_cou= nt)); @@ -1286,7 +1278,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, virReportSystemError(-r, _("writing %llu bytes failed on " "RBD image %s at offset %llu"), length, imgname, offset); - goto cleanup; + return -1; } =20 VIR_DEBUG("Wrote %llu bytes to RBD image %s at offset %llu", @@ -1295,12 +1287,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, offset +=3D length; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(writebuf); - - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backe= nd_scsi.c index 591bcb04e2..c1470fa1d5 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -57,13 +57,13 @@ virStorageBackendSCSITriggerRescan(uint32_t host) { int fd =3D -1; int retval =3D -1; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_DEBUG("Triggering rescan of host %d", host); =20 if (virAsprintf(&path, "%s/host%u/scan", LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Scan trigger path is '%s'", path); =20 @@ -89,7 +89,6 @@ virStorageBackendSCSITriggerRescan(uint32_t host) =20 cleanup: VIR_FORCE_CLOSE(fd); - VIR_FREE(path); VIR_DEBUG("Rescan of host %d complete", host); return retval; } @@ -175,7 +174,6 @@ static char * getAdapterName(virStorageAdapterPtr adapter) { char *name =3D NULL; - char *parentaddr =3D NULL; =20 if (adapter->type =3D=3D VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) { virStorageAdapterSCSIHostPtr scsi_host =3D &adapter->data.scsi_hos= t; @@ -189,7 +187,7 @@ getAdapterName(virStorageAdapterPtr adapter) addr->slot, addr->function, unique_id))) - goto cleanup; + return NULL; } else { ignore_value(VIR_STRDUP(name, scsi_host->name)); } @@ -203,8 +201,6 @@ getAdapterName(virStorageAdapterPtr adapter) } } =20 - cleanup: - VIR_FREE(parentaddr); return name; } =20 @@ -245,10 +241,10 @@ checkParent(const char *name, const char *parent_name) { unsigned int host_num; - char *scsi_host_name =3D NULL; - char *vhba_parent =3D NULL; bool retval =3D false; virConnectPtr conn =3D NULL; + VIR_AUTOFREE(char *) scsi_host_name =3D NULL; + VIR_AUTOFREE(char *) vhba_parent =3D NULL; =20 VIR_DEBUG("name=3D%s, parent_name=3D%s", name, parent_name); =20 @@ -288,8 +284,6 @@ checkParent(const char *name, =20 cleanup: virObjectUnref(conn); - VIR_FREE(vhba_parent); - VIR_FREE(scsi_host_name); return retval; } =20 @@ -299,10 +293,9 @@ createVport(virStoragePoolDefPtr def, const char *configFile, virStorageAdapterFCHostPtr fchost) { - char *name =3D NULL; virStoragePoolFCRefreshInfoPtr cbdata =3D NULL; virThread thread; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; =20 VIR_DEBUG("configFile=3D'%s' parent=3D'%s', wwnn=3D'%s' wwpn=3D'%s'", NULLSTR(configFile), NULLSTR(fchost->parent), @@ -314,14 +307,14 @@ createVport(virStoragePoolDefPtr def, */ if ((name =3D virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) { if (!(checkName(name))) - goto cleanup; + return -1; =20 /* If a parent was provided, let's make sure the 'name' we've * retrieved has the same parent. If not this will cause failure. = */ if (!fchost->parent || checkParent(name, fchost->parent)) - ret =3D 0; + return 0; =20 - goto cleanup; + return -1; } =20 /* Since we're creating the vHBA, then we need to manage removing it @@ -333,12 +326,12 @@ createVport(virStoragePoolDefPtr def, fchost->managed =3D VIR_TRISTATE_BOOL_YES; if (configFile) { if (virStoragePoolSaveConfig(configFile, def) < 0) - goto cleanup; + return -1; } } =20 if (!(name =3D virNodeDeviceCreateVport(fchost))) - goto cleanup; + return -1; =20 /* Creating our own VPORT didn't leave enough time to find any LUN's, * so, let's create a thread whose job it is to call the FindLU's with @@ -357,11 +350,7 @@ createVport(virStoragePoolDefPtr def, } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(name); - return ret; + return 0; } =20 =20 @@ -370,10 +359,9 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr po= ol, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *path =3D NULL; - char *name =3D NULL; unsigned int host; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 *isActive =3D false; =20 @@ -391,28 +379,23 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr p= ool, } =20 if (virSCSIHostGetNumber(name, &host) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&path, "%s/host%d", LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) - goto cleanup; + return -1; =20 *isActive =3D virFileExists(path); =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(name); - return ret; + return 0; } =20 static int virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *name =3D NULL; unsigned int host; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; =20 def->allocation =3D def->capacity =3D def->available =3D 0; =20 @@ -420,20 +403,17 @@ virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr= pool) return -1; =20 if (virSCSIHostGetNumber(name, &host) < 0) - goto out; + return -1; =20 VIR_DEBUG("Scanning host%u", host); =20 if (virStorageBackendSCSITriggerRescan(host) < 0) - goto out; + return -1; =20 if (virStorageBackendSCSIFindLUs(pool, host) < 0) - goto out; + return -1; =20 - ret =3D 0; - out: - VIR_FREE(name); - return ret; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index a57faaef58..99f3283a1c 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -136,9 +136,8 @@ virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr= pool, const char *diskIn static int virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool) { - int ret =3D -1; - char *output =3D NULL; size_t i; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virString) cells =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; @@ -147,11 +146,11 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 lines =3D virStringSplit(output, "\n", 0); if (lines =3D=3D NULL) - goto cleanup; + return -1; =20 for (i =3D 0; lines[i]; i++) { const char *line =3D lines[i]; @@ -163,42 +162,34 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) if (cells !=3D NULL && virStringListLength((const char * const *)cells) > 2) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) - goto cleanup; + return -1; } =20 virStringListFree(cells); cells =3D NULL; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(output); - return ret; + return 0; } =20 =20 static int virStorageBackendSheepdogRefreshPool(virStoragePoolObjPtr pool) { - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseNodeInfo(virStoragePoolObjGetDef(poo= l), output) < 0) - goto cleanup; + return -1; =20 - ret =3D virStorageBackendSheepdogRefreshAllVol(pool); - cleanup: - VIR_FREE(output); - return ret; + return virStorageBackendSheepdogRefreshAllVol(pool); } =20 =20 diff --git a/src/storage/storage_backend_vstorage.c b/src/storage/storage_b= ackend_vstorage.c index 8c5becd4c4..df157a48b1 100644 --- a/src/storage/storage_backend_vstorage.c +++ b/src/storage/storage_backend_vstorage.c @@ -39,9 +39,9 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *grp_name =3D NULL; - char *usr_name =3D NULL; - char *mode =3D NULL; + VIR_AUTOFREE(char *) grp_name =3D NULL; + VIR_AUTOFREE(char *) usr_name =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Check the permissions */ @@ -55,13 +55,13 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) /* Convert ids to names because vstorage uses names */ =20 if (!(grp_name =3D virGetGroupName(def->target.perms.gid))) - goto cleanup; + return -1; =20 if (!(usr_name =3D virGetUserName(def->target.perms.uid))) - goto cleanup; + return -1; =20 if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0) - goto cleanup; + return -1; =20 cmd =3D virCommandNewArgList(VSTORAGE_MOUNT, "-c", def->source.name, @@ -70,15 +70,7 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) "-g", grp_name, "-u", usr_name, NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - ret =3D 0; - - cleanup: - VIR_FREE(mode); - VIR_FREE(grp_name); - VIR_FREE(usr_name); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -90,7 +82,7 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool) FILE *mtab; struct mntent ent; char buf[1024]; - char *cluster =3D NULL; + VIR_AUTOFREE(char *) cluster =3D NULL; =20 if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0) return -1; @@ -115,7 +107,6 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool) =20 cleanup: VIR_FORCE_FCLOSE(mtab); - VIR_FREE(cluster); return ret; } =20 diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 7d1a3dd2cd..7ffdff638e 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -52,7 +52,7 @@ static int virStorageBackendZFSVolModeNeeded(void) { int ret =3D -1, exit_code =3D -1; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* 'zfs get' without arguments prints out @@ -77,7 +77,6 @@ virStorageBackendZFSVolModeNeeded(void) ret =3D 0; =20 cleanup: - VIR_FREE(error); return ret; } =20 @@ -86,13 +85,12 @@ virStorageBackendZFSCheckPool(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *devpath; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 if (virAsprintf(&devpath, "/dev/zvol/%s", def->source.name) < 0) return -1; *isActive =3D virFileIsDir(devpath); - VIR_FREE(devpath); =20 return 0; } @@ -178,10 +176,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *volumes_list =3D NULL; size_t i; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) volumes_list =3D NULL; =20 /** * $ zfs list -Hp -t volume -o name,volsize -r test @@ -203,10 +201,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, NULL); virCommandSetOutputBuffer(cmd, &volumes_list); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (!(lines =3D virStringSplit(volumes_list, "\n", 0))) - goto cleanup; + return -1; =20 for (i =3D 0; lines[i]; i++) { if (STREQ(lines[i], "")) @@ -216,9 +214,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, continue; } =20 - cleanup: - VIR_FREE(volumes_list); - return 0; } =20 diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_= gluster.c index 41c66c5a5d..7c2189d297 100644 --- a/src/storage/storage_file_gluster.c +++ b/src/storage/storage_file_gluster.c @@ -258,11 +258,10 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, void *data) { virStorageFileBackendGlusterPrivPtr priv =3D data; - char *buf =3D NULL; size_t bufsiz =3D 0; ssize_t ret; struct stat st; - int retval =3D -1; + VIR_AUTOFREE(char *) buf =3D NULL; =20 *linkpath =3D NULL; =20 @@ -278,13 +277,13 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, =20 realloc: if (VIR_EXPAND_N(buf, bufsiz, 256) < 0) - goto error; + return -1; =20 if ((ret =3D glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) { virReportSystemError(errno, _("failed to read link of gluster file '%s'"), path); - goto error; + return -1; } =20 if (ret =3D=3D bufsiz) @@ -294,11 +293,7 @@ virStorageFileBackendGlusterReadlinkCallback(const cha= r *path, =20 VIR_STEAL_PTR(*linkpath, buf); =20 - retval =3D 0; - - error: - VIR_FREE(buf); - return retval; + return 0; } =20 =20 @@ -306,7 +301,7 @@ static const char * virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src) { virStorageFileBackendGlusterPrivPtr priv =3D src->drv->priv; - char *filePath =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; =20 if (priv->canonpath) return priv->canonpath; @@ -322,8 +317,6 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStor= ageSourcePtr src) src->volume, filePath)); =20 - VIR_FREE(filePath); - return priv->canonpath; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 1549981168824634.3224782772955; Tue, 12 Feb 2019 06:19:28 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 479A889AC9; Tue, 12 Feb 2019 14:19:25 +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 E85A0183A0; Tue, 12 Feb 2019 14:19:24 +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 804271819AFD; Tue, 12 Feb 2019 14:19:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJNdx012905 for ; Tue, 12 Feb 2019 09:19:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2C19518971; Tue, 12 Feb 2019 14:19:23 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D80BE18B14 for ; Tue, 12 Feb 2019 14:19:19 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:01 -0500 Message-Id: <20190212141906.28995-4-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 3/8] storage: Rework ret logic in storageBackendUpdateVolTargetInfo 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 12 Feb 2019 14:19:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than overload @ret with trying serve multiple purposes, let's initialize @ret to -1 and introduce an @rc function return value that can be used for functions that may return -1 or -2 and only override @ret when rc < 0. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_util.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 57624425d0..df3dfeb319 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1754,24 +1754,26 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, unsigned int openflags, unsigned int readflags) { - int ret, fd =3D -1; + int ret =3D -1; + int rc; + int fd =3D -1; struct stat sb; ssize_t len =3D VIR_STORAGE_MAX_HEADER; VIR_AUTOFREE(char *) buf =3D NULL; =20 - if ((ret =3D virStorageBackendVolOpen(target->path, &sb, openflags)) <= 0) - goto cleanup; - fd =3D ret; + if ((rc =3D virStorageBackendVolOpen(target->path, &sb, openflags)) < = 0) + return rc; + fd =3D rc; =20 - if ((ret =3D virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) = < 0) + if ((virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0) goto cleanup; =20 if ((voltype =3D=3D VIR_STORAGE_VOL_FILE || voltype =3D=3D VIR_STORAGE= _VOL_BLOCK) && target->format !=3D VIR_STORAGE_FILE_NONE) { if (S_ISDIR(sb.st_mode)) { if (storageBackendIsPloopDir(target->path)) { - if ((ret =3D storageBackendRedoPloopUpdate(target, &sb, &f= d, - openflags)) < 0) + if ((storageBackendRedoPloopUpdate(target, &sb, &fd, + openflags)) < 0) goto cleanup; target->format =3D VIR_STORAGE_FILE_PLOOP; } else { @@ -1782,7 +1784,6 @@ storageBackendUpdateVolTargetInfo(virStorageVolType v= oltype, =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot seek to start of '%s'"),= target->path); - ret =3D -1; goto cleanup; } =20 @@ -1795,23 +1796,24 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, virReportSystemError(errno, _("cannot read header '%s'"), target->path); - ret =3D -1; } goto cleanup; } =20 - if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) { - ret =3D -1; + if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) goto cleanup; - } } =20 if (withBlockVolFormat) { - if ((ret =3D virStorageBackendDetectBlockVolFormatFD(target, fd, - readflags)) < 0) + if ((rc =3D virStorageBackendDetectBlockVolFormatFD(target, fd, + readflags)) < 0)= { + ret =3D rc; goto cleanup; + } } =20 + ret =3D 0; + cleanup: VIR_FORCE_CLOSE(fd); return ret; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 154998116893234.26031278046321; Tue, 12 Feb 2019 06:19:28 -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 A3A8366961; Tue, 12 Feb 2019 14:19:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7147D5D982; Tue, 12 Feb 2019 14:19:26 +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 2B3BD3F608; Tue, 12 Feb 2019 14:19:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJN1G012910 for ; Tue, 12 Feb 2019 09:19:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id B266618971; Tue, 12 Feb 2019 14:19:23 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55B6918979; Tue, 12 Feb 2019 14:19:23 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:02 -0500 Message-Id: <20190212141906.28995-5-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v3 4/8] storage: Use VIR_AUTOCLOSE 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]); Tue, 12 Feb 2019 14:19:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Modify code to use the VIR_AUTOCLOSE logic cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend_logical.c | 3 +- src/storage/storage_backend_scsi.c | 13 +-- src/storage/storage_file_fs.c | 15 +-- src/storage/storage_util.c | 143 +++++++++----------------- src/util/virstoragefile.c | 39 +++---- 5 files changed, 74 insertions(+), 139 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index c61d03519f..f153d23aec 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -911,10 +911,10 @@ static int virStorageBackendLogicalCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int fd =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr err; struct stat sb; + VIR_AUTOCLOSE fd =3D -1; =20 vol->type =3D VIR_STORAGE_VOL_BLOCK; =20 @@ -971,7 +971,6 @@ virStorageBackendLogicalCreateVol(virStoragePoolObjPtr = pool, =20 error: err =3D virSaveLastError(); - VIR_FORCE_CLOSE(fd); virStorageBackendLogicalDeleteVol(pool, vol, 0); virSetError(err); virFreeError(err); diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backe= nd_scsi.c index c1470fa1d5..1c27fc74f6 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -55,8 +55,7 @@ struct _virStoragePoolFCRefreshInfo { static int virStorageBackendSCSITriggerRescan(uint32_t host) { - int fd =3D -1; - int retval =3D -1; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_DEBUG("Triggering rescan of host %d", host); @@ -73,7 +72,7 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Could not open '%s' to trigger host scan"), path); - goto cleanup; + return -1; } =20 if (safewrite(fd, @@ -82,15 +81,11 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Write to '%s' to trigger host scan failed"= ), path); - goto cleanup; + return -1; } =20 - retval =3D 0; - - cleanup: - VIR_FORCE_CLOSE(fd); VIR_DEBUG("Rescan of host %d complete", host); - return retval; + return 0; } =20 /** diff --git a/src/storage/storage_file_fs.c b/src/storage/storage_file_fs.c index 3b6ed6e34d..8817970f44 100644 --- a/src/storage/storage_file_fs.c +++ b/src/storage/storage_file_fs.c @@ -83,8 +83,8 @@ virStorageFileBackendFileInit(virStorageSourcePtr src) static int virStorageFileBackendFileCreate(virStorageSourcePtr src) { - int fd =3D -1; mode_t mode =3D S_IRUSR; + VIR_AUTOCLOSE fd =3D -1; =20 if (!src->readonly) mode |=3D S_IWUSR; @@ -95,7 +95,6 @@ virStorageFileBackendFileCreate(virStorageSourcePtr src) return -1; } =20 - VIR_FORCE_CLOSE(fd); return 0; } =20 @@ -121,8 +120,8 @@ virStorageFileBackendFileRead(virStorageSourcePtr src, size_t len, char **buf) { - int fd =3D -1; ssize_t ret =3D -1; + VIR_AUTOCLOSE fd =3D -1; =20 if ((fd =3D virFileOpenAs(src->path, O_RDONLY, 0, src->drv->uid, src->drv->gid, 0)) < 0) { @@ -134,19 +133,15 @@ virStorageFileBackendFileRead(virStorageSourcePtr src, if (offset > 0) { if (lseek(fd, offset, SEEK_SET) =3D=3D (off_t) -1) { virReportSystemError(errno, _("cannot seek into '%s'"), src->p= ath); - goto cleanup; + return -1; } } =20 if ((ret =3D virFileReadHeaderFD(fd, len, buf)) < 0) { - virReportSystemError(errno, - _("cannot read header '%s'"), src->path); - goto cleanup; + virReportSystemError(errno, _("cannot read header '%s'"), src->pat= h); + return -1; } =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; } =20 diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index df3dfeb319..60a42a2828 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -130,7 +130,6 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, bool want_sparse, bool reflink_copy) { - int inputfd =3D -1; int amtread =3D -1; int ret =3D 0; size_t rbytes =3D READ_BLOCK_SIZE_DEFAULT; @@ -139,13 +138,14 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, struct stat st; VIR_AUTOFREE(char *) zerobuf =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOCLOSE inputfd =3D -1; =20 if ((inputfd =3D open(inputvol->target.path, O_RDONLY)) < 0) { ret =3D -errno; virReportSystemError(errno, _("could not open input path '%s'"), inputvol->target.path); - goto cleanup; + return ret; } =20 #ifdef __linux__ @@ -157,15 +157,11 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, if (wbytes < WRITE_BLOCK_SIZE_DEFAULT) wbytes =3D WRITE_BLOCK_SIZE_DEFAULT; =20 - if (VIR_ALLOC_N(zerobuf, wbytes) < 0) { - ret =3D -errno; - goto cleanup; - } + if (VIR_ALLOC_N(zerobuf, wbytes) < 0) + return -errno; =20 - if (VIR_ALLOC_N(buf, rbytes) < 0) { - ret =3D -errno; - goto cleanup; - } + if (VIR_ALLOC_N(buf, rbytes) < 0) + return -errno; =20 if (reflink_copy) { if (reflinkCloneFile(fd, inputfd) < 0) { @@ -173,10 +169,10 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, virReportSystemError(errno, _("failed to clone files from '%s'"), inputvol->target.path); - goto cleanup; + return ret; } else { VIR_DEBUG("btrfs clone finished."); - goto cleanup; + return 0; } } =20 @@ -191,7 +187,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, virReportSystemError(errno, _("failed reading from file '%s'"), inputvol->target.path); - goto cleanup; + return ret; } *total -=3D amtread; =20 @@ -208,14 +204,14 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, virReportSystemError(errno, _("cannot extend file '%s'"), vol->target.path); - goto cleanup; + return ret; } } else if (safewrite(fd, buf+offset, interval) < 0) { ret =3D -errno; virReportSystemError(errno, _("failed writing to file '%s'"), vol->target.path); - goto cleanup; + return ret; =20 } } while ((amtleft -=3D interval) > 0); @@ -225,23 +221,18 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, ret =3D -errno; virReportSystemError(errno, _("cannot sync data to file '%s'"), vol->target.path); - goto cleanup; + return ret; } =20 - if (VIR_CLOSE(inputfd) < 0) { ret =3D -errno; virReportSystemError(errno, _("cannot close file '%s'"), inputvol->target.path); - goto cleanup; + return ret; } - inputfd =3D -1; - - cleanup: - VIR_FORCE_CLOSE(inputfd); =20 - return ret; + return 0; } =20 static int @@ -250,14 +241,13 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED, virStorageVolDefPtr inputvol, unsigned int flags) { - int fd =3D -1; - int ret =3D -1; unsigned long long remain; struct stat st; gid_t gid; uid_t uid; mode_t mode; bool reflink_copy =3D false; + VIR_AUTOCLOSE fd =3D -1; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | VIR_STORAGE_VOL_CREATE_REFLINK, @@ -267,7 +257,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("metadata preallocation is not supported for bloc= k " "volumes")); - goto cleanup; + return -1; } =20 if (flags & VIR_STORAGE_VOL_CREATE_REFLINK) @@ -277,7 +267,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, virReportSystemError(errno, _("cannot create path '%s'"), vol->target.path); - goto cleanup; + return -1; } =20 remain =3D vol->target.capacity; @@ -285,13 +275,13 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED, if (inputvol) { if (virStorageBackendCopyToFD(vol, inputvol, fd, &remain, false, reflink_copy) < 0) - goto cleanup; + return -1; } =20 if (fstat(fd, &st) =3D=3D -1) { virReportSystemError(errno, _("stat of '%s' failed"), vol->target.path); - goto cleanup; + return -1; } uid =3D (vol->target.perms->uid !=3D st.st_uid) ? vol->target.perms->u= id : (uid_t)-1; @@ -303,7 +293,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, _("cannot chown '%s' to (%u, %u)"), vol->target.path, (unsigned int)uid, (unsigned int)gid); - goto cleanup; + return -1; } =20 mode =3D (vol->target.perms->mode =3D=3D (mode_t)-1 ? @@ -312,21 +302,16 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED, virReportSystemError(errno, _("cannot set mode of '%s' to %04o"), vol->target.path, mode); - goto cleanup; + return -1; } if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("cannot close file '%s'"), vol->target.path); - goto cleanup; + return -1; } - fd =3D -1; =20 - ret =3D 0; - cleanup: - VIR_FORCE_CLOSE(fd); - - return ret; + return 0; } =20 static int @@ -419,11 +404,11 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int ret =3D -1; - int fd =3D -1; int operation_flags; bool reflink_copy =3D false; mode_t open_mode =3D VIR_STORAGE_DEFAULT_VOL_PERM_MODE; bool created =3D false; + VIR_AUTOCLOSE fd =3D -1; =20 virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | VIR_STORAGE_VOL_CREATE_REFLINK, @@ -501,7 +486,6 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, ignore_value(virFileRemove(vol->target.path, vol->target.perms->uid, vol->target.perms->gid)); - VIR_FORCE_CLOSE(fd); return ret; } =20 @@ -542,7 +526,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr= pool, * re-open the file and attempt to force the mode change. */ if (mode !=3D (st.st_mode & S_IRWXUGO)) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; int flags =3D VIR_FILE_OPEN_FORK | VIR_FILE_OPEN_FORCE= _MODE; =20 if ((fd =3D virFileOpenAs(vol->target.path, O_RDWR, mo= de, @@ -550,7 +534,6 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr= pool, vol->target.perms->gid, flags)) >=3D 0) { /* Success - means we're good */ - VIR_FORCE_CLOSE(fd); ret =3D 0; goto cleanup; } @@ -1227,10 +1210,10 @@ storageBackendCreateQemuImgSecretPath(virStoragePoo= lObjPtr pool, { virStorageEncryptionPtr enc =3D vol->target.encryption; char *secretPath =3D NULL; - int fd =3D -1; uint8_t *secret =3D NULL; size_t secretlen =3D 0; virConnectPtr conn =3D NULL; + VIR_AUTOCLOSE fd =3D -1; =20 if (!enc) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1268,7 +1251,6 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolO= bjPtr pool, _("failed to write secret file")); goto error; } - VIR_FORCE_CLOSE(fd); =20 if ((vol->target.perms->uid !=3D (uid_t)-1) && (vol->target.perms->gid !=3D (gid_t)-1)) { @@ -1283,7 +1265,6 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolO= bjPtr pool, cleanup: virObjectUnref(conn); VIR_DISPOSE_N(secret, secretlen); - VIR_FORCE_CLOSE(fd); =20 return secretPath; =20 @@ -1754,19 +1735,18 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, unsigned int openflags, unsigned int readflags) { - int ret =3D -1; int rc; - int fd =3D -1; struct stat sb; ssize_t len =3D VIR_STORAGE_MAX_HEADER; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOCLOSE fd =3D -1; =20 if ((rc =3D virStorageBackendVolOpen(target->path, &sb, openflags)) < = 0) return rc; fd =3D rc; =20 if ((virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0) - goto cleanup; + return -1; =20 if ((voltype =3D=3D VIR_STORAGE_VOL_FILE || voltype =3D=3D VIR_STORAGE= _VOL_BLOCK) && target->format !=3D VIR_STORAGE_FILE_NONE) { @@ -1774,49 +1754,39 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, if (storageBackendIsPloopDir(target->path)) { if ((storageBackendRedoPloopUpdate(target, &sb, &fd, openflags)) < 0) - goto cleanup; + return -1; target->format =3D VIR_STORAGE_FILE_PLOOP; } else { - ret =3D 0; - goto cleanup; + return 0; } } =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot seek to start of '%s'"),= target->path); - goto cleanup; + return -1; } =20 if ((len =3D virFileReadHeaderFD(fd, len, &buf)) < 0) { if (readflags & VIR_STORAGE_VOL_READ_NOERROR) { VIR_WARN("ignoring failed header read for '%s'", target->path); - ret =3D -2; + return -2; } else { virReportSystemError(errno, _("cannot read header '%s'"), target->path); + return -1; } - goto cleanup; } =20 if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) - goto cleanup; - } - - if (withBlockVolFormat) { - if ((rc =3D virStorageBackendDetectBlockVolFormatFD(target, fd, - readflags)) < 0)= { - ret =3D rc; - goto cleanup; - } + return -1; } =20 - ret =3D 0; + if (withBlockVolFormat) + return virStorageBackendDetectBlockVolFormatFD(target, fd, readfla= gs); =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + return 0; } =20 /* @@ -2622,9 +2592,9 @@ storageBackendVolWipeLocalFile(const char *path, unsigned long long allocation, bool zero_end) { - int ret =3D -1, fd =3D -1; const char *alg_char =3D NULL; struct stat st; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 fd =3D open(path, O_RDWR); @@ -2632,14 +2602,14 @@ storageBackendVolWipeLocalFile(const char *path, virReportSystemError(errno, _("Failed to open storage volume with path '%= s'"), path); - goto cleanup; + return -1; } =20 if (fstat(fd, &st) =3D=3D -1) { virReportSystemError(errno, _("Failed to stat storage volume with path '%= s'"), path); - goto cleanup; + return -1; } =20 switch ((virStorageVolWipeAlgorithm) algorithm) { @@ -2673,12 +2643,12 @@ storageBackendVolWipeLocalFile(const char *path, case VIR_STORAGE_VOL_WIPE_ALG_TRIM: virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("'trim' algorithm not supported")); - goto cleanup; + return -1; case VIR_STORAGE_VOL_WIPE_ALG_LAST: virReportError(VIR_ERR_INVALID_ARG, _("unsupported algorithm %d"), algorithm); - goto cleanup; + return -1; } =20 VIR_DEBUG("Wiping file '%s' with algorithm '%s'", path, alg_char); @@ -2687,24 +2657,14 @@ storageBackendVolWipeLocalFile(const char *path, cmd =3D virCommandNew(SCRUB); virCommandAddArgList(cmd, "-f", "-p", alg_char, path, NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - } else { - if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)= ) { - ret =3D storageBackendVolZeroSparseFileLocal(path, st.st_size,= fd); - } else { - ret =3D storageBackendWipeLocal(path, fd, allocation, st.st_bl= ksize, - zero_end); - } - if (ret < 0) - goto cleanup; + return virCommandRun(cmd, NULL); } =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) + return storageBackendVolZeroSparseFileLocal(path, st.st_size, fd); + + return storageBackendWipeLocal(path, fd, allocation, st.st_blksize, + zero_end); } =20 =20 @@ -3397,11 +3357,11 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, virStorageEncryptionPtr *encryption) { int backingStoreFormat; - int fd =3D -1; int ret =3D -1; int rc; virStorageSourcePtr meta =3D NULL; struct stat sb; + VIR_AUTOCLOSE fd =3D -1; =20 if (encryption) *encryption =3D NULL; @@ -3502,7 +3462,6 @@ storageBackendProbeTarget(virStorageSourcePtr target, } =20 cleanup: - VIR_FORCE_CLOSE(fd); virStorageSourceFree(meta); return ret; } @@ -3574,8 +3533,9 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) struct stat statbuf; virStorageSourcePtr target =3D NULL; int direrr; - int fd =3D -1, ret =3D -1; + int ret =3D -1; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOCLOSE fd =3D -1; =20 if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; @@ -3666,7 +3626,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) ret =3D 0; cleanup: VIR_DIR_CLOSE(dir); - VIR_FORCE_CLOSE(fd); virStorageSourceFree(target); if (ret < 0) virStoragePoolObjClearVols(pool); diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b08070b782..5a8e5667f5 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1080,10 +1080,9 @@ virStorageFileGetMetadataInternal(virStorageSourcePt= r meta, int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid) { - int fd; - int ret =3D -1; struct stat sb; ssize_t len =3D VIR_STORAGE_MAX_HEADER; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOFREE(char *) header =3D NULL; =20 if ((fd =3D virFileOpenAs(path, O_RDONLY, 0, uid, gid, 0)) < 0) { @@ -1093,31 +1092,24 @@ virStorageFileProbeFormat(const char *path, uid_t u= id, gid_t gid) =20 if (fstat(fd, &sb) < 0) { virReportSystemError(errno, _("cannot stat file '%s'"), path); - goto cleanup; + return -1; } =20 /* No header to probe for directories */ - if (S_ISDIR(sb.st_mode)) { - ret =3D VIR_STORAGE_FILE_DIR; - goto cleanup; - } + if (S_ISDIR(sb.st_mode)) + return VIR_STORAGE_FILE_DIR; =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot set to start of '%s'"), path= ); - goto cleanup; + return -1; } =20 if ((len =3D virFileReadHeaderFD(fd, len, &header)) < 0) { virReportSystemError(errno, _("cannot read header '%s'"), path); - goto cleanup; + return -1; } =20 - ret =3D virStorageFileProbeFormatFromBuf(path, header, len); - - cleanup: - VIR_FORCE_CLOSE(fd); - - return ret; + return virStorageFileProbeFormatFromBuf(path, header, len); } =20 =20 @@ -1312,13 +1304,12 @@ virStorageFileResize(const char *path, unsigned long long capacity, bool pre_allocate) { - int fd =3D -1; - int ret =3D -1; int rc; + VIR_AUTOCLOSE fd =3D -1; =20 if ((fd =3D open(path, O_RDWR)) < 0) { virReportSystemError(errno, _("Unable to open '%s'"), path); - goto cleanup; + return -1; } =20 if (pre_allocate) { @@ -1331,26 +1322,22 @@ virStorageFileResize(const char *path, _("Failed to pre-allocate space for " "file '%s'"), path); } - goto cleanup; + return -1; } } =20 if (ftruncate(fd, capacity) < 0) { virReportSystemError(errno, _("Failed to truncate file '%s'"), path); - goto cleanup; + return -1; } =20 if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("Unable to save '%s'"), path); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + return 0; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 154998117277953.69302791120697; Tue, 12 Feb 2019 06:19:32 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 785C188E51; Tue, 12 Feb 2019 14:19:30 +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 4491317A62; Tue, 12 Feb 2019 14:19:30 +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 F0A7F1819AFD; Tue, 12 Feb 2019 14:19:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJRBP012927 for ; Tue, 12 Feb 2019 09:19:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 22A2718A49; Tue, 12 Feb 2019 14:19:27 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA0B718A66 for ; Tue, 12 Feb 2019 14:19:23 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:03 -0500 Message-Id: <20190212141906.28995-6-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 5/8] tests: Fix memory leak in testCompareXMLToArgvFiles 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 12 Feb 2019 14:19:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Only one path will consume the @def; otherwise, we need to free it. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- tests/storagepoolxml2argvtest.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtes= t.c index 288b81af1d..b7e32064af 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -25,29 +25,33 @@ testCompareXMLToArgvFiles(bool shouldFail, int ret =3D -1; virStoragePoolDefPtr def =3D NULL; virStoragePoolObjPtr pool =3D NULL; + const char *defTypeStr; VIR_AUTOFREE(char *) actualCmdline =3D NULL; VIR_AUTOFREE(char *) src =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(def =3D virStoragePoolDefParseFile(poolxml))) goto cleanup; + defTypeStr =3D virStoragePoolTypeToString(def->type); =20 switch ((virStoragePoolType)def->type) { case VIR_STORAGE_POOL_FS: case VIR_STORAGE_POOL_NETFS: if (!(pool =3D virStoragePoolObjNew())) { - VIR_TEST_DEBUG("pool type %d alloc pool obj fails\n", def->typ= e); + VIR_TEST_DEBUG("pool type '%s' alloc pool obj fails\n", defTyp= eStr); virStoragePoolDefFree(def); goto cleanup; } virStoragePoolObjSetDef(pool, def); =20 if (!(src =3D virStorageBackendFileSystemGetPoolSource(pool))) { - VIR_TEST_DEBUG("pool type %d has no pool source\n", def->type); + VIR_TEST_DEBUG("pool type '%s' has no pool source\n", defTypeS= tr); + def =3D NULL; goto cleanup; } =20 cmd =3D virStorageBackendFileSystemMountCmd(MOUNT, def, src); + def =3D NULL; break; =20 case VIR_STORAGE_POOL_LOGICAL: @@ -67,12 +71,12 @@ testCompareXMLToArgvFiles(bool shouldFail, case VIR_STORAGE_POOL_VSTORAGE: case VIR_STORAGE_POOL_LAST: default: - VIR_TEST_DEBUG("pool type %d has no xml2argv test\n", def->type); + VIR_TEST_DEBUG("pool type '%s' has no xml2argv test\n", defTypeStr= ); goto cleanup; }; =20 if (!(actualCmdline =3D virCommandToString(cmd, false))) { - VIR_TEST_DEBUG("pool type %d failed to get commandline\n", def->ty= pe); + VIR_TEST_DEBUG("pool type '%s' failed to get commandline\n", defTy= peStr); goto cleanup; } =20 @@ -83,6 +87,7 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: + virStoragePoolDefFree(def); virStoragePoolObjEndAPI(&pool); if (shouldFail) { virResetLastError(); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 1549981175771337.5155668301544; Tue, 12 Feb 2019 06:19:35 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE3D589ACD; Tue, 12 Feb 2019 14:19:32 +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 9C91318B28; Tue, 12 Feb 2019 14:19:32 +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 4FE69181A000; Tue, 12 Feb 2019 14:19:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJSFn012932 for ; Tue, 12 Feb 2019 09:19:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 209FC18B28; Tue, 12 Feb 2019 14:19:28 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF28918A66 for ; Tue, 12 Feb 2019 14:19:27 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:04 -0500 Message-Id: <20190212141906.28995-7-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 6/8] conf: Check for duplicate authdef during hostdev iSCSI processing 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 12 Feb 2019 14:19:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If virDomainHostdevSubsysSCSIiSCSIDefParseXML processing finds a duplicated structure, we should error out rather than continue. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9e46cf721b..2d75849e3d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7616,6 +7616,12 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePt= r sourcenode, while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, "auth")) { + if (iscsisrc->src->auth) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("an definition already found for " + "the iSCSI definition")); + return -1; + } if (!(authdef =3D virStorageAuthDefParse(cur, ctxt))) return -1; if ((auth_secret_usage =3D --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 1549981180012519.7986075128863; Tue, 12 Feb 2019 06:19:40 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F32CA80467; Tue, 12 Feb 2019 14:19:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBDC3177B6; Tue, 12 Feb 2019 14:19:36 +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 779703F60B; Tue, 12 Feb 2019 14:19:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJZtX012954 for ; Tue, 12 Feb 2019 09:19:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3234618979; Tue, 12 Feb 2019 14:19:35 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id E045118B84 for ; Tue, 12 Feb 2019 14:19:28 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:05 -0500 Message-Id: <20190212141906.28995-8-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 7/8] util: Check for duplicated id in virStorageSourceParseRBDColonString 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 12 Feb 2019 14:19:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If we find multiple "id=3D" strings during processing, then we need to force an error since we cannot have multiple 's defined for a single source volume. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5a8e5667f5..8d85d9dac4 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2840,6 +2840,11 @@ virStorageSourceParseRBDColonString(const char *rbds= tr, =20 if (STRPREFIX(p, "id=3D")) { /* formulate authdef for src->auth */ + if (src->auth) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("duplicate 'id' found in '%s'"), src->pat= h); + return -1; + } if (VIR_ALLOC(authdef) < 0) return -1; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 06:59:54 2024 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 1549981191423378.92617127100027; Tue, 12 Feb 2019 06:19:51 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id D996C36807; Tue, 12 Feb 2019 14:19:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A698617CC0; Tue, 12 Feb 2019 14:19:47 +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 5C77C3F60F; Tue, 12 Feb 2019 14:19:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CEJjS8012998 for ; Tue, 12 Feb 2019 09:19:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F76D18A66; Tue, 12 Feb 2019 14:19:45 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id E413918B23; Tue, 12 Feb 2019 14:19:35 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 09:19:06 -0500 Message-Id: <20190212141906.28995-9-jferlan@redhat.com> In-Reply-To: <20190212141906.28995-1-jferlan@redhat.com> References: <20190212141906.28995-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 8/8] util: Introduce VIR_DEFINE_AUTOPTR_FUNC for 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-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 12 Feb 2019 14:19:50 +0000 (UTC) Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 3 +- src/qemu/qemu_domain.c | 3 +- src/qemu/qemu_driver.c | 9 +- src/qemu/qemu_migration.c | 3 +- src/storage/storage_backend_gluster.c | 3 +- src/storage/storage_util.c | 25 ++--- src/util/virstoragefile.c | 141 +++++++++++--------------- src/util/virstoragefile.h | 1 + tests/qemublocktest.c | 6 +- tests/virstoragetest.c | 50 ++++----- 10 files changed, 97 insertions(+), 147 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2d75849e3d..5d49f4388c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9065,13 +9065,13 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr c= txt, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - virStorageSourcePtr backingStore =3D NULL; xmlNodePtr save_ctxt =3D ctxt->node; xmlNodePtr source; char *type =3D NULL; char *format =3D NULL; char *idx =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) backingStore =3D NULL; =20 if (!(ctxt->node =3D virXPathNode("./backingStore", ctxt))) { ret =3D 0; @@ -9132,7 +9132,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, ret =3D 0; =20 cleanup: - virStorageSourceFree(backingStore); VIR_FREE(type); VIR_FREE(format); VIR_FREE(idx); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 801d25a44b..ac01e861f7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2730,10 +2730,10 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr= node, { xmlNodePtr savedNode =3D ctxt->node; qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - virStorageSourcePtr migrSource =3D NULL; char *format =3D NULL; char *type =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) migrSource =3D NULL; =20 ctxt->node =3D node; =20 @@ -2781,7 +2781,6 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr n= ode, ret =3D 0; =20 cleanup: - virStorageSourceFree(migrSource); VIR_FREE(format); VIR_FREE(type); ctxt->node =3D savedNode; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1822248749..dc51de0310 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -274,11 +274,11 @@ qemuSecurityChownCallback(const virStorageSource *src, uid_t uid, gid_t gid) { - virStorageSourcePtr cpy =3D NULL; struct stat sb; int save_errno =3D 0; int ret =3D -1; int rv; + VIR_AUTOPTR(virStorageSource) cpy =3D NULL; =20 rv =3D virStorageFileSupportsSecurityDriver(src); if (rv <=3D 0) @@ -319,7 +319,6 @@ qemuSecurityChownCallback(const virStorageSource *src, cleanup: save_errno =3D errno; virStorageFileDeinit(cpy); - virStorageSourceFree(cpy); errno =3D save_errno; =20 return ret; @@ -17958,7 +17957,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char = *path, const char *base, virDomainObjPtr vm; int ret =3D -1; unsigned long long speed =3D bandwidth; - virStorageSourcePtr dest =3D NULL; + VIR_AUTOPTR(virStorageSource) dest =3D NULL; =20 virCheckFlags(VIR_DOMAIN_BLOCK_REBASE_SHALLOW | VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT | @@ -18020,7 +18019,6 @@ qemuDomainBlockRebase(virDomainPtr dom, const char = *path, const char *base, =20 cleanup: virDomainObjEndAPI(&vm); - virStorageSourceFree(dest); return ret; } =20 @@ -18150,10 +18148,10 @@ qemuDomainBlockCommit(virDomainPtr dom, char *topPath =3D NULL; char *basePath =3D NULL; char *backingPath =3D NULL; - virStorageSourcePtr mirror =3D NULL; unsigned long long speed =3D bandwidth; qemuBlockJobDataPtr job =3D NULL; qemuBlockJobType jobtype =3D QEMU_BLOCKJOB_TYPE_COMMIT; + VIR_AUTOPTR(virStorageSource) mirror =3D NULL; =20 /* XXX Add support for COMMIT_DELETE */ virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | @@ -18352,7 +18350,6 @@ qemuDomainBlockCommit(virDomainPtr dom, virFreeError(orig_err); } } - virStorageSourceFree(mirror); qemuBlockJobStartupFinalize(job); qemuDomainObjEndJob(driver, vm); =20 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 3107a279dd..c93ae33476 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -788,9 +788,9 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr= driver, { qemuBlockStorageSourceAttachDataPtr data =3D NULL; qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - virStorageSourcePtr copysrc =3D NULL; int mon_ret =3D 0; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) copysrc =3D NULL; =20 VIR_DEBUG("starting blockdev mirror for disk=3D%s to host=3D%s", diskA= lias, host); =20 @@ -849,7 +849,6 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr= driver, =20 cleanup: qemuBlockStorageSourceAttachDataFree(data); - virStorageSourceFree(copysrc); return ret; } =20 diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 1888314d95..846a647cb6 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -236,10 +236,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterStatePtr state, { int ret =3D -1; glfs_fd_t *fd =3D NULL; - virStorageSourcePtr meta =3D NULL; ssize_t len; int backingFormat; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; VIR_AUTOFREE(char *) header =3D NULL; =20 *volptr =3D NULL; @@ -323,7 +323,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, VIR_STEAL_PTR(*volptr, vol); ret =3D 0; cleanup: - virStorageSourceFree(meta); if (fd) glfs_close(fd); return ret; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 60a42a2828..f18e38733a 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3357,10 +3357,9 @@ storageBackendProbeTarget(virStorageSourcePtr target, virStorageEncryptionPtr *encryption) { int backingStoreFormat; - int ret =3D -1; int rc; - virStorageSourcePtr meta =3D NULL; struct stat sb; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; VIR_AUTOCLOSE fd =3D -1; =20 if (encryption) @@ -3372,17 +3371,16 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, fd =3D rc; =20 if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb) < 0) - goto cleanup; + return -1; =20 if (S_ISDIR(sb.st_mode)) { if (storageBackendIsPloopDir(target->path)) { if (storageBackendRedoPloopUpdate(target, &sb, &fd, VIR_STORAGE_VOL_FS_PROBE_FLA= GS) < 0) - goto cleanup; + return -1; } else { target->format =3D VIR_STORAGE_FILE_DIR; - ret =3D 0; - goto cleanup; + return 0; } } =20 @@ -3390,11 +3388,11 @@ storageBackendProbeTarget(virStorageSourcePtr targe= t, fd, VIR_STORAGE_FILE_AUTO, &backingStoreFormat))) - goto cleanup; + return -1; =20 if (meta->backingStoreRaw) { if (!(target->backingStore =3D virStorageSourceNewFromBacking(meta= ))) - goto cleanup; + return -1; =20 target->backingStore->format =3D backingStoreFormat; =20 @@ -3405,7 +3403,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, virStorageSourceFree(target->backingStore); =20 if (VIR_ALLOC(target->backingStore) < 0) - goto cleanup; + return -1; =20 target->backingStore->type =3D VIR_STORAGE_TYPE_NETWORK; target->backingStore->path =3D meta->backingStoreRaw; @@ -3434,8 +3432,6 @@ storageBackendProbeTarget(virStorageSourcePtr target, target->format =3D meta->format; =20 /* Default to success below this point */ - ret =3D 0; - if (meta->capacity) target->capacity =3D meta->capacity; =20 @@ -3461,9 +3457,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, VIR_STEAL_PTR(target->compat, meta->compat); } =20 - cleanup: - virStorageSourceFree(meta); - return ret; + return 0; } =20 =20 @@ -3531,11 +3525,11 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) struct dirent *ent; struct statvfs sb; struct stat statbuf; - virStorageSourcePtr target =3D NULL; int direrr; int ret =3D -1; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; VIR_AUTOCLOSE fd =3D -1; + VIR_AUTOPTR(virStorageSource) target =3D NULL; =20 if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; @@ -3626,7 +3620,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) ret =3D 0; cleanup: VIR_DIR_CLOSE(dir); - virStorageSourceFree(target); if (ret < 0) virStoragePoolObjClearVols(pool); return ret; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 8d85d9dac4..8eccc428da 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1117,7 +1117,8 @@ static virStorageSourcePtr virStorageFileMetadataNew(const char *path, int format) { - virStorageSourcePtr def =3D NULL; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -1126,13 +1127,10 @@ virStorageFileMetadataNew(const char *path, def->type =3D VIR_STORAGE_TYPE_FILE; =20 if (VIR_STRDUP(def->path, path) < 0) - goto error; - - return def; + return NULL; =20 - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -1205,11 +1203,11 @@ virStorageFileGetMetadataFromFD(const char *path, =20 { virStorageSourcePtr ret =3D NULL; - virStorageSourcePtr meta =3D NULL; ssize_t len =3D VIR_STORAGE_MAX_HEADER; struct stat sb; int dummy; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; =20 if (!backingFormat) backingFormat =3D &dummy; @@ -1231,21 +1229,21 @@ virStorageFileGetMetadataFromFD(const char *path, meta->type =3D VIR_STORAGE_TYPE_DIR; meta->format =3D VIR_STORAGE_FILE_DIR; VIR_STEAL_PTR(ret, meta); - goto cleanup; + return ret; } =20 if (lseek(fd, 0, SEEK_SET) =3D=3D (off_t)-1) { virReportSystemError(errno, _("cannot seek to start of '%s'"), met= a->path); - goto cleanup; + return NULL; } =20 if ((len =3D virFileReadHeaderFD(fd, len, &buf)) < 0) { virReportSystemError(errno, _("cannot read header '%s'"), meta->pa= th); - goto cleanup; + return NULL; } =20 if (virStorageFileGetMetadataInternal(meta, buf, len, backingFormat) <= 0) - goto cleanup; + return NULL; =20 if (S_ISREG(sb.st_mode)) meta->type =3D VIR_STORAGE_TYPE_FILE; @@ -1253,9 +1251,6 @@ virStorageFileGetMetadataFromFD(const char *path, meta->type =3D VIR_STORAGE_TYPE_BLOCK; =20 VIR_STEAL_PTR(ret, meta); - - cleanup: - virStorageSourceFree(meta); return ret; } =20 @@ -2243,7 +2238,8 @@ virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src, bool backingChain) { - virStorageSourcePtr def =3D NULL; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -2282,60 +2278,57 @@ virStorageSourceCopy(const virStorageSource *src, VIR_STRDUP(def->compat, src->compat) < 0 || VIR_STRDUP(def->tlsAlias, src->tlsAlias) < 0 || VIR_STRDUP(def->tlsCertdir, src->tlsCertdir) < 0) - goto error; + return NULL; =20 if (src->nhosts) { if (!(def->hosts =3D virStorageNetHostDefCopy(src->nhosts, src->ho= sts))) - goto error; + return NULL; =20 def->nhosts =3D src->nhosts; } =20 if (src->srcpool && !(def->srcpool =3D virStorageSourcePoolDefCopy(src->srcpool))) - goto error; + return NULL; =20 if (src->features && !(def->features =3D virBitmapNewCopy(src->features))) - goto error; + return NULL; =20 if (src->encryption && !(def->encryption =3D virStorageEncryptionCopy(src->encryption))) - goto error; + return NULL; =20 if (src->perms && !(def->perms =3D virStoragePermsCopy(src->perms))) - goto error; + return NULL; =20 if (src->timestamps && !(def->timestamps =3D virStorageTimestampsCopy(src->timestamps))) - goto error; + return NULL; =20 if (virStorageSourceSeclabelsCopy(def, src) < 0) - goto error; + return NULL; =20 if (src->auth && !(def->auth =3D virStorageAuthDefCopy(src->auth))) - goto error; + return NULL; =20 if (src->pr && !(def->pr =3D virStoragePRDefCopy(src->pr))) - goto error; + return NULL; =20 if (virStorageSourceInitiatorCopy(&def->initiator, &src->initiator)) - goto error; + return NULL; =20 if (backingChain && src->backingStore) { if (!(def->backingStore =3D virStorageSourceCopy(src->backingStore, true))) - goto error; + return NULL; } =20 - return def; - - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -2577,27 +2570,28 @@ static virStorageSourcePtr virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, const char *rel) { - virStorageSourcePtr def; + virStorageSourcePtr ret =3D NULL; VIR_AUTOFREE(char *) dirname =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; =20 /* store relative name */ if (VIR_STRDUP(def->relPath, parent->backingStoreRaw) < 0) - goto error; + return NULL; =20 if (!(dirname =3D mdir_name(parent->path))) { virReportOOMError(); - goto error; + return NULL; } =20 if (STRNEQ(dirname, "/")) { if (virAsprintf(&def->path, "%s/%s", dirname, rel) < 0) - goto error; + return NULL; } else { if (virAsprintf(&def->path, "/%s", rel) < 0) - goto error; + return NULL; } =20 if (virStorageSourceGetActualType(parent) =3D=3D VIR_STORAGE_TYPE_NETW= ORK) { @@ -2608,25 +2602,20 @@ virStorageSourceNewFromBackingRelative(virStorageSo= urcePtr parent, if (parent->nhosts) { if (!(def->hosts =3D virStorageNetHostDefCopy(parent->nhosts, parent->hosts))) - goto error; + return NULL; =20 def->nhosts =3D parent->nhosts; } =20 if (VIR_STRDUP(def->volume, parent->volume) < 0) - goto error; + return NULL; } else { /* set the type to _FILE, the caller shall update it to the actual= type */ def->type =3D VIR_STORAGE_TYPE_FILE; } =20 - cleanup: - return def; - - error: - virStorageSourceFree(def); - def =3D NULL; - goto cleanup; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -3624,8 +3613,9 @@ virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path) { const char *json; - virStorageSourcePtr def; + virStorageSourcePtr ret =3D NULL; int rc; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -3634,7 +3624,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) def->type =3D VIR_STORAGE_TYPE_FILE; =20 if (VIR_STRDUP(def->path, path) < 0) - goto error; + return NULL; } else { def->type =3D VIR_STORAGE_TYPE_NETWORK; =20 @@ -3649,7 +3639,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) rc =3D virStorageSourceParseBackingColon(def, path); =20 if (rc < 0) - goto error; + return NULL; =20 virStorageSourceNetworkAssignDefaultPorts(def); =20 @@ -3662,11 +3652,8 @@ virStorageSourceNewFromBackingAbsolute(const char *p= ath) } } =20 - return def; - - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -3674,7 +3661,8 @@ virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent) { struct stat st; - virStorageSourcePtr def; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (virStorageIsRelative(parent->backingStoreRaw)) def =3D virStorageSourceNewFromBackingRelative(parent, @@ -3697,17 +3685,14 @@ virStorageSourceNewFromBacking(virStorageSourcePtr = parent) =20 /* copy parent's labelling and other top level stuff */ if (virStorageSourceInitChainElement(def, parent, true) < 0) - goto error; + return NULL; =20 def->readonly =3D true; def->detected =3D true; } =20 - return def; - - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 =20 @@ -3848,9 +3833,8 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr sr= c, ssize_t len, bool probe) { - int ret =3D -1; - virStorageSourcePtr meta =3D NULL; int format =3D src->format; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; =20 /* Raw files: capacity is physical size. For all other files: if * the metadata has a capacity, use that, otherwise fall back to @@ -3860,12 +3844,12 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr = src, virReportError(VIR_ERR_INTERNAL_ERROR, _("no disk format for %s and probing is disable= d"), src->path); - goto cleanup; + return -1; } =20 if ((format =3D virStorageFileProbeFormatFromBuf(src->path, buf, len)) < 0) - goto cleanup; + return -1; =20 src->format =3D format; } @@ -3878,17 +3862,13 @@ virStorageSourceUpdateCapacity(virStorageSourcePtr = src, if (src->encryption && meta->encryption) src->encryption->payload_offset =3D meta->encryption->payload_= offset; } else { - goto cleanup; + return -1; } =20 if (src->encryption && src->encryption->payload_offset !=3D -1) src->capacity -=3D src->encryption->payload_offset * 512; =20 - ret =3D 0; - - cleanup: - virStorageSourceFree(meta); - return ret; + return 0; } =20 =20 @@ -4825,10 +4805,10 @@ virStorageFileGetMetadataRecurse(virStorageSourcePt= r src, int ret =3D -1; const char *uniqueName; ssize_t headerLen; - virStorageSourcePtr backingStore =3D NULL; int backingFormat; int rv; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virStorageSource) backingStore =3D NULL; =20 VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u", src->path, src->format, @@ -4911,7 +4891,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, if (virStorageSourceHasBacking(src)) src->backingStore->id =3D depth; virStorageFileDeinit(src); - virStorageSourceFree(backingStore); return ret; } =20 @@ -4980,11 +4959,10 @@ int virStorageFileGetBackingStoreStr(virStorageSourcePtr src, char **backing) { - virStorageSourcePtr tmp =3D NULL; ssize_t headerLen; - int ret =3D -1; int rv; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virStorageSource) tmp =3D NULL; =20 *backing =3D NULL; =20 @@ -5008,17 +4986,12 @@ virStorageFileGetBackingStoreStr(virStorageSourcePt= r src, } =20 if (!(tmp =3D virStorageSourceCopy(src, false))) - goto cleanup; + return -1; =20 if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0) - goto cleanup; + return -1; =20 VIR_STEAL_PTR(*backing, tmp->backingStoreRaw); =20 - ret =3D 0; - - cleanup: - virStorageSourceFree(tmp); - - return ret; + return 0; } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index eacc927ea6..8c3a36d473 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -544,5 +544,6 @@ void virStorageFileReportBrokenChain(int errcode, virStorageSourcePtr parent); =20 VIR_DEFINE_AUTOPTR_FUNC(virStorageAuthDef, virStorageAuthDefFree); +VIR_DEFINE_AUTOPTR_FUNC(virStorageSource, virStorageSourceFree); =20 #endif /* LIBVIRT_VIRSTORAGEFILE_H */ diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 5848f6b5b5..d7e5e72a0b 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -46,14 +46,14 @@ testBackingXMLjsonXML(const void *args) xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - virStorageSourcePtr xmlsrc =3D NULL; - virStorageSourcePtr jsonsrc =3D NULL; virJSONValuePtr backendprops =3D NULL; virJSONValuePtr wrapper =3D NULL; char *propsstr =3D NULL; char *protocolwrapper =3D NULL; char *actualxml =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virStorageSource) xmlsrc =3D NULL; + VIR_AUTOPTR(virStorageSource) jsonsrc =3D NULL; =20 if (VIR_ALLOC(xmlsrc) < 0) return -1; @@ -104,8 +104,6 @@ testBackingXMLjsonXML(const void *args) ret =3D 0; =20 cleanup: - virStorageSourceFree(xmlsrc); - virStorageSourceFree(jsonsrc); VIR_FREE(propsstr); VIR_FREE(protocolwrapper); VIR_FREE(actualxml); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 8db1d294b0..646ae78ff0 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -95,7 +95,8 @@ testStorageFileGetMetadata(const char *path, uid_t uid, gid_t gid) { struct stat st; - virStorageSourcePtr def =3D NULL; + virStorageSourcePtr ret =3D NULL; + VIR_AUTOPTR(virStorageSource) def =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -112,16 +113,13 @@ testStorageFileGetMetadata(const char *path, } =20 if (VIR_STRDUP(def->path, path) < 0) - goto error; + return NULL; =20 if (virStorageFileGetMetadata(def, uid, gid, false) < 0) - goto error; - - return def; + return NULL; =20 - error: - virStorageSourceFree(def); - return NULL; + VIR_STEAL_PTR(ret, def); + return ret; } =20 static int @@ -308,41 +306,40 @@ static int testStorageChain(const void *args) { const struct testChainData *data =3D args; - int ret =3D -1; - virStorageSourcePtr meta; virStorageSourcePtr elt; size_t i =3D 0; + VIR_AUTOPTR(virStorageSource) meta =3D NULL; VIR_AUTOFREE(char *) broken =3D NULL; =20 meta =3D testStorageFileGetMetadata(data->start, data->format, -1, -1); if (!meta) { if (data->flags & EXP_FAIL) { virResetLastError(); - ret =3D 0; + return 0; } - goto cleanup; + return -1; } else if (data->flags & EXP_FAIL) { fprintf(stderr, "call should have failed\n"); - goto cleanup; + return -1; } if (data->flags & EXP_WARN) { if (virGetLastErrorCode() =3D=3D VIR_ERR_OK) { fprintf(stderr, "call should have warned\n"); - goto cleanup; + return -1; } virResetLastError(); if (virStorageFileChainGetBroken(meta, &broken) || !broken) { fprintf(stderr, "call should identify broken part of chain\n"); - goto cleanup; + return -1; } } else { if (virGetLastErrorCode()) { fprintf(stderr, "call should not have warned\n"); - goto cleanup; + return -1; } if (virStorageFileChainGetBroken(meta, &broken) || broken) { fprintf(stderr, "chain should not be identified as broken\n"); - goto cleanup; + return -1; } } =20 @@ -353,7 +350,7 @@ testStorageChain(const void *args) =20 if (i =3D=3D data->nfiles) { fprintf(stderr, "probed chain was too long\n"); - goto cleanup; + return -1; } =20 if (virAsprintf(&expect, @@ -378,24 +375,21 @@ testStorageChain(const void *args) elt->format, virStorageNetProtocolTypeToString(elt->protocol), NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) = < 0) { - goto cleanup; + return -1; } if (STRNEQ(expect, actual)) { virTestDifference(stderr, expect, actual); - goto cleanup; + return -1; } elt =3D elt->backingStore; i++; } if (i !=3D data->nfiles) { fprintf(stderr, "probed chain was too short\n"); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virStorageSourceFree(meta); - return ret; + return 0; } =20 struct testLookupData @@ -646,9 +640,9 @@ testBackingParse(const void *args) { const struct testBackingParseData *data =3D args; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - virStorageSourcePtr src =3D NULL; int ret =3D -1; VIR_AUTOFREE(char *) xml =3D NULL; + VIR_AUTOPTR(virStorageSource) src =3D NULL; =20 if (!(src =3D virStorageSourceNewFromBackingAbsolute(data->backing))) { if (!data->expect) @@ -680,7 +674,6 @@ testBackingParse(const void *args) ret =3D 0; =20 cleanup: - virStorageSourceFree(src); virBufferFreeAndReset(&buf); =20 return ret; @@ -696,10 +689,10 @@ mymain(void) struct testPathCanonicalizeData data3; struct testPathRelativeBacking data4; struct testBackingParseData data5; - virStorageSourcePtr chain =3D NULL; virStorageSourcePtr chain2; /* short for chain->backingStore */ virStorageSourcePtr chain3; /* short for chain2->backingStore */ VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOPTR(virStorageSource) chain =3D NULL; =20 if (storageRegisterAll() < 0) return EXIT_FAILURE; @@ -1580,7 +1573,6 @@ mymain(void) =20 cleanup: /* Final cleanup */ - virStorageSourceFree(chain); testCleanupImages(); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list