[libvirt] [PATCH v2 01/12] migration: refactor: get rid of use_params p2p_full

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Thu Sep 10 13:20:13 UTC 2015


'useParams' parameter usage is an example of contol coupling. Most of the work
inside the function is done differently for different value of this flag except
for the uri check. Lets split this function into 2, one with extensible
parameters set and one with hardcoded parameter set. Common uri check we factor
out in different patch for clarity.

Aim of this patchset is to unify logic for differet parameters representation
so finally we merge this split back thru extensible parameters.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/libvirt-domain.c |  129 +++++++++++++++++++++----------------------------
 1 files changed, 55 insertions(+), 74 deletions(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 964a4d7..1a00485 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -3292,46 +3292,59 @@ virDomainMigrateVersion3Params(virDomainPtr domain,
                                         params, nparams, true, flags);
 }
 
+static int
+virDomainMigratePeer2PeerParams(virDomainPtr domain,
+                                const char *dconnuri,
+                                virTypedParameterPtr params,
+                                int nparams,
+                                unsigned int flags)
+{
+    virURIPtr tempuri = NULL;
+
+    VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparams=%d, flags=%x",
+                     dconnuri, params, nparams, flags);
+    VIR_TYPED_PARAMS_DEBUG(params, nparams);
+
+    if (!domain->conn->driver->domainMigratePerform3Params) {
+        virReportUnsupportedError();
+        return -1;
+    }
+
+    if (!(tempuri = virURIParse(dconnuri)))
+        return -1;
+    if (!tempuri->server || STRPREFIX(tempuri->server, "localhost")) {
+        virReportInvalidArg(dconnuri, "%s",
+                            _("unable to parse server from dconnuri"));
+        virURIFree(tempuri);
+        return -1;
+    }
+    virURIFree(tempuri);
+
+    VIR_DEBUG("Using migration protocol 3 with extensible parameters");
+    return domain->conn->driver->domainMigratePerform3Params
+            (domain, dconnuri, params, nparams,
+             NULL, 0, NULL, NULL, flags);
+}
 
-/*
- * In normal migration, the libvirt client co-ordinates communication
- * between the 2 libvirtd instances on source & dest hosts.
- *
- * In this peer-2-peer migration alternative, the libvirt client
- * only talks to the source libvirtd instance. The source libvirtd
- * then opens its own connection to the destination and co-ordinates
- * migration itself.
- *
- * If useParams is true, params and nparams contain migration parameters and
- * we know it's safe to call the API which supports extensible parameters.
- * Otherwise, we have to use xmlin, dname, uri, and bandwidth and pass them
- * to the old-style APIs.
- */
 static int
-virDomainMigratePeer2PeerFull(virDomainPtr domain,
-                              const char *dconnuri,
-                              const char *xmlin,
-                              const char *dname,
-                              const char *uri,
-                              unsigned long long bandwidth,
-                              virTypedParameterPtr params,
-                              int nparams,
-                              bool useParams,
-                              unsigned int flags)
+virDomainMigratePeer2PeerPlain(virDomainPtr domain,
+                               const char *xmlin,
+                               unsigned int flags,
+                               const char *dname,
+                               const char *dconnuri,
+                               const char *uri,
+                               unsigned long long bandwidth)
 {
     virURIPtr tempuri = NULL;
 
     VIR_DOMAIN_DEBUG(domain,
                      "dconnuri=%s, xmlin=%s, dname=%s, uri=%s, bandwidth=%llu "
-                     "params=%p, nparams=%d, useParams=%d, flags=%x",
+                     "flags=%x",
                      dconnuri, NULLSTR(xmlin), NULLSTR(dname), NULLSTR(uri),
-                     bandwidth, params, nparams, useParams, flags);
-    VIR_TYPED_PARAMS_DEBUG(params, nparams);
+                     bandwidth, flags);
 
-    if ((useParams && !domain->conn->driver->domainMigratePerform3Params) ||
-        (!useParams &&
-         !domain->conn->driver->domainMigratePerform &&
-         !domain->conn->driver->domainMigratePerform3)) {
+    if (!domain->conn->driver->domainMigratePerform &&
+        !domain->conn->driver->domainMigratePerform3) {
         virReportUnsupportedError();
         return -1;
     }
@@ -3346,12 +3359,7 @@ virDomainMigratePeer2PeerFull(virDomainPtr domain,
     }
     virURIFree(tempuri);
 
-    if (useParams) {
-        VIR_DEBUG("Using migration protocol 3 with extensible parameters");
-        return domain->conn->driver->domainMigratePerform3Params
-                (domain, dconnuri, params, nparams,
-                 NULL, 0, NULL, NULL, flags);
-    } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+    if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                         VIR_DRV_FEATURE_MIGRATION_V3)) {
         VIR_DEBUG("Using migration protocol 3");
         return domain->conn->driver->domainMigratePerform3
@@ -3375,33 +3383,6 @@ virDomainMigratePeer2PeerFull(virDomainPtr domain,
     }
 }
 
-
-static int
-virDomainMigratePeer2Peer(virDomainPtr domain,
-                          const char *xmlin,
-                          unsigned long flags,
-                          const char *dname,
-                          const char *dconnuri,
-                          const char *uri,
-                          unsigned long bandwidth)
-{
-    return virDomainMigratePeer2PeerFull(domain, dconnuri, xmlin, dname, uri,
-                                         bandwidth, NULL, 0, false, flags);
-}
-
-
-static int
-virDomainMigratePeer2PeerParams(virDomainPtr domain,
-                                const char *dconnuri,
-                                virTypedParameterPtr params,
-                                int nparams,
-                                unsigned int flags)
-{
-    return virDomainMigratePeer2PeerFull(domain, dconnuri, NULL, NULL, NULL, 0,
-                                         params, nparams, true, flags);
-}
-
-
 /*
  * In normal migration, the libvirt client co-ordinates communication
  * between the 2 libvirtd instances on source & dest hosts.
@@ -3605,8 +3586,8 @@ virDomainMigrate(virDomainPtr domain,
             }
 
             VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigratePeer2Peer(domain, NULL, flags, dname,
-                                          uri ? uri : dstURI, NULL, bandwidth) < 0) {
+            if (virDomainMigratePeer2PeerPlain(domain, NULL, flags, dname,
+                                               uri ? uri : dstURI, NULL, bandwidth) < 0) {
                 VIR_FREE(dstURI);
                 goto error;
             }
@@ -3826,8 +3807,8 @@ virDomainMigrate2(virDomainPtr domain,
                 return NULL;
 
             VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigratePeer2Peer(domain, dxml, flags, dname,
-                                          dstURI, uri, bandwidth) < 0) {
+            if (virDomainMigratePeer2PeerPlain(domain, dxml, flags, dname,
+                                               dstURI, uri, bandwidth) < 0) {
                 VIR_FREE(dstURI);
                 goto error;
             }
@@ -4207,8 +4188,8 @@ virDomainMigrateToURI(virDomainPtr domain,
         if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                      VIR_DRV_FEATURE_MIGRATION_P2P)) {
             VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigratePeer2Peer(domain, NULL, flags,
-                                          dname, duri, NULL, bandwidth) < 0)
+            if (virDomainMigratePeer2PeerPlain(domain, NULL, flags,
+                                               dname, duri, NULL, bandwidth) < 0)
                 goto error;
         } else {
             /* No peer to peer migration supported */
@@ -4353,8 +4334,8 @@ virDomainMigrateToURI2(virDomainPtr domain,
         if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                      VIR_DRV_FEATURE_MIGRATION_P2P)) {
             VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigratePeer2Peer(domain, dxml, flags,
-                                          dname, dconnuri, miguri, bandwidth) < 0)
+            if (virDomainMigratePeer2PeerPlain(domain, dxml, flags,
+                                               dname, dconnuri, miguri, bandwidth) < 0)
                 goto error;
         } else {
             /* No peer to peer migration supported */
@@ -4484,8 +4465,8 @@ virDomainMigrateToURI3(virDomainPtr domain,
                 goto error;
         } else if (compat) {
             VIR_DEBUG("Using peer2peer migration");
-            if (virDomainMigratePeer2Peer(domain, dxml, flags, dname,
-                                          dconnuri, uri, bandwidth) < 0)
+            if (virDomainMigratePeer2PeerPlain(domain, dxml, flags, dname,
+                                               dconnuri, uri, bandwidth) < 0)
                 goto error;
         } else {
             virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-- 
1.7.1




More information about the libvir-list mailing list