[PATCH 11/12] migration: refactor: introduce parameter checking function

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

 



virDomainMigrateUnmanagedParams is not a good candidate for this functionality
as it is used by migrate family functions too and its have its own checks that
are superset of extracted and we don't need to check twice.

Actually name of the function is slightly misleading as there is also a check
for consistensy of flags parameter alone. So it could be refactored further and
reused by all migrate functions but for now let it be a matter of a different
patchset.

It is *not* a pure refactoring patch as it introduces offline check for older
versions. Looks like it must be done that way and no one will be broken too.

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

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 2778a15..35dfa3f 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -4139,6 +4139,46 @@ virDomainMigrate3(virDomainPtr domain,
 }
 
 
+static
+int virDomainMigrateUnmanagedCheckCompat(virDomainPtr domain,
+                                         unsigned int flags)
+{
+    VIR_EXCLUSIVE_FLAGS_RET(VIR_MIGRATE_NON_SHARED_DISK,
+                            VIR_MIGRATE_NON_SHARED_INC,
+                            -1);
+
+    if (flags & VIR_MIGRATE_OFFLINE &&
+        !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+                                  VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                       _("offline migration is not supported by "
+                         "the source host"));
+        return -1;
+    }
+
+    if (flags & VIR_MIGRATE_PEER2PEER) {
+        if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+                                      VIR_DRV_FEATURE_MIGRATION_P2P)) {
+            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                           _("p2p migration is not supported by "
+                             "the source host"));
+            return -1;
+        }
+    } else {
+        if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+                                      VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
+            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                           _("direct migration is not supported by "
+                             "the source host"));
+            return -1;
+        }
+    }
+
+
+    return 0;
+}
+
+
 /**
  * virDomainMigrateToURI:
  * @domain: a domain object
@@ -4217,6 +4257,9 @@ virDomainMigrateToURI(virDomainPtr domain,
                       const char *dname,
                       unsigned long bandwidth)
 {
+    const char *dconnuri = NULL;
+    const char *miguri = NULL;
+
     VIR_DOMAIN_DEBUG(domain, "duri=%p, flags=%lx, dname=%s, bandwidth=%lu",
                      NULLSTR(duri), flags, NULLSTR(dname), bandwidth);
 
@@ -4225,49 +4268,19 @@ virDomainMigrateToURI(virDomainPtr domain,
     /* First checkout the source */
     virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);
-
     virCheckNonNullArgGoto(duri, error);
 
-    VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK,
-                             VIR_MIGRATE_NON_SHARED_INC,
-                             error);
-
-    if (flags & VIR_MIGRATE_OFFLINE &&
-        !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                  VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
-        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                       _("offline migration is not supported by "
-                         "the source host"));
+    if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
         goto error;
-    }
 
-    if (flags & VIR_MIGRATE_PEER2PEER) {
-        if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                     VIR_DRV_FEATURE_MIGRATION_P2P)) {
-            VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigrateUnmanaged(domain, NULL, flags,
-                                          dname, duri, NULL, bandwidth) < 0)
-                goto error;
-        } else {
-            /* No peer to peer migration supported */
-            virReportUnsupportedError();
-            goto error;
-        }
-    } else {
-        if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                     VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
-            VIR_DEBUG("Using direct migration");
-            if (virDomainMigrateUnmanaged(domain, NULL, flags,
-                                          dname, NULL, duri, bandwidth) < 0)
-                goto error;
-        } else {
-            /* Cannot do a migration with only the perform step */
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("direct migration is not supported by the"
-                             " connection driver"));
-            goto error;
-        }
-    }
+    if (flags & VIR_MIGRATE_PEER2PEER)
+        dconnuri = duri;
+    else
+        miguri = duri;
+
+    if (virDomainMigrateUnmanaged(domain, NULL, flags,
+                                  dname, dconnuri, miguri, bandwidth) < 0)
+        goto error;
 
     return 0;
 
@@ -4383,37 +4396,15 @@ virDomainMigrateToURI2(virDomainPtr domain,
     virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);
 
-    VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK,
-                             VIR_MIGRATE_NON_SHARED_INC,
-                             error);
+    if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
+        goto error;
 
-    if (flags & VIR_MIGRATE_PEER2PEER) {
-        if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                     VIR_DRV_FEATURE_MIGRATION_P2P)) {
-            VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigrateUnmanaged(domain, dxml, flags,
-                                          dname, dconnuri, miguri, bandwidth) < 0)
-                goto error;
-        } else {
-            /* No peer to peer migration supported */
-            virReportUnsupportedError();
-            goto error;
-        }
-    } else {
-        if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                     VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
-            VIR_DEBUG("Using direct migration");
-            if (virDomainMigrateUnmanaged(domain, dxml, flags,
-                                          dname, NULL, miguri, bandwidth) < 0)
-                goto error;
-        } else {
-            /* Cannot do a migration with only the perform step */
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("direct migration is not supported by the"
-                             " connection driver"));
-            goto error;
-        }
-    }
+    if (!(flags & VIR_MIGRATE_PEER2PEER))
+        dconnuri = NULL;
+
+    if (virDomainMigrateUnmanaged(domain, NULL, flags,
+                                  dname, dconnuri, miguri, bandwidth) < 0)
+        goto error;
 
     return 0;
 
@@ -4477,37 +4468,15 @@ virDomainMigrateToURI3(virDomainPtr domain,
     virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);
 
-    VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK,
-                             VIR_MIGRATE_NON_SHARED_INC,
-                             error);
-
-    if (flags & VIR_MIGRATE_PEER2PEER) {
-        if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                      VIR_DRV_FEATURE_MIGRATION_P2P)) {
-            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                           _("Peer-to-peer migration is not supported by "
-                             "the connection driver"));
-            goto error;
-        }
+    if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
+        goto error;
 
-        VIR_DEBUG("Using peer2peer migration");
-        if (virDomainMigrateUnmanagedParams(domain, dconnuri, params, nparams, flags) < 0)
-            goto error;
-    } else {
-        if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
-                                      VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
-            /* Cannot do a migration with only the perform step */
-            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                           _("Direct migration is not supported by the"
-                             " connection driver"));
-            goto error;
-        }
+    if (!(flags & VIR_MIGRATE_PEER2PEER))
+        dconnuri = NULL;
 
-        VIR_DEBUG("Using direct migration");
-        if (virDomainMigrateUnmanagedParams(domain, NULL, params,
-                                            nparams, flags) < 0)
-            goto error;
-    }
+    if (virDomainMigrateUnmanagedParams(domain, dconnuri,
+                                        params, nparams, flags) < -1)
+        goto error;
 
     return 0;
 
-- 
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]