From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
Wen Congyang <wencongyang2@huawei.com>,
Xie Changlong <xiechanglong.d@gmail.com>,
Emanuele Giuseppe Esposito <eesposit@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [PATCH v5 07/20] job.h: add _locked duplicates for job API functions called with and without job_mutex
Date: Tue, 8 Feb 2022 09:35:00 -0500 [thread overview]
Message-ID: <20220208143513.1077229-8-eesposit@redhat.com> (raw)
In-Reply-To: <20220208143513.1077229-1-eesposit@redhat.com>
In preparation to the job_lock/unlock usage, create _locked
duplicates of some functions, since they will be sometimes called with
job_mutex held (mostly within job.c),
and sometimes without (mostly from JobDrivers using the job API).
Therefore create a _locked version of such function, so that it
can be used in both cases.
List of functions duplicated as _locked:
job_is_ready (both versions are public)
job_is_completed (both versions are public)
job_is_cancelled (_locked version is public, needed by mirror.c)
job_pause_point (_locked version is static, purely done to simplify the code)
job_cancel_requested (_locked version is static)
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
include/qemu/job.h | 25 +++++++++++++++++++++---
job.c | 48 ++++++++++++++++++++++++++++++++++++++++------
2 files changed, 64 insertions(+), 9 deletions(-)
diff --git a/include/qemu/job.h b/include/qemu/job.h
index 6000463126..aa33d091b1 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -473,21 +473,40 @@ const char *job_type_str(const Job *job);
/** Returns true if the job should not be visible to the management layer. */
bool job_is_internal(Job *job);
-/** Returns whether the job is being cancelled. */
+/**
+ * Returns whether the job is being cancelled.
+ * Called with job_mutex *not* held.
+ */
bool job_is_cancelled(Job *job);
+/** Just like job_is_cancelled, but called between job_lock and job_unlock */
+bool job_is_cancelled_locked(Job *job);
+
/**
* Returns whether the job is scheduled for cancellation (at an
* indefinite point).
+ * Called with job_mutex *not* held.
*/
bool job_cancel_requested(Job *job);
-/** Returns whether the job is in a completed state. */
+/**
+ * Returns whether the job is in a completed state.
+ * Called with job_mutex *not* held.
+ */
bool job_is_completed(Job *job);
-/** Returns whether the job is ready to be completed. */
+/** Same as job_is_completed(), but assumes job_lock is held. */
+bool job_is_completed_locked(Job *job);
+
+/**
+ * Returns whether the job is ready to be completed.
+ * Called with job_mutex *not* held.
+ */
bool job_is_ready(Job *job);
+/** Same as job_is_ready(), but assumes job_lock is held. */
+bool job_is_ready_locked(Job *job);
+
/**
* Request @job to pause at the next pause point. Must be paired with
* job_resume(). If the job is supposed to be resumed by user action, call
diff --git a/job.c b/job.c
index d8c13ac0d1..6f1f529dc1 100644
--- a/job.c
+++ b/job.c
@@ -222,19 +222,32 @@ const char *job_type_str(const Job *job)
return JobType_str(job_type(job));
}
-bool job_is_cancelled(Job *job)
+bool job_is_cancelled_locked(Job *job)
{
/* force_cancel may be true only if cancelled is true, too */
assert(job->cancelled || !job->force_cancel);
return job->force_cancel;
}
-bool job_cancel_requested(Job *job)
+bool job_is_cancelled(Job *job)
+{
+ JOB_LOCK_GUARD();
+ return job_is_cancelled_locked(job);
+}
+
+/* Called with job_mutex held. */
+static bool job_cancel_requested_locked(Job *job)
{
return job->cancelled;
}
-bool job_is_ready(Job *job)
+bool job_cancel_requested(Job *job)
+{
+ JOB_LOCK_GUARD();
+ return job_cancel_requested_locked(job);
+}
+
+bool job_is_ready_locked(Job *job)
{
switch (job->status) {
case JOB_STATUS_UNDEFINED:
@@ -256,7 +269,13 @@ bool job_is_ready(Job *job)
return false;
}
-bool job_is_completed(Job *job)
+bool job_is_ready(Job *job)
+{
+ JOB_LOCK_GUARD();
+ return job_is_ready_locked(job);
+}
+
+bool job_is_completed_locked(Job *job)
{
switch (job->status) {
case JOB_STATUS_UNDEFINED:
@@ -278,6 +297,12 @@ bool job_is_completed(Job *job)
return false;
}
+bool job_is_completed(Job *job)
+{
+ JOB_LOCK_GUARD();
+ return job_is_completed_locked(job);
+}
+
static bool job_started(Job *job)
{
return job->co;
@@ -507,7 +532,8 @@ static void coroutine_fn job_do_yield(Job *job, uint64_t ns)
assert(job->busy);
}
-void coroutine_fn job_pause_point(Job *job)
+/* Called with job_mutex held, but releases it temporarly. */
+static void coroutine_fn job_pause_point_locked(Job *job)
{
assert(job && job_started(job));
@@ -538,6 +564,12 @@ void coroutine_fn job_pause_point(Job *job)
}
}
+void coroutine_fn job_pause_point(Job *job)
+{
+ JOB_LOCK_GUARD();
+ job_pause_point_locked(job);
+}
+
void job_yield(Job *job)
{
assert(job->busy);
@@ -946,11 +978,15 @@ static void job_completed(Job *job)
}
}
-/** Useful only as a type shim for aio_bh_schedule_oneshot. */
+/**
+ * Useful only as a type shim for aio_bh_schedule_oneshot.
+ * Called with job_mutex *not* held.
+ */
static void job_exit(void *opaque)
{
Job *job = (Job *)opaque;
AioContext *ctx;
+ JOB_LOCK_GUARD();
job_ref(job);
aio_context_acquire(job->aio_context);
--
2.31.1
next prev parent reply other threads:[~2022-02-08 15:24 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 14:34 [PATCH v5 00/20] job: replace AioContext lock with job_mutex Emanuele Giuseppe Esposito
2022-02-08 14:34 ` [PATCH v5 01/20] job.c: make job_mutex and job_lock/unlock() public Emanuele Giuseppe Esposito
2022-02-10 15:38 ` Stefan Hajnoczi
2022-02-08 14:34 ` [PATCH v5 02/20] job.h: categorize fields in struct Job Emanuele Giuseppe Esposito
2022-02-10 15:40 ` Stefan Hajnoczi
2022-02-10 16:26 ` Emanuele Giuseppe Esposito
2022-02-10 17:35 ` Stefan Hajnoczi
2022-02-11 9:00 ` Emanuele Giuseppe Esposito
2022-02-08 14:34 ` [PATCH v5 03/20] job.c: API functions not used outside should be static Emanuele Giuseppe Esposito
2022-02-10 15:43 ` Stefan Hajnoczi
2022-02-08 14:34 ` [PATCH v5 04/20] job.c: move inner aiocontext lock in callbacks Emanuele Giuseppe Esposito
2022-02-17 13:45 ` Stefan Hajnoczi
2022-02-24 9:20 ` Emanuele Giuseppe Esposito
2022-02-24 9:29 ` Emanuele Giuseppe Esposito
2022-02-08 14:34 ` [PATCH v5 05/20] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED Emanuele Giuseppe Esposito
2022-02-17 13:56 ` Stefan Hajnoczi
2022-02-08 14:34 ` [PATCH v5 06/20] jobs: remove aiocontext locks since the functions are under BQL Emanuele Giuseppe Esposito
2022-02-17 14:12 ` Stefan Hajnoczi
2022-02-24 9:27 ` Emanuele Giuseppe Esposito
2022-02-08 14:35 ` Emanuele Giuseppe Esposito [this message]
2022-02-17 14:20 ` [PATCH v5 07/20] job.h: add _locked duplicates for job API functions called with and without job_mutex Stefan Hajnoczi
2022-02-24 9:52 ` Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 08/20] jobs: protect jobs with job_lock/unlock Emanuele Giuseppe Esposito
2022-02-17 14:48 ` Stefan Hajnoczi
2022-02-24 12:45 ` Emanuele Giuseppe Esposito
2022-02-24 16:48 ` Stefan Hajnoczi
2022-02-24 16:55 ` Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 09/20] jobs: add job lock in find_* functions Emanuele Giuseppe Esposito
2022-02-17 15:00 ` Stefan Hajnoczi
2022-02-24 12:36 ` Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 10/20] jobs: use job locks also in the unit tests Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 11/20] block/mirror.c: use of job helpers in drivers to avoid TOC/TOU Emanuele Giuseppe Esposito
2022-02-17 16:53 ` Stefan Hajnoczi
2022-02-08 14:35 ` [PATCH v5 12/20] jobs: rename static functions called with job_mutex held Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 13/20] job.h: rename job API " Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 14/20] block_job: rename block_job " Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 15/20] job.h: define unlocked functions Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 16/20] commit and mirror: create new nodes using bdrv_get_aio_context, and not the job aiocontext Emanuele Giuseppe Esposito
2022-03-08 11:13 ` Stefan Hajnoczi
2022-02-08 14:35 ` [PATCH v5 17/20] job: detect change of aiocontext within job coroutine Emanuele Giuseppe Esposito
2022-03-08 11:19 ` Stefan Hajnoczi
2022-02-08 14:35 ` [PATCH v5 18/20] jobs: protect job.aio_context with BQL and job_mutex Emanuele Giuseppe Esposito
2022-03-08 13:41 ` Stefan Hajnoczi
2022-03-10 10:09 ` Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 19/20] job.c: enable job lock/unlock and remove Aiocontext locks Emanuele Giuseppe Esposito
2022-03-08 14:04 ` Stefan Hajnoczi
2022-03-10 10:25 ` Emanuele Giuseppe Esposito
2022-02-08 14:35 ` [PATCH v5 20/20] block_job_query: remove atomic read Emanuele Giuseppe Esposito
2022-03-08 14:06 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220208143513.1077229-8-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=armbru@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
--cc=wencongyang2@huawei.com \
--cc=xiechanglong.d@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).