|
|
357786 |
From 68b982f2790c7a8caad15f9c088402bbd9d0c611 Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Tue, 26 Jun 2018 09:48:15 +0200
|
|
|
357786 |
Subject: [PATCH 46/89] job: Add job_event_*()
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Message-id: <20180626094856.6924-33-kwolf@redhat.com>
|
|
|
357786 |
Patchwork-id: 81092
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 32/73] job: Add job_event_*()
|
|
|
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 |
Go through the Job layer in order to send QMP events. For the moment,
|
|
|
357786 |
these functions only call a notifier in the BlockJob layer that sends
|
|
|
357786 |
the existing commands.
|
|
|
357786 |
|
|
|
357786 |
This uses notifiers rather than JobDriver callbacks because internal
|
|
|
357786 |
users of jobs won't receive QMP events, but might still be interested
|
|
|
357786 |
in getting notified for the events.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit 139a9f020d49e9f863e0d46fd3d0b440dfb3b9d7)
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
blockjob.c | 41 +++++++++++++++++++++++++++--------------
|
|
|
357786 |
include/block/blockjob.h | 9 +++++++++
|
|
|
357786 |
include/qemu/job.h | 18 ++++++++++++++++++
|
|
|
357786 |
job.c | 19 +++++++++++++++++++
|
|
|
357786 |
4 files changed, 73 insertions(+), 14 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
357786 |
index b4334fb..05d7921 100644
|
|
|
357786 |
--- a/blockjob.c
|
|
|
357786 |
+++ b/blockjob.c
|
|
|
357786 |
@@ -36,10 +36,6 @@
|
|
|
357786 |
#include "qemu/coroutine.h"
|
|
|
357786 |
#include "qemu/timer.h"
|
|
|
357786 |
|
|
|
357786 |
-static void block_job_event_cancelled(BlockJob *job);
|
|
|
357786 |
-static void block_job_event_completed(BlockJob *job, const char *msg);
|
|
|
357786 |
-static void block_job_event_pending(BlockJob *job);
|
|
|
357786 |
-
|
|
|
357786 |
/* Transactional group of block jobs */
|
|
|
357786 |
struct BlockJobTxn {
|
|
|
357786 |
|
|
|
357786 |
@@ -352,13 +348,9 @@ static int block_job_finalize_single(BlockJob *job)
|
|
|
357786 |
/* Emit events only if we actually started */
|
|
|
357786 |
if (job_started(&job->job)) {
|
|
|
357786 |
if (job_is_cancelled(&job->job)) {
|
|
|
357786 |
- block_job_event_cancelled(job);
|
|
|
357786 |
+ job_event_cancelled(&job->job);
|
|
|
357786 |
} else {
|
|
|
357786 |
- const char *msg = NULL;
|
|
|
357786 |
- if (job->ret < 0) {
|
|
|
357786 |
- msg = strerror(-job->ret);
|
|
|
357786 |
- }
|
|
|
357786 |
- block_job_event_completed(job, msg);
|
|
|
357786 |
+ job_event_completed(&job->job);
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -504,7 +496,7 @@ static int block_job_transition_to_pending(BlockJob *job)
|
|
|
357786 |
{
|
|
|
357786 |
job_state_transition(&job->job, JOB_STATUS_PENDING);
|
|
|
357786 |
if (!job->job.auto_finalize) {
|
|
|
357786 |
- block_job_event_pending(job);
|
|
|
357786 |
+ job_event_pending(&job->job);
|
|
|
357786 |
}
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
@@ -712,8 +704,10 @@ static void block_job_iostatus_set_err(BlockJob *job, int error)
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void block_job_event_cancelled(BlockJob *job)
|
|
|
357786 |
+static void block_job_event_cancelled(Notifier *n, void *opaque)
|
|
|
357786 |
{
|
|
|
357786 |
+ BlockJob *job = opaque;
|
|
|
357786 |
+
|
|
|
357786 |
if (block_job_is_internal(job)) {
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
@@ -726,12 +720,19 @@ static void block_job_event_cancelled(BlockJob *job)
|
|
|
357786 |
&error_abort);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void block_job_event_completed(BlockJob *job, const char *msg)
|
|
|
357786 |
+static void block_job_event_completed(Notifier *n, void *opaque)
|
|
|
357786 |
{
|
|
|
357786 |
+ BlockJob *job = opaque;
|
|
|
357786 |
+ const char *msg = NULL;
|
|
|
357786 |
+
|
|
|
357786 |
if (block_job_is_internal(job)) {
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ if (job->ret < 0) {
|
|
|
357786 |
+ msg = strerror(-job->ret);
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
qapi_event_send_block_job_completed(job_type(&job->job),
|
|
|
357786 |
job->job.id,
|
|
|
357786 |
job->len,
|
|
|
357786 |
@@ -742,8 +743,10 @@ static void block_job_event_completed(BlockJob *job, const char *msg)
|
|
|
357786 |
&error_abort);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void block_job_event_pending(BlockJob *job)
|
|
|
357786 |
+static void block_job_event_pending(Notifier *n, void *opaque)
|
|
|
357786 |
{
|
|
|
357786 |
+ BlockJob *job = opaque;
|
|
|
357786 |
+
|
|
|
357786 |
if (block_job_is_internal(job)) {
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
@@ -799,6 +802,16 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
|
|
357786 |
job->cb = cb;
|
|
|
357786 |
job->opaque = opaque;
|
|
|
357786 |
|
|
|
357786 |
+ job->finalize_cancelled_notifier.notify = block_job_event_cancelled;
|
|
|
357786 |
+ job->finalize_completed_notifier.notify = block_job_event_completed;
|
|
|
357786 |
+ job->pending_notifier.notify = block_job_event_pending;
|
|
|
357786 |
+
|
|
|
357786 |
+ notifier_list_add(&job->job.on_finalize_cancelled,
|
|
|
357786 |
+ &job->finalize_cancelled_notifier);
|
|
|
357786 |
+ notifier_list_add(&job->job.on_finalize_completed,
|
|
|
357786 |
+ &job->finalize_completed_notifier);
|
|
|
357786 |
+ notifier_list_add(&job->job.on_pending, &job->pending_notifier);
|
|
|
357786 |
+
|
|
|
357786 |
error_setg(&job->blocker, "block device is in use by block job: %s",
|
|
|
357786 |
job_type_str(&job->job));
|
|
|
357786 |
block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
|
|
|
357786 |
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
|
|
|
357786 |
index f9aaaaa..aef0629 100644
|
|
|
357786 |
--- a/include/block/blockjob.h
|
|
|
357786 |
+++ b/include/block/blockjob.h
|
|
|
357786 |
@@ -82,6 +82,15 @@ typedef struct BlockJob {
|
|
|
357786 |
/** Block other operations when block job is running */
|
|
|
357786 |
Error *blocker;
|
|
|
357786 |
|
|
|
357786 |
+ /** Called when a cancelled job is finalised. */
|
|
|
357786 |
+ Notifier finalize_cancelled_notifier;
|
|
|
357786 |
+
|
|
|
357786 |
+ /** Called when a successfully completed job is finalised. */
|
|
|
357786 |
+ Notifier finalize_completed_notifier;
|
|
|
357786 |
+
|
|
|
357786 |
+ /** Called when the job transitions to PENDING */
|
|
|
357786 |
+ Notifier pending_notifier;
|
|
|
357786 |
+
|
|
|
357786 |
/** BlockDriverStates that are involved in this block job */
|
|
|
357786 |
GSList *nodes;
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
357786 |
index 9783e40..14d9377 100644
|
|
|
357786 |
--- a/include/qemu/job.h
|
|
|
357786 |
+++ b/include/qemu/job.h
|
|
|
357786 |
@@ -105,6 +105,15 @@ typedef struct Job {
|
|
|
357786 |
/** True if this job should automatically dismiss itself */
|
|
|
357786 |
bool auto_dismiss;
|
|
|
357786 |
|
|
|
357786 |
+ /** Notifiers called when a cancelled job is finalised */
|
|
|
357786 |
+ NotifierList on_finalize_cancelled;
|
|
|
357786 |
+
|
|
|
357786 |
+ /** Notifiers called when a successfully completed job is finalised */
|
|
|
357786 |
+ NotifierList on_finalize_completed;
|
|
|
357786 |
+
|
|
|
357786 |
+ /** Notifiers called when the job transitions to PENDING */
|
|
|
357786 |
+ NotifierList on_pending;
|
|
|
357786 |
+
|
|
|
357786 |
/** Element of the list of jobs */
|
|
|
357786 |
QLIST_ENTRY(Job) job_list;
|
|
|
357786 |
} Job;
|
|
|
357786 |
@@ -182,6 +191,15 @@ void job_ref(Job *job);
|
|
|
357786 |
*/
|
|
|
357786 |
void job_unref(Job *job);
|
|
|
357786 |
|
|
|
357786 |
+/** To be called when a cancelled job is finalised. */
|
|
|
357786 |
+void job_event_cancelled(Job *job);
|
|
|
357786 |
+
|
|
|
357786 |
+/** To be called when a successfully completed job is finalised. */
|
|
|
357786 |
+void job_event_completed(Job *job);
|
|
|
357786 |
+
|
|
|
357786 |
+/** To be called when the job transitions to PENDING */
|
|
|
357786 |
+void job_event_pending(Job *job);
|
|
|
357786 |
+
|
|
|
357786 |
/**
|
|
|
357786 |
* Conditionally enter the job coroutine if the job is ready to run, not
|
|
|
357786 |
* already busy and fn() returns true. fn() is called while under the job_lock
|
|
|
357786 |
diff --git a/job.c b/job.c
|
|
|
357786 |
index dd46170..817c3b4 100644
|
|
|
357786 |
--- a/job.c
|
|
|
357786 |
+++ b/job.c
|
|
|
357786 |
@@ -215,6 +215,10 @@ void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
|
|
|
357786 |
job->auto_finalize = !(flags & JOB_MANUAL_FINALIZE);
|
|
|
357786 |
job->auto_dismiss = !(flags & JOB_MANUAL_DISMISS);
|
|
|
357786 |
|
|
|
357786 |
+ notifier_list_init(&job->on_finalize_cancelled);
|
|
|
357786 |
+ notifier_list_init(&job->on_finalize_completed);
|
|
|
357786 |
+ notifier_list_init(&job->on_pending);
|
|
|
357786 |
+
|
|
|
357786 |
job_state_transition(job, JOB_STATUS_CREATED);
|
|
|
357786 |
aio_timer_init(qemu_get_aio_context(), &job->sleep_timer,
|
|
|
357786 |
QEMU_CLOCK_REALTIME, SCALE_NS,
|
|
|
357786 |
@@ -247,6 +251,21 @@ void job_unref(Job *job)
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+void job_event_cancelled(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ notifier_list_notify(&job->on_finalize_cancelled, job);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
+void job_event_completed(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ notifier_list_notify(&job->on_finalize_completed, job);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
+void job_event_pending(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ notifier_list_notify(&job->on_pending, job);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
void job_enter_cond(Job *job, bool(*fn)(Job *job))
|
|
|
357786 |
{
|
|
|
357786 |
if (!job_started(job)) {
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|