[PATCH 03/10] qemu: Remove cleanup label in qemuDomainSnapshotPrepareDiskExternal

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

 



Refactor the code to avoid having a cleanup label. This will simplify
the change necessary when restricting this check in an upcoming patch.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 913b57855c..29a47af0a2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14997,8 +14997,9 @@ qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk,
                                       bool active,
                                       bool reuse)
 {
-    int ret = -1;
     struct stat st;
+    int err;
+    int rc;

     if (disk->src->readonly) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -15024,31 +15025,32 @@ qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk,
     if (virStorageFileInit(snapdisk->src) < 0)
         return -1;

-    if (virStorageFileStat(snapdisk->src, &st) < 0) {
-        if (errno != ENOENT) {
-            virReportSystemError(errno,
+    rc = virStorageFileStat(snapdisk->src, &st);
+    err = errno;
+
+    virStorageFileDeinit(snapdisk->src);
+
+    if (rc < 0) {
+        if (err != ENOENT) {
+            virReportSystemError(err,
                                  _("unable to stat for disk %s: %s"),
                                  snapdisk->name, snapdisk->src->path);
-            goto cleanup;
+            return -1;
         } else if (reuse) {
-            virReportSystemError(errno,
+            virReportSystemError(err,
                                  _("missing existing file for disk %s: %s"),
                                  snapdisk->name, snapdisk->src->path);
-            goto cleanup;
+            return -1;
         }
     } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("external snapshot file for disk %s already "
                          "exists and is not a block device: %s"),
                        snapdisk->name, snapdisk->src->path);
-        goto cleanup;
+        return -1;
     }

-    ret = 0;
-
- cleanup:
-    virStorageFileDeinit(snapdisk->src);
-    return ret;
+    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