
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1205453394 25200 # Node ID 2fa4dbe7b38189aeb1ddb4b770c531a75df788d3 # Parent 311b85abee28e75975e4758b6bc0a5974d3de937 Define guest before migrating. This step ensures that the guest will persist even when the guest is shutdown / destroyed. Since prepare_offline_migration() already has most of the code for this, the re_offline_migration() function can be removed and a common define_gest function can be used instead. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 311b85abee28 -r 2fa4dbe7b381 src/Virt_VSMigrationService.c --- a/src/Virt_VSMigrationService.c Thu Mar 13 08:06:29 2008 -0700 +++ b/src/Virt_VSMigrationService.c Thu Mar 13 17:09:54 2008 -0700 @@ -578,6 +578,51 @@ static void migrate_job_set_state(struct CU_DEBUG("Failed to raise indication"); } +static CMPIStatus define_guest_on_target(virConnectPtr dconn, + virDomainPtr dom, + struct migration_job *job, + bool is_offline_migrate) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + virDomainPtr ddom = NULL; + char *xml = NULL; + + if (!is_offline_migrate) { + ddom = virDomainLookupByName(dconn, job->domain); + if (ddom == NULL) { + CU_DEBUG("Failed to lookup `%s'", job->domain); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to lookup domain `%s'", job->domain); + goto out; + } + + xml = virDomainGetXMLDesc(ddom, 0); + } + else + xml = virDomainGetXMLDesc(dom, 0); + + if (xml == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to retrieve domain XML."); + goto out; + } + + ddom = virDomainDefineXML(dconn, xml); + if (ddom == NULL) { + CU_DEBUG("Failed to define domain from XML"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to create domain"); + } + + out: + free(xml); + virDomainFree(ddom); + return s; +} + static CMPIStatus handle_migrate(virConnectPtr dconn, virDomainPtr dom, char *uri, @@ -601,8 +646,10 @@ static CMPIStatus handle_migrate(virConn return s; } -static CMPIStatus prepare_offline_migrate(virDomainPtr dom, - char **xml) +static CMPIStatus handle_offline_migrate(virConnectPtr dconn, + virDomainPtr dom, + char *uri, + struct migration_job *job) { CMPIStatus s = {CMPI_RC_OK, NULL}; virDomainInfo info; @@ -623,41 +670,13 @@ static CMPIStatus prepare_offline_migrat 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"); + s = define_guest_on_target(dconn, dom, job, true); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Define failed"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to define guest on target system"); + goto out; } out: @@ -670,7 +689,6 @@ static CMPIStatus migrate_vs(struct migr virConnectPtr conn = NULL; virDomainPtr dom = NULL; char *uri = NULL; - char *xml = NULL; conn = connect_by_classname(_BROKER, job->ref_cn, &s); if (conn == NULL) @@ -685,16 +703,10 @@ 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; - } - switch(job->type) { case CIM_MIGRATE_OTHER: CU_DEBUG("Preparing for offline migration"); - s = handle_offline_migrate(job->conn, dom, uri, xml, job); + s = handle_offline_migrate(job->conn, dom, uri, job); break; case CIM_MIGRATE_LIVE: CU_DEBUG("Preparing for live migration"); @@ -717,6 +729,15 @@ static CMPIStatus migrate_vs(struct migr goto out; CU_DEBUG("Migration succeeded"); + + s = define_guest_on_target(job->conn, NULL, job, false); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Define failed"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to define guest on target system"); + } + cu_statusf(_BROKER, &s, CMPI_RC_OK, ""); @@ -725,7 +746,6 @@ static CMPIStatus migrate_vs(struct migr raise_deleted_ind(job); free(uri); - free(xml); virDomainFree(dom); virConnectClose(conn);