Adding domain to domain list on preparation step is not correct.
First domain is not fully constructed - domain definition is
missing. Second we can't use VIR_MIGRATE_PARAM_DEST_XML parameter
to parse definition as vz sdk can patch it by itself. Let's add/remove
domain on finish step. This is for synchronization purpose only so domain
is present/absent on destination after migration completion. Actually
domain object will probably be created right after actual vz sdk
migration start by vz sdk domain defined event.

Signed-off-by: Nikolay Shirokovskiy <nshirokovs...@virtuozzo.com>
---
 src/vz/vz_driver.c | 65 ++++++++++++++++++------------------------------------
 src/vz/vz_sdk.c    | 17 +++++++++++++-
 src/vz/vz_sdk.h    |  5 +++++
 3 files changed, 42 insertions(+), 45 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index a404666..425d89a 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -2283,7 +2283,7 @@ vzDomainMigrateBegin3Params(virDomainPtr domain,
     if (!(dom = vzDomObjFromDomain(domain)))
         goto cleanup;
 
-    /* session uuid is for backward compat */
+    /* session uuid, domain uuid and domain name are for backward compat */
     if (vzBakeCookie(privconn->driver, dom, cookieout, cookieoutlen,
                      VZ_MIGRATION_COOKIE_SESSION_UUID
                      | VZ_MIGRATION_COOKIE_DOMAIN_UUID
@@ -2328,8 +2328,8 @@ static int
 vzDomainMigratePrepare3Params(virConnectPtr conn,
                               virTypedParameterPtr params,
                               int nparams,
-                              const char *cookiein,
-                              int cookieinlen,
+                              const char *cookiein ATTRIBUTE_UNUSED,
+                              int cookieinlen ATTRIBUTE_UNUSED,
                               char **cookieout,
                               int *cookieoutlen,
                               char **uri_out,
@@ -2338,8 +2338,6 @@ vzDomainMigratePrepare3Params(virConnectPtr conn,
     vzConnPtr privconn = conn->privateData;
     const char *miguri = NULL;
     const char *dname = NULL;
-    virDomainObjPtr dom = NULL;
-    vzMigrationCookiePtr mig = NULL;
     int ret = -1;
 
     virCheckFlags(VZ_MIGRATION_FLAGS, -1);
@@ -2358,11 +2356,6 @@ vzDomainMigratePrepare3Params(virConnectPtr conn,
     if (!miguri && !(*uri_out = vzMigrationCreateURI()))
         goto cleanup;
 
-    if (!(mig = vzEatCookie(cookiein, cookieinlen,
-                            VZ_MIGRATION_COOKIE_DOMAIN_UUID
-                            | VZ_MIGRATION_COOKIE_DOMAIN_NAME)))
-        goto cleanup;
-
     /* domain uuid and domain name are for backward compat */
     if (vzBakeCookie(privconn->driver, NULL,
                      cookieout, cookieoutlen,
@@ -2371,30 +2364,9 @@ vzDomainMigratePrepare3Params(virConnectPtr conn,
                      | VZ_MIGRATION_COOKIE_DOMAIN_NAME) < 0)
         goto cleanup;
 
-    virObjectLock(privconn->driver);
-    dom = virDomainObjListFindByUUID(privconn->driver->domains, mig->uuid);
-    if (dom) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(mig->uuid, uuidstr);
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("A domain with uuid '%s' already exists"),
-                       uuidstr);
-        goto unlock;
-    }
-
-    if (!(dom = vzNewDomain(privconn->driver,
-                            dname ? dname : mig->name, mig->uuid)))
-        goto unlock;
-
     ret = 0;
 
- unlock:
-    virObjectUnlock(privconn->driver);
-
  cleanup:
-    vzMigrationCookieFree(mig);
-    if (dom)
-        virObjectUnlock(dom);
     return ret;
 }
 
@@ -2639,29 +2611,32 @@ vzDomainMigrateFinish3Params(virConnectPtr dconn,
     vzConnPtr privconn = dconn->privateData;
     vzDriverPtr driver = privconn->driver;
     const char *name = NULL;
+    PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
 
     virCheckFlags(VZ_MIGRATION_FLAGS, NULL);
 
     if (virTypedParamsValidate(params, nparams, VZ_MIGRATION_PARAMETERS) < 0)
-        goto cleanup;
+        return NULL;
 
     if (virTypedParamsGetString(params, nparams,
                                 VIR_MIGRATE_PARAM_DEST_NAME, &name) < 0)
-        goto cleanup;
-
-    if (!(dom = virDomainObjListFindByName(driver->domains, name))) {
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("no domain with matching name '%s'"), name);
-        goto cleanup;
-    }
+        return NULL;
 
     if (cancelled) {
+        if (!(dom = virDomainObjListFindByName(driver->domains, name)))
+            return NULL;
+
         virDomainObjListRemove(driver->domains, dom);
-        dom = NULL;
-        goto cleanup;
+        virObjectUnref(dom);
+
+        return NULL;
     }
 
-    if (prlsdkLoadDomain(driver, dom))
+    sdkdom = prlsdkSdkDomainLookupByName(driver, name);
+    if (sdkdom == PRL_INVALID_HANDLE)
+        goto cleanup;
+
+    if (!(dom = prlsdkNewDomainByHandle(driver, sdkdom)))
         goto cleanup;
 
     domain = virGetDomain(dconn, dom->def->name, dom->def->uuid);
@@ -2671,9 +2646,11 @@ vzDomainMigrateFinish3Params(virConnectPtr dconn,
  cleanup:
     /* In this situation we have to restore domain on source. But the migration
      * is already finished. */
-    if (!cancelled && !domain)
+    if (!domain)
         VIR_WARN("Can't provide domain '%s' after successfull migration.", 
name);
-    virDomainObjEndAPI(&dom);
+    if (dom)
+        virObjectUnlock(dom);
+    PrlHandle_Free(sdkdom);
     return domain;
 }
 
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 2f3f125..72da66a 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -375,6 +375,21 @@ prlsdkSdkDomainLookupByUUID(vzDriverPtr driver, const 
unsigned char *uuid)
     return sdkdom;
 }
 
+PRL_HANDLE
+prlsdkSdkDomainLookupByName(vzDriverPtr driver, const char *name)
+{
+    PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
+
+    if (prlsdkSdkDomainLookup(driver, name,
+                              PGVC_SEARCH_BY_NAME, &sdkdom) < 0) {
+        virReportError(VIR_ERR_NO_DOMAIN,
+                       _("no domain with matching name '%s'"), name);
+        return PRL_INVALID_HANDLE;
+    }
+
+    return sdkdom;
+}
+
 static int
 prlsdkUUIDParse(const char *uuidstr, unsigned char *uuid)
 {
@@ -1243,7 +1258,7 @@ prlsdkConvertCpuMode(PRL_HANDLE sdkdom, virDomainDefPtr 
def)
     return -1;
 }
 
-static virDomainObjPtr
+virDomainObjPtr
 prlsdkNewDomainByHandle(vzDriverPtr driver, PRL_HANDLE sdkdom)
 {
     virDomainObjPtr dom = NULL;
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index f570560..75f66d6 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -93,3 +93,8 @@ prlsdkMigrate(virDomainObjPtr dom,
               const char unsigned *session_uuid,
               const char *dname,
               unsigned int flags);
+
+PRL_HANDLE
+prlsdkSdkDomainLookupByName(vzDriverPtr driver, const char *name);
+virDomainObjPtr
+prlsdkNewDomainByHandle(vzDriverPtr driver, PRL_HANDLE sdkdom);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to