qcow2-threads: qcow2_co_do_compress: protect queuing by mutex

Drop dependence on AioContext lock.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190506142741.41731-5-vsementsov@virtuozzo.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2019-05-06 17:27:37 +03:00 committed by Max Reitz
parent 269062efc8
commit 0f5636c51c

View File

@ -158,15 +158,19 @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
.func = func,
};
qemu_co_mutex_lock(&s->lock);
while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
qemu_co_queue_wait(&s->compress_wait_queue, NULL);
qemu_co_queue_wait(&s->compress_wait_queue, &s->lock);
}
s->nb_compress_threads++;
thread_pool_submit_co(pool, qcow2_compress_pool_func, &arg);
s->nb_compress_threads--;
qemu_co_mutex_unlock(&s->lock);
thread_pool_submit_co(pool, qcow2_compress_pool_func, &arg);
qemu_co_mutex_lock(&s->lock);
s->nb_compress_threads--;
qemu_co_queue_next(&s->compress_wait_queue);
qemu_co_mutex_unlock(&s->lock);
return arg.ret;
}