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

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