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

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