cryptospore / rpms / qemu-kvm

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