From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Stefan Reiter Date: Mon, 21 Oct 2019 17:32:22 +0200 Subject: [PATCH] Acquire aio_context before calling block_job_add_bdrv Otherwise backups immediately fail with 'permission denied' since _add_bdrv tries to release a lock we don't own. Signed-off-by: Stefan Reiter --- blockjob.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/blockjob.c b/blockjob.c index 20b7f557da..c6067474a2 100644 --- a/blockjob.c +++ b/blockjob.c @@ -439,10 +439,20 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, notifier_list_add(&job->job.on_ready, &job->ready_notifier); notifier_list_add(&job->job.on_idle, &job->idle_notifier); + /* block_job_add_bdrv expects us to hold the aio context lock, so acquire it + * before calling if we're not in the main context anyway. */ + if (job->job.aio_context != qemu_get_aio_context()) { + aio_context_acquire(job->job.aio_context); + } + error_setg(&job->blocker, "block device is in use by block job: %s", job_type_str(&job->job)); block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort); + if (job->job.aio_context != qemu_get_aio_context()) { + aio_context_release(job->job.aio_context); + } + bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); blk_set_allow_aio_context_change(blk, true);