Blame SOURCES/kvm-block-don-t-keep-AioContext-acquired-after-internal_.patch

4a2fec
From a9ef5c84766a00677204474b0f8d8e845b9d4d3f Mon Sep 17 00:00:00 2001
4a2fec
From: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Date: Fri, 22 Dec 2017 11:08:53 +0100
4a2fec
Subject: [PATCH 35/42] block: don't keep AioContext acquired after
4a2fec
 internal_snapshot_prepare()
4a2fec
4a2fec
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Message-id: <20171222110900.24813-14-stefanha@redhat.com>
4a2fec
Patchwork-id: 78499
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 13/20] block: don't keep AioContext acquired after internal_snapshot_prepare()
4a2fec
Bugzilla: 1519721
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
4a2fec
Reviewed-by: Eric Blake <eblake@redhat.com>
4a2fec
Message-id: 20171206144550.22295-6-stefanha@redhat.com
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
(cherry picked from commit a36e458cdda0196911c1cbe7cfe6f9530f2280e3)
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 blockdev.c | 47 +++++++++++++++++++++++++++++++----------------
4a2fec
 1 file changed, 31 insertions(+), 16 deletions(-)
4a2fec
4a2fec
diff --git a/blockdev.c b/blockdev.c
4a2fec
index 6efae53..f118444 100644
4a2fec
--- a/blockdev.c
4a2fec
+++ b/blockdev.c
4a2fec
@@ -1497,7 +1497,6 @@ struct BlkActionState {
4a2fec
 typedef struct InternalSnapshotState {
4a2fec
     BlkActionState common;
4a2fec
     BlockDriverState *bs;
4a2fec
-    AioContext *aio_context;
4a2fec
     QEMUSnapshotInfo sn;
4a2fec
     bool created;
4a2fec
 } InternalSnapshotState;
4a2fec
@@ -1528,6 +1527,7 @@ static void internal_snapshot_prepare(BlkActionState *common,
4a2fec
     qemu_timeval tv;
4a2fec
     BlockdevSnapshotInternal *internal;
4a2fec
     InternalSnapshotState *state;
4a2fec
+    AioContext *aio_context;
4a2fec
     int ret1;
4a2fec
 
4a2fec
     g_assert(common->action->type ==
4a2fec
@@ -1549,32 +1549,33 @@ static void internal_snapshot_prepare(BlkActionState *common,
4a2fec
         return;
4a2fec
     }
4a2fec
 
4a2fec
-    /* AioContext is released in .clean() */
4a2fec
-    state->aio_context = bdrv_get_aio_context(bs);
4a2fec
-    aio_context_acquire(state->aio_context);
4a2fec
+    aio_context = bdrv_get_aio_context(bs);
4a2fec
+    aio_context_acquire(aio_context);
4a2fec
 
4a2fec
     state->bs = bs;
4a2fec
+
4a2fec
+    /* Paired with .clean() */
4a2fec
     bdrv_drained_begin(bs);
4a2fec
 
4a2fec
     if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) {
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
 
4a2fec
     if (bdrv_is_read_only(bs)) {
4a2fec
         error_setg(errp, "Device '%s' is read only", device);
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
 
4a2fec
     if (!bdrv_can_snapshot(bs)) {
4a2fec
         error_setg(errp, "Block format '%s' used by device '%s' "
4a2fec
                    "does not support internal snapshots",
4a2fec
                    bs->drv->format_name, device);
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
 
4a2fec
     if (!strlen(name)) {
4a2fec
         error_setg(errp, "Name is empty");
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
 
4a2fec
     /* check whether a snapshot with name exist */
4a2fec
@@ -1582,12 +1583,12 @@ static void internal_snapshot_prepare(BlkActionState *common,
4a2fec
                                             &local_err);
4a2fec
     if (local_err) {
4a2fec
         error_propagate(errp, local_err);
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     } else if (ret) {
4a2fec
         error_setg(errp,
4a2fec
                    "Snapshot with name '%s' already exists on device '%s'",
4a2fec
                    name, device);
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
 
4a2fec
     /* 3. take the snapshot */
4a2fec
@@ -1603,11 +1604,14 @@ static void internal_snapshot_prepare(BlkActionState *common,
4a2fec
         error_setg_errno(errp, -ret1,
4a2fec
                          "Failed to create snapshot '%s' on device '%s'",
4a2fec
                          name, device);
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
 
4a2fec
     /* 4. succeed, mark a snapshot is created */
4a2fec
     state->created = true;
4a2fec
+
4a2fec
+out:
4a2fec
+    aio_context_release(aio_context);
4a2fec
 }
4a2fec
 
4a2fec
 static void internal_snapshot_abort(BlkActionState *common)
4a2fec
@@ -1616,12 +1620,16 @@ static void internal_snapshot_abort(BlkActionState *common)
4a2fec
                              DO_UPCAST(InternalSnapshotState, common, common);
4a2fec
     BlockDriverState *bs = state->bs;
4a2fec
     QEMUSnapshotInfo *sn = &state->sn;
4a2fec
+    AioContext *aio_context;
4a2fec
     Error *local_error = NULL;
4a2fec
 
4a2fec
     if (!state->created) {
4a2fec
         return;
4a2fec
     }
4a2fec
 
4a2fec
+    aio_context = bdrv_get_aio_context(state->bs);
4a2fec
+    aio_context_acquire(aio_context);
4a2fec
+
4a2fec
     if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) {
4a2fec
         error_reportf_err(local_error,
4a2fec
                           "Failed to delete snapshot with id '%s' and "
4a2fec
@@ -1629,19 +1637,26 @@ static void internal_snapshot_abort(BlkActionState *common)
4a2fec
                           sn->id_str, sn->name,
4a2fec
                           bdrv_get_device_name(bs));
4a2fec
     }
4a2fec
+
4a2fec
+    aio_context_release(aio_context);
4a2fec
 }
4a2fec
 
4a2fec
 static void internal_snapshot_clean(BlkActionState *common)
4a2fec
 {
4a2fec
     InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState,
4a2fec
                                              common, common);
4a2fec
+    AioContext *aio_context;
4a2fec
 
4a2fec
-    if (state->aio_context) {
4a2fec
-        if (state->bs) {
4a2fec
-            bdrv_drained_end(state->bs);
4a2fec
-        }
4a2fec
-        aio_context_release(state->aio_context);
4a2fec
+    if (!state->bs) {
4a2fec
+        return;
4a2fec
     }
4a2fec
+
4a2fec
+    aio_context = bdrv_get_aio_context(state->bs);
4a2fec
+    aio_context_acquire(aio_context);
4a2fec
+
4a2fec
+    bdrv_drained_end(state->bs);
4a2fec
+
4a2fec
+    aio_context_release(aio_context);
4a2fec
 }
4a2fec
 
4a2fec
 /* external snapshot private data */
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec