[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 29/31] jobs: introduce pre_run function in JobDriver
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v5 29/31] jobs: introduce pre_run function in JobDriver |
Date: |
Wed, 24 Nov 2021 01:44:16 -0500 |
.pre_run takes care of doing some initial job setup just before
the job is run inside the coroutine. Doing so can be useful
to invoke GS functions that require the BQL held.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
include/qemu/job.h | 9 +++++++++
job.c | 13 +++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/qemu/job.h b/include/qemu/job.h
index 4ea7a4a0cd..915ceff425 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -223,6 +223,15 @@ struct JobDriver {
* the GS API.
*/
+ /**
+ * Called in the Main Loop context, before the job coroutine
+ * is started in the job aiocontext. Useful to perform operations
+ * that needs to be done under BQL (like permissions setup).
+ * On success, it returns 0. Otherwise the job failed to initialize
+ * and won't start.
+ */
+ int (*pre_run)(Job *job, Error **errp);
+
/**
* Called when the job is resumed by the user (i.e. user_paused becomes
* false). .user_resume is called before .resume.
diff --git a/job.c b/job.c
index bb57ec6887..e048037099 100644
--- a/job.c
+++ b/job.c
@@ -967,11 +967,24 @@ static void coroutine_fn job_co_entry(void *opaque)
aio_bh_schedule_oneshot(qemu_get_aio_context(), job_exit, job);
}
+static int job_pre_run(Job *job)
+{
+ assert(qemu_in_main_thread());
+ if (job->driver->pre_run) {
+ return job->driver->pre_run(job, &job->err);
+ }
+
+ return 0;
+}
+
void job_start(Job *job)
{
assert(job && !job_started(job) && job->paused &&
job->driver && job->driver->run);
job->co = qemu_coroutine_create(job_co_entry, job);
+ if (job_pre_run(job)) {
+ return;
+ }
job->pause_count--;
job->busy = true;
job->paused = false;
--
2.27.0
- [PATCH v5 20/31] block/coroutines: I/O API, (continued)
- [PATCH v5 20/31] block/coroutines: I/O API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 18/31] include/block/snapshot: global state API + assertions, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 17/31] assertions for blockdev.h global state API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 19/31] block/copy-before-write.h: global state API + assertions, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 22/31] block_int-common.h: assertion in the callers of BlockDriver function pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 24/31] block_int-common.h: assertions in the callers of BdrvChildClass function pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 21/31] block_int-common.h: split function pointers in BlockDriver, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 23/31] block_int-common.h: split function pointers in BdrvChildClass, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 26/31] job.h: split function pointers in JobDriver, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 25/31] block-backend-common.h: split function pointers in BlockDevOps, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 29/31] jobs: introduce pre_run function in JobDriver,
Emanuele Giuseppe Esposito <=
- [PATCH v5 27/31] job.h: assertions in the callers of JobDriver funcion pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 30/31] crypto: delegate permission functions to JobDriver .pre_run, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 31/31] block.c: assertions to the block layer permissions API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 28/31] block.c: assert BQL lock held in bdrv_co_invalidate_cache, Emanuele Giuseppe Esposito, 2021/11/24
- Re: [PATCH v5 00/31] block layer: split block APIs in global state and I/O, Stefan Hajnoczi, 2021/11/29