[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 01/11] block: acquire AioContext in generic block
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v2 01/11] block: acquire AioContext in generic blockjob QMP commands |
Date: |
Tue, 21 Oct 2014 12:03:50 +0100 |
block-job-set-speed, block-job-cancel, block-job-pause,
block-job-resume, and block-job-complete must acquire the
BlockDriverState AioContext so that it is safe to access bs.
At the moment bs->job is always NULL when dataplane is active because op
blockers prevent blockjobs from starting. Once the rest of the blockjob
API has been made aware of AioContext we can drop the op blocker.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
blockdev.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 39 insertions(+), 13 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index e595910..1c7dab4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2399,20 +2399,35 @@ void qmp_drive_mirror(const char *device, const char
*target,
}
}
-static BlockJob *find_block_job(const char *device)
+/* Get the block job for a given device name and acquire its AioContext */
+static BlockJob *find_block_job(const char *device, AioContext **aio_context)
{
BlockDriverState *bs;
bs = bdrv_find(device);
- if (!bs || !bs->job) {
- return NULL;
+ if (!bs) {
+ goto notfound;
+ }
+
+ *aio_context = bdrv_get_aio_context(bs);
+ aio_context_acquire(*aio_context);
+
+ if (!bs->job) {
+ aio_context_release(*aio_context);
+ goto notfound;
}
+
return bs->job;
+
+notfound:
+ *aio_context = NULL;
+ return NULL;
}
void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp)
{
- BlockJob *job = find_block_job(device);
+ AioContext *aio_context;
+ BlockJob *job = find_block_job(device, &aio_context);
if (!job) {
error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device);
@@ -2420,34 +2435,40 @@ void qmp_block_job_set_speed(const char *device,
int64_t speed, Error **errp)
}
block_job_set_speed(job, speed, errp);
+ aio_context_release(aio_context);
}
void qmp_block_job_cancel(const char *device,
bool has_force, bool force, Error **errp)
{
- BlockJob *job = find_block_job(device);
-
- if (!has_force) {
- force = false;
- }
+ AioContext *aio_context;
+ BlockJob *job = find_block_job(device, &aio_context);
if (!job) {
error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device);
return;
}
+
+ if (!has_force) {
+ force = false;
+ }
+
if (job->paused && !force) {
error_setg(errp, "The block job for device '%s' is currently paused",
device);
- return;
+ goto out;
}
trace_qmp_block_job_cancel(job);
block_job_cancel(job);
+out:
+ aio_context_release(aio_context);
}
void qmp_block_job_pause(const char *device, Error **errp)
{
- BlockJob *job = find_block_job(device);
+ AioContext *aio_context;
+ BlockJob *job = find_block_job(device, &aio_context);
if (!job) {
error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device);
@@ -2456,11 +2477,13 @@ void qmp_block_job_pause(const char *device, Error
**errp)
trace_qmp_block_job_pause(job);
block_job_pause(job);
+ aio_context_release(aio_context);
}
void qmp_block_job_resume(const char *device, Error **errp)
{
- BlockJob *job = find_block_job(device);
+ AioContext *aio_context;
+ BlockJob *job = find_block_job(device, &aio_context);
if (!job) {
error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device);
@@ -2469,11 +2492,13 @@ void qmp_block_job_resume(const char *device, Error
**errp)
trace_qmp_block_job_resume(job);
block_job_resume(job);
+ aio_context_release(aio_context);
}
void qmp_block_job_complete(const char *device, Error **errp)
{
- BlockJob *job = find_block_job(device);
+ AioContext *aio_context;
+ BlockJob *job = find_block_job(device, &aio_context);
if (!job) {
error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device);
@@ -2482,6 +2507,7 @@ void qmp_block_job_complete(const char *device, Error
**errp)
trace_qmp_block_job_complete(job);
block_job_complete(job, errp);
+ aio_context_release(aio_context);
}
void qmp_change_backing_file(const char *device,
--
1.9.3
- [Qemu-devel] [PATCH v2 00/11] block: allow blockjobs to coexist with dataplane, Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 01/11] block: acquire AioContext in generic blockjob QMP commands,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v2 02/11] blockdev: acquire AioContext in do_qmp_query_block_jobs_one(), Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 03/11] blockdev: acquire AioContext in blockdev_mark_auto_del(), Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 04/11] blockdev: add note that block_job_cb() must be thread-safe, Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 05/11] blockjob: add block_job_defer_to_main_loop(), Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 06/11] block: add bdrv_drain(), Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 07/11] block: let backup blockjob run in BDS AioContext, Stefan Hajnoczi, 2014/10/21
- [Qemu-devel] [PATCH v2 09/11] block: let mirror blockjob run in BDS AioContext, Stefan Hajnoczi, 2014/10/21