[PATCH v1 02/21] storage: remove unneeded cleanup labels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 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 02b824867a..2b180c3b31 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 1c59c18b0d..7341a40f6c 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -411,17 +411,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
@@ -467,7 +465,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,
@@ -475,17 +473,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
@@ -971,14 +967,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) {
@@ -986,28 +981,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() */
@@ -1122,7 +1114,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);
@@ -1130,13 +1121,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
@@ -1145,7 +1133,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);
@@ -1153,7 +1140,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) {
@@ -1163,16 +1150,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
@@ -1392,7 +1376,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;
 
@@ -1405,7 +1388,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",
@@ -1414,10 +1397,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 c3057fede6..448616abe5 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
@@ -294,7 +291,6 @@ virStorageBackendZFSCreateVol(virStoragePoolObjPtr pool,
                               virStorageVolDefPtr vol)
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    int ret = -1;
     int volmode_needed = -1;
     g_autoptr(virCommand) cmd = NULL;
 
@@ -316,7 +312,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
@@ -347,15 +343,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 3b8332af01..6b18ca71d0 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -625,7 +625,6 @@ storageConnectFindStoragePoolSources(virConnectPtr conn,
 {
     int backend_type;
     virStorageBackendPtr backend;
-    char *ret = NULL;
 
     if (virConnectFindStoragePoolSourcesEnsureACL(conn) < 0)
         return NULL;
@@ -634,24 +633,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);
 }
 
 
@@ -1775,25 +1771,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.
@@ -1805,10 +1798,8 @@ storageVolDeleteInternal(virStorageBackendPtr backend,
     }
 
     virStoragePoolObjRemoveVol(obj, voldef);
-    ret = 0;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -2802,20 +2793,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 7b934b61e0..0cbdfcefd7 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 <linux/fs.h> 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;
 }
 
@@ -3784,7 +3783,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, ':'))) {
@@ -3792,7 +3790,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);
@@ -3800,9 +3798,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UNUSED,
         VIR_DEBUG("Block device is '%s'", *block_device);
     }
 
-    retval = 0;
- cleanup:
-    return retval;
+    return 0;
 }
 
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux