mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: Move internals of Confirm phase to qemu_migration.c
This commit is contained in:
parent
ecd811310c
commit
1004d6323a
@ -10338,53 +10338,20 @@ qemuDomainMigrateConfirm3(virDomainPtr domain,
|
|||||||
unsigned long flags,
|
unsigned long flags,
|
||||||
int cancelled)
|
int cancelled)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = domain->conn->privateData;
|
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
int ret = -1;
|
|
||||||
enum qemuMigrationJobPhase phase;
|
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
|
||||||
|
|
||||||
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
|
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
|
||||||
|
|
||||||
if (!(vm = qemuDomObjFromDomain(domain)))
|
if (!(vm = qemuDomObjFromDomain(domain)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
if (virDomainMigrateConfirm3EnsureACL(domain->conn, vm->def) < 0) {
|
||||||
|
virObjectUnlock(vm);
|
||||||
if (virDomainMigrateConfirm3EnsureACL(domain->conn, vm->def) < 0)
|
return -1;
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_OUT))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (cancelled)
|
|
||||||
phase = QEMU_MIGRATION_PHASE_CONFIRM3_CANCELLED;
|
|
||||||
else
|
|
||||||
phase = QEMU_MIGRATION_PHASE_CONFIRM3;
|
|
||||||
|
|
||||||
qemuMigrationJobStartPhase(driver, vm, phase);
|
|
||||||
virQEMUCloseCallbacksUnset(driver->closeCallbacks, vm,
|
|
||||||
qemuMigrationCleanup);
|
|
||||||
|
|
||||||
ret = qemuMigrationConfirm(driver, domain->conn, vm,
|
|
||||||
cookiein, cookieinlen,
|
|
||||||
flags, cancelled);
|
|
||||||
|
|
||||||
if (qemuMigrationJobFinish(driver, vm) == 0) {
|
|
||||||
vm = NULL;
|
|
||||||
} else if (!virDomainObjIsActive(vm) &&
|
|
||||||
(!vm->persistent || (flags & VIR_MIGRATE_UNDEFINE_SOURCE))) {
|
|
||||||
if (flags & VIR_MIGRATE_UNDEFINE_SOURCE)
|
|
||||||
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
|
|
||||||
qemuDomainRemoveInactive(driver, vm);
|
|
||||||
vm = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
return qemuMigrationConfirm(domain->conn, vm, cookiein, cookieinlen,
|
||||||
if (vm)
|
flags, cancelled);
|
||||||
virObjectUnlock(vm);
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2624,6 +2624,140 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuMigrationConfirmPhase(virQEMUDriverPtr driver,
|
||||||
|
virConnectPtr conn,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
const char *cookiein,
|
||||||
|
int cookieinlen,
|
||||||
|
unsigned int flags,
|
||||||
|
int retcode)
|
||||||
|
{
|
||||||
|
qemuMigrationCookiePtr mig;
|
||||||
|
virDomainEventPtr event = NULL;
|
||||||
|
int rv = -1;
|
||||||
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
|
||||||
|
VIR_DEBUG("driver=%p, conn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
|
||||||
|
"flags=%x, retcode=%d",
|
||||||
|
driver, conn, vm, NULLSTR(cookiein), cookieinlen,
|
||||||
|
flags, retcode);
|
||||||
|
|
||||||
|
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
|
||||||
|
|
||||||
|
qemuMigrationJobSetPhase(driver, vm,
|
||||||
|
retcode == 0
|
||||||
|
? QEMU_MIGRATION_PHASE_CONFIRM3
|
||||||
|
: QEMU_MIGRATION_PHASE_CONFIRM3_CANCELLED);
|
||||||
|
|
||||||
|
if (!(mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen, 0)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (flags & VIR_MIGRATE_OFFLINE)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
/* Did the migration go as planned? If yes, kill off the
|
||||||
|
* domain object, but if no, resume CPUs
|
||||||
|
*/
|
||||||
|
if (retcode == 0) {
|
||||||
|
/* If guest uses SPICE and supports seamless migration we have to hold
|
||||||
|
* up domain shutdown until SPICE server transfers its data */
|
||||||
|
qemuMigrationWaitForSpice(driver, vm);
|
||||||
|
|
||||||
|
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED,
|
||||||
|
VIR_QEMU_PROCESS_STOP_MIGRATED);
|
||||||
|
virDomainAuditStop(vm, "migrated");
|
||||||
|
|
||||||
|
event = virDomainEventNewFromObj(vm,
|
||||||
|
VIR_DOMAIN_EVENT_STOPPED,
|
||||||
|
VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* cancel any outstanding NBD jobs */
|
||||||
|
qemuMigrationCancelDriveMirror(mig, driver, vm);
|
||||||
|
|
||||||
|
/* run 'cont' on the destination, which allows migration on qemu
|
||||||
|
* >= 0.10.6 to work properly. This isn't strictly necessary on
|
||||||
|
* older qemu's, but it also doesn't hurt anything there
|
||||||
|
*/
|
||||||
|
if (qemuProcessStartCPUs(driver, vm, conn,
|
||||||
|
VIR_DOMAIN_RUNNING_MIGRATED,
|
||||||
|
QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) {
|
||||||
|
if (virGetLastError() == NULL)
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("resume operation failed"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
event = virDomainEventNewFromObj(vm,
|
||||||
|
VIR_DOMAIN_EVENT_RESUMED,
|
||||||
|
VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
|
||||||
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) {
|
||||||
|
VIR_WARN("Failed to save status on vm %s", vm->def->name);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
qemuMigrationCookieFree(mig);
|
||||||
|
rv = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (event)
|
||||||
|
qemuDomainEventQueue(driver, event);
|
||||||
|
virObjectUnref(cfg);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuMigrationConfirm(virConnectPtr conn,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
const char *cookiein,
|
||||||
|
int cookieinlen,
|
||||||
|
unsigned int flags,
|
||||||
|
int cancelled)
|
||||||
|
{
|
||||||
|
virQEMUDriverPtr driver = conn->privateData;
|
||||||
|
enum qemuMigrationJobPhase phase;
|
||||||
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
|
||||||
|
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_OUT))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (cancelled)
|
||||||
|
phase = QEMU_MIGRATION_PHASE_CONFIRM3_CANCELLED;
|
||||||
|
else
|
||||||
|
phase = QEMU_MIGRATION_PHASE_CONFIRM3;
|
||||||
|
|
||||||
|
qemuMigrationJobStartPhase(driver, vm, phase);
|
||||||
|
virQEMUCloseCallbacksUnset(driver->closeCallbacks, vm,
|
||||||
|
qemuMigrationCleanup);
|
||||||
|
|
||||||
|
ret = qemuMigrationConfirmPhase(driver, conn, vm,
|
||||||
|
cookiein, cookieinlen,
|
||||||
|
flags, cancelled);
|
||||||
|
|
||||||
|
if (qemuMigrationJobFinish(driver, vm) == 0) {
|
||||||
|
vm = NULL;
|
||||||
|
} else if (!virDomainObjIsActive(vm) &&
|
||||||
|
(!vm->persistent || (flags & VIR_MIGRATE_UNDEFINE_SOURCE))) {
|
||||||
|
if (flags & VIR_MIGRATE_UNDEFINE_SOURCE)
|
||||||
|
virDomainDeleteConfig(cfg->configDir, cfg->autostartDir, vm);
|
||||||
|
qemuDomainRemoveInactive(driver, vm);
|
||||||
|
vm = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (vm)
|
||||||
|
virObjectUnlock(vm);
|
||||||
|
virObjectUnref(cfg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enum qemuMigrationDestinationType {
|
enum qemuMigrationDestinationType {
|
||||||
MIGRATION_DEST_HOST,
|
MIGRATION_DEST_HOST,
|
||||||
MIGRATION_DEST_CONNECT_HOST,
|
MIGRATION_DEST_CONNECT_HOST,
|
||||||
@ -3597,9 +3731,9 @@ finish:
|
|||||||
cookieinlen = cookieoutlen;
|
cookieinlen = cookieoutlen;
|
||||||
cookieout = NULL;
|
cookieout = NULL;
|
||||||
cookieoutlen = 0;
|
cookieoutlen = 0;
|
||||||
ret = qemuMigrationConfirm(driver, sconn, vm,
|
ret = qemuMigrationConfirmPhase(driver, sconn, vm,
|
||||||
cookiein, cookieinlen,
|
cookiein, cookieinlen,
|
||||||
flags, cancelled);
|
flags, cancelled);
|
||||||
/* If Confirm3 returns -1, there's nothing more we can
|
/* If Confirm3 returns -1, there's nothing more we can
|
||||||
* do, but fortunately worst case is that there is a
|
* do, but fortunately worst case is that there is a
|
||||||
* domain left in 'paused' state on source.
|
* domain left in 'paused' state on source.
|
||||||
@ -4267,91 +4401,6 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int qemuMigrationConfirm(virQEMUDriverPtr driver,
|
|
||||||
virConnectPtr conn,
|
|
||||||
virDomainObjPtr vm,
|
|
||||||
const char *cookiein,
|
|
||||||
int cookieinlen,
|
|
||||||
unsigned int flags,
|
|
||||||
int retcode)
|
|
||||||
{
|
|
||||||
qemuMigrationCookiePtr mig;
|
|
||||||
virDomainEventPtr event = NULL;
|
|
||||||
int rv = -1;
|
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
|
||||||
|
|
||||||
VIR_DEBUG("driver=%p, conn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
|
|
||||||
"flags=%x, retcode=%d",
|
|
||||||
driver, conn, vm, NULLSTR(cookiein), cookieinlen,
|
|
||||||
flags, retcode);
|
|
||||||
|
|
||||||
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
|
|
||||||
|
|
||||||
qemuMigrationJobSetPhase(driver, vm,
|
|
||||||
retcode == 0
|
|
||||||
? QEMU_MIGRATION_PHASE_CONFIRM3
|
|
||||||
: QEMU_MIGRATION_PHASE_CONFIRM3_CANCELLED);
|
|
||||||
|
|
||||||
if (!(mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen, 0)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (flags & VIR_MIGRATE_OFFLINE)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
/* Did the migration go as planned? If yes, kill off the
|
|
||||||
* domain object, but if no, resume CPUs
|
|
||||||
*/
|
|
||||||
if (retcode == 0) {
|
|
||||||
/* If guest uses SPICE and supports seamless migration we have to hold
|
|
||||||
* up domain shutdown until SPICE server transfers its data */
|
|
||||||
qemuMigrationWaitForSpice(driver, vm);
|
|
||||||
|
|
||||||
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED,
|
|
||||||
VIR_QEMU_PROCESS_STOP_MIGRATED);
|
|
||||||
virDomainAuditStop(vm, "migrated");
|
|
||||||
|
|
||||||
event = virDomainEventNewFromObj(vm,
|
|
||||||
VIR_DOMAIN_EVENT_STOPPED,
|
|
||||||
VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/* cancel any outstanding NBD jobs */
|
|
||||||
qemuMigrationCancelDriveMirror(mig, driver, vm);
|
|
||||||
|
|
||||||
/* run 'cont' on the destination, which allows migration on qemu
|
|
||||||
* >= 0.10.6 to work properly. This isn't strictly necessary on
|
|
||||||
* older qemu's, but it also doesn't hurt anything there
|
|
||||||
*/
|
|
||||||
if (qemuProcessStartCPUs(driver, vm, conn,
|
|
||||||
VIR_DOMAIN_RUNNING_MIGRATED,
|
|
||||||
QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) {
|
|
||||||
if (virGetLastError() == NULL)
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("resume operation failed"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
event = virDomainEventNewFromObj(vm,
|
|
||||||
VIR_DOMAIN_EVENT_RESUMED,
|
|
||||||
VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
|
|
||||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) {
|
|
||||||
VIR_WARN("Failed to save status on vm %s", vm->def->name);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
done:
|
|
||||||
qemuMigrationCookieFree(mig);
|
|
||||||
rv = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (event)
|
|
||||||
qemuDomainEventQueue(driver, event);
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Helper function called while vm is active. */
|
/* Helper function called while vm is active. */
|
||||||
int
|
int
|
||||||
qemuMigrationToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
|
qemuMigrationToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
|
||||||
|
@ -143,13 +143,12 @@ virDomainPtr qemuMigrationFinish(virQEMUDriverPtr driver,
|
|||||||
int retcode,
|
int retcode,
|
||||||
bool v3proto);
|
bool v3proto);
|
||||||
|
|
||||||
int qemuMigrationConfirm(virQEMUDriverPtr driver,
|
int qemuMigrationConfirm(virConnectPtr conn,
|
||||||
virConnectPtr conn,
|
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *cookiein,
|
const char *cookiein,
|
||||||
int cookieinlen,
|
int cookieinlen,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
int retcode);
|
int cancelled);
|
||||||
|
|
||||||
bool qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
|
bool qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
|
||||||
virDomainDefPtr def, bool remote,
|
virDomainDefPtr def, bool remote,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user