[Libvirt-cim] [PATCH 4 of 4] Add offline migration support

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Feb 27 00:03:45 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1204070582 28800
# Node ID 4310ed87a132963947ad866eccca7d9697ef8fcf
# Parent  09153317203d6a60ede32daf5f2ce5765b6d9953
Add offline migration support.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 09153317203d -r 4310ed87a132 src/Virt_VSMigrationService.c
--- a/src/Virt_VSMigrationService.c	Mon Feb 25 16:36:25 2008 -0800
+++ b/src/Virt_VSMigrationService.c	Tue Feb 26 16:03:02 2008 -0800
@@ -410,6 +410,69 @@ static CMPIStatus handle_migrate(virConn
         return s;
 }
 
+static CMPIStatus prepare_offline_migrate(virDomainPtr dom,
+                                          char **xml)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        virDomainInfo info;
+        int ret;
+
+        ret = virDomainGetInfo(dom, &info);
+        if (ret != 0) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unabled to get info for domain.");
+                goto out;
+        }
+
+        if ((const int)info.state != VIR_DOMAIN_SHUTOFF) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_INVALID_PARAMETER,
+                           "Domain must be shutoff for offline migration.");
+                goto out;
+        }
+
+        *xml = virDomainGetXMLDesc(dom, 0);
+        if (*xml == NULL) {
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to retrieve domain XML.");
+                goto out;
+        }
+
+ out:
+        return s;
+}
+
+static CMPIStatus handle_offline_migrate(virConnectPtr dconn,
+                                         virDomainPtr dom,
+                                         char *uri,
+                                         char *xml,
+                                         struct migration_job *job)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        virDomainPtr new_dom;
+
+        if (domain_exists(dconn, job->domain)) {
+                CU_DEBUG("This domain already exists on the target system.");
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "This domain already exists on the target system");
+                goto out;
+        }
+
+        new_dom = virDomainDefineXML(dconn, xml);
+        if (new_dom == NULL) {
+                CU_DEBUG("Failed to define domain from XML");
+                cu_statusf(_BROKER, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Failed to create domain");
+        }
+
+ out:
+        return s;
+}
+
 static CMPIStatus migrate_vs(struct migration_job *job)
 {
         CMPIStatus s;
@@ -417,6 +480,7 @@ static CMPIStatus migrate_vs(struct migr
         virConnectPtr dconn = NULL;
         virDomainPtr dom = NULL;
         char *uri = NULL;
+        char *xml = NULL;
 
         uri = dest_uri(job->ref_cn, job->host);
         if (uri == NULL) {
@@ -439,6 +503,12 @@ static CMPIStatus migrate_vs(struct migr
                 goto out;
         }
 
+        if (job->type == CIM_MIGRATE_OTHER) {
+                s = prepare_offline_migrate(dom, &xml);
+                if (s.rc != CMPI_RC_OK)
+                        goto out;
+        }
+
         dconn = virConnectOpen(uri);
         if (dconn == NULL) {
                 CU_DEBUG("Failed to connect to remote host (%s)", uri);
@@ -450,8 +520,8 @@ static CMPIStatus migrate_vs(struct migr
 
         switch(job->type) {
         case CIM_MIGRATE_OTHER:
-                /* FIXME - Handle offline migration here */
                 CU_DEBUG("Preparing for offline migration");
+                s = handle_offline_migrate(dconn, dom, uri, xml, job);
                 break;
         case CIM_MIGRATE_LIVE:
                 CU_DEBUG("Preparing for live migration");
@@ -480,6 +550,7 @@ static CMPIStatus migrate_vs(struct migr
 
  out:
         free(uri);
+        free(xml);
         virDomainFree(dom);
         virConnectClose(conn);
         virConnectClose(dconn);




More information about the Libvirt-cim mailing list