This patch exports qemuMigrationIsAllowed and adds a new parameter to it
to denote if it's a remote migration or a local migration. Local
migrations are used in snapshots and saving of the machine state and
have fewer restrictions. This patch also adjusts callers of the function
and tweaks some error messages to be more universal.
---
src/qemu/qemu_migration.c | 45 ++++++++++++++++++++++++++-------------------
src/qemu/qemu_migration.h | 2 ++
2 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 86060dc..7e5cf01 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1011,30 +1011,38 @@ error:
* assume that checking on source is sufficient to prevent ever
* talking to the destination in the first place, we are stuck with
* the fact that older servers did not do checks on the source. */
-static bool
+bool
qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
- virDomainDefPtr def)
+ virDomainDefPtr def, bool remote)
{
int nsnapshots;
bool forbid;
int i;
if (vm) {
- if (qemuProcessAutoDestroyActive(driver, vm)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is marked for auto
destroy"));
- return false;
- }
- if ((nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL,
- 0))) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("cannot migrate domain with %d snapshots"),
- nsnapshots);
- return false;
+ /* perform these checks only when migrating to remote hosts */
+ if (remote) {
+ if (qemuProcessAutoDestroyActive(driver, vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is marked for auto
destroy"));
+ return false;
+ }
+
+ nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0);
+ if (nsnapshots < 0)
+ return false;
+
+ if (nsnapshots > 0) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("cannot migrate domain with %d snapshots"),
+ nsnapshots);
+ return false;
+ }
}
+
if (virDomainHasDiskMirror(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("cannot migrate domain with active block job"));
+ _("domain has an active block job"));
return false;
}
@@ -1055,8 +1063,7 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
}
if (forbid) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("Domain with assigned non-USB host devices "
- "cannot be migrated"));
+ _("domain has assigned non-USB host devices"));
return false;
}
@@ -1428,7 +1435,7 @@ char *qemuMigrationBegin(virQEMUDriverPtr driver,
if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT)
qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_BEGIN3);
- if (!qemuMigrationIsAllowed(driver, vm, NULL))
+ if (!qemuMigrationIsAllowed(driver, vm, NULL, true))
goto cleanup;
if (!(flags & VIR_MIGRATE_UNSAFE) && !qemuMigrationIsSafe(vm->def))
@@ -1521,7 +1528,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
- if (!qemuMigrationIsAllowed(driver, NULL, def))
+ if (!qemuMigrationIsAllowed(driver, NULL, def, true))
goto cleanup;
/* Target domain name, maybe renamed. */
@@ -2927,7 +2934,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
goto endjob;
}
- if (!qemuMigrationIsAllowed(driver, vm, NULL))
+ if (!qemuMigrationIsAllowed(driver, vm, NULL, true))
goto endjob;
if (!(flags & VIR_MIGRATE_UNSAFE) && !qemuMigrationIsSafe(vm->def))
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 62e39a0..5751ea5 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -144,6 +144,8 @@ int qemuMigrationConfirm(virQEMUDriverPtr driver,
unsigned int flags,
int retcode);
+bool qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
+ virDomainDefPtr def, bool remote);
int qemuMigrationToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
int fd, off_t offset, const char *path,
--
1.8.0