My last attempt got bogged down because I tried to do a reasonably complete job, and the complexity proved more than I could handle with the limited amount of uninterrupted time available. This time, I'm cutting BlockBackend off with an axe, leaving most of the work for later.
Done in this series already: * Introduce a BlockBackend type, and lift up BlockDriverState's device_name, device_list, dev, dev_ops, dev_opaque. Much more remains to be lifted. * Make BlockBackend own the DriveInfo. * Wean hw/ off BlockDriverState, with two small exceptions. * Fix blockdev-add not to create a bogus IDE drive (0,0). * Take a few baby steps towards use of BlockBackend in monitor command code where appropriate. Coming soon, hopefully: * QMP command blockdev-del * blockdev-add accepts node-name without id at top level * Lift up more stuff * More BlockBackend use in monitor command code I know the diffstat looks intimidating. I tried very hard to split the patches so that the bigger ones do just one simple thing, and mostly mechanically. v6: * Rebased - Straightforward conflicts in PATCH 04 and 20, R-bys kept - Straightforward semantic conflicts around John Snow's Q35 if=ide desugaring in PATCH 11, 19 and 23, R-bys kept * [PATCH 02/24] block: New BlockBackend - Explain where BBs need to be created and destroyed in commit message * [PATCH 03/23] block: Connect BlockBackend to BlockDriverState - Avoid the last remaining temporary BB leak, R-by dropped * [PATCH 04/24] block: Connect BlockBackend and DriveInfo - Simplify drive_get_by_blockdev() [Kevin] - Don't break drive_del() after blk_hide_on_behalf_of_do_drive_del() until PATCH 06, R-by dropped * [PATCH 06/24] block: Make BlockBackend own its BlockDriverState - Move the two hunks peeling off the drive_del() wrapper to the next patch * [PATCH 07/24] blockdev: Eliminate drive_del() - New * [PATCH 16/24] hw: Convert from BlockDriverState to BlockBackend, mostly - Resolve harmless semantic conflicts around bdrv_drain_all() missed in v5 v5: * Rebased - Straightforward conflicts in PATCH 10, R-bys retained - Semantic conflicts in PATCH 15 under hw/scsi/, R-by dropped Straightforward conflicts elsewhere * [PATCH 03/23] block: Connect BlockBackend to BlockDriverState - Commit message tweak regarding the FIXME * [PATCH 11/23] block: Rename BlockDriverAIOCB* to BlockAIOCB* - Clean up indentation after rename [Max] Ripples into PATCH 12 and PATCH 15 harmlessly - Rename in docs/blkdebug.txt, too [Max] * [PATCH 12/23] block: Rename BlockDriverCompletionFunc to BlockCompletionFunc - Rename in docs/blkdebug.txt, too [Max] v4: * Rebased, some R-bys dropped due to non-trivial conflicts * Spin off dropping the conditional around qemu_opts_del() [Kevin] * [PATCH 02/23] block: New BlockBackend - Fix license in block-backend.h [Kevin] - Avoid some temporary BB leaks [Kevin] * [PATCH 03/23] block: Connect BlockBackend to BlockDriverState - Move commit message paragraph on strong references to PATCH 06, because that's where they actually become strong - Update bdrv_move_feature_fields() [Kevin] - Ripple effects from PATCH 02's leak avoidance * [PATCH 04/23] block: Connect BlockBackend and DriveInfo - Use abort() instead of assert(0) to avoid hypothetical compiler warnings [Kevin] - Simplify the "is this the BB on top of this BDS" test in drive_get_by_blockdev() [Kevin] - Ripple effects from PATCH 02's leak avoidance - Avoid crash on -drive format=help [Max] - Drop a FIXME here instead of in PATCH 06, because this one actually fixes it[Kevin] * [PATCH 08/23] block: Eliminate BlockDriverState member device_name[] - Delay code motion from bdrv_new_root() to caller until the next patch * [PATCH 09/23] block: Merge BlockBackend and BlockDriverState name spaces - See PATCH 08 - Add TODO comments to bdrv_find() and bdrv_get_device_name() * [PATCH 11/23] block: Rename BlockDriverAIOCB* to BlockAIOCB* - Split rename of BlockDriverCompletionFunc into its own PATCH 12 * [PATCH 12/23] block: Rename BlockDriverCompletionFunc to BlockCompletionFunc - New, split off PATCH 11 * [PATCH 13/23] virtio-blk: Drop redundant VirtIOBlock member conf - Use conf instead of &s->blk.conf [Max] * [PATCH 14/23] virtio-blk: Rename VirtIOBlkConf variables to conf - Trivial ripple effect from change to PATCH 13 * [PATCH 15/23] hw: Convert from BlockDriverState to BlockBackend, mostly - Explain in commit message why includes are changed [Max] * [PATCH 19/23] blockdev: Fix blockdev-add not to create DriveInfo - Fix temporary breakage by squashing in the next patch [Fam] - Document legacy_dinfo exists only when created by drive_new() [Max] * [PATCH 22/23] block: Lift device model API into BlockBackend - More verbose commit message [Benoît] * [PATCH 23/23] block: Make device model's references to BlockBackend strong - Code rearranged slightly for robustness [Max] v3: * Rebased * A few comments here and there [Benoît] * PATCH 02-04: Drop flawed attempt to avoid leaking BB on drive_del while a device model is connected [Flaw pointed out by Max] * PATCH 02: Check blk_by_name()'s precondition with assert() [Benoît] * PATCH 03: blk_new_with_bs() in qemu-nbd.c [Max, Benoît] * PATCH 10: Cover hw/arm/virt.c (semantic conflict) * PATCH 14: Plenty of conflicts with Benoît's "Extract block accounting statistic code in it's own module" series v2: * General - Improved function comments [Kevin, Benoît] - Avoiding temporary badness around drive_del affects several patches up to PATCH 14/23, but by then the solution is basically v1's again, plus a simple bug fix. * [PATCH 01/23] block: Split bdrv_new_root() off bdrv_new() - Call it bdrv_new_root() instead of bdrv_new_named(), because it'll lose its name parameter in PATCH 08. In v1, it gets removed there. - Drop a condition that cannot be false due to prior assertion * [PATCH 02/23] block: New BlockBackend - Commit message amended to explain when BlockBackends get created and destroyed [Kevin] - License reluctantly changed to LGPL2.1+ [Kevin] - Plug leak on error in blk_new() [Kevin] - g_assert() is silly, stick to plain assert() [Kevin] - Fix double-free when do_drive_del() leaves BDS destruction to blockdev_auto_del(), and user adds a BB with the same name in between [Kevin] Note: bug goes away later in v1 - Plug a bunch of leaks on error in qemu-img.c [Kevin, Benoît] Note: bugs goes away later in v1 - Update for "[PATCH 3/4] qemu-nbd: Destroy the BlockDriverState properly" * [PATCH 03/23] block: Connect BlockBackend to BlockDriverState - Keep the double-free just mentioned fixed; commit message amended to explain the drive_del complications Basically move v1's solution from "[PATCH 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly" here, plus a fix for invalid queue removal in blk_delete() - Cleanup extracted and posted separately as "[PATCH 1/4] blockdev: Disentangle BlockDriverState and DriveInfo creation" [Kevin] - Inline blk_attach_bs(), blk_detach_bs() into only callers - Rebase on PATCH 02's qemu-img.c leak fixes, basically reverting its error path complications - Update for "[PATCH 3/4] qemu-nbd: Destroy the BlockDriverState properly" * [PATCH 04/23] block: Connect BlockBackend and DriveInfo - Bug fix extracted and posted separately as "[PATCH 2/4] block: Keep DriveInfo alive until BlockDriverState dies" [Kevin] Unlike v1, it takes care to preserve the guard against qemu_opts_del(NULL) Could only happen when drive_del'ing something created with blockdev-add, which is impossible since "[PATCH] blockdev: Refuse to drive_del something added with blockdev-add", but not obviously so Becomes obvious in PATCH 18, which duly drops the guard - Plug leak on error in drive_new() [Kevin] * [PATCH 05/23] block: Code motion to get rid of stubs/blockdev.c - New; to separate some of the cleanup of the mess made in said extracted bug fix from the previous patch, to keep it more readable * [PATCH 06/23] block: Make BlockBackend own its BlockDriverState - Update for "[PATCH 3/4] qemu-nbd: Destroy the BlockDriverState properly" * [PATCH 07/23] block: Eliminate bdrv_states, use block_next() instead - Drop; it can break things when a root BDS outlives its BB, because something else is holding a reference to the BDS when the BB dies * [PATCH 07/23] block: Eliminate bdrv_iterate(), use bdrv_next() - Fix accidental removal of a line [Benoît] * [PATCH 08/23] block: Eliminate BlockDriverState member device_name[] - Commit message: typo fixed [Eric], clarified - Update for [PATCH 4/4] block: Improve message for device name clashing with node name - Ripple effects from drop of PATCH 07 - Neater implementation of bdrv_get_device_name() [Benoît] * [PATCH 09/23] block: Merge BlockBackend and BlockDriverState name spaces - Update for [PATCH 4/4] block: Improve message for device name clashing with node name * [PATCH 10/23] block: Eliminate DriveInfo member bdrv, use - Commit message amended to explain the repetitive changes [Eric] * [PATCH 11/23] block: Rename BlockDriverAIOCB* to BlockAIOCB* * [PATCH 12/23] virtio-blk: Drop redundant VirtIOBlock member conf * [PATCH 13/23] virtio-blk: Rename VirtIOBlkConf variables to conf - All three unchanged * [PATCH 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly - Less the stuff now in PATCH 03; see above * [PATCH 15/23] ide: Complete conversion from BlockDriverState to BlockBackend * [PATCH 16/23] pc87312: Drop unused members of PC87312State - Both unchanged * [PATCH 17/23] blockdev: Drop superfluous DriveInfo member id - Trivial context change due to qemu_opts_del(NULL) guard mentioned above * [PATCH 18/23] blockdev: Fix blockdev-add not to create IDE drive (0,0) - Since blockdev-add no longer creates a DriveInfo, the guard just mentioned is now obviously unnecessary; drop it * [PATCH 19/23] blockdev: Drop DriveInfo member enable_auto_del - Update for [PATCH] blockdev: Refuse to drive_del something added with blockdev-add * [PATCH 20/23] block/qapi: Convert qmp_query_block() to BlockBackend * [PATCH 21/23] blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend - Both unchanged * [PATCH 22/23] block: Lift device model API into BlockBackend - Only comments and context differences * [PATCH 23/23] block: Make device model's references to BlockBackend - Unchanged Markus Armbruster (24): block: Split bdrv_new_root() off bdrv_new() block: New BlockBackend block: Connect BlockBackend to BlockDriverState block: Connect BlockBackend and DriveInfo block: Code motion to get rid of stubs/blockdev.c block: Make BlockBackend own its BlockDriverState blockdev: Eliminate drive_del() block: Eliminate bdrv_iterate(), use bdrv_next() block: Eliminate BlockDriverState member device_name[] block: Merge BlockBackend and BlockDriverState name spaces block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo() block: Rename BlockDriverAIOCB* to BlockAIOCB* block: Rename BlockDriverCompletionFunc to BlockCompletionFunc virtio-blk: Drop redundant VirtIOBlock member conf virtio-blk: Rename VirtIOBlkConf variables to conf hw: Convert from BlockDriverState to BlockBackend, mostly ide: Complete conversion from BlockDriverState to BlockBackend pc87312: Drop unused members of PC87312State blockdev: Drop superfluous DriveInfo member id blockdev: Fix blockdev-add not to create DriveInfo block/qapi: Convert qmp_query_block() to BlockBackend blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend block: Lift device model API into BlockBackend block: Make device model's references to BlockBackend strong block-migration.c | 44 ++- block.c | 390 +++++++------------ block/Makefile.objs | 2 +- block/archipelago.c | 28 +- block/backup.c | 2 +- block/blkdebug.c | 18 +- block/blkverify.c | 18 +- block/block-backend.c | 631 +++++++++++++++++++++++++++++++ block/commit.c | 2 +- block/curl.c | 6 +- block/iscsi.c | 10 +- block/linux-aio.c | 8 +- block/mirror.c | 9 +- block/null.c | 34 +- block/qapi.c | 27 +- block/qcow.c | 4 +- block/qcow2.c | 4 +- block/qed-gencb.c | 4 +- block/qed-table.c | 10 +- block/qed.c | 46 +-- block/qed.h | 12 +- block/quorum.c | 42 +- block/raw-aio.h | 8 +- block/raw-posix.c | 32 +- block/raw-win32.c | 16 +- block/raw_bsd.c | 8 +- block/rbd.c | 56 +-- block/sheepdog.c | 4 +- block/stream.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 4 +- block/vpc.c | 2 +- block/vvfat.c | 4 +- block/win32-aio.c | 6 +- blockdev.c | 201 +++++----- blockjob.c | 7 +- device-hotplug.c | 3 +- dma-helpers.c | 67 ++-- docs/blkdebug.txt | 8 +- hw/arm/collie.c | 10 +- hw/arm/gumstix.c | 6 +- hw/arm/highbank.c | 2 +- hw/arm/mainstone.c | 8 +- hw/arm/musicpal.c | 13 +- hw/arm/nseries.c | 7 +- hw/arm/omap1.c | 4 +- hw/arm/omap2.c | 4 +- hw/arm/omap_sx1.c | 10 +- hw/arm/pxa2xx.c | 7 +- hw/arm/realview.c | 2 +- hw/arm/spitz.c | 6 +- hw/arm/tosa.c | 3 +- hw/arm/versatilepb.c | 5 +- hw/arm/vexpress.c | 5 +- hw/arm/virt.c | 4 +- hw/arm/xilinx_zynq.c | 5 +- hw/arm/z2.c | 8 +- hw/block/block.c | 23 +- hw/block/dataplane/virtio-blk.c | 35 +- hw/block/dataplane/virtio-blk.h | 2 +- hw/block/fdc.c | 74 ++-- hw/block/hd-geometry.c | 24 +- hw/block/m25p80.c | 31 +- hw/block/nand.c | 50 +-- hw/block/nvme.c | 19 +- hw/block/nvme.h | 2 +- hw/block/onenand.c | 67 ++-- hw/block/pflash_cfi01.c | 24 +- hw/block/pflash_cfi02.c | 24 +- hw/block/virtio-blk.c | 149 ++++---- hw/block/xen_disk.c | 86 +++-- hw/core/qdev-properties-system.c | 26 +- hw/core/qdev-properties.c | 2 +- hw/cris/axis_dev88.c | 4 +- hw/display/tc6393xb.c | 4 +- hw/i386/pc.c | 2 +- hw/i386/pc_piix.c | 2 +- hw/i386/pc_sysfw.c | 10 +- hw/i386/xen/xen_platform.c | 5 +- hw/ide/ahci.c | 33 +- hw/ide/ahci.h | 2 +- hw/ide/atapi.c | 33 +- hw/ide/cmd646.c | 2 +- hw/ide/core.c | 200 +++++----- hw/ide/ich.c | 2 +- hw/ide/internal.h | 16 +- hw/ide/isa.c | 2 +- hw/ide/macio.c | 52 +-- hw/ide/microdrive.c | 4 +- hw/ide/mmio.c | 2 +- hw/ide/pci.c | 6 +- hw/ide/pci.h | 2 +- hw/ide/piix.c | 11 +- hw/ide/qdev.c | 13 +- hw/ide/via.c | 2 +- hw/isa/pc87312.c | 7 +- hw/lm32/lm32_boards.c | 14 +- hw/lm32/milkymist.c | 8 +- hw/microblaze/petalogix_ml605_mmu.c | 6 +- hw/microblaze/petalogix_s3adsp1800_mmu.c | 6 +- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_jazz.c | 2 +- hw/mips/mips_malta.c | 8 +- hw/mips/mips_r4k.c | 6 +- hw/nvram/spapr_nvram.c | 17 +- hw/pci/pci-hotplug-old.c | 11 +- hw/ppc/mac.h | 2 +- hw/ppc/mac_newworld.c | 2 +- hw/ppc/mac_oldworld.c | 2 +- hw/ppc/ppc405_boards.c | 27 +- hw/ppc/prep.c | 2 +- hw/ppc/spapr.c | 4 +- hw/ppc/virtex_ml507.c | 6 +- hw/s390x/s390-virtio-bus.c | 2 +- hw/s390x/s390-virtio.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/megasas.c | 15 +- hw/scsi/scsi-bus.c | 15 +- hw/scsi/scsi-disk.c | 184 ++++----- hw/scsi/scsi-generic.c | 37 +- hw/scsi/virtio-scsi-dataplane.c | 3 +- hw/scsi/virtio-scsi.c | 15 +- hw/sd/milkymist-memcard.c | 7 +- hw/sd/omap_mmc.c | 8 +- hw/sd/pl181.c | 3 +- hw/sd/pxa2xx_mmci.c | 4 +- hw/sd/sd.c | 60 +-- hw/sd/sdhci.c | 3 +- hw/sd/ssi-sd.c | 3 +- hw/sh4/r2d.c | 6 +- hw/sparc/sun4m.c | 2 +- hw/sparc64/sun4u.c | 2 +- hw/tpm/tpm_tis.c | 2 +- hw/tricore/tricore_testboard.c | 2 +- hw/usb/dev-storage.c | 19 +- hw/virtio/virtio-pci.c | 2 +- hw/xen/xen_devconfig.c | 1 + hw/xenpv/xen_machine_pv.c | 2 +- hw/xtensa/xtfpga.c | 5 +- include/block/aio.h | 14 +- include/block/block.h | 90 ++--- include/block/block_int.h | 44 ++- include/block/blockjob.h | 4 +- include/block/qapi.h | 3 - include/block/thread-pool.h | 4 +- include/hw/arm/omap.h | 4 +- include/hw/arm/pxa.h | 2 +- include/hw/block/block.h | 6 +- include/hw/block/flash.h | 6 +- include/hw/isa/pc87312.h | 3 - include/hw/qdev-properties.h | 8 +- include/hw/scsi/scsi.h | 6 +- include/hw/sd.h | 2 +- include/hw/virtio/virtio-blk.h | 10 +- include/monitor/monitor.h | 4 +- include/qemu/typedefs.h | 2 + include/sysemu/block-backend.h | 142 +++++++ include/sysemu/blockdev.h | 14 +- include/sysemu/dma.h | 28 +- monitor.c | 38 +- qemu-img.c | 150 ++++---- qemu-io.c | 15 +- qemu-nbd.c | 8 +- stubs/Makefile.objs | 1 - stubs/blockdev.c | 12 - tests/test-thread-pool.c | 2 +- thread-pool.c | 10 +- trace-events | 8 +- 169 files changed, 2390 insertions(+), 1727 deletions(-) create mode 100644 block/block-backend.c create mode 100644 include/sysemu/block-backend.h delete mode 100644 stubs/blockdev.c -- 1.9.3