[libvirt PATCH v2 76/81] qemu: Implement VIR_DOMAIN_ABORT_JOB_POSTCOPY flag

Jiri Denemark posted 81 patches 3 years, 8 months ago
[libvirt PATCH v2 76/81] qemu: Implement VIR_DOMAIN_ABORT_JOB_POSTCOPY flag
Posted by Jiri Denemark 3 years, 8 months ago
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---

Notes:
    Version 2:
    - dropped DeviceNotFound QMP error handling and replaced it with
      reporting an error if the VIR_DOMAIN_ABORT_JOB_POSTCOPY flag is used
      for something else than outgoing post-copy migration

 src/qemu/qemu_driver.c       | 48 +++++++++++++++++++++++++++---------
 src/qemu/qemu_monitor.c      |  9 +++++++
 src/qemu/qemu_monitor.h      |  3 +++
 src/qemu/qemu_monitor_json.c | 19 ++++++++++++++
 src/qemu/qemu_monitor_json.h |  3 +++
 5 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cab2859a6c..01c4a8470a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12783,6 +12783,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)
@@ -12791,11 +12815,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;
@@ -12811,6 +12834,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",
@@ -12830,15 +12861,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:
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index e9b9390c80..37bcbde31e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2425,6 +2425,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 4f6c7e40fd..91f2d0941c 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -890,6 +890,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 99c5e1b40f..8b81a07429 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 305faafce4..3b55e380b3 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -207,6 +207,9 @@ qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitor *mon,
 int
 qemuMonitorJSONMigrateCancel(qemuMonitor *mon);
 
+int
+qemuMonitorJSONMigratePause(qemuMonitor *mon);
+
 int
 qemuMonitorJSONQueryDump(qemuMonitor *mon,
                          qemuMonitorDumpStats *stats);
-- 
2.35.1
Re: [libvirt PATCH v2 76/81] qemu: Implement VIR_DOMAIN_ABORT_JOB_POSTCOPY flag
Posted by Peter Krempa 3 years, 8 months ago
On Wed, Jun 01, 2022 at 14:50:16 +0200, Jiri Denemark wrote:
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
> 
> Notes:
>     Version 2:
>     - dropped DeviceNotFound QMP error handling and replaced it with
>       reporting an error if the VIR_DOMAIN_ABORT_JOB_POSTCOPY flag is used
>       for something else than outgoing post-copy migration
> 
>  src/qemu/qemu_driver.c       | 48 +++++++++++++++++++++++++++---------
>  src/qemu/qemu_monitor.c      |  9 +++++++
>  src/qemu/qemu_monitor.h      |  3 +++
>  src/qemu/qemu_monitor_json.c | 19 ++++++++++++++
>  src/qemu/qemu_monitor_json.h |  3 +++
>  5 files changed, 71 insertions(+), 11 deletions(-)
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 99c5e1b40f..8b81a07429 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c

[...]

> @@ -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;

Even for argument-less commands we still perform validation in form of
checking whether the command is not e.g. deprecated; thus please add a
qemumonitorjsontest case even for this trivial command.
Re: [libvirt PATCH v2 76/81] qemu: Implement VIR_DOMAIN_ABORT_JOB_POSTCOPY flag
Posted by Peter Krempa 3 years, 8 months ago
On Mon, Jun 06, 2022 at 14:24:05 +0200, Peter Krempa wrote:
> On Wed, Jun 01, 2022 at 14:50:16 +0200, Jiri Denemark wrote:
> > Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> > ---
> > 
> > Notes:
> >     Version 2:
> >     - dropped DeviceNotFound QMP error handling and replaced it with
> >       reporting an error if the VIR_DOMAIN_ABORT_JOB_POSTCOPY flag is used
> >       for something else than outgoing post-copy migration
> > 
> >  src/qemu/qemu_driver.c       | 48 +++++++++++++++++++++++++++---------
> >  src/qemu/qemu_monitor.c      |  9 +++++++
> >  src/qemu/qemu_monitor.h      |  3 +++
> >  src/qemu/qemu_monitor_json.c | 19 ++++++++++++++
> >  src/qemu/qemu_monitor_json.h |  3 +++
> >  5 files changed, 71 insertions(+), 11 deletions(-)
> > diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> > index 99c5e1b40f..8b81a07429 100644
> > --- a/src/qemu/qemu_monitor_json.c
> > +++ b/src/qemu/qemu_monitor_json.c
> 
> [...]
> 
> > @@ -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;
> 
> Even for argument-less commands we still perform validation in form of
> checking whether the command is not e.g. deprecated; thus please add a
> qemumonitorjsontest case even for this trivial command.
> 

With the above, which was btw requested also in previous review:

Reviewed-by: Peter Krempa <pkrempa@redhat.com>