|
|
357786 |
From 8ca94edad4b07d6191bc4761a44d8289b0f8ad5d Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Date: Mon, 10 Sep 2018 18:17:41 +0200
|
|
|
357786 |
Subject: [PATCH 03/25] jobs: add exit shim
|
|
|
357786 |
|
|
|
357786 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Message-id: <20180910181803.11781-4-jsnow@redhat.com>
|
|
|
357786 |
Patchwork-id: 82104
|
|
|
357786 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 03/25] jobs: add exit shim
|
|
|
357786 |
Bugzilla: 1626061
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
357786 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
All jobs do the same thing when they leave their running loop:
|
|
|
357786 |
- Store the return code in a structure
|
|
|
357786 |
- wait to receive this structure in the main thread
|
|
|
357786 |
- signal job completion via job_completed
|
|
|
357786 |
|
|
|
357786 |
Few jobs do anything beyond exactly this. Consolidate this exit
|
|
|
357786 |
logic for a net reduction in SLOC.
|
|
|
357786 |
|
|
|
357786 |
More seriously, when we utilize job_defer_to_main_loop_bh to call
|
|
|
357786 |
a function that calls job_completed, job_finalize_single will run
|
|
|
357786 |
in a context where it has recursively taken the aio_context lock,
|
|
|
357786 |
which can cause hangs if it puts down a reference that causes a flush.
|
|
|
357786 |
|
|
|
357786 |
You can observe this in practice by looking at mirror_exit's careful
|
|
|
357786 |
placement of job_completed and bdrv_unref calls.
|
|
|
357786 |
|
|
|
357786 |
If we centralize job exiting, we can signal job completion from outside
|
|
|
357786 |
of the aio_context, which should allow for job cleanup code to run with
|
|
|
357786 |
only one lock, which makes cleanup callbacks less tricky to write.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Message-id: 20180830015734.19765-4-jsnow@redhat.com
|
|
|
357786 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit 00359a71d45a414ee47d8e423104dc0afd24ec65)
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
include/qemu/job.h | 11 +++++++++++
|
|
|
357786 |
job.c | 18 ++++++++++++++++++
|
|
|
357786 |
2 files changed, 29 insertions(+)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
357786 |
index 905dfdd..24b5f3f 100644
|
|
|
357786 |
--- a/include/qemu/job.h
|
|
|
357786 |
+++ b/include/qemu/job.h
|
|
|
357786 |
@@ -209,6 +209,17 @@ struct JobDriver {
|
|
|
357786 |
void (*drain)(Job *job);
|
|
|
357786 |
|
|
|
357786 |
/**
|
|
|
357786 |
+ * If the callback is not NULL, exit will be invoked from the main thread
|
|
|
357786 |
+ * when the job's coroutine has finished, but before transactional
|
|
|
357786 |
+ * convergence; before @prepare or @abort.
|
|
|
357786 |
+ *
|
|
|
357786 |
+ * FIXME TODO: This callback is only temporary to transition remaining jobs
|
|
|
357786 |
+ * to prepare/commit/abort/clean callbacks and will be removed before 3.1.
|
|
|
357786 |
+ * is released.
|
|
|
357786 |
+ */
|
|
|
357786 |
+ void (*exit)(Job *job);
|
|
|
357786 |
+
|
|
|
357786 |
+ /**
|
|
|
357786 |
* If the callback is not NULL, prepare will be invoked when all the jobs
|
|
|
357786 |
* belonging to the same transaction complete; or upon this job's completion
|
|
|
357786 |
* if it is not in a transaction.
|
|
|
357786 |
diff --git a/job.c b/job.c
|
|
|
357786 |
index 020ee0d..a814857 100644
|
|
|
357786 |
--- a/job.c
|
|
|
357786 |
+++ b/job.c
|
|
|
357786 |
@@ -530,6 +530,18 @@ void job_drain(Job *job)
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+static void job_exit(void *opaque)
|
|
|
357786 |
+{
|
|
|
357786 |
+ Job *job = (Job *)opaque;
|
|
|
357786 |
+ AioContext *aio_context = job->aio_context;
|
|
|
357786 |
+
|
|
|
357786 |
+ if (job->driver->exit) {
|
|
|
357786 |
+ aio_context_acquire(aio_context);
|
|
|
357786 |
+ job->driver->exit(job);
|
|
|
357786 |
+ aio_context_release(aio_context);
|
|
|
357786 |
+ }
|
|
|
357786 |
+ job_completed(job, job->ret);
|
|
|
357786 |
+}
|
|
|
357786 |
|
|
|
357786 |
/**
|
|
|
357786 |
* All jobs must allow a pause point before entering their job proper. This
|
|
|
357786 |
@@ -542,6 +554,12 @@ static void coroutine_fn job_co_entry(void *opaque)
|
|
|
357786 |
assert(job && job->driver && job->driver->run);
|
|
|
357786 |
job_pause_point(job);
|
|
|
357786 |
job->ret = job->driver->run(job, &job->err);
|
|
|
357786 |
+ if (!job->deferred_to_main_loop) {
|
|
|
357786 |
+ job->deferred_to_main_loop = true;
|
|
|
357786 |
+ aio_bh_schedule_oneshot(qemu_get_aio_context(),
|
|
|
357786 |
+ job_exit,
|
|
|
357786 |
+ job);
|
|
|
357786 |
+ }
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|