Blame SOURCES/kvm-test-bdrv-drain-Test-nested-poll-in-bdrv_drain_poll_.patch

383d26
From 8c657cb165e931b4eb6f3675495240437b0c1cb1 Mon Sep 17 00:00:00 2001
383d26
From: Kevin Wolf <kwolf@redhat.com>
383d26
Date: Fri, 14 Sep 2018 10:55:38 +0200
383d26
Subject: [PATCH 47/49] test-bdrv-drain: Test nested poll in
383d26
 bdrv_drain_poll_top_level()
383d26
383d26
RH-Author: Kevin Wolf <kwolf@redhat.com>
383d26
Message-id: <20180914105540.18077-41-kwolf@redhat.com>
383d26
Patchwork-id: 82189
383d26
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 40/42] test-bdrv-drain: Test nested poll in bdrv_drain_poll_top_level()
383d26
Bugzilla: 1601212
383d26
RH-Acked-by: John Snow <jsnow@redhat.com>
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Fam Zheng <famz@redhat.com>
383d26
383d26
This is a regression test for a deadlock that could occur in callbacks
383d26
called from the aio_poll() in bdrv_drain_poll_top_level(). The
383d26
AioContext lock wasn't released and therefore would be taken a second
383d26
time in the callback. This would cause a possible AIO_WAIT_WHILE() in
383d26
the callback to hang.
383d26
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
Reviewed-by: Fam Zheng <famz@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 tests/test-bdrv-drain.c | 13 +++++++++++++
383d26
 1 file changed, 13 insertions(+)
383d26
383d26
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
383d26
index 05f3b55..f4b57f7 100644
383d26
--- a/tests/test-bdrv-drain.c
383d26
+++ b/tests/test-bdrv-drain.c
383d26
@@ -636,6 +636,17 @@ static void test_iothread_aio_cb(void *opaque, int ret)
383d26
     qemu_event_set(&done_event);
383d26
 }
383d26
 
383d26
+static void test_iothread_main_thread_bh(void *opaque)
383d26
+{
383d26
+    struct test_iothread_data *data = opaque;
383d26
+
383d26
+    /* Test that the AioContext is not yet locked in a random BH that is
383d26
+     * executed during drain, otherwise this would deadlock. */
383d26
+    aio_context_acquire(bdrv_get_aio_context(data->bs));
383d26
+    bdrv_flush(data->bs);
383d26
+    aio_context_release(bdrv_get_aio_context(data->bs));
383d26
+}
383d26
+
383d26
 /*
383d26
  * Starts an AIO request on a BDS that runs in the AioContext of iothread 1.
383d26
  * The request involves a BH on iothread 2 before it can complete.
383d26
@@ -705,6 +716,8 @@ static void test_iothread_common(enum drain_type drain_type, int drain_thread)
383d26
             aio_context_acquire(ctx_a);
383d26
         }
383d26
 
383d26
+        aio_bh_schedule_oneshot(ctx_a, test_iothread_main_thread_bh, &data);
383d26
+
383d26
         /* The request is running on the IOThread a. Draining its block device
383d26
          * will make sure that it has completed as far as the BDS is concerned,
383d26
          * but the drain in this thread can continue immediately after
383d26
-- 
383d26
1.8.3.1
383d26