yeahuh / rpms / qemu-kvm

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