From: Stefan Reiter <s.rei...@proxmox.com>

Otherwise backups immediately fail with 'permission denied' since
_add_bdrv tries to release a lock we don't own.

Signed-off-by: Stefan Reiter <s.rei...@proxmox.com>
---
 blockjob.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/blockjob.c b/blockjob.c
index c6e20e2fcd..4e6074f18c 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -436,10 +436,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);
 
     /* Disable request queuing in the BlockBackend to avoid deadlocks on drain:
-- 
2.20.1

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to