Blame SOURCES/kvm-job-Add-lifecycle-QMP-commands.patch

1bdc94
From 50909c400b504bc133165f26971f621f915d5fdf Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Tue, 26 Jun 2018 09:48:32 +0200
1bdc94
Subject: [PATCH 63/89] job: Add lifecycle QMP commands
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180626094856.6924-50-kwolf@redhat.com>
1bdc94
Patchwork-id: 81129
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 49/73] job: Add lifecycle QMP commands
1bdc94
Bugzilla: 1513543
1bdc94
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: Fam Zheng <famz@redhat.com>
1bdc94
1bdc94
This adds QMP commands that control the transition between states of the
1bdc94
job lifecycle.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
(cherry picked from commit 1a90bc8128ee7d16ce4abb131961e37084d75b16)
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 MAINTAINERS   |   1 +
1bdc94
 Makefile.objs |   1 +
1bdc94
 job-qmp.c     | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1bdc94
 qapi/job.json |  99 +++++++++++++++++++++++++++++++++++++++++++
1bdc94
 trace-events  |   9 ++++
1bdc94
 5 files changed, 244 insertions(+)
1bdc94
 create mode 100644 job-qmp.c
1bdc94
1bdc94
diff --git a/MAINTAINERS b/MAINTAINERS
1bdc94
index 5aaf264..a783c92 100644
1bdc94
--- a/MAINTAINERS
1bdc94
+++ b/MAINTAINERS
1bdc94
@@ -1372,6 +1372,7 @@ S: Supported
1bdc94
 F: blockjob.c
1bdc94
 F: include/block/blockjob.h
1bdc94
 F: job.c
1bdc94
+F: job-qmp.c
1bdc94
 F: include/block/job.h
1bdc94
 F: block/backup.c
1bdc94
 F: block/commit.c
1bdc94
diff --git a/Makefile.objs b/Makefile.objs
1bdc94
index 3df8d58..c6c3554 100644
1bdc94
--- a/Makefile.objs
1bdc94
+++ b/Makefile.objs
1bdc94
@@ -97,6 +97,7 @@ io-obj-y = io/
1bdc94
 ifeq ($(CONFIG_SOFTMMU),y)
1bdc94
 common-obj-y = blockdev.o blockdev-nbd.o block/
1bdc94
 common-obj-y += bootdevice.o iothread.o
1bdc94
+common-obj-y += job-qmp.o
1bdc94
 common-obj-y += net/
1bdc94
 common-obj-y += qdev-monitor.o device-hotplug.o
1bdc94
 common-obj-$(CONFIG_WIN32) += os-win32.o
1bdc94
diff --git a/job-qmp.c b/job-qmp.c
1bdc94
new file mode 100644
1bdc94
index 0000000..b2e18cf
1bdc94
--- /dev/null
1bdc94
+++ b/job-qmp.c
1bdc94
@@ -0,0 +1,134 @@
1bdc94
+/*
1bdc94
+ * QMP interface for background jobs
1bdc94
+ *
1bdc94
+ * Copyright (c) 2011 IBM Corp.
1bdc94
+ * Copyright (c) 2012, 2018 Red Hat, Inc.
1bdc94
+ *
1bdc94
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1bdc94
+ * of this software and associated documentation files (the "Software"), to deal
1bdc94
+ * in the Software without restriction, including without limitation the rights
1bdc94
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1bdc94
+ * copies of the Software, and to permit persons to whom the Software is
1bdc94
+ * furnished to do so, subject to the following conditions:
1bdc94
+ *
1bdc94
+ * The above copyright notice and this permission notice shall be included in
1bdc94
+ * all copies or substantial portions of the Software.
1bdc94
+ *
1bdc94
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1bdc94
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1bdc94
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1bdc94
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1bdc94
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1bdc94
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1bdc94
+ * THE SOFTWARE.
1bdc94
+ */
1bdc94
+
1bdc94
+#include "qemu/osdep.h"
1bdc94
+#include "qemu-common.h"
1bdc94
+#include "qemu/job.h"
1bdc94
+#include "qapi/qapi-commands-job.h"
1bdc94
+#include "qapi/error.h"
1bdc94
+#include "trace-root.h"
1bdc94
+
1bdc94
+/* Get a job using its ID and acquire its AioContext */
1bdc94
+static Job *find_job(const char *id, AioContext **aio_context, Error **errp)
1bdc94
+{
1bdc94
+    Job *job;
1bdc94
+
1bdc94
+    *aio_context = NULL;
1bdc94
+
1bdc94
+    job = job_get(id);
1bdc94
+    if (!job) {
1bdc94
+        error_setg(errp, "Job not found");
1bdc94
+        return NULL;
1bdc94
+    }
1bdc94
+
1bdc94
+    *aio_context = job->aio_context;
1bdc94
+    aio_context_acquire(*aio_context);
1bdc94
+
1bdc94
+    return job;
1bdc94
+}
1bdc94
+
1bdc94
+void qmp_job_cancel(const char *id, Error **errp)
1bdc94
+{
1bdc94
+    AioContext *aio_context;
1bdc94
+    Job *job = find_job(id, &aio_context, errp);
1bdc94
+
1bdc94
+    if (!job) {
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_qmp_job_cancel(job);
1bdc94
+    job_user_cancel(job, true, errp);
1bdc94
+    aio_context_release(aio_context);
1bdc94
+}
1bdc94
+
1bdc94
+void qmp_job_pause(const char *id, Error **errp)
1bdc94
+{
1bdc94
+    AioContext *aio_context;
1bdc94
+    Job *job = find_job(id, &aio_context, errp);
1bdc94
+
1bdc94
+    if (!job) {
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_qmp_job_pause(job);
1bdc94
+    job_user_pause(job, errp);
1bdc94
+    aio_context_release(aio_context);
1bdc94
+}
1bdc94
+
1bdc94
+void qmp_job_resume(const char *id, Error **errp)
1bdc94
+{
1bdc94
+    AioContext *aio_context;
1bdc94
+    Job *job = find_job(id, &aio_context, errp);
1bdc94
+
1bdc94
+    if (!job) {
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_qmp_job_resume(job);
1bdc94
+    job_user_resume(job, errp);
1bdc94
+    aio_context_release(aio_context);
1bdc94
+}
1bdc94
+
1bdc94
+void qmp_job_complete(const char *id, Error **errp)
1bdc94
+{
1bdc94
+    AioContext *aio_context;
1bdc94
+    Job *job = find_job(id, &aio_context, errp);
1bdc94
+
1bdc94
+    if (!job) {
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_qmp_job_complete(job);
1bdc94
+    job_complete(job, errp);
1bdc94
+    aio_context_release(aio_context);
1bdc94
+}
1bdc94
+
1bdc94
+void qmp_job_finalize(const char *id, Error **errp)
1bdc94
+{
1bdc94
+    AioContext *aio_context;
1bdc94
+    Job *job = find_job(id, &aio_context, errp);
1bdc94
+
1bdc94
+    if (!job) {
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_qmp_job_finalize(job);
1bdc94
+    job_finalize(job, errp);
1bdc94
+    aio_context_release(aio_context);
1bdc94
+}
1bdc94
+
1bdc94
+void qmp_job_dismiss(const char *id, Error **errp)
1bdc94
+{
1bdc94
+    AioContext *aio_context;
1bdc94
+    Job *job = find_job(id, &aio_context, errp);
1bdc94
+
1bdc94
+    if (!job) {
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_qmp_job_dismiss(job);
1bdc94
+    job_dismiss(&job, errp);
1bdc94
+    aio_context_release(aio_context);
1bdc94
+}
1bdc94
diff --git a/qapi/job.json b/qapi/job.json
1bdc94
index 9fbdd0c..b84dc6c 100644
1bdc94
--- a/qapi/job.json
1bdc94
+++ b/qapi/job.json
1bdc94
@@ -106,3 +106,102 @@
1bdc94
 { 'event': 'JOB_STATUS_CHANGE',
1bdc94
   'data': { 'id': 'str',
1bdc94
             'status': 'JobStatus' } }
1bdc94
+
1bdc94
+##
1bdc94
+# @job-pause:
1bdc94
+#
1bdc94
+# Pause an active job.
1bdc94
+#
1bdc94
+# This command returns immediately after marking the active job for pausing.
1bdc94
+# Pausing an already paused job is an error.
1bdc94
+#
1bdc94
+# The job will pause as soon as possible, which means transitioning into the
1bdc94
+# PAUSED state if it was RUNNING, or into STANDBY if it was READY. The
1bdc94
+# corresponding JOB_STATUS_CHANGE event will be emitted.
1bdc94
+#
1bdc94
+# Cancelling a paused job automatically resumes it.
1bdc94
+#
1bdc94
+# @id: The job identifier.
1bdc94
+#
1bdc94
+# Since: 2.13
1bdc94
+##
1bdc94
+{ 'command': 'job-pause', 'data': { 'id': 'str' } }
1bdc94
+
1bdc94
+##
1bdc94
+# @job-resume:
1bdc94
+#
1bdc94
+# Resume a paused job.
1bdc94
+#
1bdc94
+# This command returns immediately after resuming a paused job. Resuming an
1bdc94
+# already running job is an error.
1bdc94
+#
1bdc94
+# @id : The job identifier.
1bdc94
+#
1bdc94
+# Since: 2.13
1bdc94
+##
1bdc94
+{ 'command': 'job-resume', 'data': { 'id': 'str' } }
1bdc94
+
1bdc94
+##
1bdc94
+# @job-cancel:
1bdc94
+#
1bdc94
+# Instruct an active background job to cancel at the next opportunity.
1bdc94
+# This command returns immediately after marking the active job for
1bdc94
+# cancellation.
1bdc94
+#
1bdc94
+# The job will cancel as soon as possible and then emit a JOB_STATUS_CHANGE
1bdc94
+# event. Usually, the status will change to ABORTING, but it is possible that
1bdc94
+# a job successfully completes (e.g. because it was almost done and there was
1bdc94
+# no opportunity to cancel earlier than completing the job) and transitions to
1bdc94
+# PENDING instead.
1bdc94
+#
1bdc94
+# @id: The job identifier.
1bdc94
+#
1bdc94
+# Since: 2.13
1bdc94
+##
1bdc94
+{ 'command': 'job-cancel', 'data': { 'id': 'str' } }
1bdc94
+
1bdc94
+
1bdc94
+##
1bdc94
+# @job-complete:
1bdc94
+#
1bdc94
+# Manually trigger completion of an active job in the READY state.
1bdc94
+#
1bdc94
+# @id: The job identifier.
1bdc94
+#
1bdc94
+# Since: 2.13
1bdc94
+##
1bdc94
+{ 'command': 'job-complete', 'data': { 'id': 'str' } }
1bdc94
+
1bdc94
+##
1bdc94
+# @job-dismiss:
1bdc94
+#
1bdc94
+# Deletes a job that is in the CONCLUDED state. This command only needs to be
1bdc94
+# run explicitly for jobs that don't have automatic dismiss enabled.
1bdc94
+#
1bdc94
+# This command will refuse to operate on any job that has not yet reached its
1bdc94
+# terminal state, JOB_STATUS_CONCLUDED. For jobs that make use of JOB_READY
1bdc94
+# event, job-cancel or job-complete will still need to be used as appropriate.
1bdc94
+#
1bdc94
+# @id: The job identifier.
1bdc94
+#
1bdc94
+# Since: 2.13
1bdc94
+##
1bdc94
+{ 'command': 'job-dismiss', 'data': { 'id': 'str' } }
1bdc94
+
1bdc94
+##
1bdc94
+# @job-finalize:
1bdc94
+#
1bdc94
+# Instructs all jobs in a transaction (or a single job if it is not part of any
1bdc94
+# transaction) to finalize any graph changes and do any necessary cleanup. This
1bdc94
+# command requires that all involved jobs are in the PENDING state.
1bdc94
+#
1bdc94
+# For jobs in a transaction, instructing one job to finalize will force
1bdc94
+# ALL jobs in the transaction to finalize, so it is only necessary to instruct
1bdc94
+# a single member job to finalize.
1bdc94
+#
1bdc94
+# @id: The identifier of any job in the transaction, or of a job that is not
1bdc94
+#      part of any transaction.
1bdc94
+#
1bdc94
+# Since: 2.13
1bdc94
+##
1bdc94
+{ 'command': 'job-finalize', 'data': { 'id': 'str' } }
1bdc94
diff --git a/trace-events b/trace-events
1bdc94
index ef7579a..c445f54 100644
1bdc94
--- a/trace-events
1bdc94
+++ b/trace-events
1bdc94
@@ -109,6 +109,15 @@ job_state_transition(void *job,  int ret, const char *legal, const char *s0, con
1bdc94
 job_apply_verb(void *job, const char *state, const char *verb, const char *legal) "job %p in state %s; applying verb %s (%s)"
1bdc94
 job_completed(void *job, int ret, int jret) "job %p ret %d corrected ret %d"
1bdc94
 
1bdc94
+# job-qmp.c
1bdc94
+qmp_job_cancel(void *job) "job %p"
1bdc94
+qmp_job_pause(void *job) "job %p"
1bdc94
+qmp_job_resume(void *job) "job %p"
1bdc94
+qmp_job_complete(void *job) "job %p"
1bdc94
+qmp_job_finalize(void *job) "job %p"
1bdc94
+qmp_job_dismiss(void *job) "job %p"
1bdc94
+
1bdc94
+
1bdc94
 ### Guest events, keep at bottom
1bdc94
 
1bdc94
 
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94