Currently, bdrv_close_all() force-closes all BDSs with a BlockBackend, which can lead to data corruption (see the iotest added in the final patch of this series) and is most certainly very ugly.
This series reworks bdrv_close_all() to instead eject the BDS trees from all BlockBackends and then close the monitor-owned BDS trees, which are the only BDSs without a BB. In effect, all BDSs are closed just by getting closed automatically due to their reference count becoming 0. Note that the approach taken here leaks all BlockBackends. This does not really matter, however, since qemu is about to exit anyway. *** Note: This series is based on Kevin's block branch *** v9: - Patch 1: Only release named dirty bitmaps, and assert that there are no unnamed left [Fam] - Patches 2, 15, 16: Bumped year from 2015 to 2016; I kept the R-bs because this seemed like a very straightforward change to me [Eric] - Patch 5: Set up the notifiers only after the last (and only) error path in virtio_scsi_hotplug() in order not to leak them [Kevin] - Patch 12: - Added a note to the commit message about the change to qmp_x_blockdev_del() [Fam] - Dropped the !QLIST_EMPTY() check in qmp_x_blockdev_del(); the newly introduced check fulfills the same task while being more explicit about it [Kevin] - Patch 14: - Changed the order of blk_remove_all_bs() and blockdev_close_all_bdrv_states() [Fam] - Dropped the aio_poll() loop; it is unneccessary now that block_job_cancel_sync() effectively calls block_job_unref() by itself git-backport-diff against v8: Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively 001/16:[down] 'block: Release named dirty bitmaps in bdrv_close()' 002/16:[0002] [FC] 'iotests: Add test for eject under NBD server' 003/16:[----] [--] 'block: Add BB-BDS remove/insert notifiers' 004/16:[----] [--] 'virtio-blk: Functions for op blocker management' 005/16:[0002] [FC] 'virtio-scsi: Catch BDS-BB removal/insertion' 006/16:[----] [--] 'nbd: Switch from close to eject notifier' 007/16:[----] [-C] 'block: Remove BDS close notifier' 008/16:[----] [--] 'block: Use blk_remove_bs() in blk_delete()' 009/16:[----] [--] 'blockdev: Use blk_remove_bs() in do_drive_del()' 010/16:[----] [-C] 'block: Make bdrv_close() static' 011/16:[----] [--] 'block: Add list of all BlockDriverStates' 012/16:[0004] [FC] 'blockdev: Keep track of monitor-owned BDS' 013/16:[----] [--] 'block: Add blk_remove_all_bs()' 014/16:[0013] [FC] 'block: Rewrite bdrv_close_all()' 015/16:[0002] [FC] 'iotests: Add test for multiple BB on BDS tree' 016/16:[0002] [FC] 'iotests: Add test for block jobs and BDS ejection' Max Reitz (16): block: Release named dirty bitmaps in bdrv_close() iotests: Add test for eject under NBD server block: Add BB-BDS remove/insert notifiers virtio-blk: Functions for op blocker management virtio-scsi: Catch BDS-BB removal/insertion nbd: Switch from close to eject notifier block: Remove BDS close notifier block: Use blk_remove_bs() in blk_delete() blockdev: Use blk_remove_bs() in do_drive_del() block: Make bdrv_close() static block: Add list of all BlockDriverStates blockdev: Keep track of monitor-owned BDS block: Add blk_remove_all_bs() block: Rewrite bdrv_close_all() iotests: Add test for multiple BB on BDS tree iotests: Add test for block jobs and BDS ejection block.c | 90 +++++++++++----- block/block-backend.c | 43 ++++++-- blockdev-nbd.c | 40 +------ blockdev.c | 30 +++++- hw/block/dataplane/virtio-blk.c | 77 ++++++++++---- hw/scsi/virtio-scsi.c | 55 ++++++++++ include/block/block.h | 2 - include/block/block_int.h | 8 +- include/hw/virtio/virtio-scsi.h | 10 ++ include/sysemu/block-backend.h | 4 +- nbd/server.c | 13 +++ stubs/Makefile.objs | 1 + stubs/blockdev-close-all-bdrv-states.c | 5 + tests/qemu-iotests/117 | 86 +++++++++++++++ tests/qemu-iotests/117.out | 14 +++ tests/qemu-iotests/140 | 92 ++++++++++++++++ tests/qemu-iotests/140.out | 16 +++ tests/qemu-iotests/141 | 186 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/141.out | 59 +++++++++++ tests/qemu-iotests/group | 3 + 20 files changed, 742 insertions(+), 92 deletions(-) create mode 100644 stubs/blockdev-close-all-bdrv-states.c create mode 100755 tests/qemu-iotests/117 create mode 100644 tests/qemu-iotests/117.out create mode 100755 tests/qemu-iotests/140 create mode 100644 tests/qemu-iotests/140.out create mode 100755 tests/qemu-iotests/141 create mode 100644 tests/qemu-iotests/141.out -- 2.7.0