From: Shaju Abraham <shaju.abraham@xxxxxxxxxxx> After the confirm phase Libvirt domain objects should only be on the source hash table. Move the remote hash table entry corresponding to the migrated VM to the source hash table. Delete the moved entries from remote hash table. Signed-off-by: Shaju Abraham <shaju.abraham@xxxxxxxxxxx> --- src/qemu/qemu_domain.c | 12 +++++++++- src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_driver.c | 46 ++++++++++++++++++++++++++++++++++----- src/qemu/qemu_migration.c | 13 +++++++++++ src/qemu/qemu_migration.h | 4 ++++ 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 002c092cf8..cbf779e9eb 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -16570,7 +16570,17 @@ qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason) return VIR_DOMAIN_EVENT_RESUMED_UNPAUSED; } - +int +qemuDomainInsertMigrateVMRef(virQEMUDriverPtr driver, + virDomainObjPtr remote_vm) +{ + if (virDomainObjListRemoveRemote(driver->domains, remote_vm) < 0) + return -1; + if (virDomainObjListAddEntry(driver->domains, remote_vm) < 0) + return -1; + else + return 0; +} /* qemuDomainIsUsingNoShutdown: * @priv: Domain private data diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c581b3a162..caf8b2a8a5 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -828,6 +828,8 @@ void qemuDomainRemoveInactiveJob(virQEMUDriverPtr driver, void qemuDomainRemoveInactiveJobLocked(virQEMUDriverPtr driver, virDomainObjPtr vm); +int qemuDomainInsertMigrateVMRef(virQEMUDriverPtr driver, + virDomainObjPtr vm); void qemuDomainSetFakeReboot(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3e6d14ead8..df639b5299 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -152,6 +152,33 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t fallback_gid, bool *needUnlink); static virQEMUDriverPtr qemu_driver; +/** + * qemuDomObjFromDomainRemote: + * @domain: Domain pointer that has to be looked up + * + * This function looks up @domain and returns the appropriate virDomainObjPtr + * that has to be released by calling virDomainObjEndAPI(). + * + * Returns the domain object with incremented reference counter which is locked + * on success, NULL otherwise. + */ +static virDomainObjPtr +qemuDomObjFromDomainRemote(virDomainPtr domain) +{ + virDomainObjPtr vm; + virQEMUDriverPtr driver = domain->conn->privateData; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + vm = virDomainObjListFindByUUIDRemote(driver->domains, domain->uuid); + if (!vm) { + virUUIDFormat(domain->uuid, uuidstr); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s' (%s)"), + uuidstr, domain->name); + return NULL; + } + return vm; +} /* Looks up the domain object from snapshot and unlocks the * driver. The returned domain object is locked and ref'd and the @@ -13188,8 +13215,10 @@ qemuDomainMigrateFinish3Params(virConnectPtr dconn, virReportError(VIR_ERR_NO_DOMAIN, "%s", _("missing domain name")); return NULL; } - - vm = virDomainObjListFindByName(driver->domains, dname); + if (flags & VIR_MIGRATE_LOCAL) + vm = virDomainObjListFindByNameRemote(driver->domains, dname); + else + vm = virDomainObjListFindByName(driver->domains, dname); if (!vm) { virReportError(VIR_ERR_NO_DOMAIN, _("no domain with matching name '%s'"), dname); @@ -13241,7 +13270,8 @@ qemuDomainMigrateConfirm3Params(virDomainPtr domain, unsigned int flags, int cancelled) { - virDomainObjPtr vm; + virDomainObjPtr vm, remote_vm; + int ret = 0; virCheckFlags(QEMU_MIGRATION_FLAGS, -1); @@ -13250,14 +13280,20 @@ qemuDomainMigrateConfirm3Params(virDomainPtr domain, if (!(vm = qemuDomainObjFromDomain(domain))) return -1; + if (!(remote_vm = qemuDomObjFromDomainRemote(domain))) + return -1; if (virDomainMigrateConfirm3ParamsEnsureACL(domain->conn, vm->def) < 0) { virDomainObjEndAPI(&vm); return -1; } - - return qemuMigrationSrcConfirm(domain->conn->privateData, vm, cookiein, cookieinlen, + ret = qemuMigrationSrcConfirm(domain->conn->privateData, vm, cookiein, cookieinlen, flags, cancelled); + if (ret < 0) + return ret; + ret = qemuMigrationSrcMergeHashTables(domain->conn->privateData, + remote_vm, flags); + return ret; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d22daeac9c..45403d361e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3092,6 +3092,19 @@ qemuMigrationSrcConfirm(virQEMUDriverPtr driver, virObjectUnref(cfg); return ret; } +int qemuMigrationSrcMergeHashTables(virQEMUDriverPtr driver, + virDomainObjPtr vm, + unsigned int flags) +{ + int ret = 0; + if (!(flags & VIR_MIGRATE_LOCAL)) + return ret; + ret = qemuDomainInsertMigrateVMRef(driver, vm); + if (ret < 0) + return ret; + qemuDomainSaveStatus(vm); + return ret; +} enum qemuMigrationDestinationType { diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index 2cb4bb9023..f6d67e3997 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -256,3 +256,7 @@ qemuMigrationSrcFetchMirrorStats(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob, qemuDomainJobInfoPtr jobInfo); + +int qemuMigrationSrcMergeHashTables(virQEMUDriverPtr driver, + virDomainObjPtr vm, + unsigned int flags); -- 2.24.1