From abd2899d73f10a15b100019d40a386337ec0ddc8 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Mon, 21 Oct 2019 15:18:52 -0300 Subject: [PATCH] storage: remove unneeded cleanup labels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Henrique Barboza Reviewed-by: Ján Tomko --- src/storage/storage_backend_fs.c | 13 +++---- src/storage/storage_backend_rbd.c | 58 ++++++++++--------------------- src/storage/storage_backend_zfs.c | 21 ++++------- src/storage/storage_driver.c | 38 +++++++------------- src/storage/storage_util.c | 18 ++++------ 5 files changed, 50 insertions(+), 98 deletions(-) diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 27c10982e4..536e5cf952 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -58,36 +58,33 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(char **const groups, virNetfsDiscoverState *state = data; const char *name, *path; virStoragePoolSource *src = NULL; - int ret = -1; path = groups[0]; if (!(name = strrchr(path, '/'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid netfs path (no /): %s"), path); - goto cleanup; + return -1; } name += 1; if (*name == '\0') { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid netfs path (ends in /): %s"), path); - goto cleanup; + return -1; } if (!(src = virStoragePoolSourceListNewSource(&state->list))) - goto cleanup; + return -1; if (VIR_ALLOC_N(src->hosts, 1) < 0) - goto cleanup; + return -1; src->nhost = 1; src->hosts[0].name = g_strdup(state->host); src->dir = g_strdup(path); src->format = VIR_STORAGE_POOL_NETFS_NFS; - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index bd6a9fa4df..34088f75db 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -408,17 +408,15 @@ volStorageBackendRBDGetFeatures(rbd_image_t image, const char *volname, uint64_t *features) { - int r, ret = -1; + int r; if ((r = rbd_get_features(image, features)) < 0) { virReportSystemError(-r, _("failed to get the features of RBD image " "%s"), volname); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } #if LIBRBD_VERSION_CODE > 265 @@ -464,7 +462,7 @@ virStorageBackendRBDSetAllocation(virStorageVolDefPtr vol, rbd_image_t *image, rbd_image_info_t *info) { - int r, ret = -1; + int r; size_t allocation = 0; if ((r = rbd_diff_iterate2(image, NULL, 0, info->size, 0, 1, @@ -472,17 +470,15 @@ virStorageBackendRBDSetAllocation(virStorageVolDefPtr vol, &allocation)) < 0) { virReportSystemError(-r, _("failed to iterate RBD image '%s'"), vol->name); - goto cleanup; + return -1; } VIR_DEBUG("Found %zu bytes allocated for RBD image %s", allocation, vol->name); vol->target.allocation = allocation; - ret = 0; - cleanup: - return ret; + return 0; } #else @@ -960,14 +956,13 @@ virStorageBackendRBDImageInfo(rbd_image_t image, uint64_t *stripe_unit, uint64_t *stripe_count) { - int ret = -1; int r = 0; uint8_t oldformat; if ((r = rbd_get_old_format(image, &oldformat)) < 0) { virReportSystemError(-r, _("failed to get the format of RBD image %s"), volname); - goto cleanup; + return -1; } if (oldformat != 0) { @@ -975,28 +970,25 @@ virStorageBackendRBDImageInfo(rbd_image_t image, _("RBD image %s is old format. Does not support " "extended features and striping"), volname); - goto cleanup; + return -1; } if (volStorageBackendRBDGetFeatures(image, volname, features) < 0) - goto cleanup; + return -1; if ((r = rbd_get_stripe_unit(image, stripe_unit)) < 0) { virReportSystemError(-r, _("failed to get the stripe unit of RBD image %s"), volname); - goto cleanup; + return -1; } if ((r = rbd_get_stripe_count(image, stripe_count)) < 0) { virReportSystemError(-r, _("failed to get the stripe count of RBD image %s"), volname); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } /* Callback function for rbd_diff_iterate() */ @@ -1111,7 +1103,6 @@ virStorageBackendRBDSnapshotCreate(rbd_image_t image, char *imgname, char *snapname) { - int ret = -1; int r = -1; VIR_DEBUG("Creating RBD snapshot %s@%s", imgname, snapname); @@ -1119,13 +1110,10 @@ virStorageBackendRBDSnapshotCreate(rbd_image_t image, if ((r = rbd_snap_create(image, snapname)) < 0) { virReportSystemError(-r, _("failed to create RBD snapshot %s@%s"), imgname, snapname); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int @@ -1134,7 +1122,6 @@ virStorageBackendRBDSnapshotProtect(rbd_image_t image, char *snapname) { int r = -1; - int ret = -1; int protected; VIR_DEBUG("Querying if RBD snapshot %s@%s is protected", imgname, snapname); @@ -1142,7 +1129,7 @@ virStorageBackendRBDSnapshotProtect(rbd_image_t image, if ((r = rbd_snap_is_protected(image, snapname, &protected)) < 0) { virReportSystemError(-r, _("failed to verify if RBD snapshot %s@%s " "is protected"), imgname, snapname); - goto cleanup; + return -1; } if (protected == 0) { @@ -1152,16 +1139,13 @@ virStorageBackendRBDSnapshotProtect(rbd_image_t image, if ((r = rbd_snap_protect(image, snapname)) < 0) { virReportSystemError(-r, _("failed to protect RBD snapshot %s@%s"), imgname, snapname); - goto cleanup; + return -1; } } else { VIR_DEBUG("RBD Snapshot %s@%s is already protected", imgname, snapname); } - ret = 0; - - cleanup: - return ret; + return 0; } static int @@ -1378,7 +1362,6 @@ virStorageBackendRBDVolWipeDiscard(rbd_image_t image, uint64_t stripe_count) { int r = -1; - int ret = -1; unsigned long long offset = 0; unsigned long long length; @@ -1391,7 +1374,7 @@ virStorageBackendRBDVolWipeDiscard(rbd_image_t image, virReportSystemError(-r, _("discarding %llu bytes failed on " "RBD image %s at offset %llu"), length, imgname, offset); - goto cleanup; + return -1; } VIR_DEBUG("Discarded %llu bytes of RBD image %s at offset %llu", @@ -1400,10 +1383,7 @@ virStorageBackendRBDVolWipeDiscard(rbd_image_t image, offset += length; } - ret = 0; - - cleanup: - return ret; + return 0; } static int diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c index b708c7fd4a..a3de3e46f2 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -68,16 +68,13 @@ virStorageBackendZFSVolModeNeeded(void) if ((ret < 0) || (exit_code != 2)) { VIR_WARN("Command 'zfs get' either failed " "to run or exited with unexpected status"); - goto cleanup; + return ret; } if (strstr(error, " volmode ")) - ret = 1; + return 1; else - ret = 0; - - cleanup: - return ret; + return 0; } static int @@ -291,7 +288,6 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); - int ret = -1; int volmode_needed = -1; g_autoptr(virCommand) cmd = NULL; @@ -311,7 +307,7 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool, volmode_needed = virStorageBackendZFSVolModeNeeded(); if (volmode_needed < 0) - goto cleanup; + return -1; /** * $ zfs create -o volmode=dev -V 10240K test/volname * $ zfs create -o volmode=dev -s -V 10240K test/volname @@ -342,15 +338,12 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool, virCommandAddArgFormat(cmd, "%s/%s", def->source.name, vol->name); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; if (virStorageBackendZFSFindVols(pool, vol) < 0) - goto cleanup; - - ret = 0; - cleanup: - return ret; + return -1; + return 0; } static int diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 84d76eebd0..04e4abcd6a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -621,7 +621,6 @@ storageConnectFindStoragePoolSources(virConnectPtr conn, { int backend_type; virStorageBackendPtr backend; - char *ret = NULL; if (virConnectFindStoragePoolSourcesEnsureACL(conn) < 0) return NULL; @@ -630,24 +629,21 @@ storageConnectFindStoragePoolSources(virConnectPtr conn, if (backend_type < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage pool type %s"), type); - goto cleanup; + return NULL; } backend = virStorageBackendForType(backend_type); if (backend == NULL) - goto cleanup; + return NULL; if (!backend->findPoolSources) { virReportError(VIR_ERR_NO_SUPPORT, _("pool type '%s' does not support source " "discovery"), type); - goto cleanup; + return NULL; } - ret = backend->findPoolSources(srcSpec, flags); - - cleanup: - return ret; + return backend->findPoolSources(srcSpec, flags); } @@ -1771,25 +1767,22 @@ storageVolDeleteInternal(virStorageBackendPtr backend, bool updateMeta) { virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); - int ret = -1; if (!backend->deleteVol) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("storage pool does not support vol deletion")); - goto cleanup; + return -1; } if (backend->deleteVol(obj, voldef, flags) < 0) - goto cleanup; + return -1; /* The disk backend updated the pool data including removing the * voldef from the pool (for both the deleteVol and the createVol * failure path. */ - if (def->type == VIR_STORAGE_POOL_DISK) { - ret = 0; - goto cleanup; - } + if (def->type == VIR_STORAGE_POOL_DISK) + return 0; /* Update pool metadata - don't update meta data from error paths * in this module since the allocation/available weren't adjusted yet. @@ -1801,10 +1794,8 @@ storageVolDeleteInternal(virStorageBackendPtr backend, } virStoragePoolObjRemoveVol(obj, voldef); - ret = 0; - cleanup: - return ret; + return 0; } @@ -2797,20 +2788,15 @@ static int storageConnectStoragePoolEventDeregisterAny(virConnectPtr conn, int callbackID) { - int ret = -1; - if (virConnectStoragePoolEventDeregisterAnyEnsureACL(conn) < 0) - goto cleanup; + return -1; if (virObjectEventStateDeregisterID(conn, driver->storageEventState, callbackID, true) < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - return ret; + return 0; } diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7ecb8b384a..f91c2c64ee 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -336,7 +336,7 @@ createRawFile(int fd, virStorageVolDefPtr vol, virReportSystemError(errno, _("cannot extend file '%s'"), vol->target.path); - goto cleanup; + return ret; } /* Avoid issues with older kernel's namespace pollution. */ @@ -356,7 +356,7 @@ createRawFile(int fd, virStorageVolDefPtr vol, virReportSystemError(errno, _("cannot allocate %llu bytes in file '%s'"), vol->target.allocation, vol->target.path); - goto cleanup; + return ret; } } #endif @@ -368,7 +368,7 @@ createRawFile(int fd, virStorageVolDefPtr vol, * been able to allocate the required space. */ if ((ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, !need_alloc, reflink_copy)) < 0) - goto cleanup; + return ret; /* If the new allocation is greater than the original capacity, * but fallocate failed, fill the rest with zeroes. @@ -381,7 +381,7 @@ createRawFile(int fd, virStorageVolDefPtr vol, ret = -errno; virReportSystemError(errno, _("cannot fill file '%s'"), vol->target.path); - goto cleanup; + return ret; } } @@ -389,10 +389,9 @@ createRawFile(int fd, virStorageVolDefPtr vol, ret = -errno; virReportSystemError(errno, _("cannot sync data to file '%s'"), vol->target.path); - goto cleanup; + return ret; } - cleanup: return ret; } @@ -3747,7 +3746,6 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UNUSED, char **block_device) { char *blockp = NULL; - int retval = -1; /* old-style; just parse out the sd */ if (!(blockp = strrchr(block_name, ':'))) { @@ -3755,7 +3753,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse block name %s"), block_name); - goto cleanup; + return -1; } else { blockp++; *block_device = g_strdup(blockp); @@ -3763,9 +3761,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UNUSED, VIR_DEBUG("Block device is '%s'", *block_device); } - retval = 0; - cleanup: - return retval; + return 0; } -- GitLab