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 *** v8: - Dropped seven patches which are in master or Kevin's block branch already; dropped another patch that became unnecessary - Patch 2: qemu-io doesn't prepend "qemu-io: " to error messages anymore - Patch 4: %s/BLOCK_OP_TYPE_MIRROR/BLOCK_OP_TYPE_MIRROR_SOURCE/ - Patch 5: Moved code according to what Kevin suggested - Patch 6: Call nbd_export_put() at the end of qmp_nbd_server_add() [Kevin] - Patch 7: notifier_list_notify() in bdrv_close() is now surrounded by empty lines, remove one of them - Patch 12: Remove the BDS from monitor_bdrv_states on late error in qmp_blockdev_add() - Patch 16: - Drop qcow1 [Kevin] - s/blockdev-remove-medium/x-blockdev-remove-medium/ - Test non-active block-commit [Kevin] git-backport-diff against v7: 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:[----] [-C] 'block: Release 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:[0004] [FC] 'virtio-blk: Functions for op blocker management' 005/16:[0016] [FC] 'virtio-scsi: Catch BDS-BB removal/insertion' 006/16:[0005] [FC] 'nbd: Switch from close to eject notifier' 007/16:[0001] [FC] '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:[----] [--] 'block: Make bdrv_close() static' 011/16:[----] [--] 'block: Add list of all BlockDriverStates' 012/16:[0001] [FC] 'blockdev: Keep track of monitor-owned BDS' 013/16:[----] [--] 'block: Add blk_remove_all_bs()' 014/16:[----] [--] 'block: Rewrite bdrv_close_all()' 015/16:[----] [--] 'iotests: Add test for multiple BB on BDS tree' 016/16:[0052] [FC] 'iotests: Add test for block jobs and BDS ejection' Max Reitz (16): block: Release 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 | 99 +++++++++++++----- block/block-backend.c | 43 ++++++-- blockdev-nbd.c | 40 +------ blockdev.c | 28 ++++- 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, 750 insertions(+), 91 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