]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
migration: refactor: reuse p2p url check
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Fri, 2 Oct 2015 07:52:42 +0000 (10:52 +0300)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 12 Oct 2015 11:30:53 +0000 (13:30 +0200)
Refactor dconnuri local server URI check to common API.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
src/libvirt-domain.c

index 697d58d2d0d05aa41b0fd6184393990c6d408c1d..35d60d004f8296f5757bd515ffb202f687228ff4 100644 (file)
@@ -3293,6 +3293,28 @@ virDomainMigrateVersion3Params(virDomainPtr domain,
 }
 
 
+static int ATTRIBUTE_NONNULL(1)
+virDomainMigrateCheckNotLocal(const char *dconnuri)
+{
+    virURIPtr tempuri = NULL;
+    int ret = -1;
+
+    if (!(tempuri = virURIParse(dconnuri)))
+        goto cleanup;
+    if (!tempuri->server || STRPREFIX(tempuri->server, "localhost")) {
+        virReportInvalidArg(dconnuri, "%s",
+                            _("Attempt to migrate guest to the same host %s"));
+        goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    virURIFree(tempuri);
+    return ret;
+}
+
+
 /*
  * In normal migration, the libvirt client co-ordinates communication
  * between the 2 libvirtd instances on source & dest hosts.
@@ -3311,8 +3333,6 @@ virDomainMigratePeer2PeerPlain(virDomainPtr domain,
                                const char *uri,
                                unsigned long long bandwidth)
 {
-    virURIPtr tempuri = NULL;
-
     VIR_DOMAIN_DEBUG(domain,
                      "dconnuri=%s, xmlin=%s, dname=%s, uri=%s, bandwidth=%llu "
                      "flags=%x",
@@ -3325,15 +3345,8 @@ virDomainMigratePeer2PeerPlain(virDomainPtr domain,
         return -1;
     }
 
-    if (!(tempuri = virURIParse(dconnuri)))
+    if (virDomainMigrateCheckNotLocal(dconnuri) < 0)
         return -1;
-    if (!tempuri->server || STRPREFIX(tempuri->server, "localhost")) {
-        virReportInvalidArg(dconnuri, "%s",
-                            _("unable to parse server from dconnuri"));
-        virURIFree(tempuri);
-        return -1;
-    }
-    virURIFree(tempuri);
 
     if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                  VIR_DRV_FEATURE_MIGRATION_V3)) {
@@ -3367,8 +3380,6 @@ virDomainMigratePeer2PeerParams(virDomainPtr domain,
                                 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);
@@ -3378,15 +3389,8 @@ virDomainMigratePeer2PeerParams(virDomainPtr domain,
         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);
+    if (virDomainMigrateCheckNotLocal(dconnuri) < 0)
         return -1;
-    }
-    virURIFree(tempuri);
 
     VIR_DEBUG("Using migration protocol 3 with extensible parameters");
     return domain->conn->driver->domainMigratePerform3Params