mirror_qemu/hw/block
Stefan Hajnoczi a937f8e857 virtio-blk: simplify virtio_blk_dma_restart_cb()
virtio_blk_dma_restart_cb() is tricky because the BH must deal with
virtio_blk_data_plane_start()/virtio_blk_data_plane_stop() being called.

There are two issues with the code:

1. virtio_blk_realize() should use qdev_add_vm_change_state_handler()
   instead of qemu_add_vm_change_state_handler(). This ensures the
   ordering with virtio_init()'s vm change state handler that calls
   virtio_blk_data_plane_start()/virtio_blk_data_plane_stop() is
   well-defined. Then blk's AioContext is guaranteed to be up-to-date in
   virtio_blk_dma_restart_cb() and it's no longer necessary to have a
   special case for virtio_blk_data_plane_start().

2. Only blk_drain() waits for virtio_blk_dma_restart_cb()'s
   blk_inc_in_flight() to be decremented. The bdrv_drain() family of
   functions do not wait for BlockBackend's in_flight counter to reach
   zero. virtio_blk_data_plane_stop() relies on blk_set_aio_context()'s
   implicit drain, but that's a bdrv_drain() and not a blk_drain().
   Note that virtio_blk_reset() already correctly relies on blk_drain().
   If virtio_blk_data_plane_stop() switches to blk_drain() then we can
   properly wait for pending virtio_blk_dma_restart_bh() calls.

Once these issues are taken care of the code becomes simpler. This
change is in preparation for multiple IOThreads in virtio-blk where we
need to clean up the multi-threading behavior.

I ran the reproducer from commit 49b44549ac ("virtio-blk: On restart,
process queued requests in the proper context") to check that there is
no regression.

Cc: Sergio Lopez <slp@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-id: 20221102182337.252202-1-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2023-01-23 15:01:23 -05:00
..
dataplane virtio-blk: simplify virtio_blk_dma_restart_cb() 2023-01-23 15:01:23 -05:00
Kconfig hw/block/fdc: Extract SysBus floppy controllers to fdc-sysbus.c 2021-06-25 08:53:28 -04:00
block.c include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
cdrom.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
ecc.c vmstate: Constify some VMStateDescriptions 2021-05-02 17:24:50 +02:00
fdc-internal.h hw/block/fdc: Declare shared prototypes in fdc-internal.h 2021-06-25 08:53:28 -04:00
fdc-isa.c acpi: fdc-isa: replace ISADeviceClass::build_aml with AcpiDevAmlIfClass:build_dev_aml 2022-06-09 19:32:48 -04:00
fdc-sysbus.c hw/block/fdc-sysbus: Always mark sysbus floppy controllers as not having DMA 2022-06-11 11:36:14 +02:00
fdc.c block: Change blk_{pread,pwrite}() param order 2022-07-12 12:14:56 +02:00
hd-geometry.c hw/block/hd-geometry: Do not override specified bios-chs-trans 2022-08-02 11:21:56 +02:00
m25p80.c m25p80: Add the w25q01jvq SFPD table 2022-10-24 11:20:16 +02:00
m25p80_sfdp.c m25p80: Add the w25q01jvq SFPD table 2022-10-24 11:20:16 +02:00
m25p80_sfdp.h m25p80: Add the w25q01jvq SFPD table 2022-10-24 11:20:16 +02:00
meson.build m25p80: Add the n25q256a SFDP table 2022-10-24 11:20:15 +02:00
nand.c block: Change blk_{pread,pwrite}() param order 2022-07-12 12:14:56 +02:00
onenand.c block: Change blk_{pread,pwrite}() param order 2022-07-12 12:14:56 +02:00
pflash_cfi01.c bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
pflash_cfi02.c Revert "hw/block/pflash_cfi: Error out if dev length isn't power of 2" 2022-11-08 15:53:40 -05:00
swim.c qbus: Rename qbus_create_inplace() to qbus_init() 2021-09-30 13:42:10 +01:00
tc58128.c hw/sh4: Add missing license 2021-03-06 16:18:42 +01:00
trace-events m25p80: Add basic support for the SFDP command 2022-10-24 11:20:15 +02:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vhost-user-blk.c hw/virtio: generalise CHR_EVENT_CLOSED handling 2022-12-01 02:30:13 -05:00
virtio-blk-common.c virtio-blk: move config size params to virtio-blk-common 2022-10-07 09:41:51 -04:00
virtio-blk.c virtio-blk: simplify virtio_blk_dma_restart_cb() 2023-01-23 15:01:23 -05:00
xen-block.c block: get rid of blk->guest_block_size 2022-06-24 17:07:06 +02:00
xen_blkif.h xen: Import other xen/io/*.h 2019-06-24 10:42:30 +01:00