diff mbox

[v2,02/11] blockdev: acquire AioContext in do_qmp_query_block_jobs_one()

Message ID 1413889440-32577-3-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Oct. 21, 2014, 11:03 a.m. UTC
Make sure that query-block-jobs acquires the BlockDriverState
AioContext so that the blockjob isn't running in another thread while we
access its state.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 blockdev.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Max Reitz Oct. 22, 2014, 11:10 a.m. UTC | #1
On 2014-10-21 at 13:03, Stefan Hajnoczi wrote:
> Make sure that query-block-jobs acquires the BlockDriverState
> AioContext so that the blockjob isn't running in another thread while we
> access its state.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
>   blockdev.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/blockdev.c b/blockdev.c
> index 1c7dab4..fd55904 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -2649,14 +2649,19 @@ fail:
>   static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
>   {
>       BlockJobInfoList **prev = opaque;
> -    BlockJob *job = bs->job;
> +    AioContext *aio_context;
> +
> +    aio_context = bdrv_get_aio_context(bs);
> +    aio_context_acquire(aio_context);
>   
> -    if (job) {
> +    if (bs->job) {
>           BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1);
>           elem->value = block_job_query(bs->job);
>           (*prev)->next = elem;
>           *prev = elem;
>       }
> +
> +    aio_context_release(aio_context);
>   }
>   
>   BlockJobInfoList *qmp_query_block_jobs(Error **errp)

As already said in my review for v1, this conflicts with Markus's patch 
"block: Eliminate bdrv_iterate(), use bdrv_next()"; it's still not in 
master, but by now the pull request has been sent so I guess it's up to 
you to resolve it. ;-)

Max
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 1c7dab4..fd55904 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2649,14 +2649,19 @@  fail:
 static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
 {
     BlockJobInfoList **prev = opaque;
-    BlockJob *job = bs->job;
+    AioContext *aio_context;
+
+    aio_context = bdrv_get_aio_context(bs);
+    aio_context_acquire(aio_context);
 
-    if (job) {
+    if (bs->job) {
         BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1);
         elem->value = block_job_query(bs->job);
         (*prev)->next = elem;
         *prev = elem;
     }
+
+    aio_context_release(aio_context);
 }
 
 BlockJobInfoList *qmp_query_block_jobs(Error **errp)