xemu/tests
Stefan Hajnoczi c8bf923d5e test-bdrv-drain: avoid race with BH in IOThread drain test
This patch fixes a race condition in test-bdrv-drain that is difficult
to reproduce. test-bdrv-drain sometimes fails without an error message
on the block pull request sent by Kevin Wolf on Sep 4, 2023. I was able
to reproduce it locally and found that "block-backend: process I/O in
the current AioContext" (in this patch series) is the first commit where
it reproduces.

I do not know why "block-backend: process I/O in the current AioContext"
exposes this bug. It might be related to the fact that the test's preadv
request runs in the main thread instead of IOThread a after my commit.
That might simply change the timing of the test.

Now on to the race condition in test-bdrv-drain. The main thread
schedules a BH in IOThread a and then drains the BDS:

  aio_bh_schedule_oneshot(ctx_a, test_iothread_main_thread_bh, &data);

  /* The request is running on the IOThread a. Draining its block device
   * will make sure that it has completed as far as the BDS is concerned,
   * but the drain in this thread can continue immediately after
   * bdrv_dec_in_flight() and aio_ret might be assigned only slightly
   * later. */
  do_drain_begin(drain_type, bs);

If the BH completes before do_drain_begin() then there is nothing to
worry about.

If the BH invokes bdrv_flush() before do_drain_begin(), then
do_drain_begin() waits for it to complete.

The problematic case is when do_drain_begin() runs before the BH enters
bdrv_flush(). Then do_drain_begin() misses the BH and the drain
mechanism has failed in quiescing I/O.

Fix this by incrementing the in_flight counter so that do_drain_begin()
waits for test_iothread_main_thread_bh().

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20230912231037.826804-3-stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2023-09-20 17:46:01 +02:00
..
avocado tests/: spelling fixes 2023-09-08 13:08:52 +03:00
bench migration/xbzrle: Use i386 host/cpuinfo.h 2023-05-23 16:51:18 -07:00
data tests/acpi: update virt/SSDT.memhp 2023-09-18 15:27:27 +02:00
decode tests/: spelling fixes 2023-09-08 13:08:52 +03:00
docker net: add initial support for AF_XDP network backend 2023-09-18 14:36:13 +08:00
fp tests: fp: remove unused submodules 2023-06-07 11:05:09 +02:00
guest-debug tests/tcg: clean-up gdb confirm/pagination settings 2023-08-30 14:57:50 +01:00
image-fuzzer image-fuzzer: Use OSerror.strerror instead of tuple subscript 2019-11-05 16:36:11 +01:00
include tests: add missing generated sources to testqapi 2020-10-17 10:45:50 -04:00
keys tests/vm: Add Haiku test based on their vagrant images 2020-11-17 09:45:24 +01:00
lcitool net: add initial support for AF_XDP network backend 2023-09-18 14:36:13 +08:00
migration tests/: spelling fixes 2023-09-08 13:08:52 +03:00
multiboot Remove superfluous .gitignore files 2020-10-13 12:48:17 +02:00
perf/block/qcow2 tests/perf: Test lseek influence on qcow2 block-status 2019-06-04 15:20:41 +02:00
plugin tests/: spelling fixes 2023-09-08 13:08:52 +03:00
qapi-schema tests/: spelling fixes 2023-09-08 13:08:52 +03:00
qemu-iotests qemu-img: map: report compressed data blocks 2023-09-20 17:46:01 +02:00
qtest tests/acpi: disallow virt/SSDT.memhp updates 2023-09-18 15:27:27 +02:00
rocker tests: Avoid non-portable 'echo -ARG' 2017-07-11 17:45:00 +02:00
tcg fpu: Handle m68k extended precision denormals properly 2023-09-16 14:57:16 +00:00
tsan tests/: spelling fixes 2023-09-08 13:08:52 +03:00
uefi-test-tools tests/: spelling fixes 2023-09-08 13:08:52 +03:00
unit test-bdrv-drain: avoid race with BH in IOThread drain test 2023-09-20 17:46:01 +02:00
vm tests/: spelling fixes 2023-09-08 13:08:52 +03:00
vmstate-static-checker-data hw: Replace anti-social QOM type names 2021-03-19 15:18:43 +01:00
Makefile.include configure, meson: move --enable-plugins to meson 2023-09-07 13:32:37 +02:00
dbus-vmstate-daemon.sh tests: add dbus-vmstate-test 2020-01-06 18:41:32 +04:00
meson.build configure, meson: remove target OS symbols from config-host.mak 2023-09-07 13:32:37 +02:00
test-qht-par.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
vhost-user-bridge.c error handling: Use RETRY_ON_EINTR() macro where applicable 2023-01-09 13:50:47 +01:00