[PATCH v3 1/2] libxl: refactor libxlDomainMigrationPrepare

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

 



The newly introduced function libxlDomainMigrationPrepareAny
will be shared between P2P and tunnelled variations.

Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx>
---
 src/libxl/libxl_migration.c | 92 +++++++++++++++++++++++++++------------------
 1 file changed, 56 insertions(+), 36 deletions(-)

diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index a471d2a..7beabd2 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -483,41 +483,26 @@ libxlDomainMigrationPrepareDef(libxlDriverPrivatePtr driver,
     return def;
 }
 
-int
-libxlDomainMigrationPrepare(virConnectPtr dconn,
-                            virDomainDefPtr *def,
-                            const char *uri_in,
-                            char **uri_out,
-                            const char *cookiein,
-                            int cookieinlen,
-                            unsigned int flags)
+static int
+libxlDomainMigrationPrepareAny(virConnectPtr dconn,
+                               virDomainDefPtr *def,
+                               const char *cookiein,
+                               int cookieinlen,
+                               libxlMigrationCookiePtr *mig,
+                               char **xmlout,
+                               bool *taint_hook)
 {
     libxlDriverPrivatePtr driver = dconn->privateData;
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
-    libxlMigrationCookiePtr mig = NULL;
-    virDomainObjPtr vm = NULL;
-    char *hostname = NULL;
-    char *xmlout = NULL;
-    unsigned short port;
-    char portstr[100];
-    virURIPtr uri = NULL;
-    virNetSocketPtr *socks = NULL;
-    size_t nsocks = 0;
-    int nsocks_listen = 0;
-    libxlMigrationDstArgs *args = NULL;
-    bool taint_hook = false;
-    libxlDomainObjPrivatePtr priv = NULL;
-    size_t i;
-    int ret = -1;
 
-    if (libxlMigrationEatCookie(cookiein, cookieinlen, &mig) < 0)
-        goto error;
+    if (libxlMigrationEatCookie(cookiein, cookieinlen, mig) < 0)
+        return -1;
 
-    if (mig->xenMigStreamVer > LIBXL_SAVE_VERSION) {
+    if ((*mig)->xenMigStreamVer > LIBXL_SAVE_VERSION) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("Xen migration stream version '%d' is not supported on this host"),
-                       mig->xenMigStreamVer);
-        goto error;
+                       (*mig)->xenMigStreamVer);
+        return -1;
     }
 
     /* Let migration hook filter domain XML */
@@ -528,29 +513,29 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
         if (!(xml = virDomainDefFormat(*def, cfg->caps,
                                        VIR_DOMAIN_XML_SECURE |
                                        VIR_DOMAIN_XML_MIGRATABLE)))
-            goto error;
+            return -1;
 
         hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, (*def)->name,
                               VIR_HOOK_LIBXL_OP_MIGRATE, VIR_HOOK_SUBOP_BEGIN,
-                              NULL, xml, &xmlout);
+                              NULL, xml, xmlout);
         VIR_FREE(xml);
 
         if (hookret < 0) {
-            goto error;
+            return -1;
         } else if (hookret == 0) {
-            if (virStringIsEmpty(xmlout)) {
+            if (virStringIsEmpty(*xmlout)) {
                 VIR_DEBUG("Migrate hook filter returned nothing; using the"
                           " original XML");
             } else {
                 virDomainDefPtr newdef;
 
-                VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout);
-                newdef = virDomainDefParseString(xmlout, cfg->caps, driver->xmlopt,
+                VIR_DEBUG("Using hook-filtered domain XML: %s", *xmlout);
+                newdef = virDomainDefParseString(*xmlout, cfg->caps, driver->xmlopt,
                                                  NULL,
                                                  VIR_DOMAIN_DEF_PARSE_INACTIVE |
                                                  VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
                 if (!newdef)
-                    goto error;
+                    return -1;
 
                 /* TODO At some stage we will want to have some check of what the user
                  * did in the hook. */
@@ -560,17 +545,52 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
                 /* We should taint the domain here. However, @vm and therefore
                  * privateData too are still NULL, so just notice the fact and
                  * taint it later. */
-                taint_hook = true;
+                *taint_hook = true;
             }
         }
     }
 
+    return 0;
+}
+
+int
+libxlDomainMigrationPrepare(virConnectPtr dconn,
+                            virDomainDefPtr *def,
+                            const char *uri_in,
+                            char **uri_out,
+                            const char *cookiein,
+                            int cookieinlen,
+                            unsigned int flags)
+{
+    libxlDriverPrivatePtr driver = dconn->privateData;
+    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    libxlMigrationCookiePtr mig = NULL;
+    virDomainObjPtr vm = NULL;
+    char *hostname = NULL;
+    char *xmlout = NULL;
+    unsigned short port;
+    char portstr[100];
+    virURIPtr uri = NULL;
+    virNetSocketPtr *socks = NULL;
+    size_t nsocks = 0;
+    int nsocks_listen = 0;
+    libxlMigrationDstArgs *args = NULL;
+    bool taint_hook = false;
+    libxlDomainObjPrivatePtr priv = NULL;
+    size_t i;
+    int ret = -1;
+
+    if (libxlDomainMigrationPrepareAny(dconn, def, cookiein, cookieinlen,
+                                       &mig, &xmlout, &taint_hook) < 0)
+        goto error;
+
     if (!(vm = virDomainObjListAdd(driver->domains, *def,
                                    driver->xmlopt,
                                    VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
                                    VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
                                    NULL)))
         goto error;
+
     *def = NULL;
     priv = vm->privateData;
 
-- 
2.1.4

--
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]
  Powered by Linux