[PATCH v2 12/12] migration: refactor: one return in forURI family functions

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

 



May be a matter of a taste but this version with one return point in every
function looks simplier to understand and to exetend too. Anyway after such
a heavy refactoring a little cleanup will not hurt.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/libvirt-domain.c |   61 +++++++++++++++++++++++---------------------------
 1 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 2d98997..aad2849 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -4216,6 +4216,7 @@ virDomainMigrateToURI(virDomainPtr domain,
                       const char *dname,
                       unsigned long bandwidth)
 {
+    int ret = -1;
     const char *dconnuri = NULL;
     const char *miguri = NULL;
 
@@ -4225,26 +4226,24 @@ virDomainMigrateToURI(virDomainPtr domain,
     virResetLastError();
 
     virCheckDomainReturn(domain, -1);
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    virCheckNonNullArgGoto(duri, error);
+    virCheckReadOnlyGoto(domain->conn->flags, cleanup);
+    virCheckNonNullArgGoto(duri, cleanup);
 
     if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
-        goto error;
+        goto cleanup;
 
     if (flags & VIR_MIGRATE_PEER2PEER)
         dconnuri = duri;
     else
         miguri = duri;
 
-    if (virDomainMigrateUnmanaged(domain, NULL, flags,
-                               dname, dconnuri, miguri, bandwidth) < 0)
-        goto error;
-
-    return 0;
+    ret = virDomainMigrateUnmanaged(domain, NULL, flags,
+                                    dname, dconnuri, miguri, bandwidth);
+ cleanup:
+    if (ret < 0)
+        virDispatchError(domain->conn);
 
- error:
-    virDispatchError(domain->conn);
-    return -1;
+    return ret;
 }
 
 
@@ -4343,6 +4342,7 @@ virDomainMigrateToURI2(virDomainPtr domain,
                        const char *dname,
                        unsigned long bandwidth)
 {
+    int ret = -1;
     VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, miguri=%s, dxml=%s, "
                      "flags=%lx, dname=%s, bandwidth=%lu",
                      NULLSTR(dconnuri), NULLSTR(miguri), NULLSTR(dxml),
@@ -4351,23 +4351,20 @@ virDomainMigrateToURI2(virDomainPtr domain,
     virResetLastError();
 
     virCheckDomainReturn(domain, -1);
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(domain->conn->flags, cleanup);
 
     if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
-        goto error;
+        goto cleanup;
 
     if (!(flags & VIR_MIGRATE_PEER2PEER))
         dconnuri = NULL;
 
-    if (virDomainMigrateUnmanaged(domain, NULL, flags,
-                               dname, dconnuri, miguri, bandwidth) < 0)
-        goto error;
-
-    return 0;
-
- error:
-    virDispatchError(domain->conn);
-    return -1;
+    ret = virDomainMigrateUnmanaged(domain, NULL, flags,
+                                    dname, dconnuri, miguri, bandwidth);
+ cleanup:
+    if (ret < 0)
+        virDispatchError(domain->conn);
+    return ret;
 }
 
 
@@ -4415,6 +4412,7 @@ virDomainMigrateToURI3(virDomainPtr domain,
                        unsigned int nparams,
                        unsigned int flags)
 {
+    int ret = -1;
     VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparms=%u flags=%x",
                      NULLSTR(dconnuri), params, nparams, flags);
     VIR_TYPED_PARAMS_DEBUG(params, nparams);
@@ -4422,23 +4420,20 @@ virDomainMigrateToURI3(virDomainPtr domain,
     virResetLastError();
 
     virCheckDomainReturn(domain, -1);
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(domain->conn->flags, cleanup);
 
     if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
-        goto error;
+        goto cleanup;
 
     if (!(flags & VIR_MIGRATE_PEER2PEER))
         dconnuri = NULL;
 
-    if (virDomainMigrateUnmanagedParams(domain, dconnuri,
-                                        params, nparams, flags) < 0)
-        goto error;
-
-    return 0;
-
- error:
-    virDispatchError(domain->conn);
-    return -1;
+    ret = virDomainMigrateUnmanagedParams(domain, dconnuri,
+                                          params, nparams, flags);
+ cleanup:
+    if (ret < 0)
+        virDispatchError(domain->conn);
+    return ret;
 }
 
 
-- 
1.7.1

--
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]