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

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