[libvirt] [PATCH 2/6] vz: pass cookies in xml form

nshirokovskiy at virtuozzo.com nshirokovskiy at virtuozzo.com
Mon Jul 13 12:28:52 UTC 2015


From: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>

This way we can easily keep backward compatibility
in the future.

Use 2 distinct cookies format:
1 - between phases 'prepare' and 'perform'
2 - between phases 'perform' and 'finish'
I see no reason to use unified format like in qemu yet.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/vz/vz_driver.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++------
 src/vz/vz_sdk.c    |    3 +
 2 files changed, 102 insertions(+), 12 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index e003646..d5cbdc6 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1412,6 +1412,101 @@ vzCreateMigrateUri(void)
     return out;
 }
 
+static char*
+vzFormatCookie1(const unsigned char *session_uuid)
+{
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virBufferAddLit(&buf, "<vz-migration1>\n");
+    virUUIDFormat(session_uuid, uuidstr);
+    virBufferAsprintf(&buf, "<session_uuid>%s</session_uuid>\n", uuidstr);
+    virBufferAddLit(&buf, "</vz-migration1>\n");
+
+    if (virBufferCheckError(&buf) < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
+static char*
+vzFormatCookie2(const unsigned char *domain_uuid)
+{
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virBufferAddLit(&buf, "<vz-migration2>\n");
+    virUUIDFormat(domain_uuid, uuidstr);
+    virBufferAsprintf(&buf, "<domain_uuid>%s</domain_uuid>\n", uuidstr);
+    virBufferAddLit(&buf, "</vz-migration2>\n");
+
+    if (virBufferCheckError(&buf) < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
+static int
+vzParseCookie1(const char *xml, unsigned char *session_uuid)
+{
+    xmlDocPtr doc = NULL;
+    xmlXPathContextPtr ctx = NULL;
+    char *tmp = NULL;
+    int ret = -1;
+
+    if (!(doc = virXMLParseStringCtxt(xml, _("(_migration_cookie)"), &ctx)))
+        goto cleanup;
+
+    if (!(tmp = virXPathString("string(./session_uuid[1])", ctx))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("missing session_uuid element in migration data"));
+        goto cleanup;
+    }
+    if (virUUIDParse(tmp, session_uuid) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("malformed session_uuid element in migration data"));
+        goto cleanup;
+    }
+    ret = 0;
+
+ cleanup:
+    xmlXPathFreeContext(ctx);
+    xmlFreeDoc(doc);
+    VIR_FREE(tmp);
+
+    return ret;
+}
+
+static int
+vzParseCookie2(const char *xml, unsigned char *domain_uuid)
+{
+    xmlDocPtr doc = NULL;
+    xmlXPathContextPtr ctx = NULL;
+    char *tmp = NULL;
+    int ret = -1;
+    if (!(doc = virXMLParseStringCtxt(xml, _("(_migration_cookie)"), &ctx)))
+        goto cleanup;
+
+    if (!(tmp = virXPathString("string(./domain_uuid[1])", ctx))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("missing domain_uuid element in migration data"));
+        goto cleanup;
+    }
+    if (virUUIDParse(tmp, domain_uuid) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("malformed domain_uuid element in migration data"));
+        goto cleanup;
+    }
+    ret = 0;
+
+ cleanup:
+    xmlXPathFreeContext(ctx);
+    xmlFreeDoc(doc);
+    VIR_FREE(tmp);
+
+    return ret;
+}
+
 static int
 vzDomainMigratePrepare3Params(virConnectPtr dconn,
                               virTypedParameterPtr params ATTRIBUTE_UNUSED,
@@ -1425,13 +1520,11 @@ vzDomainMigratePrepare3Params(virConnectPtr dconn,
 {
     vzConnPtr privconn = dconn->privateData;
     int ret = -1;
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     *cookieout = NULL;
     *uri_out = NULL;
 
-    virUUIDFormat(privconn->session_uuid, uuidstr);
-    if (VIR_STRDUP(*cookieout, uuidstr) < 0)
+    if (!(*cookieout = vzFormatCookie1(privconn->session_uuid)))
         goto cleanup;
     *cookieoutlen = strlen(*cookieout) + 1;
 
@@ -1465,7 +1558,6 @@ vzDomainMigratePerform3Params(virDomainPtr domain,
     virDomainObjPtr dom = NULL;
     const char *uri = NULL;
     unsigned char session_uuid[VIR_UUID_BUFLEN];
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     *cookieout = NULL;
 
@@ -1483,14 +1575,13 @@ vzDomainMigratePerform3Params(virDomainPtr domain,
         goto cleanup;
     }
 
-    if (virUUIDParse(cookiein, session_uuid) < 0)
+    if (vzParseCookie1(cookiein, session_uuid) < 0)
         goto cleanup;
 
     if (prlsdkMigrate(dom, uri, session_uuid) < 0)
         goto cleanup;
 
-    virUUIDFormat(domain->uuid, uuidstr);
-    if (VIR_STRDUP(*cookieout, uuidstr) < 0)
+    if (!(*cookieout = vzFormatCookie2(dom->def->uuid)))
         goto cleanup;
     *cookieoutlen = strlen(*cookieout) + 1;
 
@@ -1539,12 +1630,8 @@ vzDomainMigrateFinish3Params(virConnectPtr dconn,
     if (cancelled)
         return NULL;
 
-    if (virUUIDParse(cookiein, domain_uuid) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not parse UUID from string '%s'"),
-                       cookiein);
+    if (vzParseCookie2(cookiein, domain_uuid) < 0)
         goto cleanup;
-    }
 
     if (!(dom = prlsdkAddDomain(privconn, domain_uuid)))
         goto cleanup;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 908bfc1..a329c68 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -42,6 +42,9 @@ prlsdkUUIDParse(const char *uuidstr, unsigned char *uuid);
 
 VIR_LOG_INIT("parallels.sdk");
 
+static int
+prlsdkUUIDParse(const char *uuidstr, unsigned char *uuid);
+
 /*
  * Log error description
  */
-- 
1.7.1




More information about the libvir-list mailing list