diff mbox

[04/10] blockdev: acquire AioContext in hmp_commit()

Message ID 1446559933-28965-5-git-send-email-den@openvz.org
State New
Headers show

Commit Message

Denis V. Lunev Nov. 3, 2015, 2:12 p.m. UTC
From: Stefan Hajnoczi <stefanha@redhat.com>

This one slipped through.  Although we acquire AioContext when
committing all devices we don't for just a single device.

AioContext must be acquired before calling bdrv_*() functions to
synchronize access with other threads that may be using the AioContext.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 blockdev.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Denis V. Lunev Nov. 3, 2015, 2:38 p.m. UTC | #1
On 11/03/2015 05:12 PM, Denis V. Lunev wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
>
> This one slipped through.  Although we acquire AioContext when
> committing all devices we don't for just a single device.
>
> AioContext must be acquired before calling bdrv_*() functions to
> synchronize access with other threads that may be using the AioContext.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
this was Reviewed-by: Jeff Cody <jcody@redhat.com> in
the original submission.

Lost that accidentally.
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 18712d2..d611779 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1120,6 +1120,9 @@  void hmp_commit(Monitor *mon, const QDict *qdict)
     if (!strcmp(device, "all")) {
         ret = bdrv_commit_all();
     } else {
+        BlockDriverState *bs;
+        AioContext *aio_context;
+
         blk = blk_by_name(device);
         if (!blk) {
             monitor_printf(mon, "Device '%s' not found\n", device);
@@ -1129,7 +1132,14 @@  void hmp_commit(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "Device '%s' has no medium\n", device);
             return;
         }
-        ret = bdrv_commit(blk_bs(blk));
+
+        bs = blk_bs(blk);
+        aio_context = bdrv_get_aio_context(bs);
+        aio_context_acquire(aio_context);
+
+        ret = bdrv_commit(bs);
+
+        aio_context_release(aio_context);
     }
     if (ret < 0) {
         monitor_printf(mon, "'commit' error for '%s': %s\n", device,