Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_driver.c | 43 +++++++++++++++++++++++++++++-------
src/qemu/qemu_monitor.c | 9 ++++++++
src/qemu/qemu_monitor.h | 3 +++
src/qemu/qemu_monitor_json.c | 22 ++++++++++++++++++
src/qemu/qemu_monitor_json.h | 3 +++
5 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index efa6cbe14d..344bbe2196 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12770,6 +12770,36 @@ qemuDomainAbortJobMigration(virDomainObj *vm)
}
+static int
+qemuDomainAbortJobPostcopy(virDomainObj *vm,
+ unsigned int flags)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ int rc;
+
+ if (!(flags & VIR_DOMAIN_ABORT_JOB_POSTCOPY)) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("cannot abort migration in post-copy mode"));
+ return -1;
+ }
+
+ VIR_DEBUG("Suspending post-copy migration at client request");
+
+ qemuDomainObjAbortAsyncJob(vm);
+ qemuDomainObjEnterMonitor(priv->driver, vm);
+ rc = qemuMonitorMigratePause(priv->mon);
+ qemuDomainObjExitMonitor(vm);
+
+ if (rc == -2) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("cannot suspend post-copy migration"));
+ return -1;
+ }
+
+ return rc;
+}
+
+
static int
qemuDomainAbortJobFlags(virDomainPtr dom,
unsigned int flags)
@@ -12780,7 +12810,7 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
qemuDomainObjPrivate *priv;
int reason;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_ABORT_JOB_POSTCOPY, -1);
if (!(vm = qemuDomainObjFromDomain(dom)))
goto cleanup;
@@ -12817,13 +12847,10 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
case VIR_ASYNC_JOB_MIGRATION_OUT:
if ((priv->job.current->status == VIR_DOMAIN_JOB_STATUS_POSTCOPY ||
(virDomainObjGetState(vm, &reason) == VIR_DOMAIN_PAUSED &&
- reason == VIR_DOMAIN_PAUSED_POSTCOPY))) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("cannot abort migration in post-copy mode"));
- goto endjob;
- }
-
- ret = qemuDomainAbortJobMigration(vm);
+ reason == VIR_DOMAIN_PAUSED_POSTCOPY)))
+ ret = qemuDomainAbortJobPostcopy(vm, flags);
+ else
+ ret = qemuDomainAbortJobMigration(vm);
break;
case VIR_ASYNC_JOB_SAVE:
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 5424fdc4fd..af37ce7d19 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2429,6 +2429,15 @@ qemuMonitorMigrateCancel(qemuMonitor *mon)
}
+int
+qemuMonitorMigratePause(qemuMonitor *mon)
+{
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONMigratePause(mon);
+}
+
+
int
qemuMonitorQueryDump(qemuMonitor *mon,
qemuMonitorDumpStats *stats)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 812f8f4dc2..e36ce8b4eb 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -927,6 +927,9 @@ int qemuMonitorMigrateToSocket(qemuMonitor *mon,
int qemuMonitorMigrateCancel(qemuMonitor *mon);
+int
+qemuMonitorMigratePause(qemuMonitor *mon);
+
int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitor *mon,
const char *capability);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 44361ae003..66e0b870b4 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3458,6 +3458,28 @@ int qemuMonitorJSONMigrateCancel(qemuMonitor *mon)
}
+int
+qemuMonitorJSONMigratePause(qemuMonitor *mon)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("migrate-pause", NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
+ return -2;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ return 0;
+}
+
+
/* qemuMonitorJSONQueryDump:
* @mon: Monitor pointer
* @stats: Monitor dump stats
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index a60c0bfac4..20c3f63f93 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -208,6 +208,9 @@ qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitor *mon,
int
qemuMonitorJSONMigrateCancel(qemuMonitor *mon);
+int
+qemuMonitorJSONMigratePause(qemuMonitor *mon);
+
int
qemuMonitorJSONQueryDump(qemuMonitor *mon,
qemuMonitorDumpStats *stats);
--
2.35.1