diff mbox

[03/11] blockdev: acquire AioContext in blockdev_mark_auto_del()

Message ID 1412182919-9550-4-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Oct. 1, 2014, 5:01 p.m. UTC
When an emulated storage controller is unrealized it will call
blockdev_mark_auto_del().  This will cancel any running block job (and
that eventually releases its reference to the BDS so it can be freed).

Since the block job may be executing in another AioContext we must
acquire/release to ensure thread safety.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 blockdev.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Max Reitz Oct. 1, 2014, 6:39 p.m. UTC | #1
On 01.10.2014 19:01, Stefan Hajnoczi wrote:
> When an emulated storage controller is unrealized it will call
> blockdev_mark_auto_del().  This will cancel any running block job (and
> that eventually releases its reference to the BDS so it can be freed).
>
> Since the block job may be executing in another AioContext we must
> acquire/release to ensure thread safety.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   blockdev.c | 7 +++++++
>   1 file changed, 7 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 270425d..5e38f34 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -89,14 +89,21 @@  static const int if_max_devs[IF_COUNT] = {
 void blockdev_mark_auto_del(BlockDriverState *bs)
 {
     DriveInfo *dinfo = drive_get_by_blockdev(bs);
+    AioContext *aio_context;
 
     if (dinfo && !dinfo->enable_auto_del) {
         return;
     }
 
+    aio_context = bdrv_get_aio_context(bs);
+    aio_context_acquire(aio_context);
+
     if (bs->job) {
         block_job_cancel(bs->job);
     }
+
+    aio_context_release(aio_context);
+
     if (dinfo) {
         dinfo->auto_del = 1;
     }