]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Implement VIR_DOMAIN_ABORT_JOB_POSTCOPY flag
authorJiri Denemark <jdenemar@redhat.com>
Tue, 10 May 2022 13:20:25 +0000 (15:20 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 7 Jun 2022 15:40:21 +0000 (17:40 +0200)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 55badcf1a0fdf44fdc1fbfb3fbb94f6b6e18c1ae..2a1a7f52f14326b8a883ff4398f6d585d6f55669 100644 (file)
@@ -12788,6 +12788,30 @@ 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);
+
+    return rc;
+}
+
+
 static int
 qemuDomainAbortJobFlags(virDomainPtr dom,
                         unsigned int flags)
@@ -12796,11 +12820,10 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
     virDomainObj *vm;
     int ret = -1;
     qemuDomainObjPrivate *priv;
-    int reason;
 
     VIR_DEBUG("flags=0x%x", flags);
 
-    virCheckFlags(0, -1);
+    virCheckFlags(VIR_DOMAIN_ABORT_JOB_POSTCOPY, -1);
 
     if (!(vm = qemuDomainObjFromDomain(dom)))
         goto cleanup;
@@ -12816,6 +12839,14 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
 
     priv = vm->privateData;
 
+    if (flags & VIR_DOMAIN_ABORT_JOB_POSTCOPY &&
+        (priv->job.asyncJob != VIR_ASYNC_JOB_MIGRATION_OUT ||
+         !virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT))) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("current job is not outgoing migration in post-copy mode"));
+        goto endjob;
+    }
+
     switch (priv->job.asyncJob) {
     case VIR_ASYNC_JOB_NONE:
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -12835,15 +12866,10 @@ qemuDomainAbortJobFlags(virDomainPtr dom,
         break;
 
     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);
+        if (virDomainObjIsPostcopy(vm, VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT))
+            ret = qemuDomainAbortJobPostcopy(vm, flags);
+        else
+            ret = qemuDomainAbortJobMigration(vm);
         break;
 
     case VIR_ASYNC_JOB_SAVE:
index e9b9390c80e373b310eaf1edaff748f9fe57c19d..37bcbde31e0e79fc638795f6bb2c9a742abb9da9 100644 (file)
@@ -2425,6 +2425,15 @@ qemuMonitorMigrateCancel(qemuMonitor *mon)
 }
 
 
+int
+qemuMonitorMigratePause(qemuMonitor *mon)
+{
+    QEMU_CHECK_MONITOR(mon);
+
+    return qemuMonitorJSONMigratePause(mon);
+}
+
+
 int
 qemuMonitorQueryDump(qemuMonitor *mon,
                      qemuMonitorDumpStats *stats)
index 4f6c7e40fdd100197e94af1579a9e1e3a815a178..91f2d0941cf710094eebe9329686395f9a6625a9 100644 (file)
@@ -890,6 +890,9 @@ int qemuMonitorMigrateToSocket(qemuMonitor *mon,
 
 int qemuMonitorMigrateCancel(qemuMonitor *mon);
 
+int
+qemuMonitorMigratePause(qemuMonitor *mon);
+
 int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitor *mon,
                                             const char *capability);
 
index 99c5e1b40f52afe59a1d3f13eb62a9f948eef354..8b81a07429cd80829d804319c5e673c60ff5d4f8 100644 (file)
@@ -3455,6 +3455,25 @@ 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 (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /* qemuMonitorJSONQueryDump:
  * @mon: Monitor pointer
  * @stats: Monitor dump stats
index 305faafce423c317fd50943abc404a78968ccf4c..3b55e380b3aae9af44dd59504e2fd89cfa5a45e0 100644 (file)
@@ -207,6 +207,9 @@ qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitor *mon,
 int
 qemuMonitorJSONMigrateCancel(qemuMonitor *mon);
 
+int
+qemuMonitorJSONMigratePause(qemuMonitor *mon);
+
 int
 qemuMonitorJSONQueryDump(qemuMonitor *mon,
                          qemuMonitorDumpStats *stats);
index 96d6da1f4789657fdd884325b5f2f630245930d4..1019661aa1aa2ae1d141730ec0817bfbba0b8f57 100644 (file)
@@ -3111,6 +3111,7 @@ mymain(void)
     DO_TEST_GEN_DEPRECATED(qemuMonitorJSONSetMigrationDowntime, true);
     DO_TEST_GEN(qemuMonitorJSONMigrate);
     DO_TEST_GEN(qemuMonitorJSONMigrateRecover);
+    DO_TEST_SIMPLE("migrate-pause", qemuMonitorJSONMigratePause);
     DO_TEST_GEN(qemuMonitorJSONDump);
     DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate);
     DO_TEST_GEN(qemuMonitorJSONRemoveNetdev);