From nobody Sun Feb 8 16:30:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549460594776481.8374680783845; Wed, 6 Feb 2019 05:43:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66B952D806; Wed, 6 Feb 2019 13:43:12 +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 C63FF104811C; Wed, 6 Feb 2019 13:43:11 +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 2993E3D3A6; Wed, 6 Feb 2019 13:43:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x16DgB2u002049 for ; Wed, 6 Feb 2019 08:42:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6CA426426E; Wed, 6 Feb 2019 13:42:11 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-19.phx2.redhat.com [10.3.116.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 201B55C26D for ; Wed, 6 Feb 2019 13:42:11 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 6 Feb 2019 08:41:46 -0500 Message-Id: <20190206134147.18032-15-jferlan@redhat.com> In-Reply-To: <20190206134147.18032-1-jferlan@redhat.com> References: <20190206134147.18032-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/15] 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 06 Feb 2019 13:43:13 +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 --- src/storage/storage_backend_logical.c | 3 +- src/storage/storage_backend_scsi.c | 12 +-- src/storage/storage_file_fs.c | 15 +-- src/storage/storage_util.c | 150 ++++++++++---------------- src/util/virstoragefile.c | 39 +++---- 5 files changed, 77 insertions(+), 142 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 2a205a4e95..8ae866f23e 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -911,7 +911,7 @@ static int virStorageBackendLogicalCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr err; struct stat sb; @@ -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 1a10e43647..2ae55af6c9 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,24 +72,19 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Could not open '%s' to trigger host scan"), path); - goto cleanup; + return -1; } =20 if (safewrite(fd, LINUX_SYSFS_SCSI_HOST_SCAN_STRING, sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) { - VIR_FORCE_CLOSE(fd); virReportSystemError(errno, _("Write to '%s' to trigger host scan failed"= ), path); } =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..0028389e60 100644 --- a/src/storage/storage_file_fs.c +++ b/src/storage/storage_file_fs.c @@ -83,7 +83,7 @@ virStorageFileBackendFileInit(virStorageSourcePtr src) static int virStorageFileBackendFileCreate(virStorageSourcePtr src) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; mode_t mode =3D S_IRUSR; =20 if (!src->readonly) @@ -95,7 +95,6 @@ virStorageFileBackendFileCreate(virStorageSourcePtr src) return -1; } =20 - VIR_FORCE_CLOSE(fd); return 0; } =20 @@ -121,7 +120,7 @@ virStorageFileBackendFileRead(virStorageSourcePtr src, size_t len, char **buf) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; ssize_t ret =3D -1; =20 if ((fd =3D virFileOpenAs(src->path, O_RDONLY, 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 d87d2eca1e..345566a3af 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; @@ -138,6 +137,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, int interval; VIR_AUTOFREE(char *) zerobuf =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOCLOSE inputfd =3D -1; struct stat st; =20 if ((inputfd =3D open(inputvol->target.path, O_RDONLY)) < 0) { @@ -145,7 +145,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, 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,8 +241,7 @@ storageBackendCreateBlockFrom(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, virStorageVolDefPtr inputvol, unsigned int flags) { - int fd =3D -1; - int ret =3D -1; + VIR_AUTOCLOSE fd =3D -1; unsigned long long remain; struct stat st; gid_t gid; @@ -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,7 +404,7 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int ret =3D -1; - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; int operation_flags; bool reflink_copy =3D false; mode_t open_mode =3D VIR_STORAGE_DEFAULT_VOL_PERM_MODE; @@ -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,7 +1210,7 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolO= bjPtr pool, { virStorageEncryptionPtr enc =3D vol->target.encryption; char *secretPath =3D NULL; - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; uint8_t *secret =3D NULL; size_t secretlen =3D 0; virConnectPtr conn =3D NULL; @@ -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 @@ -1751,17 +1732,17 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, unsigned int openflags, unsigned int readflags) { - int ret, fd =3D -1; + int ret; struct stat sb; + VIR_AUTOCLOSE fd =3D -1; VIR_AUTOFREE(char *) buf =3D NULL; ssize_t len =3D VIR_STORAGE_MAX_HEADER; =20 - if ((ret =3D virStorageBackendVolOpen(target->path, &sb, openflags)) <= 0) - goto cleanup; - fd =3D ret; + if ((fd =3D virStorageBackendVolOpen(target->path, &sb, openflags)) < = 0) + return -1; =20 if ((ret =3D virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) = < 0) - goto cleanup; + return ret; =20 if ((voltype =3D=3D VIR_STORAGE_VOL_FILE || voltype =3D=3D VIR_STORAGE= _VOL_BLOCK) && target->format !=3D VIR_STORAGE_FILE_NONE) { @@ -1769,49 +1750,39 @@ storageBackendUpdateVolTargetInfo(virStorageVolType= voltype, if (storageBackendIsPloopDir(target->path)) { if ((ret =3D storageBackendRedoPloopUpdate(target, &sb, &f= d, openflags)) < 0) - goto cleanup; + return ret; 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); - ret =3D -1; - 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); - ret =3D -1; + return -1; } - goto cleanup; } =20 - if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) { - ret =3D -1; - goto cleanup; - } + if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) + return -1; } =20 - if (withBlockVolFormat) { - if ((ret =3D virStorageBackendDetectBlockVolFormatFD(target, fd, - readflags)) < 0) - goto cleanup; - } + if (withBlockVolFormat) + return virStorageBackendDetectBlockVolFormatFD(target, fd, readfla= gs); =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + return 0; } =20 /* @@ -2617,9 +2588,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); @@ -2627,14 +2598,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) { @@ -2668,12 +2639,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); @@ -2682,24 +2653,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 @@ -3392,7 +3353,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, virStorageEncryptionPtr *encryption) { int backingStoreFormat; - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; int ret =3D -1; int rc; virStorageSourcePtr meta =3D NULL; @@ -3499,7 +3460,6 @@ storageBackendProbeTarget(virStorageSourcePtr target, } =20 cleanup: - VIR_FORCE_CLOSE(fd); virStorageSourceFree(meta); return ret; } @@ -3570,9 +3530,10 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr p= ool) struct statvfs sb; struct stat statbuf; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOCLOSE fd =3D -1; virStorageSourcePtr target =3D NULL; int direrr; - int fd =3D -1, ret =3D -1; + int ret =3D -1; =20 if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; @@ -3663,7 +3624,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 c2f044d2db..1d77f6ac4c 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; + VIR_AUTOCLOSE fd =3D -1; int rc; =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