[libvirt] [PATCH v2 23/32] storage: Use VIR_AUTOCLOSE
Ján Tomko
jtomko at redhat.com
Mon Feb 11 13:53:56 UTC 2019
On Fri, Feb 08, 2019 at 01:37:17PM -0500, John Ferlan wrote:
>Modify code to use the VIR_AUTOCLOSE logic cleaning up any
>now unnecessary goto paths.
>
>Signed-off-by: John Ferlan <jferlan at redhat.com>
>Reviewed-by: Erik Skultety <eskultet at redhat.com>
>---
> 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(-)
>
>@@ -1751,17 +1732,17 @@ storageBackendUpdateVolTargetInfo(virStorageVolType voltype,
> unsigned int openflags,
> unsigned int readflags)
> {
>- int ret, fd = -1;
>+ int ret;
Usually we use 'ret' for the values that will eventually be returned by
the function. For storing the values of functions we call, I suggest
using 'rc'.
> struct stat sb;
> ssize_t len = VIR_STORAGE_MAX_HEADER;
> VIR_AUTOFREE(char *) buf = NULL;
>+ VIR_AUTOCLOSE fd = -1;
>
>- if ((ret = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0)
>- goto cleanup;
Before, we propagated the return value of virStorageBackendVolOpen on
failure.
>- fd = ret;
>+ if ((fd = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0)
>+ return -1;
Now it's always -1.
>
> if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0)
>- goto cleanup;
>+ return ret;
>
> if ((voltype == VIR_STORAGE_VOL_FILE || voltype == VIR_STORAGE_VOL_BLOCK) &&
> target->format != VIR_STORAGE_FILE_NONE) {
storageBackendUpdateVolTargetInfo could use a preparatory patch that
will make all the changes here:
- ret = %s
- goto cleanup
+ return %s;
To the rest:
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190211/8815b181/attachment-0001.sig>
More information about the libvir-list
mailing list