Skip to contentSkip to conversation

Split BlockBackend off BDS with an axe

PATCH Superseded Markus Armbruster 4 participants 110 messages Sep 16, 2014 – Sep 30, 2014 Page 1 of 2

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Split BlockBackend off BDS with an axe

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

Depends on my
[PATCH 0/4] Miscellaneous block fixes

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.

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 (23):
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
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*
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 IDE drive (0,0)
blockdev: Drop DriveInfo member enable_auto_del 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                                  | 379 +++++++------------
 block/Makefile.objs                      |   2 +-
 block/archipelago.c                      |  30 +-
 block/backup.c                           |   2 +-
 block/blkdebug.c                         |  22 +-
 block/blkverify.c                        |  20 +-
 block/block-backend.c                    | 622 +++++++++++++++++++++++++++++++
 block/commit.c                           |   2 +-
 block/cow.c                              |   2 +-
 block/curl.c                             |   8 +-
 block/iscsi.c                            |  10 +-
 block/linux-aio.c                        |   8 +-
 block/mirror.c                           |   9 +-
 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                              |  48 +--
 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                              |  58 +--
 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                        |   8 +-
 blockdev.c                               | 193 ++++------
 blockjob.c                               |   7 +-
 dma-helpers.c                            |  69 ++--
 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                            | 202 +++++-----
 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                            |   9 +-
 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                 |  10 +-
 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                       |  11 +-
 hw/scsi/scsi-disk.c                      | 188 +++++-----
 hw/scsi/scsi-generic.c                   |  41 +-
 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                      |  12 +-
 include/block/block.h                    |  88 ++---
 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           | 141 +++++++
 include/sysemu/blockdev.h                |  13 +-
 include/sysemu/dma.h                     |  26 +-
 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                            |   8 +-
 trace-events                             |   8 +-
 165 files changed, 2341 insertions(+), 1698 deletions(-)
 create mode 100644 block/block-backend.c
 create mode 100644 include/sysemu/block-backend.h
 delete mode 100644 stubs/blockdev.c
Signature · 1 line
1.9.3
#1 lore raw

PATCH v3 1/23 block: Split bdrv_new_root() off bdrv_new()

Creating an anonymous BDS can't fail. Make that obvious.

---
 block.c               | 28 +++++++++++++++++++---------
 block/iscsi.c         |  2 +-
 block/vvfat.c         |  2 +-
 blockdev.c            |  2 +-
 hw/block/xen_disk.c   |  2 +-
 include/block/block.h |  3 ++-
 qemu-img.c            |  6 +++---
 qemu-io.c             |  2 +-
 qemu-nbd.c            |  2 +-
 9 files changed, 30 insertions(+), 19 deletions(-)
block.c +19 -9
index 2ac6a3b..934881f 100644
@@ -336,10 +336,11 @@ void bdrv_register(BlockDriver *bdrv)
 }
 
 /* create a new block device (by default it is empty) */
-BlockDriverState *bdrv_new(const char *device_name, Error **errp)
+BlockDriverState *bdrv_new_root(const char *device_name, Error **errp)
 {
     BlockDriverState *bs;
-    int i;
+
+    assert(*device_name);
 
     if (bdrv_find(device_name)) {
         error_setg(errp, "Device with id '%s' already exists",
@@ -353,12 +354,21 @@ BlockDriverState *bdrv_new(const char *device_name, Error **errp)
         return NULL;
     }
 
+    bs = bdrv_new();
+
+    pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
+    QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
+
+    return bs;
+}
+
+BlockDriverState *bdrv_new(void)
+{
+    BlockDriverState *bs;
+    int i;
+
     bs = g_new0(BlockDriverState, 1);
     QLIST_INIT(&bs->dirty_bitmaps);
-    pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
-    if (device_name[0] != '\0') {
-        QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
-    }
     for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) {
         QLIST_INIT(&bs->op_blockers[i]);
     }
@@ -1219,7 +1229,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
         goto free_exit;
     }
 
-    backing_hd = bdrv_new("", errp);
+    backing_hd = bdrv_new();
 
     if (bs->backing_format[0] != '\0') {
         back_drv = bdrv_find_format(bs->backing_format);
@@ -1348,7 +1358,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     qdict_put(snapshot_options, "file.filename",
               qstring_from_str(tmp_filename));
 
-    bs_snapshot = bdrv_new("", &error_abort);
+    bs_snapshot = bdrv_new();
 
     ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
                     flags, bdrv_qcow2, &local_err);
@@ -1419,7 +1429,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
     if (*pbs) {
         bs = *pbs;
     } else {
-        bs = bdrv_new("", &error_abort);
+        bs = bdrv_new();
     }
 
     /* NULL means an empty set of options */
block/iscsi.c +1 -1
index 84bcae8..166d1b9 100644
@@ -1528,7 +1528,7 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
     IscsiLun *iscsilun = NULL;
     QDict *bs_options;
 
-    bs = bdrv_new("", &error_abort);
+    bs = bdrv_new();
 
     /* Read out options */
     total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
block/vvfat.c +1 -1
index 731e591..6c9fde0 100644
@@ -2939,7 +2939,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
     unlink(s->qcow_filename);
 #endif
 
-    bdrv_set_backing_hd(s->bs, bdrv_new("", &error_abort));
+    bdrv_set_backing_hd(s->bs, bdrv_new());
     s->bs->backing_hd->drv = &vvfat_write_target;
     s->bs->backing_hd->opaque = g_new(void *, 1);
     *(void**)s->bs->backing_hd->opaque = s;
blockdev.c +1 -1
index 450f95c..c9463e3 100644
@@ -463,7 +463,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
     }
 
     /* init */
-    bs = bdrv_new(qemu_opts_id(opts), errp);
+    bs = bdrv_new_root(qemu_opts_id(opts), errp);
     if (!bs) {
         goto early_err;
     }
hw/block/xen_disk.c +1 -1
index 0d27ab1..7f0f66b 100644
@@ -858,7 +858,7 @@ static int blk_connect(struct XenDevice *xendev)
 
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
-        blkdev->bs = bdrv_new(blkdev->dev, NULL);
+        blkdev->bs = bdrv_new_root(blkdev->dev, NULL);
         if (!blkdev->bs) {
             return -1;
         }
include/block/block.h +2 -1
index 07d6d8e..8cf953a 100644
@@ -204,7 +204,8 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
 int bdrv_create(BlockDriver *drv, const char* filename,
                 QemuOpts *opts, Error **errp);
 int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
-BlockDriverState *bdrv_new(const char *device_name, Error **errp);
+BlockDriverState *bdrv_new_root(const char *device_name, Error **errp);
+BlockDriverState *bdrv_new(void);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
qemu-img.c +3 -3
index 91d1ac3..58d59d0 100644
@@ -296,7 +296,7 @@ static BlockDriverState *bdrv_new_open(const char *id,
     Error *local_err = NULL;
     int ret;
 
-    bs = bdrv_new(id, &error_abort);
+    bs = bdrv_new_root(id, &error_abort);
 
     if (fmt) {
         drv = bdrv_find_format(fmt);
@@ -2425,7 +2425,7 @@ static int img_rebase(int argc, char **argv)
     if (!unsafe) {
         char backing_name[1024];
 
-        bs_old_backing = bdrv_new("old_backing", &error_abort);
+        bs_old_backing = bdrv_new_root("old_backing", &error_abort);
         bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
         ret = bdrv_open(&bs_old_backing, backing_name, NULL, NULL, src_flags,
                         old_backing_drv, &local_err);
@@ -2436,7 +2436,7 @@ static int img_rebase(int argc, char **argv)
             goto out;
         }
         if (out_baseimg[0]) {
-            bs_new_backing = bdrv_new("new_backing", &error_abort);
+            bs_new_backing = bdrv_new_root("new_backing", &error_abort);
             ret = bdrv_open(&bs_new_backing, out_baseimg, NULL, NULL, src_flags,
                             new_backing_drv, &local_err);
             if (ret) {
qemu-io.c +1 -1
index d2ab694..24ca59c 100644
@@ -58,7 +58,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
         return 1;
     }
 
-    qemuio_bs = bdrv_new("hda", &error_abort);
+    qemuio_bs = bdrv_new_root("hda", &error_abort);
 
     if (growable) {
         flags |= BDRV_O_PROTOCOL;
qemu-nbd.c +1 -1
index f3cf8a2..24b8454 100644
@@ -687,7 +687,7 @@ int main(int argc, char **argv)
         drv = NULL;
     }
 
-    bs = bdrv_new("hda", &error_abort);
+    bs = bdrv_new_root("hda", &error_abort);
 
     srcpath = argv[optind];
     ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err);
Signature · 1 line
1.9.3
#3 lore raw

PATCH v3 2/23 block: New BlockBackend

In reply to Markus Armbruster

A block device consists of a frontend device model and a backend.

A block backend has a tree of block drivers doing the actual work. The tree is managed by the block layer.

We currently use a single abstraction BlockDriverState both for tree nodes and the backend as a whole. Drawbacks:

* Its API includes both stuff that makes sense only at the block backend level (root of the tree) and stuff that's only for use within the block layer. This makes the API bigger and more complex than necessary. Moreover, it's not obvious which interfaces are meant for device models, and which really aren't.

* Since device models keep a reference to their backend, the backend object can't just be destroyed. But for media change, we need to replace the tree. Our solution is to make the BlockDriverState generic, with actual driver state in a separate object, pointed to by member opaque. That lets us replace the tree by deinitializing and reinitializing its root. This special need of the root makes the data structure awkward everywhere in the tree.

The general plan is to separate the APIs into "block backend", for use by device models, monitor and whatever other code dealing with block backends, and "block driver", for use by the block layer and whatever other code (if any) dealing with trees and tree nodes.

Code dealing with block backends, device models in particular, should become completely oblivious of BlockDriverState. This should let us clean up both APIs, and the tree data structures.

This commit is a first step. It creates a minimal "block backend"
API: type BlockBackend and functions to create, destroy and find them.

BlockBackend objects are created and destroyed exactly when root BlockDriverState objects are created and destroyed. "Root" in the sense of "in bdrv_states". They're not yet used for anything; that'll come shortly.

BlockBackend is reference-counted. Its reference count never exceeds one so far, but that's going to change.

---
 block/Makefile.objs            |   2 +-
 block/block-backend.c          | 120 +++++++++++++++++++++++++++++++++++++++++
 blockdev.c                     |  11 +++-
 hw/block/xen_disk.c            |  11 ++++
 include/qemu/typedefs.h        |   1 +
 include/sysemu/block-backend.h |  26 +++++++++
 qemu-img.c                     |  70 +++++++++++++++++++++---
 qemu-io.c                      |   8 +++
 qemu-nbd.c                     |   5 +-
 9 files changed, 243 insertions(+), 11 deletions(-)
 create mode 100644 block/block-backend.c
 create mode 100644 include/sysemu/block-backend.h
block/Makefile.objs +1 -1
index c9c8bbb..e410e7a 100644
@@ -5,7 +5,7 @@ block-obj-y += qed-check.o
 block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-$(CONFIG_QUORUM) += quorum.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
-block-obj-y += snapshot.o qapi.o
+block-obj-y += block-backend.o snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
 block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
block/block-backend.c new file +120 -0

120 lines not on this page · raw message

blockdev.c +10 -1
index c9463e3..583235a 100644
@@ -30,6 +30,7 @@
  * THE SOFTWARE.
  */
 
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/block/block.h"
 #include "block/blockjob.h"
@@ -307,6 +308,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
     int ro = 0;
     int bdrv_flags = 0;
     int on_read_error, on_write_error;
+    BlockBackend *blk;
     BlockDriverState *bs;
     DriveInfo *dinfo;
     ThrottleConfig cfg;
@@ -463,9 +465,13 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
     }
 
     /* init */
+    blk = blk_new(qemu_opts_id(opts), errp);
+    if (!blk) {
+        goto early_err;
+    }
     bs = bdrv_new_root(qemu_opts_id(opts), errp);
     if (!bs) {
-        goto early_err;
+        goto bdrv_new_err;
     }
     bs->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
     bs->read_only = ro;
@@ -531,6 +537,8 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
 
 err:
     bdrv_unref(bs);
+bdrv_new_err:
+    blk_unref(blk);
 early_err:
     qemu_opts_del(opts);
 err_no_opts:
@@ -1791,6 +1799,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     } else {
         drive_del(dinfo);
     }
+    blk_unref(blk_by_name(id));
 
     aio_context_release(aio_context);
     return 0;
hw/block/xen_disk.c +11 -0
index 7f0f66b..265cf13 100644
@@ -39,6 +39,7 @@
 #include "hw/xen/xen_backend.h"
 #include "xen_blkif.h"
 #include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 
 /* ------------------------------------------------------------- */
 
@@ -854,12 +855,18 @@ static int blk_connect(struct XenDevice *xendev)
     blkdev->dinfo = drive_get(IF_XEN, 0, index);
     if (!blkdev->dinfo) {
         Error *local_err = NULL;
+        BlockBackend *blk;
         BlockDriver *drv;
 
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
+        blk = blk_new(blkdev->dev, NULL);
+        if (!blk) {
+            return -1;
+        }
         blkdev->bs = bdrv_new_root(blkdev->dev, NULL);
         if (!blkdev->bs) {
+            blk_unref(blk);
             return -1;
         }
 
@@ -870,6 +877,7 @@ static int blk_connect(struct XenDevice *xendev)
                           error_get_pretty(local_err));
             error_free(local_err);
             bdrv_unref(blkdev->bs);
+            blk_unref(blk);
             blkdev->bs = NULL;
             return -1;
         }
@@ -985,6 +993,9 @@ static void blk_disconnect(struct XenDevice *xendev)
     if (blkdev->bs) {
         bdrv_detach_dev(blkdev->bs, blkdev);
         bdrv_unref(blkdev->bs);
+        if (!blkdev->dinfo) {
+            blk_unref(blk_by_name(blkdev->dev));
+        }
         blkdev->bs = NULL;
     }
     xen_be_unbind_evtchn(&blkdev->xendev);
include/qemu/typedefs.h +1 -0
index 5f20b0e..198da2e 100644
@@ -35,6 +35,7 @@ typedef struct MachineClass MachineClass;
 typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
+typedef struct BlockBackend BlockBackend;
 typedef struct BlockDriverState BlockDriverState;
 typedef struct DriveInfo DriveInfo;
 typedef struct DisplayState DisplayState;
include/sysemu/block-backend.h new file +26 -0
new file mode 100644
index 0000000..3f8371c
@@ -0,0 +1,26 @@
+/*
+ * QEMU Block backends
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * Authors:
+ *  Markus Armbruster <[email protected]>,
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#ifndef BLOCK_BACKEND_H
+#define BLOCK_BACKEND_H
+
+#include "qemu/typedefs.h"
+#include "qapi/error.h"
+
+BlockBackend *blk_new(const char *name, Error **errp);
+void blk_ref(BlockBackend *blk);
+void blk_unref(BlockBackend *blk);
+const char *blk_name(BlockBackend *blk);
+BlockBackend *blk_by_name(const char *name);
+BlockBackend *blk_next(BlockBackend *blk);
+
+#endif
qemu-img.c +62 -8

328 lines not on this page · raw message

qemu-io.c +8 -0
index 24ca59c..57090de 100644
@@ -19,6 +19,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "qemu/readline.h"
+#include "sysemu/block-backend.h"
 #include "block/block_int.h"
 #include "trace/control.h"
 
@@ -26,6 +27,7 @@
 
 static char *progname;
 
+static BlockBackend *qemuio_blk;
 static BlockDriverState *qemuio_bs;
 
 /* qemu-io commands passed using -c */
@@ -37,7 +39,9 @@ static ReadLineState *readline_state;
 static int close_f(BlockDriverState *bs, int argc, char **argv)
 {
     bdrv_unref(bs);
+    blk_unref(qemuio_blk);
     qemuio_bs = NULL;
+    qemuio_blk = NULL;
     return 0;
 }
 
@@ -58,6 +62,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
         return 1;
     }
 
+    qemuio_blk = blk_new("hda", &error_abort);
     qemuio_bs = bdrv_new_root("hda", &error_abort);
 
     if (growable) {
@@ -70,7 +75,9 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
                 error_get_pretty(local_err));
         error_free(local_err);
         bdrv_unref(qemuio_bs);
+        blk_unref(qemuio_blk);
         qemuio_bs = NULL;
+        qemuio_blk = NULL;
         return 1;
     }
 
@@ -479,6 +486,7 @@ int main(int argc, char **argv)
     if (qemuio_bs) {
         bdrv_unref(qemuio_bs);
     }
+    blk_unref(qemuio_blk);
     g_free(readline_state);
     return 0;
 }
qemu-nbd.c +4 -1
index 24b8454..ff95da6 100644
@@ -17,7 +17,7 @@
  */
 
 #include "qemu-common.h"
-#include "block/block.h"
+#include "sysemu/block-backend.h"
 #include "block/block_int.h"
 #include "block/nbd.h"
 #include "qemu/main-loop.h"
@@ -384,6 +384,7 @@ static void nbd_accept(void *opaque)
 
 int main(int argc, char **argv)
 {
+    BlockBackend *blk;
     BlockDriverState *bs;
     BlockDriver *drv;
     off_t dev_offset = 0;
@@ -687,6 +688,7 @@ int main(int argc, char **argv)
         drv = NULL;
     }
 
+    blk = blk_new("hda", &error_abort);
     bs = bdrv_new_root("hda", &error_abort);
 
     srcpath = argv[optind];
@@ -770,6 +772,7 @@ int main(int argc, char **argv)
     } while (state != TERMINATED);
 
     bdrv_unref(bs);
+    blk_unref(blk);
     if (sockpath) {
         unlink(sockpath);
     }
Signature · 1 line
1.9.3
#4 lore raw

Re: [Qemu-devel] [PATCH v3 02/23] block: New BlockBackend

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 51 lines

A block device consists of a frontend device model and a backend.

A block backend has a tree of block drivers doing the actual work. The tree is managed by the block layer.

We currently use a single abstraction BlockDriverState both for tree nodes and the backend as a whole. Drawbacks:

* Its API includes both stuff that makes sense only at the block backend level (root of the tree) and stuff that's only for use within the block layer. This makes the API bigger and more complex than necessary. Moreover, it's not obvious which interfaces are meant for device models, and which really aren't.

* Since device models keep a reference to their backend, the backend object can't just be destroyed. But for media change, we need to replace the tree. Our solution is to make the BlockDriverState generic, with actual driver state in a separate object, pointed to by member opaque. That lets us replace the tree by deinitializing and reinitializing its root. This special need of the root makes the data structure awkward everywhere in the tree.

The general plan is to separate the APIs into "block backend", for use by device models, monitor and whatever other code dealing with block backends, and "block driver", for use by the block layer and whatever other code (if any) dealing with trees and tree nodes.

Code dealing with block backends, device models in particular, should become completely oblivious of BlockDriverState. This should let us clean up both APIs, and the tree data structures.

This commit is a first step. It creates a minimal "block backend"
API: type BlockBackend and functions to create, destroy and find them.

BlockBackend objects are created and destroyed exactly when root BlockDriverState objects are created and destroyed. "Root" in the sense of "in bdrv_states". They're not yet used for anything; that'll come shortly.

BlockBackend is reference-counted. Its reference count never exceeds one so far, but that's going to change.

include/sysemu/block-backend.h new file +1 -0
new file mode 100644
index 0000000..3f8371c
@@ -0,0 +1,26 @@
+/*

include/sysemu/block-backend.h line 11

Quoted 10 lines
include/sysemu/block-backend.h new file +10 -0
+ * QEMU Block backends
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * Authors:
+ *  Markus Armbruster <[email protected]>,
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */

This one should be LGPL as well.

The distribution of blk_unref() should be good enough. To be correct it requires the assumption that the blockdev-add reference to any given BDS is the last one that goes away. I'm not sure if this is the case here (I suspect it isn't), but at the end of the series, we should be good.

With the license fixed, you can add:

Reviewed-by Kevin Wolf <[email protected]>

Kevin

#5 lore raw

Re: [Qemu-devel] [PATCH v3 02/23] block: New BlockBackend

Quoted 56 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 55 lines

A block device consists of a frontend device model and a backend.

A block backend has a tree of block drivers doing the actual work. The tree is managed by the block layer.

We currently use a single abstraction BlockDriverState both for tree nodes and the backend as a whole. Drawbacks:

* Its API includes both stuff that makes sense only at the block backend level (root of the tree) and stuff that's only for use within the block layer. This makes the API bigger and more complex than necessary. Moreover, it's not obvious which interfaces are meant for device models, and which really aren't.

* Since device models keep a reference to their backend, the backend object can't just be destroyed. But for media change, we need to replace the tree. Our solution is to make the BlockDriverState generic, with actual driver state in a separate object, pointed to by member opaque. That lets us replace the tree by deinitializing and reinitializing its root. This special need of the root makes the data structure awkward everywhere in the tree.

The general plan is to separate the APIs into "block backend", for use by device models, monitor and whatever other code dealing with block backends, and "block driver", for use by the block layer and whatever other code (if any) dealing with trees and tree nodes.

Code dealing with block backends, device models in particular, should become completely oblivious of BlockDriverState. This should let us clean up both APIs, and the tree data structures.

This commit is a first step. It creates a minimal "block backend"
API: type BlockBackend and functions to create, destroy and find them.

BlockBackend objects are created and destroyed exactly when root BlockDriverState objects are created and destroyed. "Root" in the sense of "in bdrv_states". They're not yet used for anything; that'll come shortly.

BlockBackend is reference-counted. Its reference count never exceeds one so far, but that's going to change.

include/sysemu/block-backend.h new file +5 -0
new file mode 100644
index 0000000..3f8371c
@@ -0,0 +1,26 @@
+/*
+ * QEMU Block backends
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
Quoted 8 lines

include/sysemu/block-backend.h line 11

Quoted 6 lines
include/sysemu/block-backend.h new file +6 -0
+ * Authors:
+ *  Markus Armbruster <[email protected]>,
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */

This one should be LGPL as well.

Forgot %-}

Quoted 4 lines

The distribution of blk_unref() should be good enough. To be correct it requires the assumption that the blockdev-add reference to any given BDS is the last one that goes away. I'm not sure if this is the case here (I suspect it isn't), but at the end of the series, we should be good.

You're doubting the code works when a BB dies, but something else still holds a reference to its BDS, keeping it alive. Yes, that's the troublesome case. Let me review how it develops throughout this series.

PATCH 02: BB and BDS are not yet connected, and independently reference counted. Anything that creates a root BDS also creates a BB. The two are unref'ed at the same time. The BB dies for sure, because nothing else has a reference. The BDS may live on, but isn't affected by the death of the BB.

PATCH 03: BB and BDS point to each other, but neither owns the other, yet. The BDS is now exposed to the BDS's death: it's pointer bs->blk becomes null. However, it's only ever used right after creation, when the BB surely lives.

PATCH 04: BB owns DriveInfo. Adds a few uses of bs->blk, but they're still all in code where the BB surely lives: device model initialization and destruction, drive_del command.

PATCH 06: BB owns BDS, taking over the reference from its creator.

PATCH 08: First patch that makes the BDS be affected by the death of the
BB: the value of bdrv_get_device_name() becomes "" then. The two interesting BB killers are do_drive_del() and blockdev_auto_del(). Both were coded before BDS reference counting, and both used to actually kill the BDS. When do_drive_del() can't kill it, because a device model still has an (uncounted!) reference, it makes it anonymous. Which changes the name to "". I believe both killers need a deep think on what they're supposed to do when the BDS reference count is > 1.

PATCH 23: Device models' references to BB become strong.

Quoted 3 lines

With the license fixed, you can add:

Reviewed-by Kevin Wolf <[email protected]>

Thanks!

Reviewed-by on v3 2/23
#6 lore raw

Re: [Qemu-devel] [PATCH v3 02/23] block: New BlockBackend

In reply to Markus Armbruster
Quoted 56 lines · Markus Armbruster

A block device consists of a frontend device model and a backend.

A block backend has a tree of block drivers doing the actual work. The tree is managed by the block layer.

We currently use a single abstraction BlockDriverState both for tree nodes and the backend as a whole. Drawbacks:

* Its API includes both stuff that makes sense only at the block backend level (root of the tree) and stuff that's only for use within the block layer. This makes the API bigger and more complex than necessary. Moreover, it's not obvious which interfaces are meant for device models, and which really aren't.

* Since device models keep a reference to their backend, the backend object can't just be destroyed. But for media change, we need to replace the tree. Our solution is to make the BlockDriverState generic, with actual driver state in a separate object, pointed to by member opaque. That lets us replace the tree by deinitializing and reinitializing its root. This special need of the root makes the data structure awkward everywhere in the tree.

The general plan is to separate the APIs into "block backend", for use by device models, monitor and whatever other code dealing with block backends, and "block driver", for use by the block layer and whatever other code (if any) dealing with trees and tree nodes.

Code dealing with block backends, device models in particular, should become completely oblivious of BlockDriverState. This should let us clean up both APIs, and the tree data structures.

This commit is a first step. It creates a minimal "block backend"
API: type BlockBackend and functions to create, destroy and find them.

BlockBackend objects are created and destroyed exactly when root BlockDriverState objects are created and destroyed. "Root" in the sense of "in bdrv_states". They're not yet used for anything; that'll come shortly.

BlockBackend is reference-counted. Its reference count never exceeds one so far, but that's going to change.

---
  block/Makefile.objs            |   2 +-
  block/block-backend.c          | 120 +++++++++++++++++++++++++++++++++++++++++
  blockdev.c                     |  11 +++-
  hw/block/xen_disk.c            |  11 ++++
  include/qemu/typedefs.h        |   1 +
  include/sysemu/block-backend.h |  26 +++++++++
  qemu-img.c                     |  70 +++++++++++++++++++++---
  qemu-io.c                      |   8 +++
  qemu-nbd.c                     |   5 +-
  9 files changed, 243 insertions(+), 11 deletions(-)

create mode 100644 block/block-backend.c create mode 100644 include/sysemu/block-backend.h

[snip]

Quoted 4 lines
blockdev.c +0 -0
index c9463e3..583235a 100644

[snip]

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1805

Quoted 8 lines
blockdev.c +1 -0
@@ -1791,6 +1799,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
      } else {
          drive_del(dinfo);
      }
+    blk_unref(blk_by_name(id));
 
      aio_context_release(aio_context);
      return 0;

Well, now if a BB is created by blockdev_init() but not deleted from the monitor, it will not be unref'd. But first of all this is not bad, because the time it should be unref'd is exactly when qemu is exiting anyway and second, the BDS is not unref'd either. Therefore:

#7 lore raw

Re: [Qemu-devel] [PATCH v3 02/23] block: New BlockBackend

Quoted 67 lines · Max Reitz
Quoted 56 lines · Markus Armbruster

A block device consists of a frontend device model and a backend.

A block backend has a tree of block drivers doing the actual work. The tree is managed by the block layer.

We currently use a single abstraction BlockDriverState both for tree nodes and the backend as a whole. Drawbacks:

* Its API includes both stuff that makes sense only at the block backend level (root of the tree) and stuff that's only for use within the block layer. This makes the API bigger and more complex than necessary. Moreover, it's not obvious which interfaces are meant for device models, and which really aren't.

* Since device models keep a reference to their backend, the backend object can't just be destroyed. But for media change, we need to replace the tree. Our solution is to make the BlockDriverState generic, with actual driver state in a separate object, pointed to by member opaque. That lets us replace the tree by deinitializing and reinitializing its root. This special need of the root makes the data structure awkward everywhere in the tree.

The general plan is to separate the APIs into "block backend", for use by device models, monitor and whatever other code dealing with block backends, and "block driver", for use by the block layer and whatever other code (if any) dealing with trees and tree nodes.

Code dealing with block backends, device models in particular, should become completely oblivious of BlockDriverState. This should let us clean up both APIs, and the tree data structures.

This commit is a first step. It creates a minimal "block backend"
API: type BlockBackend and functions to create, destroy and find them.

BlockBackend objects are created and destroyed exactly when root BlockDriverState objects are created and destroyed. "Root" in the sense of "in bdrv_states". They're not yet used for anything; that'll come shortly.

BlockBackend is reference-counted. Its reference count never exceeds one so far, but that's going to change.

---
  block/Makefile.objs            |   2 +-
  block/block-backend.c          | 120 +++++++++++++++++++++++++++++++++++++++++
  blockdev.c                     |  11 +++-
  hw/block/xen_disk.c            |  11 ++++
  include/qemu/typedefs.h        |   1 +
  include/sysemu/block-backend.h |  26 +++++++++
  qemu-img.c                     |  70 +++++++++++++++++++++---
  qemu-io.c                      |   8 +++
  qemu-nbd.c                     |   5 +-
  9 files changed, 243 insertions(+), 11 deletions(-)

create mode 100644 block/block-backend.c create mode 100644 include/sysemu/block-backend.h

[snip]

Quoted 4 lines
blockdev.c +0 -0
index c9463e3..583235a 100644

[snip]

Quoted 12 lines

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1804

Quoted 7 lines
blockdev.c +1 -0
@@ -1791,6 +1799,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
      } else {
          drive_del(dinfo);
      }
+    blk_unref(blk_by_name(id));
        aio_context_release(aio_context);
      return 0;

Well, now if a BB is created by blockdev_init() but not deleted from the monitor, it will not be unref'd. But first of all this is not bad, because the time it should be unref'd is exactly when qemu is exiting anyway and second, the BDS is not unref'd either.

Yes. Such a BDS can get destroyed either by explicit monitor command (here), or when the device using it is unplugged (blockdev_auto_del(), but only when blockdev_init() created it on behalf of drive_new()).

In this patch, the idea is to match the BB's lifetime to its BDS's lifetime.

Quoted 3 lines

Therefore:

Thanks!

#8 lore raw

PATCH v3 3/23 block: Connect BlockBackend to BlockDriverState

In reply to Markus Armbruster

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

---
 block.c                        |  10 ++--
 block/block-backend.c          |  71 ++++++++++++++++++++++-
 blockdev.c                     |  21 ++++---
 hw/block/xen_disk.c            |   8 +--
 include/block/block_int.h      |   2 +
 include/sysemu/block-backend.h |   5 ++
 qemu-img.c                     | 125 +++++++++++++++++++----------------------
 qemu-io.c                      |   4 +-
 qemu-nbd.c                     |   4 +-
 9 files changed, 156 insertions(+), 94 deletions(-)
block.c +6 -4
index 934881f..7ccf443 100644
@@ -2032,7 +2032,7 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
  * This will modify the BlockDriverState fields, and swap contents
  * between bs_new and bs_old. Both bs_new and bs_old are modified.
  *
- * bs_new is required to be anonymous.
+ * bs_new must be nameless and not attached to a BlockBackend.
  *
  * This function does not create any image files.
  */
@@ -2051,8 +2051,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
         QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);
     }
 
-    /* bs_new must be anonymous and shouldn't have anything fancy enabled */
+    /* bs_new must be nameless and shouldn't have anything fancy enabled */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);
     assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));
     assert(bs_new->job == NULL);
     assert(bs_new->dev == NULL);
@@ -2068,8 +2069,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
     bdrv_move_feature_fields(bs_old, bs_new);
     bdrv_move_feature_fields(bs_new, &tmp);
 
-    /* bs_new shouldn't be in bdrv_states even after the swap!  */
+    /* bs_new must remain nameless and unattached */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);
 
     /* Check a few fields that should remain attached to the device */
     assert(bs_new->dev == NULL);
@@ -2096,7 +2098,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
  * This will modify the BlockDriverState fields, and swap contents
  * between bs_new and bs_top. Both bs_new and bs_top are modified.
  *
- * bs_new is required to be anonymous.
+ * bs_new must be nameless and not attached to a BlockBackend.
  *
  * This function does not create any image files.
  */
block/block-backend.c +68 -3

104 lines not on this page · raw message

blockdev.c +10 -11
index 583235a..5da6028 100644
@@ -228,6 +228,7 @@ void drive_info_del(DriveInfo *dinfo)
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
     }
+
     g_free(dinfo->id);
     QTAILQ_REMOVE(&drives, dinfo, next);
     g_free(dinfo->serial);
@@ -465,14 +466,11 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
     }
 
     /* init */
-    blk = blk_new(qemu_opts_id(opts), errp);
+    blk = blk_new_with_bs(qemu_opts_id(opts), errp);
     if (!blk) {
         goto early_err;
     }
-    bs = bdrv_new_root(qemu_opts_id(opts), errp);
-    if (!bs) {
-        goto bdrv_new_err;
-    }
+    bs = blk_bs(blk);
     bs->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
     bs->read_only = ro;
     bs->detect_zeroes = detect_zeroes;
@@ -537,7 +535,6 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
 
 err:
     bdrv_unref(bs);
-bdrv_new_err:
     blk_unref(blk);
 early_err:
     qemu_opts_del(opts);
@@ -1752,16 +1749,18 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     const char *id = qdict_get_str(qdict, "id");
+    BlockBackend *blk;
     BlockDriverState *bs;
     DriveInfo *dinfo;
     AioContext *aio_context;
     Error *local_err = NULL;
 
-    bs = bdrv_find(id);
-    if (!bs) {
+    blk = blk_by_name(id);
+    if (!blk) {
         error_report("Device '%s' not found", id);
         return -1;
     }
+    bs = blk_bs(blk);
 
     dinfo = drive_get_by_blockdev(bs);
     if (dinfo && !dinfo->enable_auto_del) {
@@ -1791,15 +1790,15 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
      * then we can just get rid of the block driver state right here.
      */
     if (bdrv_get_attached_dev(bs)) {
-        bdrv_make_anon(bs);
-
+        blk_hide_on_behalf_of_do_drive_del(blk);
         /* Further I/O must not pause the guest */
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
+        /* FIXME bs->blk leaked when bs dies */
     } else {
         drive_del(dinfo);
+        blk_unref(blk);
     }
-    blk_unref(blk_by_name(id));
 
     aio_context_release(aio_context);
     return 0;
hw/block/xen_disk.c +2 -6
index 265cf13..0022083 100644
@@ -860,15 +860,11 @@ static int blk_connect(struct XenDevice *xendev)
 
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
-        blk = blk_new(blkdev->dev, NULL);
+        blk = blk_new_with_bs(blkdev->dev, NULL);
         if (!blk) {
             return -1;
         }
-        blkdev->bs = bdrv_new_root(blkdev->dev, NULL);
-        if (!blkdev->bs) {
-            blk_unref(blk);
-            return -1;
-        }
+        blkdev->bs = blk_bs(blk);
 
         drv = bdrv_find_whitelisted_format(blkdev->fileproto, readonly);
         if (bdrv_open(&blkdev->bs, blkdev->filename, NULL, NULL, qflags,
include/block/block_int.h +2 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;
include/sysemu/block-backend.h +5 -0
index 3f8371c..fa8f623 100644
@@ -17,10 +17,15 @@
 #include "qapi/error.h"
 
 BlockBackend *blk_new(const char *name, Error **errp);
+BlockBackend *blk_new_with_bs(const char *name, Error **errp);
 void blk_ref(BlockBackend *blk);
 void blk_unref(BlockBackend *blk);
 const char *blk_name(BlockBackend *blk);
 BlockBackend *blk_by_name(const char *name);
 BlockBackend *blk_next(BlockBackend *blk);
 
+BlockDriverState *blk_bs(BlockBackend *blk);
+
+void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk);
+
 #endif
qemu-img.c +59 -66

279 lines not on this page · raw message

qemu-io.c +2 -2
index 57090de..ef1d3ea 100644
@@ -62,8 +62,8 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
         return 1;
     }
 
-    qemuio_blk = blk_new("hda", &error_abort);
-    qemuio_bs = bdrv_new_root("hda", &error_abort);
+    qemuio_blk = blk_new_with_bs("hda", &error_abort);
+    qemuio_bs = blk_bs(qemuio_blk);
 
     if (growable) {
         flags |= BDRV_O_PROTOCOL;
qemu-nbd.c +2 -2
index ff95da6..24808e8 100644
@@ -688,8 +688,8 @@ int main(int argc, char **argv)
         drv = NULL;
     }
 
-    blk = blk_new("hda", &error_abort);
-    bs = bdrv_new_root("hda", &error_abort);
+    blk = blk_new_with_bs("hda", &error_abort);
+    bs = blk_bs(blk);
 
     srcpath = argv[optind];
     ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err);
Signature · 1 line
1.9.3
Reviewed-by on v3 3/23
#9 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Quoted 15 lines · Markus Armbruster

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

Quoted 4 lines

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

Good.

Quoted 12 lines
---
  block.c                        |  10 ++--
  block/block-backend.c          |  71 ++++++++++++++++++++++-
  blockdev.c                     |  21 ++++---
  hw/block/xen_disk.c            |   8 +--
  include/block/block_int.h      |   2 +
  include/sysemu/block-backend.h |   5 ++
  qemu-img.c                     | 125 +++++++++++++++++++----------------------
  qemu-io.c                      |   4 +-
  qemu-nbd.c                     |   4 +-
  9 files changed, 156 insertions(+), 94 deletions(-)
Reviewed-by on v3 3/23
#10 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 25 lines

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

block/block-backend.c +3 -0
+/*
+ * Hide @blk.
+ * @blk must not have been hidden already.

block/block-backend.c BlockBackend *blk_by_name(const char *name) · line 181

Quoted 10 lines
block/block-backend.c +10 -0
+ * Make attached BlockDriverState, if any, anonymous.
+ * Once hidden, @blk is invisible to all functions that don't receive
+ * it as argument.  For example, blk_by_name() won't return it.
+ * Strictly for use by do_drive_del().
+ * TODO get rid of it!
+ */
+void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk)
+{
+    QTAILQ_REMOVE(&blk_backends, blk, link);
+    blk->name[0] = 0;

Style nit: I prefer '\0' when dealing with strings.

Quoted 9 lines
block/block-backend.c +4 -0
+    if (blk->bs) {
+        bdrv_make_anon(blk->bs);
+    }
+}
blockdev.c +0 -0
index 583235a..5da6028 100644

blockdev.c void drive_info_del(DriveInfo *dinfo) · line 234

Quoted 7 lines
blockdev.c +1 -0
@@ -228,6 +228,7 @@ void drive_info_del(DriveInfo *dinfo)
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
     }
+
     g_free(dinfo->id);
     QTAILQ_REMOVE(&drives, dinfo, next);
     g_free(dinfo->serial);

This hunk is a rebasing artifact, I guess?

include/block/block_int.h struct BlockDriverState { · line 331

Quoted 13 lines
include/block/block_int.h +2 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;

Just to make sure that we agree on where we're going: This makes the assumption that a BDS has at most one BB that owns it. Which is not the final state that we want to have, so this will have to go away later. (Where "later" isn't necessarily part of this series.)

For now, the use of the field is limited to callbacks and bdrv_get_device_name(). Callbacks could always only serve a single device, so nothing became worse here.

I'm not entirely sure about bdrv_get_device_name(), whether it needs to go or to be rewritten to get the name of any BB pointing to it (I suspect for most callers we want to replace it by something that uses node-name by default if there is one and only fall back to BB names if there isn't), but that's not an issue to block this patch.

What I would consider, however, is adding a TODO comment that tells people that this field needs to go and if you need to use it, something is wrong with your design (which happens to be true for the existing design of some code).

Nothing critical in this patch, so with or without addressing the comments:

#11 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Quoted 23 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 21 lines

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

Quoted 15 lines

block/block-backend.c BlockBackend *blk_by_name(const char *name) · line 181

Quoted 13 lines
block/block-backend.c +13 -0
+/*
+ * Hide @blk.
+ * @blk must not have been hidden already.
+ * Make attached BlockDriverState, if any, anonymous.
+ * Once hidden, @blk is invisible to all functions that don't receive
+ * it as argument.  For example, blk_by_name() won't return it.
+ * Strictly for use by do_drive_del().
+ * TODO get rid of it!
+ */
+void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk)
+{
+    QTAILQ_REMOVE(&blk_backends, blk, link);
+    blk->name[0] = 0;

Style nit: I prefer '\0' when dealing with strings.

I don't, but if you feel strongly about it, I'll do it your way.

Quoted 10 lines
Quoted 10 lines
block/block-backend.c +4 -0
+    if (blk->bs) {
+        bdrv_make_anon(blk->bs);
+    }
+}
blockdev.c +0 -0
index 583235a..5da6028 100644
@@ -228,6 +228,7 @@ void drive_info_del(DriveInfo *dinfo)
     if (dinfo->opts) {
Quoted 8 lines

blockdev.c void drive_info_del(DriveInfo *dinfo) · line 234

Quoted 6 lines
blockdev.c +1 -0
         qemu_opts_del(dinfo->opts);
     }
+
     g_free(dinfo->id);
     QTAILQ_REMOVE(&drives, dinfo, next);
     g_free(dinfo->serial);

This hunk is a rebasing artifact, I guess?

Consider it gone.

Quoted 8 lines
Quoted 8 lines
include/block/block_int.h +0 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
Quoted 8 lines

include/block/block_int.h struct BlockDriverState { · line 331

Quoted 5 lines
include/block/block_int.h +2 -0
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;

Just to make sure that we agree on where we're going: This makes the assumption that a BDS has at most one BB that owns it.

Yes.

Quoted 2 lines

Which is not the
final state that we want to have, so this will have to go away later.

I don't know. Can you explain why you think we're going to want multiple BBs?

Quoted 5 lines

(Where "later" isn't necessarily part of this series.)

For now, the use of the field is limited to callbacks and bdrv_get_device_name(). Callbacks could always only serve a single device, so nothing became worse here.

In *this* patch, member blk is only read in bdrv_swap(), which asserts it's null. Later on in the series, it gets indeed used as you describe.

PATCH 22 puts it to use for BlockDevOps callbacks. The patch moves the callbacks from BDS to BB. I hope you'll agree that's where they belong.

Naturally, the *calls* of the callbacks remain where they are, in block.c. They get updated like this:

- bdrv_dev_FOO(bs, ARGS)
+ if (bs->blk) {
+ blk_dev_FOO(bs->blk ARGS)
+ }

PATCH 08 uses it to eliminate BDS member device_name[].

Quoted 5 lines

I'm not entirely sure about bdrv_get_device_name(), whether it needs to go or to be rewritten to get the name of any BB pointing to it (I suspect for most callers we want to replace it by something that uses node-name by default if there is one and only fall back to BB names if there isn't), but that's not an issue to block this patch.

I agree users of bdrv_get_device_name() need to be examined, and the ones that really want a BDS name should probably be changed to use the BDS name (a.k.a. node-name) and fall back to the BB name.

This series makes this need more visible, by emphasizing the distinctness of the two names.

Aside: which one to fall back to if we have multiple BBs?

Quoted 4 lines

What I would consider, however, is adding a TODO comment that tells people that this field needs to go and if you need to use it, something is wrong with your design (which happens to be true for the existing design of some code).

For the device callbacks, we need a way to find the BB. If multiple BBs can sit on top of the same BDS, we need to find the one with a device models attached. Ot even the ones, if we permit that.

Let's discuss this a bit, and depending on what we learn, add a suitable comment. Possibly on top.

Quoted 4 lines

Nothing critical in this patch, so with or without addressing the comments:

Thanks!

#12 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Am 22.09.2014 um 18:34 hat Markus Armbruster geschrieben:

Quoted 20 lines
Quoted 9 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines
include/block/block_int.h +0 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
Quoted 8 lines

include/block/block_int.h struct BlockDriverState { · line 331

Quoted 5 lines
include/block/block_int.h +2 -0
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;

Just to make sure that we agree on where we're going: This makes the assumption that a BDS has at most one BB that owns it.

Quoted 7 lines

Yes.

Quoted 2 lines

Which is not the
final state that we want to have, so this will have to go away later.

I don't know. Can you explain why you think we're going to want multiple BBs?

We already agreed that we'll have multiple parents for a BDS, for scenarios like having an NBD server on a snapshot or sharing backing files, potentially also some block jobs.

The question is whether among these multiple parents we want to have a limitation to one BlockBackend, forbidding e.g. an NBD server on the active layer. This would be a problem for live storage migration if we don't want the NBD server to reuse the same BB as the guest device.

More generally, if we can indirectly have multiple BBs on a single BDS by putting a filter in between, do we have good reasons to forbid having them attached directly?

Quoted 8 lines
Quoted 5 lines

(Where "later" isn't necessarily part of this series.)

For now, the use of the field is limited to callbacks and bdrv_get_device_name(). Callbacks could always only serve a single device, so nothing became worse here.

In *this* patch, member blk is only read in bdrv_swap(), which asserts it's null. Later on in the series, it gets indeed used as you describe.

Yes, my "now" depends on context and either refers to the patch I'm commenting on or the end of the series. In most cases when I see something that I feel is worth having a closer look, the first thing I do is looking at the fully applied series.

Review

Quoted 10 lines

PATCH 22 puts it to use for BlockDevOps callbacks. The patch moves the callbacks from BDS to BB. I hope you'll agree that's where they belong.

Naturally, the *calls* of the callbacks remain where they are, in block.c. They get updated like this:

(quoted diff) +3 -1
-       bdrv_dev_FOO(bs, ARGS)
+       if (bs->blk) {
+           blk_dev_FOO(bs->blk ARGS)
+       }

Yes, as I said, this is fine for now. When we allow multiple BBs, we'll have to turn it into something like notifier lists, but that can wait.

Quoted 8 lines

PATCH 08 uses it to eliminate BDS member device_name[].

Quoted 5 lines

I'm not entirely sure about bdrv_get_device_name(), whether it needs to go or to be rewritten to get the name of any BB pointing to it (I suspect for most callers we want to replace it by something that uses node-name by default if there is one and only fall back to BB names if there isn't), but that's not an issue to block this patch.

Quoted 8 lines

I agree users of bdrv_get_device_name() need to be examined, and the ones that really want a BDS name should probably be changed to use the BDS name (a.k.a. node-name) and fall back to the BB name.

This series makes this need more visible, by emphasizing the distinctness of the two names.

Aside: which one to fall back to if we have multiple BBs?

My first attempt would be "any", and in cases where this isn't good enough, you can't use a fallback at all.

Quoted 11 lines
Quoted 4 lines

What I would consider, however, is adding a TODO comment that tells people that this field needs to go and if you need to use it, something is wrong with your design (which happens to be true for the existing design of some code).

For the device callbacks, we need a way to find the BB. If multiple BBs can sit on top of the same BDS, we need to find the one with a device models attached. Ot even the ones, if we permit that.

Let's discuss this a bit, and depending on what we learn, add a suitable comment. Possibly on top.

Are you sure that nothing else than device models can be interested in callbacks? I expect that whatever block layer user we have, they will always be interested in resizes, for example. Media change might also not be entirely uninteresting, though in most cases what other users want is probably a blocker.

Kevin

#13 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Quoted 26 lines · Kevin Wolf

Am 22.09.2014 um 18:34 hat Markus Armbruster geschrieben:

Quoted 25 lines
Quoted 9 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines
include/block/block_int.h +0 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
Quoted 8 lines

include/block/block_int.h struct BlockDriverState { · line 331

Quoted 5 lines
include/block/block_int.h +2 -0
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;

Just to make sure that we agree on where we're going: This makes the assumption that a BDS has at most one BB that owns it.

Yes.

Quoted 2 lines

Which is not the
final state that we want to have, so this will have to go away later.

Quoted 6 lines
Quoted 2 lines

I don't know. Can you explain why you think we're going to want multiple BBs?

We already agreed that we'll have multiple parents for a BDS, for scenarios like having an NBD server on a snapshot or sharing backing files, potentially also some block jobs.

We certainly want to provide for multiple "users" (intentionally vague language here), such NBD server, block jobs, device models. Should they share a BB, or does each one need its own BB?

Quoted 8 lines

The question is whether among these multiple parents we want to have a limitation to one BlockBackend, forbidding e.g. an NBD server on the active layer. This would be a problem for live storage migration if we don't want the NBD server to reuse the same BB as the guest device.

More generally, if we can indirectly have multiple BBs on a single BDS by putting a filter in between, do we have good reasons to forbid having them attached directly?

Keeping code simple?

Not a valid argument when we *need* multiple BBs, i.e. when the answer to my prior question is "each one needs its own BB".

Quoted 20 lines
Quoted 8 lines
Quoted 5 lines

(Where "later" isn't necessarily part of this series.)

For now, the use of the field is limited to callbacks and bdrv_get_device_name(). Callbacks could always only serve a single device, so nothing became worse here.

In *this* patch, member blk is only read in bdrv_swap(), which asserts it's null. Later on in the series, it gets indeed used as you describe.

Yes, my "now" depends on context and either refers to the patch I'm commenting on or the end of the series. In most cases when I see something that I feel is worth having a closer look, the first thing I do is looking at the fully applied series.

Quoted 6 lines

PATCH 22 puts it to use for BlockDevOps callbacks. The patch moves the callbacks from BDS to BB. I hope you'll agree that's where they belong.

Naturally, the *calls* of the callbacks remain where they are, in block.c. They get updated like this:

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -1
-       bdrv_dev_FOO(bs, ARGS)
+       if (bs->blk) {
+           blk_dev_FOO(bs->blk ARGS)
+       }

Yes, as I said, this is fine for now. When we allow multiple BBs, we'll have to turn it into something like notifier lists, but that can wait.

Okay.

Quoted 12 lines
Quoted 12 lines

PATCH 08 uses it to eliminate BDS member device_name[].

Quoted 5 lines

I'm not entirely sure about bdrv_get_device_name(), whether it needs to go or to be rewritten to get the name of any BB pointing to it (I suspect for most callers we want to replace it by something that uses node-name by default if there is one and only fall back to BB names if there isn't), but that's not an issue to block this patch.

I agree users of bdrv_get_device_name() need to be examined, and the ones that really want a BDS name should probably be changed to use the BDS name (a.k.a. node-name) and fall back to the BB name.

Quoted 7 lines
Quoted 4 lines

This series makes this need more visible, by emphasizing the distinctness of the two names.

Aside: which one to fall back to if we have multiple BBs?

My first attempt would be "any", and in cases where this isn't good enough, you can't use a fallback at all.

This is going to be fun :)

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

What I would consider, however, is adding a TODO comment that tells people that this field needs to go and if you need to use it, something is wrong with your design (which happens to be true for the existing design of some code).

For the device callbacks, we need a way to find the BB. If multiple BBs can sit on top of the same BDS, we need to find the one with a device models attached. Ot even the ones, if we permit that.

Quoted 8 lines
Quoted 2 lines

Let's discuss this a bit, and depending on what we learn, add a suitable comment. Possibly on top.

Are you sure that nothing else than device models can be interested in callbacks? I expect that whatever block layer user we have, they will always be interested in resizes, for example. Media change might also not be entirely uninteresting, though in most cases what other users want is probably a blocker.

I designed BlockDevOps for device models only. If other users emerge, it needs a rename, and possibly a rethink.

#14 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Am 23.09.2014 um 14:52 hat Markus Armbruster geschrieben:

Quoted 31 lines
Quoted 29 lines · Kevin Wolf

Am 22.09.2014 um 18:34 hat Markus Armbruster geschrieben:

Quoted 27 lines
Quoted 9 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines
include/block/block_int.h +0 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
Quoted 8 lines

include/block/block_int.h struct BlockDriverState { · line 331

Quoted 5 lines
include/block/block_int.h +2 -0
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;

Just to make sure that we agree on where we're going: This makes the assumption that a BDS has at most one BB that owns it.

Yes.

Quoted 2 lines

Which is not the
final state that we want to have, so this will have to go away later.

I don't know. Can you explain why you think we're going to want multiple BBs?

Quoted 7 lines
Quoted 3 lines

We already agreed that we'll have multiple parents for a BDS, for scenarios like having an NBD server on a snapshot or sharing backing files, potentially also some block jobs.

We certainly want to provide for multiple "users" (intentionally vague language here), such NBD server, block jobs, device models. Should they share a BB, or does each one need its own BB?

I think they should have their own BB, but I can still be convinced otherwise.

The first reason is that frontends (= BB users, more or less) and backends are easiest to understand when they come in pairs. Having multiple frontends for a single backend might be confusion.

Second, if the NBD server doesn't sit at the root but accesses a backing file, it already has to get its own BB with its own name and with no device model attached. Doing the same at the root helps with consistency.

Third, we'll probably want to have some things like werror/rerror or I/O accounting handled separately for device models and NBD servers.

If we look at another type of users, we might easily find more reasons, but for me this is already a pretty strong indicator that shared BBs are probably not a good idea.

Quoted 5 lines
Quoted 5 lines

The question is whether among these multiple parents we want to have a limitation to one BlockBackend, forbidding e.g. an NBD server on the active layer. This would be a problem for live storage migration if we don't want the NBD server to reuse the same BB as the guest device.

Quoted 8 lines
Quoted 3 lines

More generally, if we can indirectly have multiple BBs on a single BDS by putting a filter in between, do we have good reasons to forbid having them attached directly?

Keeping code simple?

Not a valid argument when we *need* multiple BBs, i.e. when the answer to my prior question is "each one needs its own BB".

Are there more places than just the callbacks that would be complicated by multiple BBs per BDS?

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

What I would consider, however, is adding a TODO comment that tells people that this field needs to go and if you need to use it, something is wrong with your design (which happens to be true for the existing design of some code).

For the device callbacks, we need a way to find the BB. If multiple BBs can sit on top of the same BDS, we need to find the one with a device models attached. Ot even the ones, if we permit that.

Let's discuss this a bit, and depending on what we learn, add a suitable comment. Possibly on top.

Quoted 8 lines
Quoted 5 lines

Are you sure that nothing else than device models can be interested in callbacks? I expect that whatever block layer user we have, they will always be interested in resizes, for example. Media change might also not be entirely uninteresting, though in most cases what other users want is probably a blocker.

I designed BlockDevOps for device models only. If other users emerge, it needs a rename, and possibly a rethink.

Very likely to happen in the long run. Block jobs are today blocking resizes, but that's mostly because they don't have an easy way to respond to a resize. Sooner or later someone will want to grow their images while they are being mirrored (which is a completely reasonable, even if not trivial, thing to want).

Do we have a KVM Forum block layer agenda yet? I think this thread could already contain a few topics to discuss there.

Kevin

#15 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Quoted 43 lines · Kevin Wolf

Am 23.09.2014 um 14:52 hat Markus Armbruster geschrieben:

Quoted 31 lines
Quoted 29 lines · Kevin Wolf

Am 22.09.2014 um 18:34 hat Markus Armbruster geschrieben:

Quoted 27 lines
Quoted 9 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines
include/block/block_int.h +0 -0
index 8d86a6c..14e0b7c 100644
@@ -324,6 +324,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
Quoted 8 lines

include/block/block_int.h struct BlockDriverState { · line 331

Quoted 5 lines
include/block/block_int.h +2 -0
+    BlockBackend *blk;          /* owning backend, if any */
+
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
     const BlockDevOps *dev_ops;

Just to make sure that we agree on where we're going: This makes the assumption that a BDS has at most one BB that owns it.

Yes.

Quoted 2 lines

Which is not the
final state that we want to have, so this will have to go away later.

I don't know. Can you explain why you think we're going to want multiple BBs?

Quoted 7 lines
Quoted 3 lines

We already agreed that we'll have multiple parents for a BDS, for scenarios like having an NBD server on a snapshot or sharing backing files, potentially also some block jobs.

We certainly want to provide for multiple "users" (intentionally vague language here), such NBD server, block jobs, device models. Should they share a BB, or does each one need its own BB?

I think they should have their own BB, but I can still be convinced otherwise.

Quoted 8 lines

The first reason is that frontends (= BB users, more or less) and backends are easiest to understand when they come in pairs. Having multiple frontends for a single backend might be confusion.

Second, if the NBD server doesn't sit at the root but accesses a backing file, it already has to get its own BB with its own name and with no device model attached. Doing the same at the root helps with consistency.

These are valid, but fairly weak.

Quoted 2 lines

Third, we'll probably want to have some things like werror/rerror or I/O accounting handled separately for device models and NBD servers.

This one's pretty convincing.

Quoted 13 lines

If we look at another type of users, we might easily find more reasons, but for me this is already a pretty strong indicator that shared BBs are probably not a good idea.

Quoted 9 lines
Quoted 8 lines

The question is whether among these multiple parents we want to have a limitation to one BlockBackend, forbidding e.g. an NBD server on the active layer. This would be a problem for live storage migration if we don't want the NBD server to reuse the same BB as the guest device.

More generally, if we can indirectly have multiple BBs on a single BDS by putting a filter in between, do we have good reasons to forbid having them attached directly?

Quoted 7 lines
Quoted 4 lines

Keeping code simple?

Not a valid argument when we *need* multiple BBs, i.e. when the answer to my prior question is "each one needs its own BB".

Are there more places than just the callbacks that would be complicated by multiple BBs per BDS?

We'll know when we're done lifting stuff from BDS into BB.

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

What I would consider, however, is adding a TODO comment that tells people that this field needs to go and if you need to use it, something is wrong with your design (which happens to be true for the existing design of some code).

For the device callbacks, we need a way to find the BB. If multiple BBs can sit on top of the same BDS, we need to find the one with a device models attached. Ot even the ones, if we permit that.

Let's discuss this a bit, and depending on what we learn, add a suitable comment. Possibly on top.

Quoted 8 lines
Quoted 5 lines

Are you sure that nothing else than device models can be interested in callbacks? I expect that whatever block layer user we have, they will always be interested in resizes, for example. Media change might also not be entirely uninteresting, though in most cases what other users want is probably a blocker.

I designed BlockDevOps for device models only. If other users emerge, it needs a rename, and possibly a rethink.

Quoted 8 lines

Very likely to happen in the long run. Block jobs are today blocking resizes, but that's mostly because they don't have an easy way to respond to a resize. Sooner or later someone will want to grow their images while they are being mirrored (which is a completely reasonable, even if not trivial, thing to want).

Do we have a KVM Forum block layer agenda yet? I think this thread could already contain a few topics to discuss there.

No agenda yet, as far as I know.

#16 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

In reply to Kevin Wolf
Quoted 2 lines · Kevin Wolf

Do we have a KVM Forum block layer agenda yet? I think this thread could already contain a few topics to discuss there.

Being the guy who constantly bring back painfull issues
(Block filters, Block Backend) on the table I think we should also do a BOFH (Stefan's idea on a private discussion) about how we can further tweak and improve the review process.

I experienced on some other open sources projects as complex as the QEMU block layer a feeling of reactivity while contributing patches and while the new QEMU block layer review process is starting we are not here yet.

One idea I have is that we could benefit from this event to establish semi informal peering review contracts between contributors like the ISP does for bandwith.

Of course we should be carefull to avoid to go the academic review circle route and left some for unknown people.

Best regards

Benoît

Quoted 2 lines

Kevin

#17 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 58 lines

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

---
 block.c                        |  10 ++--
 block/block-backend.c          |  71 ++++++++++++++++++++++-
 blockdev.c                     |  21 ++++---
 hw/block/xen_disk.c            |   8 +--
 include/block/block_int.h      |   2 +
 include/sysemu/block-backend.h |   5 ++
 qemu-img.c                     | 125 +++++++++++++++++++----------------------
 qemu-io.c                      |   4 +-
 qemu-nbd.c                     |   4 +-
 9 files changed, 156 insertions(+), 94 deletions(-)
block.c +3 -2
index 934881f..7ccf443 100644
@@ -2032,7 +2032,7 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
  * This will modify the BlockDriverState fields, and swap contents
  * between bs_new and bs_old. Both bs_new and bs_old are modified.
  *
- * bs_new is required to be anonymous.
+ * bs_new must be nameless and not attached to a BlockBackend.
  *
  * This function does not create any image files.
  */
@@ -2051,8 +2051,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
         QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);
     }
 
-    /* bs_new must be anonymous and shouldn't have anything fancy enabled */
+    /* bs_new must be nameless and shouldn't have anything fancy enabled */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);
     assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));
     assert(bs_new->job == NULL);
     assert(bs_new->dev == NULL);

block.c void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old) · line 2074

Quoted 7 lines
block.c +2 -1
@@ -2068,8 +2069,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
     bdrv_move_feature_fields(bs_old, bs_new);
     bdrv_move_feature_fields(bs_new, &tmp);
 
-    /* bs_new shouldn't be in bdrv_states even after the swap!  */
+    /* bs_new must remain nameless and unattached */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);

Taking back my R-b: You tricked us, this assertion doesn't hold true. Easy to reproduce by taking a live snapshot. qemu-iotests case 052 catches it. Didn't you run it?

You probably need to swap bs->blk in bdrv_move_feature_fields().

Kevin

#18 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Quoted 62 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 61 lines

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

---
 block.c                        |  10 ++--
 block/block-backend.c          |  71 ++++++++++++++++++++++-
 blockdev.c                     |  21 ++++---
 hw/block/xen_disk.c            |   8 +--
 include/block/block_int.h      |   2 +
 include/sysemu/block-backend.h |   5 ++
 qemu-img.c                     | 125 +++++++++++++++++++----------------------
 qemu-io.c                      |   4 +-
 qemu-nbd.c                     |   4 +-
 9 files changed, 156 insertions(+), 94 deletions(-)
block.c +3 -2
index 934881f..7ccf443 100644
@@ -2032,7 +2032,7 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
  * This will modify the BlockDriverState fields, and swap contents
  * between bs_new and bs_old. Both bs_new and bs_old are modified.
  *
- * bs_new is required to be anonymous.
+ * bs_new must be nameless and not attached to a BlockBackend.
  *
  * This function does not create any image files.
  */
@@ -2051,8 +2051,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
         QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);
     }
 
-    /* bs_new must be anonymous and shouldn't have anything fancy enabled */
+    /* bs_new must be nameless and shouldn't have anything fancy enabled */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);
     assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));
     assert(bs_new->job == NULL);
     assert(bs_new->dev == NULL);
@@ -2068,8 +2069,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
     bdrv_move_feature_fields(bs_old, bs_new);
     bdrv_move_feature_fields(bs_new, &tmp);
 
Quoted 8 lines

block.c void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old) · line 2074

Quoted 4 lines
block.c +2 -1
-    /* bs_new shouldn't be in bdrv_states even after the swap!  */
+    /* bs_new must remain nameless and unattached */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);

Taking back my R-b: You tricked us, this assertion doesn't hold true. Easy to reproduce by taking a live snapshot. qemu-iotests case 052 catches it. Didn't you run it?

I run "make check-qtest check-block" on every commit before I submit. No idea what went wrong with this one.

Quoted 1 line

You probably need to swap bs->blk in bdrv_move_feature_fields().

I'll look into it, thanks!

#19 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Am 30.09.2014 um 12:56 hat Markus Armbruster geschrieben:

Quoted 73 lines
Quoted 62 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 61 lines

The pointer from BlockBackend to BlockDriverState is a strong reference, managed with bdrv_ref() / bdrv_unref(), the back-pointer is a weak one.

Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState.

Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name:
blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant.

The patch adds a memory leak: drive_del while a device model is connected leaks the BlockBackend. Avoiding the leak here is rather hairy, but it'll become straightforward in a few commits, so I mark it FIXME in the code now, and plug it when it's easy.

---
 block.c                        |  10 ++--
 block/block-backend.c          |  71 ++++++++++++++++++++++-
 blockdev.c                     |  21 ++++---
 hw/block/xen_disk.c            |   8 +--
 include/block/block_int.h      |   2 +
 include/sysemu/block-backend.h |   5 ++
 qemu-img.c                     | 125 +++++++++++++++++++----------------------
 qemu-io.c                      |   4 +-
 qemu-nbd.c                     |   4 +-
 9 files changed, 156 insertions(+), 94 deletions(-)
block.c +3 -2
index 934881f..7ccf443 100644
@@ -2032,7 +2032,7 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
  * This will modify the BlockDriverState fields, and swap contents
  * between bs_new and bs_old. Both bs_new and bs_old are modified.
  *
- * bs_new is required to be anonymous.
+ * bs_new must be nameless and not attached to a BlockBackend.
  *
  * This function does not create any image files.
  */
@@ -2051,8 +2051,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
         QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);
     }
 
-    /* bs_new must be anonymous and shouldn't have anything fancy enabled */
+    /* bs_new must be nameless and shouldn't have anything fancy enabled */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);
     assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));
     assert(bs_new->job == NULL);
     assert(bs_new->dev == NULL);
@@ -2068,8 +2069,9 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
     bdrv_move_feature_fields(bs_old, bs_new);
     bdrv_move_feature_fields(bs_new, &tmp);
 
Quoted 8 lines

block.c void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old) · line 2074

Quoted 4 lines
block.c +2 -1
-    /* bs_new shouldn't be in bdrv_states even after the swap!  */
+    /* bs_new must remain nameless and unattached */
     assert(bs_new->device_name[0] == '\0');
+    assert(!bs_new->blk);

Taking back my R-b: You tricked us, this assertion doesn't hold true. Easy to reproduce by taking a live snapshot. qemu-iotests case 052 catches it. Didn't you run it?

Quoted 2 lines

I run "make check-qtest check-block" on every commit before I submit. No idea what went wrong with this one.

When run for raw, it's only 052 that catches it. For qcow2, I got some more failures: 039 040 041 051 052 085

I see the problem: Only 039 and 052 are marked as 'quick', i.e. the rest is already excluded from 'make check-block'. 039 and 052 don't work with cache=none and 'make check-block' uses -nocache, so those are skipped as well. I'll send a patch to remove the -nocache option and let it run with the default options.

Kevin

#20 lore raw

Re: [Qemu-devel] [PATCH v3 03/23] block: Connect BlockBackend to BlockDriverState

Quoted 2 lines · Kevin Wolf

Am 30.09.2014 um 12:56 hat Markus Armbruster geschrieben:

Quoted 1 line

Kevin Wolf <[email protected]> writes:

[...]

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Taking back my R-b: You tricked us, this assertion doesn't hold true. Easy to reproduce by taking a live snapshot. qemu-iotests case 052 catches it. Didn't you run it?

I run "make check-qtest check-block" on every commit before I submit. No idea what went wrong with this one.

Quoted 7 lines

When run for raw, it's only 052 that catches it. For qcow2, I got some more failures: 039 040 041 051 052 085

I see the problem: Only 039 and 052 are marked as 'quick', i.e. the rest is already excluded from 'make check-block'. 039 and 052 don't work with cache=none and 'make check-block' uses -nocache, so those are skipped as well.

Yes, that's why I missed it.

Quoted 2 lines

I'll send a patch to remove the -nocache option and let it run
with the default options.

Appreciated!

#21 lore raw

PATCH v3 4/23 block: Connect BlockBackend and DriveInfo

In reply to Markus Armbruster

Make the BlockBackend own the DriveInfo. Change blockdev_init() to return the BlockBackend instead of the DriveInfo.

---
 block.c                   |  2 --
 block/block-backend.c     | 38 ++++++++++++++++++++++++
 blockdev.c                | 73 ++++++++++++++++++++++++-----------------------
 include/sysemu/blockdev.h |  4 +++
 4 files changed, 79 insertions(+), 38 deletions(-)
block.c +0 -2
index 7ccf443..5f7dc45 100644
@@ -29,7 +29,6 @@
 #include "qemu/module.h"
 #include "qapi/qmp/qjson.h"
 #include "sysemu/sysemu.h"
-#include "sysemu/blockdev.h"    /* FIXME layering violation */
 #include "qemu/notify.h"
 #include "block/coroutine.h"
 #include "block/qapi.h"
@@ -2124,7 +2123,6 @@ static void bdrv_delete(BlockDriverState *bs)
     /* remove from list, if necessary */
     bdrv_make_anon(bs);
 
-    drive_info_del(drive_get_by_blockdev(bs));
     g_free(bs);
 }
 
block/block-backend.c +38 -0
index a12215a..9ee57c7 100644
@@ -12,11 +12,13 @@
 
 #include "sysemu/block-backend.h"
 #include "block/block_int.h"
+#include "sysemu/blockdev.h"
 
 struct BlockBackend {
     char *name;
     int refcnt;
     BlockDriverState *bs;
+    DriveInfo *legacy_dinfo;
     QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
 };
 
@@ -87,6 +89,7 @@ static void blk_delete(BlockBackend *blk)
         QTAILQ_REMOVE(&blk_backends, blk, link);
     }
     g_free(blk->name);
+    drive_info_del(blk->legacy_dinfo);
     g_free(blk);
 }
 
@@ -167,6 +170,41 @@ BlockDriverState *blk_bs(BlockBackend *blk)
 }
 
 /*
+ * Return @blk's DriveInfo if any, else null.
+ */
+DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
+{
+    return blk->legacy_dinfo;
+}
+
+/*
+ * Set @blk's DriveInfo to @dinfo, and return it.
+ * @blk must not have a DriveInfo set already.
+ * No other BlockBackend may have the same DriveInfo set.
+ */
+DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo)
+{
+    assert(!blk->legacy_dinfo);
+    return blk->legacy_dinfo = dinfo;
+}
+
+/*
+ * Return the BlockBackend with DriveInfo @dinfo.
+ * It must exist.
+ */
+BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo)
+{
+    BlockBackend *blk;
+
+    QTAILQ_FOREACH(blk, &blk_backends, link) {
+        if (blk->legacy_dinfo == dinfo) {
+            return blk;
+        }
+    }
+    assert(0);
+}
+
+/*
  * Hide @blk.
  * @blk must not have been hidden already.
  * Make attached BlockDriverState, if any, anonymous.
blockdev.c +37 -36

202 lines not on this page · raw message

include/sysemu/blockdev.h +4 -0
index abec381..1dc5906 100644
@@ -45,6 +45,10 @@ struct DriveInfo {
     QTAILQ_ENTRY(DriveInfo) next;
 };
 
+DriveInfo *blk_legacy_dinfo(BlockBackend *blk);
+DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo);
+BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo);
+
 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
 int drive_get_max_bus(BlockInterfaceType type);
Signature · 1 line
1.9.3
#22 lore raw

Re: [Qemu-devel] [PATCH v3 04/23] block: Connect BlockBackend and DriveInfo

Quoted 10 lines · Markus Armbruster

Make the BlockBackend own the DriveInfo. Change blockdev_init() to return the BlockBackend instead of the DriveInfo.

---
  block.c                   |  2 --
  block/block-backend.c     | 38 ++++++++++++++++++++++++
  blockdev.c                | 73 ++++++++++++++++++++++++-----------------------
  include/sysemu/blockdev.h |  4 +++
  4 files changed, 79 insertions(+), 38 deletions(-)

[snip]

Quoted 4 lines
blockdev.c +0 -0
index 5da6028..722d083 100644

[snip]

Quoted 6 lines
blockdev.c +1 -1
@@ -920,19 +922,18 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
      }
 
      /* Actual block device init: Functionality shared with blockdev-add */
-    dinfo = blockdev_init(filename, bs_opts, &local_err);
+    blk = blockdev_init(filename, bs_opts, &local_err);

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 930

Quoted 10 lines
blockdev.c +3 -5
      bs_opts = NULL;
-    if (dinfo == NULL) {
-        if (local_err) {
-            error_report("%s", error_get_pretty(local_err));
-            error_free(local_err);
-        }
+    if (!blk) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
          goto fail;

Not all of blockdev_init() sets errp on failure. Try "qemu-system-x86_64 -drive format=help" and you'll see a segfault with this patch applied. So either you can make blockdev_init() do things right, which is, set errp for format=help instead of dumping the list to stdout (but I'm not even sure whether that's really correct, because it's not really an error), or you keep the "if" around error_report() and error_free() here.

Looks good otherwise, though.

Max

#23 lore raw

Re: [Qemu-devel] [PATCH v3 04/23] block: Connect BlockBackend and DriveInfo

Quoted 33 lines · Max Reitz
Quoted 10 lines · Markus Armbruster

Make the BlockBackend own the DriveInfo. Change blockdev_init() to return the BlockBackend instead of the DriveInfo.

---
  block.c                   |  2 --
  block/block-backend.c     | 38 ++++++++++++++++++++++++
  blockdev.c | 73 ++++++++++++++++++++++++-----------------------
  include/sysemu/blockdev.h |  4 +++
  4 files changed, 79 insertions(+), 38 deletions(-)

[snip]

Quoted 4 lines
blockdev.c +0 -0
index 5da6028..722d083 100644

[snip]

Quoted 12 lines
blockdev.c +0 -0
@@ -920,19 +922,18 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
      }
        /* Actual block device init: Functionality shared with

blockdev-add */

blockdev.c +1 -6
-    dinfo = blockdev_init(filename, bs_opts, &local_err);
+    blk = blockdev_init(filename, bs_opts, &local_err);
      bs_opts = NULL;
-    if (dinfo == NULL) {
-        if (local_err) {
-            error_report("%s", error_get_pretty(local_err));
-            error_free(local_err);
-        }
Quoted 8 lines

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 930

Quoted 4 lines
blockdev.c +3 -0
+    if (!blk) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
          goto fail;

Not all of blockdev_init() sets errp on failure. Try "qemu-system-x86_64 -drive format=help" and you'll see a segfault with this patch applied.

Good catch!

The common contract is:

1. On success, return the new object and leave *errp alone.

2. On failure, return null and set *errp.

blockdev_init() adds:

3. On help, return null and leave *errp alone.

Fine, but it really needs a function comment. More so since the unusual case is buried in the middle of a 200+ line function. Separate patch, outside the scope of this series.

Quoted 5 lines

So either you can make blockdev_init() do things
right, which is, set errp for format=help instead of dumping the list to stdout (but I'm not even sure whether that's really correct, because it's not really an error), or you keep the "if" around error_report() and error_free() here.

Your doubts are justified: help is not an error.

How to ask for help with -drive is obvious enough:

-drive format=help

Is the a way to ask for help with blockdev-add? Hard to see, as its arguments meander through QAPI-generated types, QDicts and QemuOpts. When I try, I either get "QMP input object member 'format' is unexpected", or crash in visitors; suspecting the bug fixed by "qapi:
fix crash in dealloc visitor for union types".

We'll need one Once we expose blockdev-add on the command line and in the human monitor. Since printing help to a QMP monitor isn't at all helpful, we'll have to either catch and reject the attempt to ask for it there, or print help with error_printf_unless_qmp().

I figure the cleanest solution would be to lift format help out of blockdev_init() into drive_new() now and later on the command line code.

For this series, I'll simply refrain from breaking the existing logic.

Quoted 1 line

Looks good otherwise, though.

Thanks!

#24 lore raw

Re: [Qemu-devel] [PATCH v3 04/23] block: Connect BlockBackend and DriveInfo

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 67 lines

Make the BlockBackend own the DriveInfo. Change blockdev_init() to return the BlockBackend instead of the DriveInfo.

---
 block.c                   |  2 --
 block/block-backend.c     | 38 ++++++++++++++++++++++++
 blockdev.c                | 73 ++++++++++++++++++++++++-----------------------
 include/sysemu/blockdev.h |  4 +++
 4 files changed, 79 insertions(+), 38 deletions(-)
block.c +0 -2
index 7ccf443..5f7dc45 100644
@@ -29,7 +29,6 @@
 #include "qemu/module.h"
 #include "qapi/qmp/qjson.h"
 #include "sysemu/sysemu.h"
-#include "sysemu/blockdev.h"    /* FIXME layering violation */
 #include "qemu/notify.h"
 #include "block/coroutine.h"
 #include "block/qapi.h"
@@ -2124,7 +2123,6 @@ static void bdrv_delete(BlockDriverState *bs)
     /* remove from list, if necessary */
     bdrv_make_anon(bs);
 
-    drive_info_del(drive_get_by_blockdev(bs));
     g_free(bs);
 }
 
block/block-backend.c +9 -0
index a12215a..9ee57c7 100644
@@ -12,11 +12,13 @@
 
 #include "sysemu/block-backend.h"
 #include "block/block_int.h"
+#include "sysemu/blockdev.h"
 
 struct BlockBackend {
     char *name;
     int refcnt;
     BlockDriverState *bs;
+    DriveInfo *legacy_dinfo;
     QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
 };
 
@@ -87,6 +89,7 @@ static void blk_delete(BlockBackend *blk)
         QTAILQ_REMOVE(&blk_backends, blk, link);
     }
     g_free(blk->name);
+    drive_info_del(blk->legacy_dinfo);
     g_free(blk);
 }
 
@@ -167,6 +170,41 @@ BlockDriverState *blk_bs(BlockBackend *blk)
 }
 
 /*
+ * Return @blk's DriveInfo if any, else null.
+ */
+DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
+{
+    return blk->legacy_dinfo;
+}

block/block-backend.c BlockDriverState *blk_bs(BlockBackend *blk) · line 188

Quoted 10 lines
block/block-backend.c +10 -0
+
+/*
+ * Set @blk's DriveInfo to @dinfo, and return it.
+ * @blk must not have a DriveInfo set already.
+ * No other BlockBackend may have the same DriveInfo set.
+ */
+DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo)
+{
+    assert(!blk->legacy_dinfo);
+    return blk->legacy_dinfo = dinfo;

Ugh, I don't like assignments in a return statement much more than setters that return something.

Fortunately, nobody uses the return value, so this can become a void function.

Quoted 5 lines
block/block-backend.c +5 -0
+}
+/*
+ * Return the BlockBackend with DriveInfo @dinfo.
+ * It must exist.
+ */

block/block-backend.c BlockDriverState *blk_bs(BlockBackend *blk) · line 204

Quoted 10 lines
block/block-backend.c +10 -0
+BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo)
+{
+    BlockBackend *blk;
+
+    QTAILQ_FOREACH(blk, &blk_backends, link) {
+        if (blk->legacy_dinfo == dinfo) {
+            return blk;
+        }
+    }
+    assert(0);

I'm surprised that the compiler doesn't complain here. Seems it understands that the condition is always false and the libc header sets the noreturn attribute for the internal function handling a failure. With NDEBUG set, this wouldn't work any more.

I think abort() is better.

Quoted 86 lines
block/block-backend.c +3 -0
+}
+
+/*
  * Hide @blk.
  * @blk must not have been hidden already.
  * Make attached BlockDriverState, if any, anonymous.
blockdev.c +16 -14
index 5da6028..722d083 100644
@@ -47,8 +47,6 @@
 #include "trace.h"
 #include "sysemu/arch_init.h"
 
-static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
-
 static const char *const if_name[IF_COUNT] = {
     [IF_NONE] = "none",
     [IF_IDE] = "ide",
@@ -89,7 +87,8 @@ static const int if_max_devs[IF_COUNT] = {
  */
 void blockdev_mark_auto_del(BlockDriverState *bs)
 {
-    DriveInfo *dinfo = drive_get_by_blockdev(bs);
+    BlockBackend *blk = bs->blk;
+    DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && !dinfo->enable_auto_del) {
         return;
@@ -105,7 +104,8 @@ void blockdev_mark_auto_del(BlockDriverState *bs)
 
 void blockdev_auto_del(BlockDriverState *bs)
 {
-    DriveInfo *dinfo = drive_get_by_blockdev(bs);
+    BlockBackend *blk = bs->blk;
+    DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && dinfo->auto_del) {
         drive_del(dinfo);
@@ -153,15 +153,15 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
 
 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
 {
+    BlockBackend *blk;
     DriveInfo *dinfo;
 
-    /* seek interface, bus and unit */
-
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if (dinfo->type == type &&
-	    dinfo->bus == bus &&
-	    dinfo->unit == unit)
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+        dinfo = blk_legacy_dinfo(blk);
+        if (dinfo && dinfo->type == type
+            && dinfo->bus == bus && dinfo->unit == unit) {
             return dinfo;
+        }
     }
 
     return NULL;
@@ -177,13 +177,15 @@ DriveInfo *drive_get_by_index(BlockInterfaceType type, int index)
 int drive_get_max_bus(BlockInterfaceType type)
 {
     int max_bus;
+    BlockBackend *blk;
     DriveInfo *dinfo;
 
     max_bus = -1;
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if(dinfo->type == type &&
-           dinfo->bus > max_bus)
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+        dinfo = blk_legacy_dinfo(blk);
+        if (dinfo && dinfo->type == type && dinfo->bus > max_bus) {
             max_bus = dinfo->bus;
+        }
     }
     return max_bus;
 }
@@ -200,11 +202,11 @@ DriveInfo *drive_get_next(BlockInterfaceType type)
 
 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs)
 {
-    DriveInfo *dinfo;
+    BlockBackend *blk;

blockdev.c DriveInfo *drive_get_next(BlockInterfaceType type) · line 212

Quoted 10 lines
blockdev.c +3 -3
 
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if (dinfo->bdrv == bs) {
-            return dinfo;
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+        if (blk_bs(blk) == bs) {
+            return blk_legacy_dinfo(blk);
         }
     }
     return NULL;

Why don't you use bs->blk here?

Also, why replace calls to drive_get_by_blockdev() above when the function stays? Wouldn't it make more sense to remove all callers in a single patch instead of doing part of it in an unrelated patch?

blockdev.c static void bdrv_format_print(void *opaque, const char *name) · line 224

Quoted 6 lines
blockdev.c +1 -0
@@ -218,6 +220,7 @@ static void bdrv_format_print(void *opaque, const char *name)
 void drive_del(DriveInfo *dinfo)
 {
     bdrv_unref(dinfo->bdrv);
+    blk_unref(blk_by_legacy_dinfo(dinfo));
 }

Hmm, let's see. drive_del() has four callers:

* do_drive_del(): A blk_unref() is removed there, so the code remains equivalent. Good.

* blockdev_auto_del(): Here, the blk_unref() is new. If I'm reading the code right, unplugging a device doesn't only automagically destroy the DriveInfo now, but also the BlockBackend. Is this really magic that we want BlockBackend to inherit? (I don't think so.)

* drive_hot_add(): This is an error paths that frees a previously leaked BlockBackend created by an indirect drive_new() call. Silent bug fix?

* pci_piix3_xen_ide_unplug(): Xen magic I don't fully understand. The guest can tell us to remove the IDE drives (because it sees the same image through the PV driver, I think). Whether or not we want to remove the BlockBackend, I'm not completely sure.

Kevin

#25 lore raw

Re: [Qemu-devel] [PATCH v3 04/23] block: Connect BlockBackend and DriveInfo

Quoted 73 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 72 lines

Make the BlockBackend own the DriveInfo. Change blockdev_init() to return the BlockBackend instead of the DriveInfo.

---
 block.c                   |  2 --
 block/block-backend.c     | 38 ++++++++++++++++++++++++
 blockdev.c                | 73 ++++++++++++++++++++++++-----------------------
 include/sysemu/blockdev.h |  4 +++
 4 files changed, 79 insertions(+), 38 deletions(-)
block.c +0 -2
index 7ccf443..5f7dc45 100644
@@ -29,7 +29,6 @@
 #include "qemu/module.h"
 #include "qapi/qmp/qjson.h"
 #include "sysemu/sysemu.h"
-#include "sysemu/blockdev.h"    /* FIXME layering violation */
 #include "qemu/notify.h"
 #include "block/coroutine.h"
 #include "block/qapi.h"
@@ -2124,7 +2123,6 @@ static void bdrv_delete(BlockDriverState *bs)
     /* remove from list, if necessary */
     bdrv_make_anon(bs);
 
-    drive_info_del(drive_get_by_blockdev(bs));
     g_free(bs);
 }
 
block/block-backend.c +14 -0
index a12215a..9ee57c7 100644
@@ -12,11 +12,13 @@
 
 #include "sysemu/block-backend.h"
 #include "block/block_int.h"
+#include "sysemu/blockdev.h"
 
 struct BlockBackend {
     char *name;
     int refcnt;
     BlockDriverState *bs;
+    DriveInfo *legacy_dinfo;
     QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
 };
 
@@ -87,6 +89,7 @@ static void blk_delete(BlockBackend *blk)
         QTAILQ_REMOVE(&blk_backends, blk, link);
     }
     g_free(blk->name);
+    drive_info_del(blk->legacy_dinfo);
     g_free(blk);
 }
 
@@ -167,6 +170,41 @@ BlockDriverState *blk_bs(BlockBackend *blk)
 }
 
 /*
+ * Return @blk's DriveInfo if any, else null.
+ */
+DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
+{
+    return blk->legacy_dinfo;
+}
+
+/*
+ * Set @blk's DriveInfo to @dinfo, and return it.
+ * @blk must not have a DriveInfo set already.
+ * No other BlockBackend may have the same DriveInfo set.
Quoted 8 lines

block/block-backend.c BlockDriverState *blk_bs(BlockBackend *blk) · line 188

Quoted 5 lines
block/block-backend.c +5 -0
+ */
+DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo)
+{
+    assert(!blk->legacy_dinfo);
+    return blk->legacy_dinfo = dinfo;

Ugh, I don't like assignments in a return statement much more than setters that return something.

It's an assignment. In C, assignments return a value.

Quoted 24 lines

Fortunately, nobody uses the return value, so this can become a void function.

Quoted 5 lines
block/block-backend.c +5 -0
+}
+/*
+ * Return the BlockBackend with DriveInfo @dinfo.
+ * It must exist.
+ */

block/block-backend.c BlockDriverState *blk_bs(BlockBackend *blk) · line 204

Quoted 10 lines
block/block-backend.c +10 -0
+BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo)
+{
+    BlockBackend *blk;
+
+    QTAILQ_FOREACH(blk, &blk_backends, link) {
+        if (blk->legacy_dinfo == dinfo) {
+            return blk;
+        }
+    }
+    assert(0);

I'm surprised that the compiler doesn't complain here. Seems it understands that the condition is always false and the libc header sets the noreturn attribute for the internal function handling a failure. With NDEBUG set, this wouldn't work any more.

Quoted 1 line

I think abort() is better.

Okay.

Quoted 87 lines
Quoted 87 lines
block/block-backend.c +3 -0
+}
+
+/*
  * Hide @blk.
  * @blk must not have been hidden already.
  * Make attached BlockDriverState, if any, anonymous.
blockdev.c +16 -14
index 5da6028..722d083 100644
@@ -47,8 +47,6 @@
 #include "trace.h"
 #include "sysemu/arch_init.h"
 
-static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
-
 static const char *const if_name[IF_COUNT] = {
     [IF_NONE] = "none",
     [IF_IDE] = "ide",
@@ -89,7 +87,8 @@ static const int if_max_devs[IF_COUNT] = {
  */
 void blockdev_mark_auto_del(BlockDriverState *bs)
 {
-    DriveInfo *dinfo = drive_get_by_blockdev(bs);
+    BlockBackend *blk = bs->blk;
+    DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && !dinfo->enable_auto_del) {
         return;
@@ -105,7 +104,8 @@ void blockdev_mark_auto_del(BlockDriverState *bs)
 
 void blockdev_auto_del(BlockDriverState *bs)
 {
-    DriveInfo *dinfo = drive_get_by_blockdev(bs);
+    BlockBackend *blk = bs->blk;
+    DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && dinfo->auto_del) {
         drive_del(dinfo);
@@ -153,15 +153,15 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
 
 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
 {
+    BlockBackend *blk;
     DriveInfo *dinfo;
 
-    /* seek interface, bus and unit */
-
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if (dinfo->type == type &&
-	    dinfo->bus == bus &&
-	    dinfo->unit == unit)
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+        dinfo = blk_legacy_dinfo(blk);
+        if (dinfo && dinfo->type == type
+            && dinfo->bus == bus && dinfo->unit == unit) {
             return dinfo;
+        }
     }
 
     return NULL;
@@ -177,13 +177,15 @@ DriveInfo *drive_get_by_index(BlockInterfaceType type, int index)
 int drive_get_max_bus(BlockInterfaceType type)
 {
     int max_bus;
+    BlockBackend *blk;
     DriveInfo *dinfo;
 
     max_bus = -1;
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if(dinfo->type == type &&
-           dinfo->bus > max_bus)
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+        dinfo = blk_legacy_dinfo(blk);
+        if (dinfo && dinfo->type == type && dinfo->bus > max_bus) {
             max_bus = dinfo->bus;
+        }
     }
     return max_bus;
 }
@@ -200,11 +202,11 @@ DriveInfo *drive_get_next(BlockInterfaceType type)
 
 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs)
 {
-    DriveInfo *dinfo;
+    BlockBackend *blk;
 
Quoted 11 lines

blockdev.c DriveInfo *drive_get_next(BlockInterfaceType type) · line 212

Quoted 9 lines
blockdev.c +3 -3
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if (dinfo->bdrv == bs) {
-            return dinfo;
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+        if (blk_bs(blk) == bs) {
+            return blk_legacy_dinfo(blk);
         }
     }
     return NULL;

Why don't you use bs->blk here?

Beats me; I guess I let my fingers pick it. I'll switch to bs->blk.

Quoted 3 lines

Also, why replace calls to drive_get_by_blockdev() above when the function stays? Wouldn't it make more sense to remove all callers in a single patch instead of doing part of it in an unrelated patch?

The general idea is to convert users of drive_get_by_blockdev() to blk_legacy_dinfo() as soon as they use BlockBackend.

PATCH 04 (this one) converts do_drive_del(), because it's already using BlockBackend.

It also converts blockdev_mark_auto_del() and blockdev_auto_del() to BlockBackend. I admit that's not yet necessary at this point of the series. I did it because I don't like having both old drive_get_by_blockdev() and new blk_legacy_dinfo() used in the same file. Even when the file is still providing drive_get_by_blockdev() to other users, which get converted to BB only in PATCH 14.

PATCH 14 "hw: Convert from BlockDriverState to BlockBackend, mostly" converts all the other callers.

Quoted 9 lines

blockdev.c static void bdrv_format_print(void *opaque, const char *name) · line 224

Quoted 6 lines
blockdev.c +1 -0
@@ -218,6 +220,7 @@ static void bdrv_format_print(void *opaque, const char *name)
 void drive_del(DriveInfo *dinfo)
 {
     bdrv_unref(dinfo->bdrv);
+    blk_unref(blk_by_legacy_dinfo(dinfo));
 }

Hmm, let's see. drive_del() has four callers:

Quoted 7 lines

* do_drive_del(): A blk_unref() is removed there, so the code remains equivalent. Good.

* blockdev_auto_del(): Here, the blk_unref() is new. If I'm reading the code right, unplugging a device doesn't only automagically destroy the DriveInfo now, but also the BlockBackend. Is this really magic that we want BlockBackend to inherit? (I don't think so.)

Let me explain this stuff, not least because it helps me think.

"Unplug of device model destroys any block backends it's using" is a misfeature we want to confine to backends created "the old way". Where "the old way" really means whatever we want to remain misfeature- compatible. Definitely not blockdev-add. My working hypothesis for "old way" is "anything that goes through drive_new()".

Both old and new way create a tree of BDS. Before this series, they both create a DriveInfo. Afterwards, they both create a BlockBackend, but only -drive & friends creates a DriveInfo.

blockdev_auto_del() is supposed to *nothing* for a "new way" argument. Its condition guarding drive_del() must ensure that.

On device unplug, blockdev_auto_del() runs for all its backends.

For an "old way" backend, it destroys. This patch makes it destroy the BlockBackend, too. Which means PATCH 02 leaked it. Meh. I can try to avoid the temporary leak in v4.

For a "new way" backend, it does nothing. No change with this patch.

Quoted 2 lines

* drive_hot_add(): This is an error paths that frees a previously leaked BlockBackend created by an indirect drive_new() call. Silent bug fix?

Similar temporary leak. Can try to avoid in v4.

Quoted 4 lines

* pci_piix3_xen_ide_unplug(): Xen magic I don't fully understand. The guest can tell us to remove the IDE drives (because it sees the same image through the PV driver, I think). Whether or not we want to remove the BlockBackend, I'm not completely sure.

The general idea is to delete a BB exactly when the corresponding root BDS gets deleted. PATCH 02 doesn't get that completely right, but this patch should heal it. Getting it completely right in PATCH 02 is impractical because HMP command drive_del is so nasty. Getting it less wrong would be nice, and I'm going to try.

Thanks!

#26 lore raw

PATCH v3 5/23 block: Code motion to get rid of stubs/blockdev.c

In reply to Markus Armbruster
---
 block/block-backend.c     | 15 +++++++++++++++
 blockdev.c                | 13 -------------
 include/sysemu/blockdev.h |  1 -
 stubs/Makefile.objs       |  1 -
 stubs/blockdev.c          | 12 ------------
 5 files changed, 15 insertions(+), 27 deletions(-)
 delete mode 100644 stubs/blockdev.c
block/block-backend.c +15 -0
index 9ee57c7..be9acda 100644
@@ -22,6 +22,8 @@ struct BlockBackend {
     QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
 };
 
+static void drive_info_del(DriveInfo *dinfo);
+
 /* All the BlockBackends (except for hidden ones) */
 static QTAILQ_HEAD(, BlockBackend) blk_backends =
     QTAILQ_HEAD_INITIALIZER(blk_backends);
@@ -93,6 +95,19 @@ static void blk_delete(BlockBackend *blk)
     g_free(blk);
 }
 
+static void drive_info_del(DriveInfo *dinfo)
+{
+    if (!dinfo) {
+        return;
+    }
+    if (dinfo->opts) {
+        qemu_opts_del(dinfo->opts);
+    }
+    g_free(dinfo->id);
+    g_free(dinfo->serial);
+    g_free(dinfo);
+}
+
 /*
  * Increment @blk's reference count.
  * @blk must not be null.
blockdev.c +0 -13
index 722d083..1c97faa 100644
@@ -223,19 +223,6 @@ void drive_del(DriveInfo *dinfo)
     blk_unref(blk_by_legacy_dinfo(dinfo));
 }
 
-void drive_info_del(DriveInfo *dinfo)
-{
-    if (!dinfo) {
-        return;
-    }
-    if (dinfo->opts) {
-        qemu_opts_del(dinfo->opts);
-    }
-    g_free(dinfo->id);
-    g_free(dinfo->serial);
-    g_free(dinfo);
-}
-
 typedef struct {
     QEMUBH *bh;
     BlockDriverState *bs;
include/sysemu/blockdev.h +0 -1
index 1dc5906..2ed297b 100644
@@ -60,7 +60,6 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
 DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
 void drive_del(DriveInfo *dinfo);
-void drive_info_del(DriveInfo *dinfo);
 
 /* device-hotplug */
 
stubs/Makefile.objs +0 -1
index c0b1f6a..5e347d0 100644
@@ -1,6 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
 stub-obj-y += bdrv-commit-all.o
-stub-obj-y += blockdev.o
 stub-obj-y += chr-baum-init.o
 stub-obj-y += chr-msmouse.o
 stub-obj-y += chr-testdev.o
stubs/blockdev.c deleted +0 -12
deleted file mode 100644
index 5d0a79c..0000000
@@ -1,12 +0,0 @@
-#include <assert.h>
-#include "sysemu/blockdev.h"
-
-DriveInfo *drive_get_by_blockdev(BlockDriverState *bs)
-{
-    return NULL;
-}
-
-void drive_info_del(DriveInfo *dinfo)
-{
-    assert(!dinfo);
-}
Signature · 1 line
1.9.3
Reviewed-by on v3 5/23
#27 lore raw

Re: [Qemu-devel] [PATCH v3 05/23] block: Code motion to get rid of stubs/blockdev.c

Quoted 10 lines · Markus Armbruster
---
  block/block-backend.c     | 15 +++++++++++++++
  blockdev.c                | 13 -------------
  include/sysemu/blockdev.h |  1 -
  stubs/Makefile.objs       |  1 -
  stubs/blockdev.c          | 12 ------------
  5 files changed, 15 insertions(+), 27 deletions(-)

delete mode 100644 stubs/blockdev.c

#29 lore raw

PATCH v3 6/23 block: Make BlockBackend own its BlockDriverState

In reply to Markus Armbruster

On BlockBackend destruction, unref its BlockDriverState. Replaces the callers' unrefs.

---
 block/block-backend.c |  6 ++----
 blockdev.c            |  8 ++------
 hw/block/xen_disk.c   |  6 +++---
 qemu-img.c            | 35 +----------------------------------
 qemu-io.c             |  5 -----
 qemu-nbd.c            |  1 -
 6 files changed, 8 insertions(+), 53 deletions(-)
block/block-backend.c +2 -4
index be9acda..ed4873e 100644
@@ -54,8 +54,6 @@ BlockBackend *blk_new(const char *name, Error **errp)
 
 /*
  * Create a new BlockBackend with a new BlockDriverState attached.
- * Both have a reference count of one.  Caller owns *both* references.
- * TODO Let caller own only the BlockBackend reference
  * Otherwise just like blk_new(), which see.
  */
 BlockBackend *blk_new_with_bs(const char *name, Error **errp)
@@ -83,7 +81,9 @@ static void blk_delete(BlockBackend *blk)
 {
     assert(!blk->refcnt);
     if (blk->bs) {
+        assert(blk->bs->blk == blk);
         blk->bs->blk = NULL;
+        bdrv_unref(blk->bs);
         blk->bs = NULL;
     }
     /* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */
@@ -121,8 +121,6 @@ void blk_ref(BlockBackend *blk)
  * Decrement @blk's reference count.
  * If this drops it to zero, destroy @blk.
  * For convenience, do nothing if @blk is null.
- * Does *not* touch the attached BlockDriverState's reference count.
- * TODO Decrement it!
  */
 void blk_unref(BlockBackend *blk)
 {
blockdev.c +2 -6
index 1c97faa..3a6fd46 100644
@@ -108,7 +108,7 @@ void blockdev_auto_del(BlockDriverState *bs)
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && dinfo->auto_del) {
-        drive_del(dinfo);
+        blk_unref(blk);
     }
 }
 
@@ -219,7 +219,6 @@ static void bdrv_format_print(void *opaque, const char *name)
 
 void drive_del(DriveInfo *dinfo)
 {
-    bdrv_unref(dinfo->bdrv);
     blk_unref(blk_by_legacy_dinfo(dinfo));
 }
 
@@ -522,7 +521,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     return blk;
 
 err:
-    bdrv_unref(bs);
     blk_unref(blk);
 early_err:
     qemu_opts_del(opts);
@@ -1782,9 +1780,8 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         /* Further I/O must not pause the guest */
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
-        /* FIXME bs->blk leaked when bs dies */
     } else {
-        drive_del(dinfo);
+        blk_unref(blk);
     }
 
     aio_context_release(aio_context);
@@ -2521,7 +2518,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
     }
 
     if (bdrv_key_required(blk_bs(blk))) {
-        bdrv_unref(blk_bs(blk));
         blk_unref(blk);
         error_setg(errp, "blockdev-add doesn't support encrypted devices");
         goto fail;
hw/block/xen_disk.c +3 -3
index 0022083..feb227f 100644
@@ -872,7 +872,6 @@ static int blk_connect(struct XenDevice *xendev)
             xen_be_printf(&blkdev->xendev, 0, "error: %s\n",
                           error_get_pretty(local_err));
             error_free(local_err);
-            bdrv_unref(blkdev->bs);
             blk_unref(blk);
             blkdev->bs = NULL;
             return -1;
@@ -888,7 +887,9 @@ static int blk_connect(struct XenDevice *xendev)
         }
         /* blkdev->bs is not create by us, we get a reference
          * so we can bdrv_unref() unconditionally */
-        bdrv_ref(blkdev->bs);
+        /* Except we don't bdrv_unref() anymore, we blk_unref().
+         * Conditionally, because we can't easily blk_ref() here.
+         * TODO Clean this up! */
     }
     bdrv_attach_dev_nofail(blkdev->bs, blkdev);
     blkdev->file_size = bdrv_getlength(blkdev->bs);
@@ -988,7 +989,6 @@ static void blk_disconnect(struct XenDevice *xendev)
 
     if (blkdev->bs) {
         bdrv_detach_dev(blkdev->bs, blkdev);
-        bdrv_unref(blkdev->bs);
         if (!blkdev->dinfo) {
             blk_unref(blk_by_name(blkdev->dev));
         }
qemu-img.c +1 -34
index 206a513..40bd129 100644
@@ -329,7 +329,6 @@ static BlockBackend *img_open(const char *id, const char *filename,
     }
     return blk;
 fail:
-    bdrv_unref(bs);
     blk_unref(blk);
     return NULL;
 }
@@ -712,9 +711,7 @@ static int img_check(int argc, char **argv)
 
 fail:
     qapi_free_ImageCheck(check);
-    bdrv_unref(bs);
     blk_unref(blk);
-
     return ret;
 }
 
@@ -786,7 +783,6 @@ static int img_commit(int argc, char **argv)
         break;
     }
 
-    bdrv_unref(bs);
     blk_unref(blk);
     if (ret) {
         return 1;
@@ -1196,10 +1192,8 @@ static int img_compare(int argc, char **argv)
 out:
     qemu_vfree(buf1);
     qemu_vfree(buf2);
-    bdrv_unref(bs2);
     blk_unref(blk2);
 out2:
-    bdrv_unref(bs1);
     blk_unref(blk1);
 out3:
     qemu_progress_end();
@@ -1756,18 +1750,8 @@ out:
     if (sn_opts) {
         qemu_opts_del(sn_opts);
     }
-    if (out_bs) {
-        bdrv_unref(out_bs);
-    }
     blk_unref(out_blk);
-    if (bs) {
-        for (bs_i = 0; bs_i < bs_n; bs_i++) {
-            if (bs[bs_i]) {
-                bdrv_unref(bs[bs_i]);
-            }
-        }
-        g_free(bs);
-    }
+    g_free(bs);
     if (blk) {
         for (bs_i = 0; bs_i < bs_n; bs_i++) {
             blk_unref(blk[bs_i]);
@@ -1905,7 +1889,6 @@ static ImageInfoList *collect_image_info_list(const char *filename,
         if (err) {
             error_report("%s", error_get_pretty(err));
             error_free(err);
-            bdrv_unref(bs);
             blk_unref(blk);
             goto err;
         }
@@ -1915,7 +1898,6 @@ static ImageInfoList *collect_image_info_list(const char *filename,
         *last = elem;
         last = &elem->next;
 
-        bdrv_unref(bs);
         blk_unref(blk);
 
         filename = fmt = NULL;
@@ -2204,7 +2186,6 @@ static int img_map(int argc, char **argv)
     dump_map_entry(output_format, &curr, NULL);
 
 out:
-    bdrv_unref(bs);
     blk_unref(blk);
     return ret < 0;
 }
@@ -2329,7 +2310,6 @@ static int img_snapshot(int argc, char **argv)
     }
 
     /* Cleanup */
-    bdrv_unref(bs);
     blk_unref(blk);
     if (ret) {
         return 1;
@@ -2649,17 +2629,10 @@ out:
     qemu_progress_end();
     /* Cleanup */
     if (!unsafe) {
-        if (bs_old_backing != NULL) {
-            bdrv_unref(bs_old_backing);
-        }
         blk_unref(blk_old_backing);
-        if (bs_new_backing != NULL) {
-            bdrv_unref(bs_new_backing);
-        }
         blk_unref(blk_new_backing);
     }
 
-    bdrv_unref(bs);
     blk_unref(blk);
     if (ret) {
         return 1;
@@ -2785,9 +2758,6 @@ static int img_resize(int argc, char **argv)
         break;
     }
 out:
-    if (bs) {
-        bdrv_unref(bs);
-    }
     blk_unref(blk);
     if (ret) {
         return 1;
@@ -2899,9 +2869,6 @@ static int img_amend(int argc, char **argv)
     }
 
 out:
-    if (bs) {
-        bdrv_unref(bs);
-    }
     blk_unref(blk);
     qemu_opts_del(opts);
     qemu_opts_free(create_opts);
qemu-io.c +0 -5
index ef1d3ea..45e8167 100644
@@ -38,7 +38,6 @@ static ReadLineState *readline_state;
 
 static int close_f(BlockDriverState *bs, int argc, char **argv)
 {
-    bdrv_unref(bs);
     blk_unref(qemuio_blk);
     qemuio_bs = NULL;
     qemuio_blk = NULL;
@@ -74,7 +73,6 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
                 name ? " device " : "", name ?: "",
                 error_get_pretty(local_err));
         error_free(local_err);
-        bdrv_unref(qemuio_bs);
         blk_unref(qemuio_blk);
         qemuio_bs = NULL;
         qemuio_blk = NULL;
@@ -483,9 +481,6 @@ int main(int argc, char **argv)
      */
     bdrv_drain_all();
 
-    if (qemuio_bs) {
-        bdrv_unref(qemuio_bs);
-    }
     blk_unref(qemuio_blk);
     g_free(readline_state);
     return 0;
qemu-nbd.c +0 -1
index 24808e8..c973569 100644
@@ -771,7 +771,6 @@ int main(int argc, char **argv)
         }
     } while (state != TERMINATED);
 
-    bdrv_unref(bs);
     blk_unref(blk);
     if (sockpath) {
         unlink(sockpath);
Signature · 1 line
1.9.3
Reviewed-by on v3 6/23
#30 lore raw

Re: [Qemu-devel] [PATCH v3 06/23] block: Make BlockBackend own its BlockDriverState

Quoted 4 lines · Markus Armbruster

On BlockBackend destruction, unref its BlockDriverState. Replaces the callers' unrefs.

Quoted 8 lines
---
  block/block-backend.c |  6 ++----
  blockdev.c            |  8 ++------
  hw/block/xen_disk.c   |  6 +++---
  qemu-img.c            | 35 +----------------------------------
  qemu-io.c             |  5 -----
  qemu-nbd.c            |  1 -
  6 files changed, 8 insertions(+), 53 deletions(-)
Reviewed-by on v3 6/23
#31 lore raw

Re: [Qemu-devel] [PATCH v3 06/23] block: Make BlockBackend own its BlockDriverState

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 75 lines

On BlockBackend destruction, unref its BlockDriverState. Replaces the callers' unrefs.

---
 block/block-backend.c |  6 ++----
 blockdev.c            |  8 ++------
 hw/block/xen_disk.c   |  6 +++---
 qemu-img.c            | 35 +----------------------------------
 qemu-io.c             |  5 -----
 qemu-nbd.c            |  1 -
 6 files changed, 8 insertions(+), 53 deletions(-)
block/block-backend.c +2 -4
index be9acda..ed4873e 100644
@@ -54,8 +54,6 @@ BlockBackend *blk_new(const char *name, Error **errp)
 
 /*
  * Create a new BlockBackend with a new BlockDriverState attached.
- * Both have a reference count of one.  Caller owns *both* references.
- * TODO Let caller own only the BlockBackend reference
  * Otherwise just like blk_new(), which see.
  */
 BlockBackend *blk_new_with_bs(const char *name, Error **errp)
@@ -83,7 +81,9 @@ static void blk_delete(BlockBackend *blk)
 {
     assert(!blk->refcnt);
     if (blk->bs) {
+        assert(blk->bs->blk == blk);
         blk->bs->blk = NULL;
+        bdrv_unref(blk->bs);
         blk->bs = NULL;
     }
     /* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */
@@ -121,8 +121,6 @@ void blk_ref(BlockBackend *blk)
  * Decrement @blk's reference count.
  * If this drops it to zero, destroy @blk.
  * For convenience, do nothing if @blk is null.
- * Does *not* touch the attached BlockDriverState's reference count.
- * TODO Decrement it!
  */
 void blk_unref(BlockBackend *blk)
 {
blockdev.c +1 -3
index 1c97faa..3a6fd46 100644
@@ -108,7 +108,7 @@ void blockdev_auto_del(BlockDriverState *bs)
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && dinfo->auto_del) {
-        drive_del(dinfo);
+        blk_unref(blk);
     }
 }
 
@@ -219,7 +219,6 @@ static void bdrv_format_print(void *opaque, const char *name)
 
 void drive_del(DriveInfo *dinfo)
 {
-    bdrv_unref(dinfo->bdrv);
     blk_unref(blk_by_legacy_dinfo(dinfo));
 }
 
@@ -522,7 +521,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     return blk;
 
 err:
-    bdrv_unref(bs);
     blk_unref(blk);
 early_err:
     qemu_opts_del(opts);

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1785

Quoted 4 lines
blockdev.c +0 -1
@@ -1782,9 +1780,8 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         /* Further I/O must not pause the guest */
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
-        /* FIXME bs->blk leaked when bs dies */

Which hunk of the patch fixes this? I can't see a new blk_unref() anywhere.

Hm, rereading this before sending the mail out, I think what this comment was intended for is already fixed in patch 4. I'll leave my original thoughts here anyway because they are about an independent problem:

I never completely understood where this anonymous BDS gets freed eventually. It only occurs to me now that this is probably because it doesn't? The original commit (d22b2f41) doesn't mention how this was intended to work.

In some cases (and this may cover all of the original cases) the autodel behaviour might actually happen to free it when the device is gone. But if the BDS was created with blockdev-add, it certainly isn't (that would be a bug introduced by my blockdev-add series). If there is any non-hotpluggable device that doesn't call blockdev_mark_auto_del() in its unrealize function, it also isn't freed for that device.

Can we make this whole mechanism more obvious eventually by getting a user/monitor reference only for blockdev-add, but not for -drive, and getting a second reference for devices that use the BB?

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1787

Quoted 6 lines
blockdev.c +1 -1
     } else {
-        drive_del(dinfo);
+        blk_unref(blk);
     }
 
     aio_context_release(aio_context);

Looks like I once again found questions that took me a lot of time to investigate and perhaps even a bug, but it doesn't look like a bug in this patch. Feel free to add:

Kevin

#32 lore raw

Re: [Qemu-devel] [PATCH v3 06/23] block: Make BlockBackend own its BlockDriverState

Quoted 84 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 75 lines

On BlockBackend destruction, unref its BlockDriverState. Replaces the callers' unrefs.

---
 block/block-backend.c |  6 ++----
 blockdev.c            |  8 ++------
 hw/block/xen_disk.c   |  6 +++---
 qemu-img.c            | 35 +----------------------------------
 qemu-io.c             |  5 -----
 qemu-nbd.c            |  1 -
 6 files changed, 8 insertions(+), 53 deletions(-)
block/block-backend.c +2 -4
index be9acda..ed4873e 100644
@@ -54,8 +54,6 @@ BlockBackend *blk_new(const char *name, Error **errp)
 
 /*
  * Create a new BlockBackend with a new BlockDriverState attached.
- * Both have a reference count of one.  Caller owns *both* references.
- * TODO Let caller own only the BlockBackend reference
  * Otherwise just like blk_new(), which see.
  */
 BlockBackend *blk_new_with_bs(const char *name, Error **errp)
@@ -83,7 +81,9 @@ static void blk_delete(BlockBackend *blk)
 {
     assert(!blk->refcnt);
     if (blk->bs) {
+        assert(blk->bs->blk == blk);
         blk->bs->blk = NULL;
+        bdrv_unref(blk->bs);
         blk->bs = NULL;
     }
     /* Avoid double-remove after blk_hide_on_behalf_of_do_drive_del() */
@@ -121,8 +121,6 @@ void blk_ref(BlockBackend *blk)
  * Decrement @blk's reference count.
  * If this drops it to zero, destroy @blk.
  * For convenience, do nothing if @blk is null.
- * Does *not* touch the attached BlockDriverState's reference count.
- * TODO Decrement it!
  */
 void blk_unref(BlockBackend *blk)
 {
blockdev.c +1 -3
index 1c97faa..3a6fd46 100644
@@ -108,7 +108,7 @@ void blockdev_auto_del(BlockDriverState *bs)
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && dinfo->auto_del) {
-        drive_del(dinfo);
+        blk_unref(blk);
     }
 }
 
@@ -219,7 +219,6 @@ static void bdrv_format_print(void *opaque, const char *name)
 
 void drive_del(DriveInfo *dinfo)
 {
-    bdrv_unref(dinfo->bdrv);
     blk_unref(blk_by_legacy_dinfo(dinfo));
 }
 
@@ -522,7 +521,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     return blk;
 
 err:
-    bdrv_unref(bs);
     blk_unref(blk);
 early_err:
     qemu_opts_del(opts);

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1785

Quoted 4 lines
blockdev.c +0 -1
@@ -1782,9 +1780,8 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         /* Further I/O must not pause the guest */
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
-        /* FIXME bs->blk leaked when bs dies */

Which hunk of the patch fixes this? I can't see a new blk_unref() anywhere.

Quoted 2 lines

Hm, rereading this before sending the mail out, I think what this comment was intended for is already fixed in patch 4.

Yes, here:

@@ -218,6 +220,7 @@ static void bdrv_format_print(void *opaque, const char *name)
void drive_del(DriveInfo *dinfo)

 {
     bdrv_unref(dinfo->bdrv);

+ blk_unref(blk_by_legacy_dinfo(dinfo));
}

I'll amend PATCH 04 to drop the FIXME.

Quoted 8 lines

I'll leave my
original thoughts here anyway because they are about an independent problem:

I never completely understood where this anonymous BDS gets freed eventually. It only occurs to me now that this is probably because it doesn't? The original commit (d22b2f41) doesn't mention how this was intended to work.

We discussed how this works in the context of your review of [PATCH v1 02]. Quoting myself:

Commit 9063f81 makes drive_del immediately destroy the root BDS. Nice:
the device name becomes available for reuse immediately. Not so nice:
the device model's pointer to the root BDS dangles, and we're prone to crash when the memory gets reused.

Commit d22b2f4 fixed that by hiding the root BDS instead of destroying it. Destruction only happens on unplug. "Hiding" means removing it from bdrv_states and graph_bdrv_states; see bdrv_make_anon().

Quoted 2 lines

In some cases (and this may cover all of the original cases) the autodel behaviour might actually happen to free it when the device is gone.

Yes.

Quoted 3 lines

But
if the BDS was created with blockdev-add, it certainly isn't (that would be a bug introduced by my blockdev-add series).

"Fixed" by my commit 48f364d "blockdev: Refuse to drive_del something added with blockdev-add" :)

The plan is to have separate commands to revoke guest access to a backend, and to delete an otherwise unused backend. Then we deprecate drive_del.

Quoted 2 lines

If there is any
non-hotpluggable device that doesn't call blockdev_mark_auto_del() in

You mean hot-pluggable. Same as unpluggable.

Quoted 1 line

its unrealize function, it also isn't freed for that device.

Yes.

Commit 14bafc5 added blockdev_mark_auto_del(), and made all unpluggable block device models call it: scsi-disk, scsi-generic, virtio-blk-pci. It has since moved from virtio-blk-pci to virtio-blk-device (where it also covers the other virtio-blk-FOO), and spread to related device models scsi-block, scsi-cd, scsi-hd.

I searched for additional unpluggable block device models, and found just one: nvme. No blockdev_mark_auto_del(), thus doesn't auto-delete its backend on unplug.

Could be delared a feature. Mind, the whole auto-delete crap is just for backward compatibility, which doesn't apply to new devices. But perhaps wewant to have new devices auto-delete anyway, for consistency's sake.

If we do, then the need to call blockdev_mark_auto_del() is a trap. Doing without isn't easy, because the backend is to be destroyed only after unplug, *not* when device_add fails. Implemented like this:
release_drive() before blockdev_mark_auto_del() must be device_add failure (no delete), afterwards it must be unplug (delete unless created by blockdev-add).

Quoted 3 lines

Can we make this whole mechanism more obvious eventually by getting a user/monitor reference only for blockdev-add, but not for -drive, and getting a second reference for devices that use the BB?

Doing this with reference counts would certainly be much nicer. One reason for PATCH 23.

Quoted 5 lines
Quoted 5 lines
blockdev.c +1 -1
     } else {
-        drive_del(dinfo);
+        blk_unref(blk);
     }
 
Quoted 7 lines

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1787

Quoted 1 line
blockdev.c +0 -0
     aio_context_release(aio_context);

Looks like I once again found questions that took me a lot of time to investigate and perhaps even a bug, but it doesn't look like a bug in this patch. Feel free to add:

Thanks!

Take heart, the hairiest part of this series (in my reckoning) ends here.

#33 lore raw

PATCH v3 7/23 block: Eliminate bdrv_iterate(), use bdrv_next()

In reply to Markus Armbruster
---
 block-migration.c     | 30 +++++++++++++++---------------
 block.c               |  9 ---------
 blockdev.c            | 31 +++++++++++++------------------
 include/block/block.h |  2 --
 monitor.c             | 32 +++++++++-----------------------
 5 files changed, 37 insertions(+), 67 deletions(-)
block-migration.c +15 -15
index 3ad31a2..cb3e16c 100644
@@ -343,12 +343,25 @@ static void unset_dirty_tracking(void)
     }
 }
 
-static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
+static void init_blk_migration(QEMUFile *f)
 {
+    BlockDriverState *bs;
     BlkMigDevState *bmds;
     int64_t sectors;
 
-    if (!bdrv_is_read_only(bs)) {
+    block_mig_state.submitted = 0;
+    block_mig_state.read_done = 0;
+    block_mig_state.transferred = 0;
+    block_mig_state.total_sector_sum = 0;
+    block_mig_state.prev_progress = -1;
+    block_mig_state.bulk_completed = 0;
+    block_mig_state.zero_blocks = migrate_zero_blocks();
+
+    for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
+        if (bdrv_is_read_only(bs)) {
+            continue;
+        }
+
         sectors = bdrv_nb_sectors(bs);
         if (sectors <= 0) {
             return;
@@ -378,19 +391,6 @@ static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
     }
 }
 
-static void init_blk_migration(QEMUFile *f)
-{
-    block_mig_state.submitted = 0;
-    block_mig_state.read_done = 0;
-    block_mig_state.transferred = 0;
-    block_mig_state.total_sector_sum = 0;
-    block_mig_state.prev_progress = -1;
-    block_mig_state.bulk_completed = 0;
-    block_mig_state.zero_blocks = migrate_zero_blocks();
-
-    bdrv_iterate(init_blk_migration_it, NULL);
-}
-
 /* Called with no lock taken.  */
 
 static int blk_mig_save_bulked_block(QEMUFile *f)
block.c +0 -9
index 5f7dc45..50ccafd 100644
@@ -3899,15 +3899,6 @@ BlockDriverState *bdrv_next(BlockDriverState *bs)
     return QTAILQ_NEXT(bs, device_list);
 }
 
-void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void *opaque)
-{
-    BlockDriverState *bs;
-
-    QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
-        it(opaque, bs);
-    }
-}
-
 const char *bdrv_get_device_name(BlockDriverState *bs)
 {
     return bs->device_name;
blockdev.c +13 -18
index 3a6fd46..85f574b 100644
@@ -2527,26 +2527,21 @@ fail:
     qmp_output_visitor_cleanup(ov);
 }
 
-static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
-{
-    BlockJobInfoList **prev = opaque;
-    BlockJob *job = bs->job;
-
-    if (job) {
-        BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1);
-        elem->value = block_job_query(bs->job);
-        (*prev)->next = elem;
-        *prev = elem;
-    }
-}
-
 BlockJobInfoList *qmp_query_block_jobs(Error **errp)
 {
-    /* Dummy is a fake list element for holding the head pointer */
-    BlockJobInfoList dummy = {};
-    BlockJobInfoList *prev = &dummy;
-    bdrv_iterate(do_qmp_query_block_jobs_one, &prev);
-    return dummy.next;
+    BlockJobInfoList *head = NULL, **p_next = &head;
+    BlockDriverState *bs;
+
+    for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
+        if (bs->job) {
+            BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1);
+            elem->value = block_job_query(bs->job);
+            *p_next = elem;
+            p_next = &elem->next;
+        }
+    }
+
+    return head;
 }
 
 QemuOptsList qemu_common_drive_opts = {
include/block/block.h +0 -2
index 8cf953a..02cf956 100644
@@ -410,8 +410,6 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
                                  Error **errp);
 bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base);
 BlockDriverState *bdrv_next(BlockDriverState *bs);
-void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
-                  void *opaque);
 int bdrv_is_encrypted(BlockDriverState *bs);
 int bdrv_key_required(BlockDriverState *bs);
 int bdrv_set_key(BlockDriverState *bs, const char *key);
monitor.c +9 -23
index 667efb7..7e450ec 100644
@@ -4208,24 +4208,6 @@ static void file_completion(Monitor *mon, const char *input)
     closedir(ffs);
 }
 
-typedef struct MonitorBlockComplete {
-    Monitor *mon;
-    const char *input;
-} MonitorBlockComplete;
-
-static void block_completion_it(void *opaque, BlockDriverState *bs)
-{
-    const char *name = bdrv_get_device_name(bs);
-    MonitorBlockComplete *mbc = opaque;
-    Monitor *mon = mbc->mon;
-    const char *input = mbc->input;
-
-    if (input[0] == '\0' ||
-        !strncmp(name, (char *)input, strlen(input))) {
-        readline_add_completion(mon->rs, name);
-    }
-}
-
 static const char *next_arg_type(const char *typestr)
 {
     const char *p = strchr(typestr, ':');
@@ -4663,9 +4645,9 @@ static void monitor_find_completion_by_table(Monitor *mon,
 {
     const char *cmdname;
     int i;
-    const char *ptype, *str;
+    const char *ptype, *str, *name;
     const mon_cmd_t *cmd;
-    MonitorBlockComplete mbs;
+    BlockDriverState *bs;
 
     if (nb_args <= 1) {
         /* command completion */
@@ -4717,10 +4699,14 @@ static void monitor_find_completion_by_table(Monitor *mon,
             break;
         case 'B':
             /* block device name completion */
-            mbs.mon = mon;
-            mbs.input = str;
             readline_set_completion_index(mon->rs, strlen(str));
-            bdrv_iterate(block_completion_it, &mbs);
+            for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
+                name = bdrv_get_device_name(bs);
+                if (str[0] == '\0' ||
+                    !strncmp(name, str, strlen(str))) {
+                    readline_add_completion(mon->rs, name);
+                }
+            }
             break;
         case 's':
         case 'S':
Signature · 1 line
1.9.3
Reviewed-by on v3 7/23
#34 lore raw

Re: [Qemu-devel] [PATCH v3 07/23] block: Eliminate bdrv_iterate(), use bdrv_next()

Quoted 9 lines · Markus Armbruster
---
  block-migration.c     | 30 +++++++++++++++---------------
  block.c               |  9 ---------
  blockdev.c            | 31 +++++++++++++------------------
  include/block/block.h |  2 --
  monitor.c             | 32 +++++++++-----------------------
  5 files changed, 37 insertions(+), 67 deletions(-)
#36 lore raw

PATCH v3 8/23 block: Eliminate BlockDriverState member device_name[]

In reply to Markus Armbruster

device_name[] can become non-empty only in bdrv_new_root() and bdrv_move_feature_fields(). The latter is used only to undo damage done by bdrv_swap(). The former is called only by blk_new_with_bs(). Therefore, when a BlockDriverState's device_name[] is non-empty, then it's been created with a BlockBackend, and vice versa. Furthermore, blk_new_with_bs() keeps the two names equal.

Therefore, device_name[] is redundant. Eliminate it.

---
 block-migration.c         | 12 ++++----
 block.c                   | 70 ++++++++++++++++++++---------------------------
 block/block-backend.c     | 14 ++++++----
 block/cow.c               |  2 +-
 block/mirror.c            |  3 +-
 block/qapi.c              |  6 ++--
 block/qcow.c              |  4 +--
 block/qcow2.c             |  4 +--
 block/qed.c               |  2 +-
 block/quorum.c            |  4 +--
 block/vdi.c               |  2 +-
 block/vhdx.c              |  2 +-
 block/vmdk.c              |  4 +--
 block/vpc.c               |  2 +-
 block/vvfat.c             |  2 +-
 blockjob.c                |  3 +-
 include/block/block.h     |  4 +--
 include/block/block_int.h |  2 --
 18 files changed, 67 insertions(+), 75 deletions(-)
block-migration.c +7 -5
index cb3e16c..da30e93 100644
@@ -14,7 +14,9 @@
  */
 
 #include "qemu-common.h"
-#include "block/block_int.h"
+#include "block/block.h"
+#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
 #include "hw/hw.h"
 #include "qemu/queue.h"
 #include "qemu/timer.h"
@@ -130,9 +132,9 @@ static void blk_send(QEMUFile *f, BlkMigBlock * blk)
                      | flags);
 
     /* device name */
-    len = strlen(blk->bmds->bs->device_name);
+    len = strlen(bdrv_get_device_name(blk->bmds->bs));
     qemu_put_byte(f, len);
-    qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
+    qemu_put_buffer(f, (uint8_t *)bdrv_get_device_name(blk->bmds->bs), len);
 
     /* if a block is zero we need to flush here since the network
      * bandwidth is now a lot higher than the storage device bandwidth.
@@ -382,9 +384,9 @@ static void init_blk_migration(QEMUFile *f)
 
         if (bmds->shared_base) {
             DPRINTF("Start migration for %s with shared base image\n",
-                    bs->device_name);
+                    bdrv_get_device_name(bs));
         } else {
-            DPRINTF("Start full migration for %s\n", bs->device_name);
+            DPRINTF("Start full migration for %s\n", bdrv_get_device_name(bs));
         }
 
         QSIMPLEQ_INSERT_TAIL(&block_mig_state.bmds_list, bmds, entry);
block.c +29 -41

177 lines not on this page · raw message

block/block-backend.c +8 -6
index ed4873e..f14a291 100644
@@ -61,17 +61,19 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)
     BlockBackend *blk;
     BlockDriverState *bs;
 
+    if (bdrv_find_node(name)) {
+        error_setg(errp,
+                   "Device name '%s' conflicts with an existing node name",
+                   name);
+        return NULL;
+    }
+
     blk = blk_new(name, errp);
     if (!blk) {
         return NULL;
     }
 
-    bs = bdrv_new_root(name, errp);
-    if (!bs) {
-        blk_unref(blk);
-        return NULL;
-    }
-
+    bs = bdrv_new_root();
     blk->bs = bs;
     bs->blk = blk;
     return blk;
block/cow.c +1 -1
index c3769fe..ff0d4ae 100644
@@ -84,7 +84,7 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,
         snprintf(version, sizeof(version),
                "COW version %" PRIu32, cow_header.version);
         error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-            bs->device_name, "cow", version);
+            bdrv_get_device_name(bs), "cow", version);
         ret = -ENOTSUP;
         goto fail;
     }
block/mirror.c +2 -1
index 18b18e0..829be2f 100644
@@ -567,7 +567,8 @@ static void mirror_complete(BlockJob *job, Error **errp)
         return;
     }
     if (!s->synced) {
-        error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name);
+        error_set(errp, QERR_BLOCK_JOB_NOT_READY,
+                  bdrv_get_device_name(job->bs));
         return;
     }
 
block/qapi.c +3 -3
index 9733ebd..d071ee5 100644
@@ -272,7 +272,7 @@ void bdrv_query_info(BlockDriverState *bs,
     BlockDriverState *bs0;
     ImageInfo **p_image_info;
     Error *local_err = NULL;
-    info->device = g_strdup(bs->device_name);
+    info->device = g_strdup(bdrv_get_device_name(bs));
     info->type = g_strdup("unknown");
     info->locked = bdrv_dev_is_medium_locked(bs);
     info->removable = bdrv_dev_has_removable_media(bs);
@@ -327,9 +327,9 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 
     s = g_malloc0(sizeof(*s));
 
-    if (bs->device_name[0]) {
+    if (bdrv_get_device_name(bs)[0]) {
         s->has_device = true;
-        s->device = g_strdup(bs->device_name);
+        s->device = g_strdup(bdrv_get_device_name(bs));
     }
 
     s->stats = g_malloc0(sizeof(*s->stats));
block/qcow.c +2 -2
index a87bd69..ece2269 100644
@@ -124,7 +124,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
         snprintf(version, sizeof(version), "QCOW version %" PRIu32,
                  header.version);
         error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-                  bs->device_name, "qcow", version);
+                  bdrv_get_device_name(bs), "qcow", version);
         ret = -ENOTSUP;
         goto fail;
     }
@@ -231,7 +231,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
     /* Disable migration when qcow images are used */
     error_set(&s->migration_blocker,
               QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "qcow", bs->device_name, "live migration");
+              "qcow", bdrv_get_device_name(bs), "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     qemu_co_mutex_init(&s->lock);
block/qcow2.c +2 -2
index 0daf25c..d5836bb 100644
@@ -204,8 +204,8 @@ static void GCC_FMT_ATTR(3, 4) report_unsupported(BlockDriverState *bs,
     vsnprintf(msg, sizeof(msg), fmt, ap);
     va_end(ap);
 
-    error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, bs->device_name, "qcow2",
-              msg);
+    error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
+              bdrv_get_device_name(bs), "qcow2", msg);
 }
 
 static void report_unsupported_feature(BlockDriverState *bs,
block/qed.c +1 -1
index f8d9e12..9181340 100644
@@ -422,7 +422,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
         snprintf(buf, sizeof(buf), "%" PRIx64,
             s->header.features & ~QED_FEATURE_MASK);
         error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-            bs->device_name, "QED", buf);
+            bdrv_get_device_name(bs), "QED", buf);
         return -ENOTSUP;
     }
     if (!qed_is_cluster_size_valid(s->header.cluster_size)) {
block/quorum.c +2 -2
index 093382e..f958269 100644
@@ -227,8 +227,8 @@ static void quorum_report_bad(QuorumAIOCB *acb, char *node_name, int ret)
 
 static void quorum_report_failure(QuorumAIOCB *acb)
 {
-    const char *reference = acb->common.bs->device_name[0] ?
-                            acb->common.bs->device_name :
+    const char *reference = bdrv_get_device_name(acb->common.bs)[0] ?
+                            bdrv_get_device_name(acb->common.bs) :
                             acb->common.bs->node_name;
 
     qapi_event_send_quorum_failure(reference, acb->sector_num,
block/vdi.c +1 -1
index cfa08b0..9604721 100644
@@ -490,7 +490,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
     /* Disable migration when vdi images are used */
     error_set(&s->migration_blocker,
               QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "vdi", bs->device_name, "live migration");
+              "vdi", bdrv_get_device_name(bs), "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
block/vhdx.c +1 -1
index 796b7bd..03b564e 100644
@@ -1003,7 +1003,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
     /* Disable migration when VHDX images are used */
     error_set(&s->migration_blocker,
             QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-            "vhdx", bs->device_name, "live migration");
+            "vhdx", bdrv_get_device_name(bs), "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
block/vmdk.c +2 -2
index afdea1a..811095b 100644
@@ -657,7 +657,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
         snprintf(buf, sizeof(buf), "VMDK version %" PRId32,
                  le32_to_cpu(header.version));
         error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-                  bs->device_name, "vmdk", buf);
+                  bdrv_get_device_name(bs), "vmdk", buf);
         return -ENOTSUP;
     } else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR)) {
         /* VMware KB 2064959 explains that version 3 added support for
@@ -939,7 +939,7 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
     /* Disable migration when VMDK images are used */
     error_set(&s->migration_blocker,
               QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "vmdk", bs->device_name, "live migration");
+              "vmdk", bdrv_get_device_name(bs), "live migration");
     migrate_add_blocker(s->migration_blocker);
     g_free(buf);
     return 0;
block/vpc.c +1 -1
index 4947369..cdc6896 100644
@@ -320,7 +320,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
     /* Disable migration when VHD images are used */
     error_set(&s->migration_blocker,
               QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "vpc", bs->device_name, "live migration");
+              "vpc", bdrv_get_device_name(bs), "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
block/vvfat.c +1 -1
index 6c9fde0..cefe3a4 100644
@@ -1182,7 +1182,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
     if (s->qcow) {
         error_set(&s->migration_blocker,
                   QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-                  "vvfat (rw)", bs->device_name, "live migration");
+                  "vvfat (rw)", bdrv_get_device_name(bs), "live migration");
         migrate_add_blocker(s->migration_blocker);
     }
 
blockjob.c +2 -1
index 0689fdd..3af0f6c 100644
@@ -107,7 +107,8 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
 void block_job_complete(BlockJob *job, Error **errp)
 {
     if (job->paused || job->cancelled || !job->driver->complete) {
-        error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name);
+        error_set(errp, QERR_BLOCK_JOB_NOT_READY,
+                  bdrv_get_device_name(job->bs));
         return;
     }
 
include/block/block.h +2 -2
index 02cf956..27d002d 100644
@@ -204,7 +204,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
 int bdrv_create(BlockDriver *drv, const char* filename,
                 QemuOpts *opts, Error **errp);
 int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
-BlockDriverState *bdrv_new_root(const char *device_name, Error **errp);
+BlockDriverState *bdrv_new_root(void);
 BlockDriverState *bdrv_new(void);
 void bdrv_make_anon(BlockDriverState *bs);
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
@@ -416,7 +416,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key);
 int bdrv_query_missing_keys(void);
 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
                          void *opaque);
-const char *bdrv_get_device_name(BlockDriverState *bs);
+const char *bdrv_get_device_name(const BlockDriverState *bs);
 int bdrv_get_flags(BlockDriverState *bs);
 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
                           const uint8_t *buf, int nb_sectors);
include/block/block_int.h +0 -2
index 14e0b7c..da00aa5 100644
@@ -392,8 +392,6 @@ struct BlockDriverState {
     char node_name[32];
     /* element of the list of named nodes building the graph */
     QTAILQ_ENTRY(BlockDriverState) node_list;
-    /* Device name is the name associated with the "drive" the guest sees */
-    char device_name[32];
     /* element of the list of "drives" the guest sees */
     QTAILQ_ENTRY(BlockDriverState) device_list;
     QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;
Signature · 1 line
1.9.3
Reviewed-by on v3 8/23
#37 lore raw

Re: [Qemu-devel] [PATCH v3 08/23] block: Eliminate BlockDriverState member device_name[]

Quoted 22 lines · Markus Armbruster

device_name[] can become non-empty only in bdrv_new_root() and bdrv_move_feature_fields(). The latter is used only to undo damage done by bdrv_swap(). The former is called only by blk_new_with_bs(). Therefore, when a BlockDriverState's device_name[] is non-empty, then it's been created with a BlockBackend, and vice versa. Furthermore, blk_new_with_bs() keeps the two names equal.

Therefore, device_name[] is redundant. Eliminate it.

---
  block-migration.c         | 12 ++++----
  block.c                   | 70 ++++++++++++++++++++---------------------------
  block/block-backend.c     | 14 ++++++----
  block/cow.c               |  2 +-
  block/mirror.c            |  3 +-
  block/qapi.c              |  6 ++--
  block/qcow.c              |  4 +--
  block/qcow2.c             |  4 +--
  block/qed.c               |  2 +-
  block/quorum.c            |  4 +--
  block/vdi.c               |  2 +-
Quoted 8 lines
  block/vhdx.c              |  2 +-
  block/vmdk.c              |  4 +--
  block/vpc.c               |  2 +-
  block/vvfat.c             |  2 +-
  blockjob.c                |  3 +-
  include/block/block.h     |  4 +--
  include/block/block_int.h |  2 --
  18 files changed, 67 insertions(+), 75 deletions(-)
Reviewed-by on v3 8/23
#38 lore raw

Re: [Qemu-devel] [PATCH v3 08/23] block: Eliminate BlockDriverState member device_name[]

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 10 lines

device_name[] can become non-empty only in bdrv_new_root() and bdrv_move_feature_fields(). The latter is used only to undo damage done by bdrv_swap(). The former is called only by blk_new_with_bs(). Therefore, when a BlockDriverState's device_name[] is non-empty, then it's been created with a BlockBackend, and vice versa. Furthermore, blk_new_with_bs() keeps the two names equal.

Therefore, device_name[] is redundant. Eliminate it.

#39 lore raw

PATCH v3 9/23 block: Merge BlockBackend and BlockDriverState name spaces

In reply to Markus Armbruster

BlockBackend's name space is separate only to keep the initial patches simple. Time to merge the two.

---
 block.c               | 11 +++--------
 block/block-backend.c | 13 ++++++-------
 2 files changed, 9 insertions(+), 15 deletions(-)
block.c +3 -8
index c3fa3da..f68f06c 100644
@@ -861,7 +861,7 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
     }
 
     /* takes care of avoiding namespaces collisions */
-    if (bdrv_find(node_name)) {
+    if (blk_by_name(node_name)) {
         error_setg(errp, "node-name=%s is conflicting with a device id",
                    node_name);
         return;
@@ -3795,14 +3795,9 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
 /* This function is to find block backend bs */
 BlockDriverState *bdrv_find(const char *name)
 {
-    BlockDriverState *bs;
+    BlockBackend *blk = blk_by_name(name);
 
-    QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
-        if (!strcmp(name, bdrv_get_device_name(bs))) {
-            return bs;
-        }
-    }
-    return NULL;
+    return blk ? blk_bs(blk) : NULL;
 }
 
 /* This function is to find a node in the bs graph */
block/block-backend.c +6 -7
index f14a291..7fd832d 100644
@@ -44,6 +44,12 @@ BlockBackend *blk_new(const char *name, Error **errp)
         error_setg(errp, "Device with id '%s' already exists", name);
         return NULL;
     }
+    if (bdrv_find_node(name)) {
+        error_setg(errp,
+                   "Device name '%s' conflicts with an existing node name",
+                   name);
+        return NULL;
+    }
 
     blk = g_new0(BlockBackend, 1);
     blk->name = g_strdup(name);
@@ -61,13 +67,6 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)
     BlockBackend *blk;
     BlockDriverState *bs;
 
-    if (bdrv_find_node(name)) {
-        error_setg(errp,
-                   "Device name '%s' conflicts with an existing node name",
-                   name);
-        return NULL;
-    }
-
     blk = blk_new(name, errp);
     if (!blk) {
         return NULL;
Signature · 1 line
1.9.3
Reviewed-by on v3 9/23
#40 lore raw

Re: [Qemu-devel] [PATCH v3 09/23] block: Merge BlockBackend and BlockDriverState name spaces

Quoted 9 lines · Markus Armbruster

BlockBackend's name space is separate only to keep the initial patches simple. Time to merge the two.

---
  block.c               | 11 +++--------
  block/block-backend.c | 13 ++++++-------
  2 files changed, 9 insertions(+), 15 deletions(-)
Reviewed-by on v3 9/23
#41 lore raw

Re: [Qemu-devel] [PATCH v3 09/23] block: Merge BlockBackend and BlockDriverState name spaces

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 5 lines

BlockBackend's name space is separate only to keep the initial patches simple. Time to merge the two.

#42 lore raw

PATCH v3 10/23 block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo()

In reply to Markus Armbruster

The patch is big, but all it really does is replacing

    dinfo->bdrv

by

blk_bs(blk_by_legacy_dinfo(dinfo))

The replacement is repetitive, but the conversion of device models to BlockBackend is imminent, and will shorten it to just blk_legacy_dinfo(dinfo).

Line wrapping muddies the waters a bit. I also omit tests whether dinfo->bdrv is null, because it never is.

---
 blockdev.c                               |  3 +--
 hw/arm/collie.c                          |  9 +++++----
 hw/arm/gumstix.c                         |  5 +++--
 hw/arm/mainstone.c                       |  8 ++++----
 hw/arm/musicpal.c                        | 11 ++++++-----
 hw/arm/nseries.c                         |  6 ++++--
 hw/arm/omap1.c                           |  4 +++-
 hw/arm/omap2.c                           |  4 +++-
 hw/arm/omap_sx1.c                        |  9 +++++----
 hw/arm/pxa2xx.c                          |  7 +++++--
 hw/arm/spitz.c                           |  4 +++-
 hw/arm/versatilepb.c                     |  4 +++-
 hw/arm/vexpress.c                        |  4 +++-
 hw/arm/virt.c                            |  4 +++-
 hw/arm/xilinx_zynq.c                     |  4 +++-
 hw/arm/z2.c                              |  7 ++++---
 hw/block/fdc.c                           | 16 +++++++++++-----
 hw/block/m25p80.c                        |  5 +++--
 hw/block/xen_disk.c                      |  2 +-
 hw/cris/axis_dev88.c                     |  3 ++-
 hw/display/tc6393xb.c                    |  4 +++-
 hw/i386/pc_sysfw.c                       |  3 ++-
 hw/ide/piix.c                            |  6 ++++--
 hw/ide/qdev.c                            |  4 +++-
 hw/isa/pc87312.c                         |  7 +++++--
 hw/lm32/lm32_boards.c                    | 13 +++++++------
 hw/lm32/milkymist.c                      |  7 ++++---
 hw/microblaze/petalogix_ml605_mmu.c      |  5 +++--
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  5 +++--
 hw/mips/mips_malta.c                     |  4 +++-
 hw/mips/mips_r4k.c                       |  5 +++--
 hw/pci/pci-hotplug-old.c                 |  9 ++++++---
 hw/ppc/ppc405_boards.c                   | 25 ++++++++++++++++---------
 hw/ppc/spapr.c                           |  4 +++-
 hw/ppc/virtex_ml507.c                    |  5 +++--
 hw/scsi/scsi-bus.c                       |  5 +++--
 hw/sd/milkymist-memcard.c                |  7 +++++--
 hw/sd/pl181.c                            |  3 ++-
 hw/sd/sdhci.c                            |  3 ++-
 hw/sd/ssi-sd.c                           |  3 ++-
 hw/sh4/r2d.c                             |  5 +++--
 hw/usb/dev-storage.c                     |  4 +++-
 hw/xtensa/xtfpga.c                       |  4 +++-
 include/sysemu/blockdev.h                |  1 -
 44 files changed, 166 insertions(+), 94 deletions(-)
blockdev.c +1 -2
index 85f574b..49496b6 100644
@@ -472,7 +472,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->id = g_strdup(qemu_opts_id(opts));
-    dinfo->bdrv = bs;
     blk_set_legacy_dinfo(blk, dinfo);
 
     if (!file || !*file) {
@@ -502,7 +501,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     QINCREF(bs_opts);
     ret = bdrv_open(&bs, file, NULL, bs_opts, bdrv_flags, drv, &error);
-    assert(bs == dinfo->bdrv);
+    assert(bs == blk_bs(blk));
 
     if (ret < 0) {
         error_setg(errp, "could not open disk image %s: %s",
hw/arm/collie.c +5 -4
index ed7851f..0247290 100644
@@ -15,6 +15,7 @@
 #include "strongarm.h"
 #include "hw/arm/arm.h"
 #include "hw/block/flash.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
@@ -41,13 +42,13 @@ static void collie_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x02000000,
-                    dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                    512, 4, 0x00, 0x00, 0x00, 0x00, 0);
+                    dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                    (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     dinfo = drive_get(IF_PFLASH, 0, 1);
     pflash_cfi01_register(SA_CS1, NULL, "collie.fl2", 0x02000000,
-                    dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                    512, 4, 0x00, 0x00, 0x00, 0x00, 0);
+                    dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                    (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     sysbus_create_simple("scoop", 0x40800000, NULL);
 
hw/arm/gumstix.c +3 -2
index 3f8465e..49f9339 100644
@@ -40,6 +40,7 @@
 #include "hw/block/flash.h"
 #include "hw/devices.h"
 #include "hw/boards.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
@@ -71,7 +72,7 @@ static void connex_init(MachineState *machine)
     be = 0;
 #endif
     if (!pflash_cfi01_register(0x00000000, NULL, "connext.rom", connex_rom,
-                               dinfo ? dinfo->bdrv : NULL,
+                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
                                sector_len, connex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
@@ -109,7 +110,7 @@ static void verdex_init(MachineState *machine)
     be = 0;
 #endif
     if (!pflash_cfi01_register(0x00000000, NULL, "verdex.rom", verdex_rom,
-                               dinfo ? dinfo->bdrv : NULL,
+                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
                                sector_len, verdex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
hw/arm/mainstone.c +4 -4
index 2f1d618..a4a25b5 100644
@@ -18,7 +18,7 @@
 #include "hw/devices.h"
 #include "hw/boards.h"
 #include "hw/block/flash.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
@@ -149,9 +149,9 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
         if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
                                    i ? "mainstone.flash1" : "mainstone.flash0",
                                    MAINSTONE_FLASH,
-                                   dinfo->bdrv, sector_len,
-                                   MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0,
-                                   be)) {
+                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   sector_len, MAINSTONE_FLASH / sector_len,
+                                   4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory.\n");
             exit(1);
         }
hw/arm/musicpal.c +6 -5
index c541455..77ad4eb 100644
@@ -22,6 +22,7 @@
 #include "hw/block/flash.h"
 #include "ui/console.h"
 #include "hw/i2c/i2c.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "ui/pixel_ops.h"
@@ -1632,7 +1633,9 @@ static void musicpal_init(MachineState *machine)
     /* Register flash */
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (dinfo) {
-        flash_size = bdrv_getlength(dinfo->bdrv);
+        BlockDriverState *bs = blk_bs(blk_by_legacy_dinfo(dinfo));
+
+        flash_size = bdrv_getlength(bs);
         if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 &&
             flash_size != 32*1024*1024) {
             fprintf(stderr, "Invalid flash image size\n");
@@ -1647,16 +1650,14 @@ static void musicpal_init(MachineState *machine)
 #ifdef TARGET_WORDS_BIGENDIAN
         pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
                               "musicpal.flash", flash_size,
-                              dinfo->bdrv, 0x10000,
-                              (flash_size + 0xffff) >> 16,
+                              bs, 0x10000, (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 1);
 #else
         pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
                               "musicpal.flash", flash_size,
-                              dinfo->bdrv, 0x10000,
-                              (flash_size + 0xffff) >> 16,
+                              bs, 0x10000, (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 0);
hw/arm/nseries.c +4 -2
index 4f092d6..2536078 100644
@@ -31,6 +31,7 @@
 #include "hw/hw.h"
 #include "hw/bt.h"
 #include "hw/loader.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
@@ -172,8 +173,9 @@ static void n8x0_nand_setup(struct n800_s *s)
     qdev_prop_set_uint16(s->nand, "version_id", 0);
     qdev_prop_set_int32(s->nand, "shift", 1);
     dinfo = drive_get(IF_MTD, 0, 0);
-    if (dinfo && dinfo->bdrv) {
-        qdev_prop_set_drive_nofail(s->nand, "drive", dinfo->bdrv);
+    if (dinfo) {
+        qdev_prop_set_drive_nofail(s->nand, "drive",
+                                   blk_bs(blk_by_legacy_dinfo(dinfo)));
     }
     qdev_init_nofail(s->nand);
     sysbus_connect_irq(SYS_BUS_DEVICE(s->nand), 0,
hw/arm/omap1.c +3 -1
index 306cf17..74dac49 100644
@@ -21,6 +21,7 @@
 #include "hw/arm/omap.h"
 #include "sysemu/sysemu.h"
 #include "hw/arm/soc_dma.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "qemu/range.h"
 #include "hw/sysbus.h"
@@ -3978,7 +3979,8 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
         fprintf(stderr, "qemu: missing SecureDigital device\n");
         exit(1);
     }
-    s->mmc = omap_mmc_init(0xfffb7800, system_memory, dinfo->bdrv,
+    s->mmc = omap_mmc_init(0xfffb7800, system_memory,
+                           blk_bs(blk_by_legacy_dinfo(dinfo)),
                            qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN),
                            &s->drq[OMAP_DMA_MMC_TX],
                     omap_findclk(s, "mmc_ck"));
hw/arm/omap2.c +3 -1
index d6e19ae..0b6a95e 100644
@@ -18,6 +18,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/hw.h"
 #include "hw/arm/arm.h"
@@ -2461,7 +2462,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
         fprintf(stderr, "qemu: missing SecureDigital device\n");
         exit(1);
     }
-    s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), dinfo->bdrv,
+    s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9),
+                    blk_bs(blk_by_legacy_dinfo(dinfo)),
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_MMC_IRQ),
                     &s->drq[OMAP24XX_DMA_MMC1_TX],
                     omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
hw/arm/omap_sx1.c +5 -4
index 320b39c..0a4e740 100644
@@ -31,6 +31,7 @@
 #include "hw/boards.h"
 #include "hw/arm/arm.h"
 #include "hw/block/flash.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/qtest.h"
 #include "exec/address-spaces.h"
@@ -154,8 +155,8 @@ static void sx1_init(MachineState *machine, const int version)
     if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
         if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
                                    "omap_sx1.flash0-1", flash_size,
-                                   dinfo->bdrv, sector_size,
-                                   flash_size / sector_size,
+                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   sector_size, flash_size / sector_size,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                            fl_idx);
@@ -178,8 +179,8 @@ static void sx1_init(MachineState *machine, const int version)
 
         if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
                                    "omap_sx1.flash1-1", flash1_size,
-                                   dinfo->bdrv, sector_size,
-                                   flash1_size / sector_size,
+                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   sector_size, flash1_size / sector_size,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                            fl_idx);
hw/arm/pxa2xx.c +5 -2
index 7d306fb..6b7abe1 100644
@@ -14,6 +14,7 @@
 #include "hw/i2c/i2c.h"
 #include "hw/ssi.h"
 #include "sysemu/char.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 
 static struct {
@@ -2085,7 +2086,8 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
         fprintf(stderr, "qemu: missing SecureDigital device\n");
         exit(1);
     }
-    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000, dinfo->bdrv,
+    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000,
+                    blk_bs(blk_by_legacy_dinfo(dinfo)),
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_MMC),
                     qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_MMCI),
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
@@ -2217,7 +2219,8 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)
         fprintf(stderr, "qemu: missing SecureDigital device\n");
         exit(1);
     }
-    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000, dinfo->bdrv,
+    s->mmc = pxa2xx_mmci_init(address_space, 0x41100000,
+                    blk_bs(blk_by_legacy_dinfo(dinfo)),
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_MMC),
                     qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_MMCI),
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
hw/arm/spitz.c +3 -1
index 9260896..ff12f9b 100644
@@ -25,6 +25,7 @@
 #include "block/block.h"
 #include "audio/audio.h"
 #include "hw/boards.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
@@ -170,7 +171,8 @@ static int sl_nand_init(SysBusDevice *dev)
 
     s->ctl = 0;
     nand = drive_get(IF_MTD, 0, 0);
-    s->nand = nand_init(nand ? nand->bdrv : NULL, s->manf_id, s->chip_id);
+    s->nand = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
+                        s->manf_id, s->chip_id);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &sl_ops, s, "sl", 0x40);
     sysbus_init_mmio(dev, &s->iomem);
hw/arm/versatilepb.c +3 -1
index 7696be1..2ff46b0 100644
@@ -15,6 +15,7 @@
 #include "hw/pci/pci.h"
 #include "hw/i2c/i2c.h"
 #include "hw/boards.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "hw/block/flash.h"
@@ -338,7 +339,8 @@ static void versatile_init(MachineState *machine, int board_id)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, NULL, "versatile.flash",
-                          VERSATILE_FLASH_SIZE, dinfo ? dinfo->bdrv : NULL,
+                          VERSATILE_FLASH_SIZE,
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
                           VERSATILE_FLASH_SECT_SIZE,
                           VERSATILE_FLASH_SIZE / VERSATILE_FLASH_SECT_SIZE,
                           4, 0x0089, 0x0018, 0x0000, 0x0, 0)) {
hw/arm/vexpress.c +3 -1
index aed218f..828228c 100644
@@ -30,6 +30,7 @@
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/block/flash.h"
 #include "sysemu/device_tree.h"
@@ -491,7 +492,8 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
 {
     DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
 
-    if (di && qdev_prop_set_drive(dev, "drive", di->bdrv)) {
+    if (di && qdev_prop_set_drive(dev, "drive",
+                                  blk_bs(blk_by_legacy_dinfo(di)))) {
         abort();
     }
 
hw/arm/virt.c +3 -1
index 8c6b171..e5fce2a 100644
@@ -33,6 +33,7 @@
 #include "hw/arm/primecell.h"
 #include "hw/devices.h"
 #include "net/net.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/device_tree.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
@@ -450,7 +451,8 @@ static void create_one_flash(const char *name, hwaddr flashbase,
     DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
     const uint64_t sectorlength = 256 * 1024;
 
-    if (dinfo && qdev_prop_set_drive(dev, "drive", dinfo->bdrv)) {
+    if (dinfo && qdev_prop_set_drive(dev, "drive",
+                                     blk_bs(blk_by_legacy_dinfo(dinfo)))) {
         abort();
     }
 
hw/arm/xilinx_zynq.c +3 -1
index ad85c7a..415344f 100644
@@ -22,6 +22,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/block/flash.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/loader.h"
 #include "hw/ssi.h"
@@ -164,7 +165,8 @@ static void zynq_init(MachineState *machine)
 
     /* AMD */
     pflash_cfi02_register(0xe2000000, NULL, "zynq.pflash", FLASH_SIZE,
-                          dinfo ? dinfo->bdrv : NULL, FLASH_SECTOR_SIZE,
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          FLASH_SECTOR_SIZE,
                           FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
                           1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa,
                               0);
hw/arm/z2.c +4 -3
index 36b3b50..9b38a2b 100644
@@ -20,6 +20,7 @@
 #include "hw/boards.h"
 #include "sysemu/sysemu.h"
 #include "hw/block/flash.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "ui/console.h"
 #include "audio/audio.h"
@@ -336,9 +337,9 @@ static void z2_init(MachineState *machine)
 
     if (!pflash_cfi01_register(Z2_FLASH_BASE,
                                NULL, "z2.flash0", Z2_FLASH_SIZE,
-                               dinfo ? dinfo->bdrv : NULL, sector_len,
-                               Z2_FLASH_SIZE / sector_len, 4, 0, 0, 0, 0,
-                               be)) {
+                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                               sector_len, Z2_FLASH_SIZE / sector_len,
+                               4, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
         exit(1);
     }
hw/block/fdc.c +11 -5
index 6c86a6b..666a4d5 100644
@@ -33,6 +33,7 @@
 #include "qemu/timer.h"
 #include "hw/isa/isa.h"
 #include "hw/sysbus.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/sysemu.h"
 #include "qemu/log.h"
@@ -2107,10 +2108,12 @@ ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds)
     dev = DEVICE(isadev);
 
     if (fds[0]) {
-        qdev_prop_set_drive_nofail(dev, "driveA", fds[0]->bdrv);
+        qdev_prop_set_drive_nofail(dev, "driveA",
+                                   blk_bs(blk_by_legacy_dinfo(fds[0])));
     }
     if (fds[1]) {
-        qdev_prop_set_drive_nofail(dev, "driveB", fds[1]->bdrv);
+        qdev_prop_set_drive_nofail(dev, "driveB",
+                                   blk_bs(blk_by_legacy_dinfo(fds[1])));
     }
     qdev_init_nofail(dev);
 
@@ -2130,10 +2133,12 @@ void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
     fdctrl = &sys->state;
     fdctrl->dma_chann = dma_chann; /* FIXME */
     if (fds[0]) {
-        qdev_prop_set_drive_nofail(dev, "driveA", fds[0]->bdrv);
+        qdev_prop_set_drive_nofail(dev, "driveA",
+                                   blk_bs(blk_by_legacy_dinfo(fds[0])));
     }
     if (fds[1]) {
-        qdev_prop_set_drive_nofail(dev, "driveB", fds[1]->bdrv);
+        qdev_prop_set_drive_nofail(dev, "driveB",
+                                   blk_bs(blk_by_legacy_dinfo(fds[1])));
     }
     qdev_init_nofail(dev);
     sbd = SYS_BUS_DEVICE(dev);
@@ -2149,7 +2154,8 @@ void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base,
 
     dev = qdev_create(NULL, "SUNW,fdtwo");
     if (fds[0]) {
-        qdev_prop_set_drive_nofail(dev, "drive", fds[0]->bdrv);
+        qdev_prop_set_drive_nofail(dev, "drive",
+                                   blk_bs(blk_by_legacy_dinfo(fds[0])));
     }
     qdev_init_nofail(dev);
     sys = SYSBUS_FDC(dev);
hw/block/m25p80.c +3 -2
index 5893773..78280a8 100644
@@ -22,6 +22,7 @@
  */
 
 #include "hw/hw.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/ssi.h"
 
@@ -624,9 +625,9 @@ static int m25p80_init(SSISlave *ss)
 
     dinfo = drive_get_next(IF_MTD);
 
-    if (dinfo && dinfo->bdrv) {
+    if (dinfo) {
         DB_PRINT_L(0, "Binding to IF_MTD drive\n");
-        s->bdrv = dinfo->bdrv;
+        s->bdrv = blk_bs(blk_by_legacy_dinfo(dinfo));
 
         /* FIXME: Move to late init */
         if (bdrv_read(s->bdrv, 0, s->storage, DIV_ROUND_UP(s->size,
hw/block/xen_disk.c +1 -1
index feb227f..ca4f855 100644
@@ -879,7 +879,7 @@ static int blk_connect(struct XenDevice *xendev)
     } else {
         /* setup via qemu cmdline -> already setup for us */
         xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
-        blkdev->bs = blkdev->dinfo->bdrv;
+        blkdev->bs = blk_bs(blk_by_legacy_dinfo(blkdev->dinfo));
         if (bdrv_is_read_only(blkdev->bs) && !readonly) {
             xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive");
             blkdev->bs = NULL;
hw/cris/axis_dev88.c +2 -1
index 2fb3aa8..417702a 100644
@@ -30,6 +30,7 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "boot.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
@@ -284,7 +285,7 @@ void axisdev88_init(MachineState *machine)
 
       /* Attach a NAND flash to CS1.  */
     nand = drive_get(IF_MTD, 0, 0);
-    nand_state.nand = nand_init(nand ? nand->bdrv : NULL,
+    nand_state.nand = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
                                 NAND_MFR_STMICRO, 0x39);
     memory_region_init_io(&nand_state.iomem, NULL, &nand_ops, &nand_state,
                           "nand", 0x05000000);
hw/display/tc6393xb.c +3 -1
index c19c055..576f319 100644
@@ -15,6 +15,7 @@
 #include "hw/block/flash.h"
 #include "ui/console.h"
 #include "ui/pixel_ops.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 
 #define IRQ_TC6393_NAND		0
@@ -576,7 +577,8 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq)
     s->sub_irqs = qemu_allocate_irqs(tc6393xb_sub_irq, s, TC6393XB_NR_IRQS);
 
     nand = drive_get(IF_MTD, 0, 0);
-    s->flash = nand_init(nand ? nand->bdrv : NULL, NAND_MFR_TOSHIBA, 0x76);
+    s->flash = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
+                         NAND_MFR_TOSHIBA, 0x76);
 
     memory_region_init_io(&s->iomem, NULL, &tc6393xb_ops, s, "tc6393xb", 0x10000);
     memory_region_add_subregion(sysmem, base, &s->iomem);
hw/i386/pc_sysfw.c +2 -1
index bbe367a..9bf22b6 100644
@@ -23,6 +23,7 @@
  * THE SOFTWARE.
  */
 
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "qemu/error-report.h"
 #include "hw/sysbus.h"
@@ -119,7 +120,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
          (unit < FLASH_MAP_UNIT_MAX &&
           (pflash_drv = drive_get(IF_PFLASH, 0, unit)) != NULL);
          ++unit) {
-        bdrv = pflash_drv->bdrv;
+        bdrv = blk_bs(blk_by_legacy_dinfo(pflash_drv));
         size = bdrv_getlength(bdrv);
         if (size < 0) {
             fatal_errmsg = g_strdup_printf("failed to get backing file size");
hw/ide/piix.c +4 -2
index 49e78a7..c6c256f 100644
@@ -27,6 +27,7 @@
 #include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
 #include <hw/isa/isa.h>
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
@@ -178,9 +179,10 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev)
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {
-            DeviceState *ds = bdrv_get_attached_dev(di->bdrv);
+            BlockDriverState *bs = blk_bs(blk_by_legacy_dinfo(di));
+            DeviceState *ds = bdrv_get_attached_dev(bs);
             if (ds) {
-                bdrv_detach_dev(di->bdrv, ds);
+                bdrv_detach_dev(bs, ds);
             }
             pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_del(di);
hw/ide/qdev.c +3 -1
index efab95b..75e8eb3 100644
@@ -20,6 +20,7 @@
 #include "sysemu/dma.h"
 #include "qemu/error-report.h"
 #include <hw/ide/internal.h>
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/block/block.h"
 #include "sysemu/sysemu.h"
@@ -116,7 +117,8 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
 
     dev = qdev_create(&bus->qbus, drive->media_cd ? "ide-cd" : "ide-hd");
     qdev_prop_set_uint32(dev, "unit", unit);
-    qdev_prop_set_drive_nofail(dev, "drive", drive->bdrv);
+    qdev_prop_set_drive_nofail(dev, "drive",
+                               blk_bs(blk_by_legacy_dinfo(drive)));
     qdev_init_nofail(dev);
     return DO_UPCAST(IDEDevice, qdev, dev);
 }
hw/isa/pc87312.c +5 -2
index 9327c53..b691a0c 100644
@@ -25,6 +25,7 @@
 
 #include "hw/isa/pc87312.h"
 #include "qemu/error-report.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/char.h"
@@ -320,11 +321,13 @@ static void pc87312_realize(DeviceState *dev, Error **errp)
         qdev_prop_set_uint32(d, "irq", 6);
         drive = drive_get(IF_FLOPPY, 0, 0);
         if (drive != NULL) {
-            qdev_prop_set_drive_nofail(d, "driveA", drive->bdrv);
+            qdev_prop_set_drive_nofail(d, "driveA",
+                                       blk_bs(blk_by_legacy_dinfo(drive)));
         }
         drive = drive_get(IF_FLOPPY, 0, 1);
         if (drive != NULL) {
-            qdev_prop_set_drive_nofail(d, "driveB", drive->bdrv);
+            qdev_prop_set_drive_nofail(d, "driveB",
+                                       blk_bs(blk_by_legacy_dinfo(drive)));
         }
         qdev_init_nofail(d);
         s->fdc.dev = isa;
hw/lm32/lm32_boards.c +7 -6
index 5ae6cad..2a1d3de 100644
@@ -23,6 +23,7 @@
 #include "hw/devices.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "elf.h"
 #include "lm32_hwsetup.h"
@@ -119,9 +120,9 @@ static void lm32_evr_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
     pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
-                          dinfo ? dinfo->bdrv : NULL, flash_sector_size,
-                          flash_size / flash_sector_size, 1, 2,
-                          0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          flash_sector_size, flash_size / flash_sector_size,
+                          1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
 
     /* create irq lines */
     cpu_irq = qemu_allocate_irqs(cpu_irq_handler, cpu, 1);
@@ -222,9 +223,9 @@ static void lm32_uclinux_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
     pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
-                          dinfo ? dinfo->bdrv : NULL, flash_sector_size,
-                          flash_size / flash_sector_size, 1, 2,
-                          0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          flash_sector_size, flash_size / flash_sector_size,
+                          1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
 
     /* create irq lines */
     cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
hw/lm32/milkymist.c +4 -3
index c8832f0..8411895 100644
@@ -26,6 +26,7 @@
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "elf.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "milkymist-hw.h"
 #include "lm32.h"
@@ -126,9 +127,9 @@ milkymist_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Numonyx JS28F256J3F105 */
     pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
-                          dinfo ? dinfo->bdrv : NULL, flash_sector_size,
-                          flash_size / flash_sector_size, 2,
-                          0x00, 0x89, 0x00, 0x1d, 1);
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          flash_sector_size, flash_size / flash_sector_size,
+                          2, 0x00, 0x89, 0x00, 0x1d, 1);
 
     /* create irq lines */
     cpu_irq = qemu_allocate_irqs(cpu_irq_handler, cpu, 1);
hw/microblaze/petalogix_ml605_mmu.c +3 -2
index fcb51bc..8c0532d 100644
@@ -32,6 +32,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/devices.h"
 #include "hw/boards.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/char/serial.h"
 #include "exec/address-spaces.h"
@@ -113,8 +114,8 @@ petalogix_ml605_init(MachineState *machine)
      * 10th paremeter 0 means little-endian */
     pflash_cfi01_register(FLASH_BASEADDR,
                           NULL, "petalogix_ml605.flash", FLASH_SIZE,
-                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                          FLASH_SIZE >> 16,
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          (64 * 1024), FLASH_SIZE >> 16,
                           2, 0x89, 0x18, 0x0000, 0x0, 0);
 
 
hw/microblaze/petalogix_s3adsp1800_mmu.c +3 -2
index 8e0fca9..c3fd743 100644
@@ -30,6 +30,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/devices.h"
 #include "hw/boards.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
@@ -94,8 +95,8 @@ petalogix_s3adsp1800_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(FLASH_BASEADDR,
                           NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
-                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                          FLASH_SIZE >> 16,
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          (64 * 1024), FLASH_SIZE >> 16,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
 
     dev = qdev_create(NULL, "xlnx.xps-intc");
hw/mips/mips_malta.c +3 -1
index 2d87de9..6d81cbf 100644
@@ -44,6 +44,7 @@
 #include "elf.h"
 #include "hw/timer/mc146818rtc.h"
 #include "hw/timer/i8254.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "hw/sysbus.h"             /* SysBusDevice */
@@ -1036,7 +1037,8 @@ void mips_malta_init(MachineState *machine)
     }
 #endif
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
-                               BIOS_SIZE, dinfo ? dinfo->bdrv : NULL,
+                               BIOS_SIZE,
+                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
                                65536, fl_sectors,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
     bios = pflash_cfi01_get_memory(fl);
hw/mips/mips_r4k.c +3 -2
index e219766..f07fe6b 100644
@@ -24,6 +24,7 @@
 #include "elf.h"
 #include "hw/timer/mc146818rtc.h"
 #include "hw/timer/i8254.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
@@ -241,8 +242,8 @@ void mips_r4k_init(MachineState *machine)
     } else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
         uint32_t mips_rom = 0x00400000;
         if (!pflash_cfi01_register(0x1fc00000, NULL, "mips_r4k.bios", mips_rom,
-                                   dinfo->bdrv, sector_len,
-                                   mips_rom / sector_len,
+                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   sector_len, mips_rom / sector_len,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory.\n");
 	}
hw/pci/pci-hotplug-old.c +6 -3
index cf2caeb..e4d51de 100644
@@ -33,6 +33,7 @@
 #include "hw/scsi/scsi.h"
 #include "hw/virtio/virtio-blk.h"
 #include "qemu/config-file.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "qapi/error.h"
 
@@ -126,8 +127,9 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
      */
     dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
     dinfo->bus = scsibus->busnr;
-    scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
-                                        false, -1, NULL, NULL);
+    scsidev = scsi_bus_legacy_add_drive(scsibus,
+                                        blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                        dinfo->unit, false, -1, NULL, NULL);
     if (!scsidev) {
         return -1;
     }
@@ -247,7 +249,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
             return NULL;
         }
         dev = pci_create(bus, devfn, "virtio-blk-pci");
-        if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
+        if (qdev_prop_set_drive(&dev->qdev, "drive",
+                                blk_bs(blk_by_legacy_dinfo(dinfo))) < 0) {
             object_unparent(OBJECT(dev));
             dev = NULL;
             break;
hw/ppc/ppc405_boards.c +16 -9
index 18a4ec5..aeae450 100644
@@ -33,6 +33,7 @@
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "hw/loader.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
@@ -225,17 +226,19 @@ static void ref405ep_init(MachineState *machine)
 #ifdef USE_FLASH_BIOS
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
     if (dinfo) {
-        bios_size = bdrv_getlength(dinfo->bdrv);
+        BlockDriverState *bs = blk_bs(blk_by_legacy_dinfo(dinfo));
+
+        bios_size = bdrv_getlength(bs);
         fl_sectors = (bios_size + 65535) >> 16;
 #ifdef DEBUG_BOARD_INIT
         printf("Register parallel flash %d size %lx"
                " at addr %lx '%s' %d\n",
                fl_idx, bios_size, -bios_size,
-               bdrv_get_device_name(dinfo->bdrv), fl_sectors);
+               bdrv_get_device_name(bs), fl_sectors);
 #endif
         pflash_cfi02_register((uint32_t)(-bios_size),
                               NULL, "ef405ep.bios", bios_size,
-                              dinfo->bdrv, 65536, fl_sectors, 1,
+                              bs, 65536, fl_sectors, 1,
                               2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
@@ -548,7 +551,9 @@ static void taihu_405ep_init(MachineState *machine)
 #if defined(USE_FLASH_BIOS)
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
     if (dinfo) {
-        bios_size = bdrv_getlength(dinfo->bdrv);
+        BlockDriverState *bs = blk_bs(blk_by_legacy_dinfo(dinfo));
+
+        bios_size = bdrv_getlength(bs);
         /* XXX: should check that size is 2MB */
         //        bios_size = 2 * 1024 * 1024;
         fl_sectors = (bios_size + 65535) >> 16;
@@ -556,11 +561,11 @@ static void taihu_405ep_init(MachineState *machine)
         printf("Register parallel flash %d size %lx"
                " at addr %lx '%s' %d\n",
                fl_idx, bios_size, -bios_size,
-               bdrv_get_device_name(dinfo->bdrv), fl_sectors);
+               bdrv_get_device_name(bs), fl_sectors);
 #endif
         pflash_cfi02_register((uint32_t)(-bios_size),
                               NULL, "taihu_405ep.bios", bios_size,
-                              dinfo->bdrv, 65536, fl_sectors, 1,
+                              bs, 65536, fl_sectors, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
@@ -595,7 +600,9 @@ static void taihu_405ep_init(MachineState *machine)
     /* Register Linux flash */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
     if (dinfo) {
-        bios_size = bdrv_getlength(dinfo->bdrv);
+        BlockDriverState *bs = blk_bs(blk_by_legacy_dinfo(dinfo));
+
+        bios_size = bdrv_getlength(bs);
         /* XXX: should check that size is 32MB */
         bios_size = 32 * 1024 * 1024;
         fl_sectors = (bios_size + 65535) >> 16;
@@ -603,10 +610,10 @@ static void taihu_405ep_init(MachineState *machine)
         printf("Register parallel flash %d size %lx"
                " at addr " TARGET_FMT_lx " '%s'\n",
                fl_idx, bios_size, (target_ulong)0xfc000000,
-               bdrv_get_device_name(dinfo->bdrv));
+               bdrv_get_device_name(bs));
 #endif
         pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
-                              dinfo->bdrv, 65536, fl_sectors, 1,
+                              bs, 65536, fl_sectors, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
hw/ppc/spapr.c +3 -1
index 2ab4460..a577812 100644
@@ -29,6 +29,7 @@
 #include "hw/fw-path-provider.h"
 #include "elf.h"
 #include "net/net.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/cpus.h"
 #include "sysemu/kvm.h"
@@ -925,7 +926,8 @@ static void spapr_create_nvram(sPAPREnvironment *spapr)
     DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
 
     if (dinfo) {
-        qdev_prop_set_drive_nofail(dev, "drive", dinfo->bdrv);
+        qdev_prop_set_drive_nofail(dev, "drive",
+                                   blk_bs(blk_by_legacy_dinfo(dinfo)));
     }
 
     qdev_init_nofail(dev);
hw/ppc/virtex_ml507.c +3 -2
index 0de5148..a0ce447 100644
@@ -39,6 +39,7 @@
 #include "hw/ppc/ppc4xx.h"
 #include "ppc405.h"
 
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "qapi/qmp/qerror.h"
 
@@ -227,8 +228,8 @@ static void virtex_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(PFLASH_BASEADDR, NULL, "virtex.flash", FLASH_SIZE,
-                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                          FLASH_SIZE >> 16,
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          (64 * 1024), FLASH_SIZE >> 16,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
 
     cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
hw/scsi/scsi-bus.c +3 -2
index 954c607..f5156ae 100644
@@ -3,6 +3,7 @@
 #include "hw/scsi/scsi.h"
 #include "block/scsi.h"
 #include "hw/qdev.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "trace.h"
 #include "sysemu/dma.h"
@@ -267,8 +268,8 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp)
             continue;
         }
         qemu_opts_loc_restore(dinfo->opts);
-        scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL,
-                                  &err);
+        scsi_bus_legacy_add_drive(bus, blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                  unit, false, -1, NULL, &err);
         if (err != NULL) {
             error_report("%s", error_get_pretty(err));
             error_propagate(errp, err);
hw/sd/milkymist-memcard.c +5 -2
index 2a40f92..501aa3a 100644
@@ -26,6 +26,7 @@
 #include "sysemu/sysemu.h"
 #include "trace.h"
 #include "qemu/error-report.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/sd.h"
 
@@ -252,14 +253,16 @@ static int milkymist_memcard_init(SysBusDevice *dev)
 {
     MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev);
     DriveInfo *dinfo;
+    BlockDriverState *bs;
 
     dinfo = drive_get_next(IF_SD);
-    s->card = sd_init(dinfo ? dinfo->bdrv : NULL, false);
+    bs = dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL;
+    s->card = sd_init(bs, false);
     if (s->card == NULL) {
         return -1;
     }
 
-    s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;
+    s->enabled = bs && bdrv_is_inserted(bs);
 
     memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s,
             "milkymist-memcard", R_MAX * 4);
hw/sd/pl181.c +2 -1
index 462558b..0501d40 100644
@@ -7,6 +7,7 @@
  * This code is licensed under the GPL.
  */
 
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "hw/sd.h"
@@ -490,7 +491,7 @@ static int pl181_init(SysBusDevice *sbd)
     sysbus_init_irq(sbd, &s->irq[1]);
     qdev_init_gpio_out(dev, s->cardstatus, 2);
     dinfo = drive_get_next(IF_SD);
-    s->card = sd_init(dinfo ? dinfo->bdrv : NULL, false);
+    s->card = sd_init(dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL, false);
     if (s->card == NULL) {
         return -1;
     }
hw/sd/sdhci.c +2 -1
index f9fe700..0b7d754 100644
@@ -23,6 +23,7 @@
  */
 
 #include "hw/hw.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/dma.h"
 #include "qemu/timer.h"
@@ -1165,7 +1166,7 @@ static void sdhci_initfn(Object *obj)
     DriveInfo *di;
 
     di = drive_get_next(IF_SD);
-    s->card = sd_init(di ? di->bdrv : NULL, false);
+    s->card = sd_init(di ? blk_bs(blk_by_legacy_dinfo(di)) : NULL, false);
     if (s->card == NULL) {
         exit(1);
     }
hw/sd/ssi-sd.c +2 -1
index b012e57..6ae99e4 100644
@@ -10,6 +10,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/ssi.h"
 #include "hw/sd.h"
@@ -255,7 +256,7 @@ static int ssi_sd_init(SSISlave *d)
 
     s->mode = SSI_SD_CMD;
     dinfo = drive_get_next(IF_SD);
-    s->sd = sd_init(dinfo ? dinfo->bdrv : NULL, true);
+    s->sd = sd_init(dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL, true);
     if (s->sd == NULL) {
         return -1;
     }
hw/sh4/r2d.c +3 -2
index 321379e..80ac132 100644
@@ -36,6 +36,7 @@
 #include "hw/loader.h"
 #include "hw/usb.h"
 #include "hw/block/flash.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
@@ -290,8 +291,8 @@ static void r2d_init(MachineState *machine)
     /* onboard flash memory */
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
-                          dinfo ? dinfo->bdrv : NULL, (16 * 1024),
-                          FLASH_SIZE >> 16,
+                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          (16 * 1024), FLASH_SIZE >> 16,
                           1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
                           0x555, 0x2aa, 0);
 
hw/usb/dev-storage.c +3 -1
index eb75f6a..0d6e7c6 100644
@@ -16,6 +16,7 @@
 #include "ui/console.h"
 #include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 
 //#define DEBUG_MSD
@@ -704,7 +705,8 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
     if (!dev) {
         return NULL;
     }
-    if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
+    if (qdev_prop_set_drive(&dev->qdev, "drive",
+                            blk_bs(blk_by_legacy_dinfo(dinfo))) < 0) {
         object_unparent(OBJECT(dev));
         return NULL;
     }
hw/xtensa/xtfpga.c +3 -1
index ed06ff7..4ac1cef 100644
@@ -35,6 +35,7 @@
 #include "net/net.h"
 #include "hw/sysbus.h"
 #include "hw/block/flash.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "sysemu/char.h"
 #include "sysemu/device_tree.h"
@@ -230,7 +231,8 @@ static void lx_init(const LxBoardDesc *board, MachineState *machine)
     if (dinfo) {
         flash = pflash_cfi01_register(board->flash_base,
                 NULL, "lx60.io.flash", board->flash_size,
-                dinfo->bdrv, board->flash_sector_size,
+                blk_bs(blk_by_legacy_dinfo(dinfo)),
+                board->flash_sector_size,
                 board->flash_size / board->flash_sector_size,
                 4, 0x0000, 0x0000, 0x0000, 0x0000, be);
         if (flash == NULL) {
include/sysemu/blockdev.h +0 -1
index 2ed297b..75f6ac6 100644
@@ -30,7 +30,6 @@ typedef enum {
 } BlockInterfaceType;
 
 struct DriveInfo {
-    BlockDriverState *bdrv;
     char *id;
     const char *devaddr;
     BlockInterfaceType type;
Signature · 1 line
1.9.3
Reviewed-by on v3 10/23
#43 lore raw

Re: [Qemu-devel] [PATCH v3 10/23] block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo()

hw/sd/milkymist-memcard.c static int milkymist_memcard_init(SysBusDevice *dev) · line 265

Quoted 2 lines · Markus Armbruster
hw/sd/milkymist-memcard.c +1 -1
-    s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;
+    s->enabled = bs && bdrv_is_inserted(bs);

This is not so mechanical but seems correct anyway.

#44 lore raw

Re: [Qemu-devel] [PATCH v3 10/23] block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo()

Quoted 1 line · Benoît Canet

On Tue, Sep 16, 2014 at 08:12:15PM +0200, Markus Armbruster wrote:

Restoring context...

   @@ -252,14 +253,16 @@ static int milkymist_memcard_init(SysBusDevice *dev)
    {
        MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev);
        DriveInfo *dinfo;
   +    BlockDriverState *bs;
        dinfo = drive_get_next(IF_SD);
   -    s->card = sd_init(dinfo ? dinfo->bdrv : NULL, false);
   +    bs = dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL;
   +    s->card = sd_init(bs, false);
        if (s->card == NULL) {
            return -1;
        }
Quoted 2 lines

hw/sd/milkymist-memcard.c static int milkymist_memcard_init(SysBusDevice *dev) · line 265

Quoted 2 lines
hw/sd/milkymist-memcard.c +1 -1
-    s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0;
+    s->enabled = bs && bdrv_is_inserted(bs);
        memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s,
                "milkymist-memcard", R_MAX * 4);
Quoted 2 lines

This is not so mechanical but seems correct anyway.

The mechanical change would be

    s->enabled = dinfo ? bdrv_is_inserted(blk_by_legacy_dinfo(dinfo)) : 0;

My actual change exploits that the value of blk_by_legacy_dinfo(dinfo) is already available in bs, and that bs is null if and only if dinfo is null.

Quoted 1 line

Thanks!

Reviewed-by on v3 10/23
#45 lore raw

Re: [Qemu-devel] [PATCH v3 10/23] block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo()

In reply to Markus Armbruster
Quoted 54 lines · Markus Armbruster

The patch is big, but all it really does is replacing

     dinfo->bdrv

by

blk_bs(blk_by_legacy_dinfo(dinfo))

The replacement is repetitive, but the conversion of device models to BlockBackend is imminent, and will shorten it to just blk_legacy_dinfo(dinfo).

Line wrapping muddies the waters a bit. I also omit tests whether dinfo->bdrv is null, because it never is.

---
  blockdev.c                               |  3 +--
  hw/arm/collie.c                          |  9 +++++----
  hw/arm/gumstix.c                         |  5 +++--
  hw/arm/mainstone.c                       |  8 ++++----
  hw/arm/musicpal.c                        | 11 ++++++-----
  hw/arm/nseries.c                         |  6 ++++--
  hw/arm/omap1.c                           |  4 +++-
  hw/arm/omap2.c                           |  4 +++-
  hw/arm/omap_sx1.c                        |  9 +++++----
  hw/arm/pxa2xx.c                          |  7 +++++--
  hw/arm/spitz.c                           |  4 +++-
  hw/arm/versatilepb.c                     |  4 +++-
  hw/arm/vexpress.c                        |  4 +++-
  hw/arm/virt.c                            |  4 +++-
  hw/arm/xilinx_zynq.c                     |  4 +++-
  hw/arm/z2.c                              |  7 ++++---
  hw/block/fdc.c                           | 16 +++++++++++-----
  hw/block/m25p80.c                        |  5 +++--
  hw/block/xen_disk.c                      |  2 +-
  hw/cris/axis_dev88.c                     |  3 ++-
  hw/display/tc6393xb.c                    |  4 +++-
  hw/i386/pc_sysfw.c                       |  3 ++-
  hw/ide/piix.c                            |  6 ++++--
  hw/ide/qdev.c                            |  4 +++-
  hw/isa/pc87312.c                         |  7 +++++--
  hw/lm32/lm32_boards.c                    | 13 +++++++------
  hw/lm32/milkymist.c                      |  7 ++++---
  hw/microblaze/petalogix_ml605_mmu.c      |  5 +++--
  hw/microblaze/petalogix_s3adsp1800_mmu.c |  5 +++--
  hw/mips/mips_malta.c                     |  4 +++-
  hw/mips/mips_r4k.c                       |  5 +++--
  hw/pci/pci-hotplug-old.c                 |  9 ++++++---
  hw/ppc/ppc405_boards.c                   | 25 ++++++++++++++++---------
  hw/ppc/spapr.c                           |  4 +++-
  hw/ppc/virtex_ml507.c                    |  5 +++--
  hw/scsi/scsi-bus.c                       |  5 +++--
  hw/sd/milkymist-memcard.c                |  7 +++++--
Quoted 8 lines
  hw/sd/pl181.c                            |  3 ++-
  hw/sd/sdhci.c                            |  3 ++-
  hw/sd/ssi-sd.c                           |  3 ++-
  hw/sh4/r2d.c                             |  5 +++--
  hw/usb/dev-storage.c                     |  4 +++-
  hw/xtensa/xtfpga.c                       |  4 +++-
  include/sysemu/blockdev.h                |  1 -
  44 files changed, 166 insertions(+), 94 deletions(-)
Reviewed-by on v3 10/23
#46 lore raw

Re: [Qemu-devel] [PATCH v3 10/23] block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo()

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines

The patch is big, but all it really does is replacing

    dinfo->bdrv

by

blk_bs(blk_by_legacy_dinfo(dinfo))

Quoted 8 lines

The replacement is repetitive, but the conversion of device models to BlockBackend is imminent, and will shorten it to just blk_legacy_dinfo(dinfo).

Line wrapping muddies the waters a bit. I also omit tests whether dinfo->bdrv is null, because it never is.

#47 lore raw

PATCH v3 11/23 block: Rename BlockDriverAIOCB* to BlockAIOCB*

In reply to Markus Armbruster

I'll use BlockDriverAIOCB with block backends shortly, and the name is going to fit badly there. It's a block layer thing anyway, not just a block driver thing.

---
 block-migration.c           |   2 +-
 block.c                     | 151 ++++++++++++++++++++++----------------------
 block/archipelago.c         |  30 ++++-----
 block/backup.c              |   2 +-
 block/blkdebug.c            |  22 +++----
 block/blkverify.c           |  20 +++---
 block/commit.c              |   2 +-
 block/curl.c                |   8 +--
 block/iscsi.c               |   8 +--
 block/linux-aio.c           |   8 +--
 block/mirror.c              |   6 +-
 block/qed-gencb.c           |   4 +-
 block/qed-table.c           |  10 +--
 block/qed.c                 |  46 +++++++-------
 block/qed.h                 |  12 ++--
 block/quorum.c              |  38 +++++------
 block/raw-aio.h             |   8 +--
 block/raw-posix.c           |  32 +++++-----
 block/raw-win32.c           |  16 ++---
 block/raw_bsd.c             |   8 +--
 block/rbd.c                 |  58 ++++++++---------
 block/sheepdog.c            |   4 +-
 block/stream.c              |   2 +-
 block/win32-aio.c           |   8 +--
 blockjob.c                  |   4 +-
 dma-helpers.c               |  24 +++----
 hw/block/nvme.h             |   2 +-
 hw/ide/ahci.c               |   2 +-
 hw/ide/ahci.h               |   2 +-
 hw/ide/core.c               |  12 ++--
 hw/ide/internal.h           |  12 ++--
 hw/ide/macio.c              |   2 +-
 hw/ide/pci.c                |   2 +-
 hw/ide/pci.h                |   2 +-
 hw/ppc/mac.h                |   2 +-
 hw/scsi/scsi-generic.c      |   2 +-
 include/block/aio.h         |  12 ++--
 include/block/block.h       |  36 +++++------
 include/block/block_int.h   |  30 ++++-----
 include/block/blockjob.h    |   4 +-
 include/block/thread-pool.h |   4 +-
 include/hw/scsi/scsi.h      |   2 +-
 include/monitor/monitor.h   |   4 +-
 include/sysemu/dma.h        |  26 ++++----
 monitor.c                   |   6 +-
 tests/test-thread-pool.c    |   2 +-
 thread-pool.c               |   8 +--
 47 files changed, 353 insertions(+), 354 deletions(-)
block-migration.c +1 -1
index da30e93..08db01a 100644
@@ -72,7 +72,7 @@ typedef struct BlkMigBlock {
     int nr_sectors;
     struct iovec iov;
     QEMUIOVector qiov;
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
 
     /* Protected by block migration lock.  */
     int ret;
block.c +75 -76

347 lines not on this page · raw message

block/archipelago.c +15 -15
index 93fb7c0..296e639 100644
@@ -86,7 +86,7 @@ typedef enum {
 } ARCHIPCmd;
 
 typedef struct ArchipelagoAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUBH *bh;
     struct BDRVArchipelagoState *s;
     QEMUIOVector *qiov;
@@ -725,7 +725,7 @@ static int qemu_archipelago_create(const char *filename,
     return ret;
 }
 
-static void qemu_archipelago_aio_cancel(BlockDriverAIOCB *blockacb)
+static void qemu_archipelago_aio_cancel(BlockAIOCB *blockacb)
 {
     ArchipelagoAIOCB *aio_cb = (ArchipelagoAIOCB *) blockacb;
     aio_cb->cancelled = true;
@@ -870,13 +870,13 @@ err_exit:
     return ret;
 }
 
-static BlockDriverAIOCB *qemu_archipelago_aio_rw(BlockDriverState *bs,
-                                                 int64_t sector_num,
-                                                 QEMUIOVector *qiov,
-                                                 int nb_sectors,
-                                                 BlockDriverCompletionFunc *cb,
-                                                 void *opaque,
-                                                 int op)
+static BlockAIOCB *qemu_archipelago_aio_rw(BlockDriverState *bs,
+                                           int64_t sector_num,
+                                           QEMUIOVector *qiov,
+                                           int nb_sectors,
+                                           BlockCompletionFunc *cb,
+                                           void *opaque,
+                                           int op)
 {
     ArchipelagoAIOCB *aio_cb;
     BDRVArchipelagoState *s = bs->opaque;
@@ -909,17 +909,17 @@ err_exit:
     return NULL;
 }
 
-static BlockDriverAIOCB *qemu_archipelago_aio_readv(BlockDriverState *bs,
+static BlockAIOCB *qemu_archipelago_aio_readv(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     return qemu_archipelago_aio_rw(bs, sector_num, qiov, nb_sectors, cb,
                                    opaque, ARCHIP_OP_READ);
 }
 
-static BlockDriverAIOCB *qemu_archipelago_aio_writev(BlockDriverState *bs,
+static BlockAIOCB *qemu_archipelago_aio_writev(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     return qemu_archipelago_aio_rw(bs, sector_num, qiov, nb_sectors, cb,
                                    opaque, ARCHIP_OP_WRITE);
@@ -1067,8 +1067,8 @@ static QemuOptsList qemu_archipelago_create_opts = {
     }
 };
 
-static BlockDriverAIOCB *qemu_archipelago_aio_flush(BlockDriverState *bs,
-        BlockDriverCompletionFunc *cb, void *opaque)
+static BlockAIOCB *qemu_archipelago_aio_flush(BlockDriverState *bs,
+        BlockCompletionFunc *cb, void *opaque)
 {
     return qemu_archipelago_aio_rw(bs, 0, NULL, 0, cb, opaque,
                                    ARCHIP_OP_FLUSH);
block/backup.c +1 -1
index d0b0225..e334740 100644
@@ -353,7 +353,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
                   int64_t speed, MirrorSyncMode sync_mode,
                   BlockdevOnError on_source_error,
                   BlockdevOnError on_target_error,
-                  BlockDriverCompletionFunc *cb, void *opaque,
+                  BlockCompletionFunc *cb, void *opaque,
                   Error **errp)
 {
     int64_t len;
block/blkdebug.c +11 -11
index 69b330e..008d3e3 100644
@@ -41,7 +41,7 @@ typedef struct BDRVBlkdebugState {
 } BDRVBlkdebugState;
 
 typedef struct BlkdebugAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUBH *bh;
     int ret;
 } BlkdebugAIOCB;
@@ -52,7 +52,7 @@ typedef struct BlkdebugSuspendedReq {
     QLIST_ENTRY(BlkdebugSuspendedReq) next;
 } BlkdebugSuspendedReq;
 
-static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb);
+static void blkdebug_aio_cancel(BlockAIOCB *blockacb);
 
 static const AIOCBInfo blkdebug_aiocb_info = {
     .aiocb_size = sizeof(BlkdebugAIOCB),
@@ -450,7 +450,7 @@ static void error_callback_bh(void *opaque)
     qemu_aio_release(acb);
 }
 
-static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
+static void blkdebug_aio_cancel(BlockAIOCB *blockacb)
 {
     BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common);
     if (acb->bh) {
@@ -460,8 +460,8 @@ static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
     qemu_aio_release(acb);
 }
 
-static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
-    BlockDriverCompletionFunc *cb, void *opaque, BlkdebugRule *rule)
+static BlockAIOCB *inject_error(BlockDriverState *bs,
+    BlockCompletionFunc *cb, void *opaque, BlkdebugRule *rule)
 {
     BDRVBlkdebugState *s = bs->opaque;
     int error = rule->options.inject.error;
@@ -486,9 +486,9 @@ static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
     return &acb->common;
 }
 
-static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
+static BlockAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
     int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-    BlockDriverCompletionFunc *cb, void *opaque)
+    BlockCompletionFunc *cb, void *opaque)
 {
     BDRVBlkdebugState *s = bs->opaque;
     BlkdebugRule *rule = NULL;
@@ -508,9 +508,9 @@ static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
     return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
 }
 
-static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
+static BlockAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
     int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-    BlockDriverCompletionFunc *cb, void *opaque)
+    BlockCompletionFunc *cb, void *opaque)
 {
     BDRVBlkdebugState *s = bs->opaque;
     BlkdebugRule *rule = NULL;
@@ -530,8 +530,8 @@ static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
     return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
 }
 
-static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
-    BlockDriverCompletionFunc *cb, void *opaque)
+static BlockAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
+    BlockCompletionFunc *cb, void *opaque)
 {
     BDRVBlkdebugState *s = bs->opaque;
     BlkdebugRule *rule = NULL;
block/blkverify.c +10 -10
index 163064c..d4553cc 100644
@@ -19,7 +19,7 @@ typedef struct {
 
 typedef struct BlkverifyAIOCB BlkverifyAIOCB;
 struct BlkverifyAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUBH *bh;
 
     /* Request metadata */
@@ -38,7 +38,7 @@ struct BlkverifyAIOCB {
     void (*verify)(BlkverifyAIOCB *acb);
 };
 
-static void blkverify_aio_cancel(BlockDriverAIOCB *blockacb)
+static void blkverify_aio_cancel(BlockAIOCB *blockacb)
 {
     BlkverifyAIOCB *acb = (BlkverifyAIOCB *)blockacb;
     AioContext *aio_context = bdrv_get_aio_context(blockacb->bs);
@@ -180,7 +180,7 @@ static int64_t blkverify_getlength(BlockDriverState *bs)
 static BlkverifyAIOCB *blkverify_aio_get(BlockDriverState *bs, bool is_write,
                                          int64_t sector_num, QEMUIOVector *qiov,
                                          int nb_sectors,
-                                         BlockDriverCompletionFunc *cb,
+                                         BlockCompletionFunc *cb,
                                          void *opaque)
 {
     BlkverifyAIOCB *acb = qemu_aio_get(&blkverify_aiocb_info, bs, cb, opaque);
@@ -248,9 +248,9 @@ static void blkverify_verify_readv(BlkverifyAIOCB *acb)
     }
 }
 
-static BlockDriverAIOCB *blkverify_aio_readv(BlockDriverState *bs,
+static BlockAIOCB *blkverify_aio_readv(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     BDRVBlkverifyState *s = bs->opaque;
     BlkverifyAIOCB *acb = blkverify_aio_get(bs, false, sector_num, qiov,
@@ -268,9 +268,9 @@ static BlockDriverAIOCB *blkverify_aio_readv(BlockDriverState *bs,
     return &acb->common;
 }
 
-static BlockDriverAIOCB *blkverify_aio_writev(BlockDriverState *bs,
+static BlockAIOCB *blkverify_aio_writev(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     BDRVBlkverifyState *s = bs->opaque;
     BlkverifyAIOCB *acb = blkverify_aio_get(bs, true, sector_num, qiov,
@@ -283,9 +283,9 @@ static BlockDriverAIOCB *blkverify_aio_writev(BlockDriverState *bs,
     return &acb->common;
 }
 
-static BlockDriverAIOCB *blkverify_aio_flush(BlockDriverState *bs,
-                                             BlockDriverCompletionFunc *cb,
-                                             void *opaque)
+static BlockAIOCB *blkverify_aio_flush(BlockDriverState *bs,
+                                       BlockCompletionFunc *cb,
+                                       void *opaque)
 {
     BDRVBlkverifyState *s = bs->opaque;
 
block/commit.c +1 -1
index 91517d3..60a2acc 100644
@@ -182,7 +182,7 @@ static const BlockJobDriver commit_job_driver = {
 
 void commit_start(BlockDriverState *bs, BlockDriverState *base,
                   BlockDriverState *top, int64_t speed,
-                  BlockdevOnError on_error, BlockDriverCompletionFunc *cb,
+                  BlockdevOnError on_error, BlockCompletionFunc *cb,
                   void *opaque, const char *backing_file_str, Error **errp)
 {
     CommitBlockJob *s;
block/curl.c +4 -4
index 938f9d9..5e96b05 100644
@@ -78,7 +78,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
 struct BDRVCURLState;
 
 typedef struct CURLAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUBH *bh;
     QEMUIOVector *qiov;
 
@@ -613,7 +613,7 @@ out_noclean:
     return -EINVAL;
 }
 
-static void curl_aio_cancel(BlockDriverAIOCB *blockacb)
+static void curl_aio_cancel(BlockAIOCB *blockacb)
 {
     // Do we have to implement canceling? Seems to work without...
 }
@@ -686,9 +686,9 @@ static void curl_readv_bh_cb(void *p)
     curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
 }
 
-static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
+static BlockAIOCB *curl_aio_readv(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     CURLAIOCB *acb;
 
block/iscsi.c +4 -4
index 166d1b9..abbd341 100644
@@ -81,7 +81,7 @@ typedef struct IscsiTask {
 } IscsiTask;
 
 typedef struct IscsiAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUIOVector *qiov;
     QEMUBH *bh;
     IscsiLun *iscsilun;
@@ -231,7 +231,7 @@ iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
 }
 
 static void
-iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
+iscsi_aio_cancel(BlockAIOCB *blockacb)
 {
     IscsiAIOCB *acb = (IscsiAIOCB *)blockacb;
     IscsiLun *iscsilun = acb->iscsilun;
@@ -669,9 +669,9 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
     iscsi_schedule_bh(acb);
 }
 
-static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
+static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         unsigned long int req, void *buf,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     IscsiLun *iscsilun = bs->opaque;
     struct iscsi_context *iscsi = iscsilun->iscsi;
block/linux-aio.c +4 -4
index 9aca758..2436140 100644
@@ -28,7 +28,7 @@
 #define MAX_QUEUED_IO  128
 
 struct qemu_laiocb {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     struct qemu_laio_state *ctx;
     struct iocb iocb;
     ssize_t ret;
@@ -147,7 +147,7 @@ static void qemu_laio_completion_cb(EventNotifier *e)
     }
 }
 
-static void laio_cancel(BlockDriverAIOCB *blockacb)
+static void laio_cancel(BlockAIOCB *blockacb)
 {
     struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb;
     struct io_event event;
@@ -257,9 +257,9 @@ int laio_io_unplug(BlockDriverState *bs, void *aio_ctx, bool unplug)
     return ret;
 }
 
-BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
+BlockAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type)
+        BlockCompletionFunc *cb, void *opaque, int type)
 {
     struct qemu_laio_state *s = aio_ctx;
     struct qemu_laiocb *laiocb;
block/mirror.c +3 -3
index 829be2f..e8a43eb 100644
@@ -613,7 +613,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
                              int64_t buf_size,
                              BlockdevOnError on_source_error,
                              BlockdevOnError on_target_error,
-                             BlockDriverCompletionFunc *cb,
+                             BlockCompletionFunc *cb,
                              void *opaque, Error **errp,
                              const BlockJobDriver *driver,
                              bool is_none_mode, BlockDriverState *base)
@@ -673,7 +673,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
                   int64_t speed, int64_t granularity, int64_t buf_size,
                   MirrorSyncMode mode, BlockdevOnError on_source_error,
                   BlockdevOnError on_target_error,
-                  BlockDriverCompletionFunc *cb,
+                  BlockCompletionFunc *cb,
                   void *opaque, Error **errp)
 {
     bool is_none_mode;
@@ -690,7 +690,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
 void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
                          int64_t speed,
                          BlockdevOnError on_error,
-                         BlockDriverCompletionFunc *cb,
+                         BlockCompletionFunc *cb,
                          void *opaque, Error **errp)
 {
     int64_t length, base_length;
block/qed-gencb.c +2 -2
index 7d7ac1f..b817a8b 100644
@@ -13,7 +13,7 @@
 
 #include "qed.h"
 
-void *gencb_alloc(size_t len, BlockDriverCompletionFunc *cb, void *opaque)
+void *gencb_alloc(size_t len, BlockCompletionFunc *cb, void *opaque)
 {
     GenericCB *gencb = g_malloc(len);
     gencb->cb = cb;
@@ -24,7 +24,7 @@ void *gencb_alloc(size_t len, BlockDriverCompletionFunc *cb, void *opaque)
 void gencb_complete(void *opaque, int ret)
 {
     GenericCB *gencb = opaque;
-    BlockDriverCompletionFunc *cb = gencb->cb;
+    BlockCompletionFunc *cb = gencb->cb;
     void *user_opaque = gencb->opaque;
 
     g_free(gencb);
block/qed-table.c +5 -5
index f61107a..513aa87 100644
@@ -49,7 +49,7 @@ out:
 }
 
 static void qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
-                           BlockDriverCompletionFunc *cb, void *opaque)
+                           BlockCompletionFunc *cb, void *opaque)
 {
     QEDReadTableCB *read_table_cb = gencb_alloc(sizeof(*read_table_cb),
                                                 cb, opaque);
@@ -119,7 +119,7 @@ out:
  */
 static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
                             unsigned int index, unsigned int n, bool flush,
-                            BlockDriverCompletionFunc *cb, void *opaque)
+                            BlockCompletionFunc *cb, void *opaque)
 {
     QEDWriteTableCB *write_table_cb;
     unsigned int sector_mask = BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1;
@@ -180,7 +180,7 @@ int qed_read_l1_table_sync(BDRVQEDState *s)
 }
 
 void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n,
-                        BlockDriverCompletionFunc *cb, void *opaque)
+                        BlockCompletionFunc *cb, void *opaque)
 {
     BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE);
     qed_write_table(s, s->header.l1_table_offset,
@@ -235,7 +235,7 @@ static void qed_read_l2_table_cb(void *opaque, int ret)
 }
 
 void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
-                       BlockDriverCompletionFunc *cb, void *opaque)
+                       BlockCompletionFunc *cb, void *opaque)
 {
     QEDReadL2TableCB *read_l2_table_cb;
 
@@ -275,7 +275,7 @@ int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset
 
 void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
                         unsigned int index, unsigned int n, bool flush,
-                        BlockDriverCompletionFunc *cb, void *opaque)
+                        BlockCompletionFunc *cb, void *opaque)
 {
     BLKDBG_EVENT(s->bs->file, BLKDBG_L2_UPDATE);
     qed_write_table(s, request->l2_table->offset,
block/qed.c +23 -23

110 lines not on this page · raw message

block/qed.h +6 -6
index 2b0e724..d3934a0 100644
@@ -128,7 +128,7 @@ enum {
 };
 
 typedef struct QEDAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUBH *bh;
     int bh_ret;                     /* final return status for completion bh */
     QSIMPLEQ_ENTRY(QEDAIOCB) next;  /* next request */
@@ -203,11 +203,11 @@ typedef void QEDFindClusterFunc(void *opaque, int ret, uint64_t offset, size_t l
  * Generic callback for chaining async callbacks
  */
 typedef struct {
-    BlockDriverCompletionFunc *cb;
+    BlockCompletionFunc *cb;
     void *opaque;
 } GenericCB;
 
-void *gencb_alloc(size_t len, BlockDriverCompletionFunc *cb, void *opaque);
+void *gencb_alloc(size_t len, BlockCompletionFunc *cb, void *opaque);
 void gencb_complete(void *opaque, int ret);
 
 /**
@@ -230,16 +230,16 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table);
  */
 int qed_read_l1_table_sync(BDRVQEDState *s);
 void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n,
-                        BlockDriverCompletionFunc *cb, void *opaque);
+                        BlockCompletionFunc *cb, void *opaque);
 int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
                             unsigned int n);
 int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
                            uint64_t offset);
 void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset,
-                       BlockDriverCompletionFunc *cb, void *opaque);
+                       BlockCompletionFunc *cb, void *opaque);
 void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
                         unsigned int index, unsigned int n, bool flush,
-                        BlockDriverCompletionFunc *cb, void *opaque);
+                        BlockCompletionFunc *cb, void *opaque);
 int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
                             unsigned int index, unsigned int n, bool flush);
 
block/quorum.c +19 -19
index f958269..26f8dfa 100644
@@ -92,7 +92,7 @@ typedef struct QuorumAIOCB QuorumAIOCB;
  * $children_count QuorumChildRequest.
  */
 typedef struct QuorumChildRequest {
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
     QEMUIOVector qiov;
     uint8_t *buf;
     int ret;
@@ -105,7 +105,7 @@ typedef struct QuorumChildRequest {
  * used to do operations on each children and track overall progress.
  */
 struct QuorumAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
 
     /* Request metadata */
     uint64_t sector_num;
@@ -130,7 +130,7 @@ struct QuorumAIOCB {
 
 static bool quorum_vote(QuorumAIOCB *acb);
 
-static void quorum_aio_cancel(BlockDriverAIOCB *blockacb)
+static void quorum_aio_cancel(BlockAIOCB *blockacb)
 {
     QuorumAIOCB *acb = container_of(blockacb, QuorumAIOCB, common);
     BDRVQuorumState *s = acb->common.bs->opaque;
@@ -187,7 +187,7 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
                                    QEMUIOVector *qiov,
                                    uint64_t sector_num,
                                    int nb_sectors,
-                                   BlockDriverCompletionFunc *cb,
+                                   BlockCompletionFunc *cb,
                                    void *opaque)
 {
     QuorumAIOCB *acb = qemu_aio_get(&quorum_aiocb_info, bs, cb, opaque);
@@ -265,7 +265,7 @@ static void quorum_rewrite_aio_cb(void *opaque, int ret)
     quorum_aio_finalize(acb);
 }
 
-static BlockDriverAIOCB *read_fifo_child(QuorumAIOCB *acb);
+static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb);
 
 static void quorum_copy_qiov(QEMUIOVector *dest, QEMUIOVector *source)
 {
@@ -641,7 +641,7 @@ free_exit:
     return rewrite;
 }
 
-static BlockDriverAIOCB *read_quorum_children(QuorumAIOCB *acb)
+static BlockAIOCB *read_quorum_children(QuorumAIOCB *acb)
 {
     BDRVQuorumState *s = acb->common.bs->opaque;
     int i;
@@ -660,7 +660,7 @@ static BlockDriverAIOCB *read_quorum_children(QuorumAIOCB *acb)
     return &acb->common;
 }
 
-static BlockDriverAIOCB *read_fifo_child(QuorumAIOCB *acb)
+static BlockAIOCB *read_fifo_child(QuorumAIOCB *acb)
 {
     BDRVQuorumState *s = acb->common.bs->opaque;
 
@@ -676,12 +676,12 @@ static BlockDriverAIOCB *read_fifo_child(QuorumAIOCB *acb)
     return &acb->common;
 }
 
-static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
-                                          int64_t sector_num,
-                                          QEMUIOVector *qiov,
-                                          int nb_sectors,
-                                          BlockDriverCompletionFunc *cb,
-                                          void *opaque)
+static BlockAIOCB *quorum_aio_readv(BlockDriverState *bs,
+                                    int64_t sector_num,
+                                    QEMUIOVector *qiov,
+                                    int nb_sectors,
+                                    BlockCompletionFunc *cb,
+                                    void *opaque)
 {
     BDRVQuorumState *s = bs->opaque;
     QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num,
@@ -697,12 +697,12 @@ static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
     return read_fifo_child(acb);
 }
 
-static BlockDriverAIOCB *quorum_aio_writev(BlockDriverState *bs,
-                                          int64_t sector_num,
-                                          QEMUIOVector *qiov,
-                                          int nb_sectors,
-                                          BlockDriverCompletionFunc *cb,
-                                          void *opaque)
+static BlockAIOCB *quorum_aio_writev(BlockDriverState *bs,
+                                     int64_t sector_num,
+                                     QEMUIOVector *qiov,
+                                     int nb_sectors,
+                                     BlockCompletionFunc *cb,
+                                     void *opaque)
 {
     BDRVQuorumState *s = bs->opaque;
     QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num, nb_sectors,
block/raw-aio.h +4 -4
index e18c975..80681ce 100644
@@ -35,9 +35,9 @@
 #ifdef CONFIG_LINUX_AIO
 void *laio_init(void);
 void laio_cleanup(void *s);
-BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
+BlockAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type);
+        BlockCompletionFunc *cb, void *opaque, int type);
 void laio_detach_aio_context(void *s, AioContext *old_context);
 void laio_attach_aio_context(void *s, AioContext *new_context);
 void laio_io_plug(BlockDriverState *bs, void *aio_ctx);
@@ -49,10 +49,10 @@ typedef struct QEMUWin32AIOState QEMUWin32AIOState;
 QEMUWin32AIOState *win32_aio_init(void);
 void win32_aio_cleanup(QEMUWin32AIOState *aio);
 int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfile);
-BlockDriverAIOCB *win32_aio_submit(BlockDriverState *bs,
+BlockAIOCB *win32_aio_submit(BlockDriverState *bs,
         QEMUWin32AIOState *aio, HANDLE hfile,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type);
+        BlockCompletionFunc *cb, void *opaque, int type);
 void win32_aio_detach_aio_context(QEMUWin32AIOState *aio,
                                   AioContext *old_context);
 void win32_aio_attach_aio_context(QEMUWin32AIOState *aio,
block/raw-posix.c +16 -16
index a253697..9255d53 100644
@@ -1041,9 +1041,9 @@ static int paio_submit_co(BlockDriverState *bs, int fd,
     return thread_pool_submit_co(pool, aio_worker, acb);
 }
 
-static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
+static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type)
+        BlockCompletionFunc *cb, void *opaque, int type)
 {
     RawPosixAIOData *acb = g_slice_new(RawPosixAIOData);
     ThreadPool *pool;
@@ -1066,9 +1066,9 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
     return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
 }
 
-static BlockDriverAIOCB *raw_aio_submit(BlockDriverState *bs,
+static BlockAIOCB *raw_aio_submit(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type)
+        BlockCompletionFunc *cb, void *opaque, int type)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1125,24 +1125,24 @@ static void raw_aio_flush_io_queue(BlockDriverState *bs)
 #endif
 }
 
-static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
+static BlockAIOCB *raw_aio_readv(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     return raw_aio_submit(bs, sector_num, qiov, nb_sectors,
                           cb, opaque, QEMU_AIO_READ);
 }
 
-static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
+static BlockAIOCB *raw_aio_writev(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     return raw_aio_submit(bs, sector_num, qiov, nb_sectors,
                           cb, opaque, QEMU_AIO_WRITE);
 }
 
-static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
-        BlockDriverCompletionFunc *cb, void *opaque)
+static BlockAIOCB *raw_aio_flush(BlockDriverState *bs,
+        BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1585,9 +1585,9 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
     return ret;
 }
 
-static coroutine_fn BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,
+static coroutine_fn BlockAIOCB *raw_aio_discard(BlockDriverState *bs,
     int64_t sector_num, int nb_sectors,
-    BlockDriverCompletionFunc *cb, void *opaque)
+    BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1925,9 +1925,9 @@ static int hdev_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
     return ioctl(s->fd, req, buf);
 }
 
-static BlockDriverAIOCB *hdev_aio_ioctl(BlockDriverState *bs,
+static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs,
         unsigned long int req, void *buf,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
     RawPosixAIOData *acb;
@@ -1966,9 +1966,9 @@ static int fd_open(BlockDriverState *bs)
 
 #endif /* !linux && !FreeBSD */
 
-static coroutine_fn BlockDriverAIOCB *hdev_aio_discard(BlockDriverState *bs,
+static coroutine_fn BlockAIOCB *hdev_aio_discard(BlockDriverState *bs,
     int64_t sector_num, int nb_sectors,
-    BlockDriverCompletionFunc *cb, void *opaque)
+    BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
 
block/raw-win32.c +8 -8
index 9bf8225..7b58881 100644
@@ -138,9 +138,9 @@ static int aio_worker(void *arg)
     return ret;
 }
 
-static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile,
+static BlockAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type)
+        BlockCompletionFunc *cb, void *opaque, int type)
 {
     RawWin32AIOData *acb = g_slice_new(RawWin32AIOData);
     ThreadPool *pool;
@@ -369,9 +369,9 @@ fail:
     return ret;
 }
 
-static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
+static BlockAIOCB *raw_aio_readv(BlockDriverState *bs,
                          int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-                         BlockDriverCompletionFunc *cb, void *opaque)
+                         BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
     if (s->aio) {
@@ -383,9 +383,9 @@ static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
     }
 }
 
-static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
+static BlockAIOCB *raw_aio_writev(BlockDriverState *bs,
                           int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-                          BlockDriverCompletionFunc *cb, void *opaque)
+                          BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
     if (s->aio) {
@@ -397,8 +397,8 @@ static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
     }
 }
 
-static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
-                         BlockDriverCompletionFunc *cb, void *opaque)
+static BlockAIOCB *raw_aio_flush(BlockDriverState *bs,
+                         BlockCompletionFunc *cb, void *opaque)
 {
     BDRVRawState *s = bs->opaque;
     return paio_submit(bs, s->hfile, 0, NULL, 0, cb, opaque, QEMU_AIO_FLUSH);
block/raw_bsd.c +4 -4
index f82f4c2..401b967 100644
@@ -129,10 +129,10 @@ static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
     return bdrv_ioctl(bs->file, req, buf);
 }
 
-static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
-                                       unsigned long int req, void *buf,
-                                       BlockDriverCompletionFunc *cb,
-                                       void *opaque)
+static BlockAIOCB *raw_aio_ioctl(BlockDriverState *bs,
+                                 unsigned long int req, void *buf,
+                                 BlockCompletionFunc *cb,
+                                 void *opaque)
 {
     return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
 }
block/rbd.c +29 -29

99 lines not on this page · raw message

block/sheepdog.c +2 -2
index 7da36e1..2457b74 100644
@@ -301,7 +301,7 @@ enum AIOCBState {
 };
 
 struct SheepdogAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
 
     QEMUIOVector *qiov;
 
@@ -477,7 +477,7 @@ static bool sd_acb_cancelable(const SheepdogAIOCB *acb)
     return true;
 }
 
-static void sd_aio_cancel(BlockDriverAIOCB *blockacb)
+static void sd_aio_cancel(BlockAIOCB *blockacb)
 {
     SheepdogAIOCB *acb = (SheepdogAIOCB *)blockacb;
     BDRVSheepdogState *s = acb->common.bs->opaque;
block/stream.c +1 -1
index cdea3e8..a1dc8da 100644
@@ -220,7 +220,7 @@ static const BlockJobDriver stream_job_driver = {
 void stream_start(BlockDriverState *bs, BlockDriverState *base,
                   const char *backing_file_str, int64_t speed,
                   BlockdevOnError on_error,
-                  BlockDriverCompletionFunc *cb,
+                  BlockCompletionFunc *cb,
                   void *opaque, Error **errp)
 {
     StreamBlockJob *s;
block/win32-aio.c +4 -4
index 5030e32..de273b8 100644
@@ -44,7 +44,7 @@ struct QEMUWin32AIOState {
 };
 
 typedef struct QEMUWin32AIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     struct QEMUWin32AIOState *ctx;
     int nbytes;
     OVERLAPPED ov;
@@ -106,7 +106,7 @@ static void win32_aio_completion_cb(EventNotifier *e)
     }
 }
 
-static void win32_aio_cancel(BlockDriverAIOCB *blockacb)
+static void win32_aio_cancel(BlockAIOCB *blockacb)
 {
     QEMUWin32AIOCB *waiocb = (QEMUWin32AIOCB *)blockacb;
 
@@ -124,10 +124,10 @@ static const AIOCBInfo win32_aiocb_info = {
     .cancel             = win32_aio_cancel,
 };
 
-BlockDriverAIOCB *win32_aio_submit(BlockDriverState *bs,
+BlockAIOCB *win32_aio_submit(BlockDriverState *bs,
         QEMUWin32AIOState *aio, HANDLE hfile,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque, int type)
+        BlockCompletionFunc *cb, void *opaque, int type)
 {
     struct QEMUWin32AIOCB *waiocb;
     uint64_t offset = sector_num * 512;
blockjob.c +2 -2
index 3af0f6c..ff0908a 100644
@@ -36,7 +36,7 @@
 #include "qapi-event.h"
 
 void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
-                       int64_t speed, BlockDriverCompletionFunc *cb,
+                       int64_t speed, BlockCompletionFunc *cb,
                        void *opaque, Error **errp)
 {
     BlockJob *job;
@@ -155,7 +155,7 @@ void block_job_iostatus_reset(BlockJob *job)
 
 struct BlockCancelData {
     BlockJob *job;
-    BlockDriverCompletionFunc *cb;
+    BlockCompletionFunc *cb;
     void *opaque;
     bool cancelled;
     int ret;
dma-helpers.c +12 -12
index f6811fa..0486798 100644
@@ -67,9 +67,9 @@ void qemu_sglist_destroy(QEMUSGList *qsg)
 }
 
 typedef struct {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     BlockDriverState *bs;
-    BlockDriverAIOCB *acb;
+    BlockAIOCB *acb;
     QEMUSGList *sg;
     uint64_t sector_num;
     DMADirection dir;
@@ -179,14 +179,14 @@ static void dma_bdrv_cb(void *opaque, int ret)
     assert(dbs->acb);
 }
 
-static void dma_aio_cancel(BlockDriverAIOCB *acb)
+static void dma_aio_cancel(BlockAIOCB *acb)
 {
     DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common);
 
     trace_dma_aio_cancel(dbs);
 
     if (dbs->acb) {
-        BlockDriverAIOCB *acb = dbs->acb;
+        BlockAIOCB *acb = dbs->acb;
         dbs->acb = NULL;
         dbs->in_cancel = true;
         bdrv_aio_cancel(acb);
@@ -201,9 +201,9 @@ static const AIOCBInfo dma_aiocb_info = {
     .cancel             = dma_aio_cancel,
 };
 
-BlockDriverAIOCB *dma_bdrv_io(
+BlockAIOCB *dma_bdrv_io(
     BlockDriverState *bs, QEMUSGList *sg, uint64_t sector_num,
-    DMAIOFunc *io_func, BlockDriverCompletionFunc *cb,
+    DMAIOFunc *io_func, BlockCompletionFunc *cb,
     void *opaque, DMADirection dir)
 {
     DMAAIOCB *dbs = qemu_aio_get(&dma_aiocb_info, bs, cb, opaque);
@@ -226,17 +226,17 @@ BlockDriverAIOCB *dma_bdrv_io(
 }
 
 
-BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs,
-                                QEMUSGList *sg, uint64_t sector,
-                                void (*cb)(void *opaque, int ret), void *opaque)
+BlockAIOCB *dma_bdrv_read(BlockDriverState *bs,
+                          QEMUSGList *sg, uint64_t sector,
+                          void (*cb)(void *opaque, int ret), void *opaque)
 {
     return dma_bdrv_io(bs, sg, sector, bdrv_aio_readv, cb, opaque,
                        DMA_DIRECTION_FROM_DEVICE);
 }
 
-BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
-                                 QEMUSGList *sg, uint64_t sector,
-                                 void (*cb)(void *opaque, int ret), void *opaque)
+BlockAIOCB *dma_bdrv_write(BlockDriverState *bs,
+                           QEMUSGList *sg, uint64_t sector,
+                           void (*cb)(void *opaque, int ret), void *opaque)
 {
     return dma_bdrv_io(bs, sg, sector, bdrv_aio_writev, cb, opaque,
                        DMA_DIRECTION_TO_DEVICE);
hw/block/nvme.h +1 -1
index bd8fc3e..993c511 100644
@@ -636,7 +636,7 @@ typedef struct NvmeAsyncEvent {
 
 typedef struct NvmeRequest {
     struct NvmeSQueue       *sq;
-    BlockDriverAIOCB        *aiocb;
+    BlockAIOCB              *aiocb;
     uint16_t                status;
     NvmeCqe                 cqe;
     BlockAcctCookie         acct;
hw/ide/ahci.c +1 -1
index ba69de3..f301fe1 100644
@@ -1105,7 +1105,7 @@ out:
 }
 
 static void ahci_start_dma(IDEDMA *dma, IDEState *s,
-                           BlockDriverCompletionFunc *dma_cb)
+                           BlockCompletionFunc *dma_cb)
 {
 #ifdef DEBUG_AHCI
     AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma);
hw/ide/ahci.h +1 -1
index 1543df7..fe32eab 100644
@@ -241,7 +241,7 @@ typedef struct AHCIDevice AHCIDevice;
 
 typedef struct NCQTransferState {
     AHCIDevice *drive;
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
     QEMUSGList sglist;
     BlockAcctCookie acct;
     uint16_t sector_count;
hw/ide/core.c +6 -6
index 6fba056..0c74919 100644
@@ -360,15 +360,15 @@ static void ide_set_signature(IDEState *s)
 }
 
 typedef struct TrimAIOCB {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     QEMUBH *bh;
     int ret;
     QEMUIOVector *qiov;
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
     int i, j;
 } TrimAIOCB;
 
-static void trim_aio_cancel(BlockDriverAIOCB *acb)
+static void trim_aio_cancel(BlockAIOCB *acb)
 {
     TrimAIOCB *iocb = container_of(acb, TrimAIOCB, common);
 
@@ -440,9 +440,9 @@ static void ide_issue_trim_cb(void *opaque, int ret)
     }
 }
 
-BlockDriverAIOCB *ide_issue_trim(BlockDriverState *bs,
+BlockAIOCB *ide_issue_trim(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     TrimAIOCB *iocb;
 
@@ -785,7 +785,7 @@ static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
     ide_start_dma(s, ide_dma_cb);
 }
 
-void ide_start_dma(IDEState *s, BlockDriverCompletionFunc *cb)
+void ide_start_dma(IDEState *s, BlockCompletionFunc *cb)
 {
     if (s->bus->dma->ops->start_dma) {
         s->bus->dma->ops->start_dma(s->bus->dma, s, cb);
hw/ide/internal.h +6 -6
index 5c19f79..9314c80 100644
@@ -319,7 +319,7 @@ typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;
 
 typedef void EndTransferFunc(IDEState *);
 
-typedef void DMAStartFunc(IDEDMA *, IDEState *, BlockDriverCompletionFunc *);
+typedef void DMAStartFunc(IDEDMA *, IDEState *, BlockCompletionFunc *);
 typedef void DMAVoidFunc(IDEDMA *);
 typedef int DMAIntFunc(IDEDMA *, int);
 typedef void DMAStopFunc(IDEDMA *, bool);
@@ -389,7 +389,7 @@ struct IDEState {
     int cd_sector_size;
     int atapi_dma; /* true if dma is requested for the packet cmd */
     BlockAcctCookie acct;
-    BlockDriverAIOCB *pio_aiocb;
+    BlockAIOCB *pio_aiocb;
     struct iovec iov;
     QEMUIOVector qiov;
     /* ATA DMA state */
@@ -442,7 +442,7 @@ struct IDEDMA {
     const struct IDEDMAOps *ops;
     struct iovec iov;
     QEMUIOVector qiov;
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
 };
 
 struct IDEBus {
@@ -521,7 +521,7 @@ void ide_bus_reset(IDEBus *bus);
 int64_t ide_get_sector(IDEState *s);
 void ide_set_sector(IDEState *s, int64_t sector_num);
 
-void ide_start_dma(IDEState *s, BlockDriverCompletionFunc *cb);
+void ide_start_dma(IDEState *s, BlockCompletionFunc *cb);
 void ide_dma_error(IDEState *s);
 
 void ide_atapi_cmd_ok(IDEState *s);
@@ -555,9 +555,9 @@ void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
                         EndTransferFunc *end_transfer_func);
 void ide_transfer_stop(IDEState *s);
 void ide_set_inactive(IDEState *s, bool more);
-BlockDriverAIOCB *ide_issue_trim(BlockDriverState *bs,
+BlockAIOCB *ide_issue_trim(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque);
+        BlockCompletionFunc *cb, void *opaque);
 
 /* hw/ide/atapi.c */
 void ide_atapi_cmd(IDEState *s);
hw/ide/macio.c +1 -1
index cefc85c..6b5cce5 100644
@@ -558,7 +558,7 @@ static void ide_nop_restart(void *opaque, int x, RunState y)
 }
 
 static void ide_dbdma_start(IDEDMA *dma, IDEState *s,
-                            BlockDriverCompletionFunc *cb)
+                            BlockCompletionFunc *cb)
 {
     MACIOIDEState *m = container_of(dma, MACIOIDEState, dma);
 
hw/ide/pci.c +1 -1
index 2397f35..6ff1c58 100644
@@ -38,7 +38,7 @@
         IDE_RETRY_READ | IDE_RETRY_FLUSH)
 
 static void bmdma_start_dma(IDEDMA *dma, IDEState *s,
-                            BlockDriverCompletionFunc *dma_cb)
+                            BlockCompletionFunc *dma_cb)
 {
     BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
 
hw/ide/pci.h +1 -1
index 517711f..2e9314a 100644
@@ -23,7 +23,7 @@ typedef struct BMDMAState {
     uint32_t cur_prd_addr;
     uint32_t cur_prd_len;
     uint8_t unit;
-    BlockDriverCompletionFunc *dma_cb;
+    BlockCompletionFunc *dma_cb;
     int64_t sector_num;
     uint32_t nsector;
     MemoryRegion addr_ioport;
hw/ppc/mac.h +1 -1
index aff2b9a..8bdba30 100644
@@ -131,7 +131,7 @@ typedef struct MACIOIDEState {
 
     MemoryRegion mem;
     IDEBus bus;
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
     IDEDMA dma;
     void *dbdma;
     bool dma_active;
hw/scsi/scsi-generic.c +1 -1
index 20587b4..5301886 100644
@@ -157,7 +157,7 @@ static void scsi_cancel_io(SCSIRequest *req)
 
 static int execute_command(BlockDriverState *bdrv,
                            SCSIGenericReq *r, int direction,
-			   BlockDriverCompletionFunc *complete)
+                           BlockCompletionFunc *complete)
 {
     r->io_header.interface_id = 'S';
     r->io_header.dxfer_direction = direction;
include/block/aio.h +6 -6
index 4603c0f..57619ab 100644
@@ -22,23 +22,23 @@
 #include "qemu/rfifolock.h"
 #include "qemu/timer.h"
 
-typedef struct BlockDriverAIOCB BlockDriverAIOCB;
-typedef void BlockDriverCompletionFunc(void *opaque, int ret);
+typedef struct BlockAIOCB BlockAIOCB;
+typedef void BlockCompletionFunc(void *opaque, int ret);
 
 typedef struct AIOCBInfo {
-    void (*cancel)(BlockDriverAIOCB *acb);
+    void (*cancel)(BlockAIOCB *acb);
     size_t aiocb_size;
 } AIOCBInfo;
 
-struct BlockDriverAIOCB {
+struct BlockAIOCB {
     const AIOCBInfo *aiocb_info;
     BlockDriverState *bs;
-    BlockDriverCompletionFunc *cb;
+    BlockCompletionFunc *cb;
     void *opaque;
 };
 
 void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs,
-                   BlockDriverCompletionFunc *cb, void *opaque);
+                   BlockCompletionFunc *cb, void *opaque);
 void qemu_aio_release(void *p);
 
 typedef struct AioHandler AioHandler;
include/block/block.h +18 -18
index 27d002d..5b45743 100644
@@ -248,9 +248,9 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
                const uint8_t *buf, int nb_sectors);
 int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
                int nb_sectors, BdrvRequestFlags flags);
-BlockDriverAIOCB *bdrv_aio_write_zeroes(BlockDriverState *bs, int64_t sector_num,
-                                        int nb_sectors, BdrvRequestFlags flags,
-                                        BlockDriverCompletionFunc *cb, void *opaque);
+BlockAIOCB *bdrv_aio_write_zeroes(BlockDriverState *bs, int64_t sector_num,
+                                  int nb_sectors, BdrvRequestFlags flags,
+                                  BlockCompletionFunc *cb, void *opaque);
 int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
 int bdrv_pread(BlockDriverState *bs, int64_t offset,
                void *buf, int count);
@@ -326,18 +326,18 @@ BlockDriverState *check_to_replace_node(const char *node_name, Error **errp);
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
-BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
-                                 QEMUIOVector *iov, int nb_sectors,
-                                 BlockDriverCompletionFunc *cb, void *opaque);
-BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
-                                  QEMUIOVector *iov, int nb_sectors,
-                                  BlockDriverCompletionFunc *cb, void *opaque);
-BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
-                                 BlockDriverCompletionFunc *cb, void *opaque);
-BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
-                                   int64_t sector_num, int nb_sectors,
-                                   BlockDriverCompletionFunc *cb, void *opaque);
-void bdrv_aio_cancel(BlockDriverAIOCB *acb);
+BlockAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
+                           QEMUIOVector *iov, int nb_sectors,
+                           BlockCompletionFunc *cb, void *opaque);
+BlockAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
+                            QEMUIOVector *iov, int nb_sectors,
+                            BlockCompletionFunc *cb, void *opaque);
+BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs,
+                           BlockCompletionFunc *cb, void *opaque);
+BlockAIOCB *bdrv_aio_discard(BlockDriverState *bs,
+                             int64_t sector_num, int nb_sectors,
+                             BlockCompletionFunc *cb, void *opaque);
+void bdrv_aio_cancel(BlockAIOCB *acb);
 
 typedef struct BlockRequest {
     /* Fields to be filled by multiwrite caller */
@@ -345,7 +345,7 @@ typedef struct BlockRequest {
     int nb_sectors;
     int flags;
     QEMUIOVector *qiov;
-    BlockDriverCompletionFunc *cb;
+    BlockCompletionFunc *cb;
     void *opaque;
 
     /* Filled by multiwrite implementation */
@@ -357,9 +357,9 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
 
 /* sg packet commands */
 int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
-BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
+BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
         unsigned long int req, void *buf,
-        BlockDriverCompletionFunc *cb, void *opaque);
+        BlockCompletionFunc *cb, void *opaque);
 
 /* Invalidate any cached metadata used by image formats */
 void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
include/block/block_int.h +15 -15
index da00aa5..e8e33a8 100644
@@ -128,17 +128,17 @@ struct BlockDriver {
     void (*bdrv_refresh_filename)(BlockDriverState *bs);
 
     /* aio */
-    BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs,
+    BlockAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque);
-    BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs,
+        BlockCompletionFunc *cb, void *opaque);
+    BlockAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque);
-    BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
-        BlockDriverCompletionFunc *cb, void *opaque);
-    BlockDriverAIOCB *(*bdrv_aio_discard)(BlockDriverState *bs,
+        BlockCompletionFunc *cb, void *opaque);
+    BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
+        BlockCompletionFunc *cb, void *opaque);
+    BlockAIOCB *(*bdrv_aio_discard)(BlockDriverState *bs,
         int64_t sector_num, int nb_sectors,
-        BlockDriverCompletionFunc *cb, void *opaque);
+        BlockCompletionFunc *cb, void *opaque);
 
     int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
         int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
@@ -218,9 +218,9 @@ struct BlockDriver {
 
     /* to control generic scsi devices */
     int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
-    BlockDriverAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs,
+    BlockAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs,
         unsigned long int req, void *buf,
-        BlockDriverCompletionFunc *cb, void *opaque);
+        BlockCompletionFunc *cb, void *opaque);
 
     /* List of options for creating images, terminated by name == NULL */
     QemuOptsList *create_opts;
@@ -501,7 +501,7 @@ int is_windows_drive(const char *filename);
  */
 void stream_start(BlockDriverState *bs, BlockDriverState *base,
                   const char *base_id, int64_t speed, BlockdevOnError on_error,
-                  BlockDriverCompletionFunc *cb,
+                  BlockCompletionFunc *cb,
                   void *opaque, Error **errp);
 
 /**
@@ -519,7 +519,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
  */
 void commit_start(BlockDriverState *bs, BlockDriverState *base,
                  BlockDriverState *top, int64_t speed,
-                 BlockdevOnError on_error, BlockDriverCompletionFunc *cb,
+                 BlockdevOnError on_error, BlockCompletionFunc *cb,
                  void *opaque, const char *backing_file_str, Error **errp);
 /**
  * commit_active_start:
@@ -535,7 +535,7 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
 void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
                          int64_t speed,
                          BlockdevOnError on_error,
-                         BlockDriverCompletionFunc *cb,
+                         BlockCompletionFunc *cb,
                          void *opaque, Error **errp);
 /*
  * mirror_start:
@@ -563,7 +563,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
                   int64_t speed, int64_t granularity, int64_t buf_size,
                   MirrorSyncMode mode, BlockdevOnError on_source_error,
                   BlockdevOnError on_target_error,
-                  BlockDriverCompletionFunc *cb,
+                  BlockCompletionFunc *cb,
                   void *opaque, Error **errp);
 
 /*
@@ -584,7 +584,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
                   int64_t speed, MirrorSyncMode sync_mode,
                   BlockdevOnError on_source_error,
                   BlockdevOnError on_target_error,
-                  BlockDriverCompletionFunc *cb, void *opaque,
+                  BlockCompletionFunc *cb, void *opaque,
                   Error **errp);
 
 #endif /* BLOCK_INT_H */
include/block/blockjob.h +2 -2
index 60aa835..acb399f 100644
@@ -104,7 +104,7 @@ struct BlockJob {
     int64_t speed;
 
     /** The completion function that will be called when the job completes.  */
-    BlockDriverCompletionFunc *cb;
+    BlockCompletionFunc *cb;
 
     /** Block other operations when block job is running */
     Error *blocker;
@@ -132,7 +132,7 @@ struct BlockJob {
  * called from a wrapper that is specific to the job type.
  */
 void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
-                       int64_t speed, BlockDriverCompletionFunc *cb,
+                       int64_t speed, BlockCompletionFunc *cb,
                        void *opaque, Error **errp);
 
 /**
include/block/thread-pool.h +2 -2
index 4723752..42eb5e8 100644
@@ -27,9 +27,9 @@ typedef struct ThreadPool ThreadPool;
 ThreadPool *thread_pool_new(struct AioContext *ctx);
 void thread_pool_free(ThreadPool *pool);
 
-BlockDriverAIOCB *thread_pool_submit_aio(ThreadPool *pool,
+BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool,
         ThreadPoolFunc *func, void *arg,
-        BlockDriverCompletionFunc *cb, void *opaque);
+        BlockCompletionFunc *cb, void *opaque);
 int coroutine_fn thread_pool_submit_co(ThreadPool *pool,
         ThreadPoolFunc *func, void *arg);
 void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg);
include/hw/scsi/scsi.h +1 -1
index 2e3a8f9..e3e27cb 100644
@@ -52,7 +52,7 @@ struct SCSIRequest {
     uint32_t          status;
     size_t            resid;
     SCSICommand       cmd;
-    BlockDriverAIOCB  *aiocb;
+    BlockAIOCB        *aiocb;
     QEMUSGList        *sg;
     bool              dma_started;
     uint8_t sense[SCSI_SENSE_BUF_SIZE];
include/monitor/monitor.h +2 -2
index 78a5fc8..47606d0 100644
@@ -27,10 +27,10 @@ int monitor_suspend(Monitor *mon);
 void monitor_resume(Monitor *mon);
 
 int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
-                                BlockDriverCompletionFunc *completion_cb,
+                                BlockCompletionFunc *completion_cb,
                                 void *opaque);
 int monitor_read_block_device_key(Monitor *mon, const char *device,
-                                  BlockDriverCompletionFunc *completion_cb,
+                                  BlockCompletionFunc *completion_cb,
                                   void *opaque);
 
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
include/sysemu/dma.h +13 -13
index 73ff86d..bcff53a 100644
@@ -197,20 +197,20 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len);
 void qemu_sglist_destroy(QEMUSGList *qsg);
 #endif
 
-typedef BlockDriverAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num,
-                                 QEMUIOVector *iov, int nb_sectors,
-                                 BlockDriverCompletionFunc *cb, void *opaque);
+typedef BlockAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num,
+                              QEMUIOVector *iov, int nb_sectors,
+                              BlockCompletionFunc *cb, void *opaque);
 
-BlockDriverAIOCB *dma_bdrv_io(BlockDriverState *bs,
-                              QEMUSGList *sg, uint64_t sector_num,
-                              DMAIOFunc *io_func, BlockDriverCompletionFunc *cb,
-                              void *opaque, DMADirection dir);
-BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs,
-                                QEMUSGList *sg, uint64_t sector,
-                                BlockDriverCompletionFunc *cb, void *opaque);
-BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
-                                 QEMUSGList *sg, uint64_t sector,
-                                 BlockDriverCompletionFunc *cb, void *opaque);
+BlockAIOCB *dma_bdrv_io(BlockDriverState *bs,
+                        QEMUSGList *sg, uint64_t sector_num,
+                        DMAIOFunc *io_func, BlockCompletionFunc *cb,
+                        void *opaque, DMADirection dir);
+BlockAIOCB *dma_bdrv_read(BlockDriverState *bs,
+                          QEMUSGList *sg, uint64_t sector,
+                          BlockCompletionFunc *cb, void *opaque);
+BlockAIOCB *dma_bdrv_write(BlockDriverState *bs,
+                           QEMUSGList *sg, uint64_t sector,
+                           BlockCompletionFunc *cb, void *opaque);
 uint64_t dma_buf_read(uint8_t *ptr, int32_t len, QEMUSGList *sg);
 uint64_t dma_buf_write(uint8_t *ptr, int32_t len, QEMUSGList *sg);
 
monitor.c +3 -3
index 7e450ec..59653cd 100644
@@ -206,7 +206,7 @@ struct Monitor {
     ReadLineState *rs;
     MonitorControl *mc;
     CPUState *mon_cpu;
-    BlockDriverCompletionFunc *password_completion_cb;
+    BlockCompletionFunc *password_completion_cb;
     void *password_opaque;
     mon_cmd_t *cmd_table;
     QError *error;
@@ -5365,7 +5365,7 @@ ReadLineState *monitor_get_rs(Monitor *mon)
 }
 
 int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
-                                BlockDriverCompletionFunc *completion_cb,
+                                BlockCompletionFunc *completion_cb,
                                 void *opaque)
 {
     int err;
@@ -5397,7 +5397,7 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
 }
 
 int monitor_read_block_device_key(Monitor *mon, const char *device,
-                                  BlockDriverCompletionFunc *completion_cb,
+                                  BlockCompletionFunc *completion_cb,
                                   void *opaque)
 {
     BlockDriverState *bs;
tests/test-thread-pool.c +1 -1
index f40b7fc..acc911b 100644
@@ -10,7 +10,7 @@ static ThreadPool *pool;
 static int active;
 
 typedef struct {
-    BlockDriverAIOCB *aiocb;
+    BlockAIOCB *aiocb;
     int n;
     int ret;
 } WorkerTestData;
thread-pool.c +4 -4
index bc07d7a..f9e9901 100644
@@ -35,7 +35,7 @@ enum ThreadState {
 };
 
 struct ThreadPoolElement {
-    BlockDriverAIOCB common;
+    BlockAIOCB common;
     ThreadPool *pool;
     ThreadPoolFunc *func;
     void *arg;
@@ -201,7 +201,7 @@ restart:
     }
 }
 
-static void thread_pool_cancel(BlockDriverAIOCB *acb)
+static void thread_pool_cancel(BlockAIOCB *acb)
 {
     ThreadPoolElement *elem = (ThreadPoolElement *)acb;
     ThreadPool *pool = elem->pool;
@@ -235,9 +235,9 @@ static const AIOCBInfo thread_pool_aiocb_info = {
     .cancel             = thread_pool_cancel,
 };
 
-BlockDriverAIOCB *thread_pool_submit_aio(ThreadPool *pool,
+BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool,
         ThreadPoolFunc *func, void *arg,
-        BlockDriverCompletionFunc *cb, void *opaque)
+        BlockCompletionFunc *cb, void *opaque)
 {
     ThreadPoolElement *req;
 
Signature · 1 line
1.9.3
Reviewed-by on v3 11/23
#48 lore raw

Re: [Qemu-devel] [PATCH v3 11/23] block: Rename BlockDriverAIOCB* to BlockAIOCB*

Quoted 46 lines · Markus Armbruster

I'll use BlockDriverAIOCB with block backends shortly, and the name is going to fit badly there. It's a block layer thing anyway, not just a block driver thing.

---
  block-migration.c           |   2 +-
  block.c                     | 151 ++++++++++++++++++++++----------------------
  block/archipelago.c         |  30 ++++-----
  block/backup.c              |   2 +-
  block/blkdebug.c            |  22 +++----
  block/blkverify.c           |  20 +++---
  block/commit.c              |   2 +-
  block/curl.c                |   8 +--
  block/iscsi.c               |   8 +--
  block/linux-aio.c           |   8 +--
  block/mirror.c              |   6 +-
  block/qed-gencb.c           |   4 +-
  block/qed-table.c           |  10 +--
  block/qed.c                 |  46 +++++++-------
  block/qed.h                 |  12 ++--
  block/quorum.c              |  38 +++++------
  block/raw-aio.h             |   8 +--
  block/raw-posix.c           |  32 +++++-----
  block/raw-win32.c           |  16 ++---
  block/raw_bsd.c             |   8 +--
  block/rbd.c                 |  58 ++++++++---------
  block/sheepdog.c            |   4 +-
  block/stream.c              |   2 +-
  block/win32-aio.c           |   8 +--
  blockjob.c                  |   4 +-
  dma-helpers.c               |  24 +++----
  hw/block/nvme.h             |   2 +-
  hw/ide/ahci.c               |   2 +-
  hw/ide/ahci.h               |   2 +-
  hw/ide/core.c               |  12 ++--
  hw/ide/internal.h           |  12 ++--
  hw/ide/macio.c              |   2 +-
  hw/ide/pci.c                |   2 +-
  hw/ide/pci.h                |   2 +-
  hw/ppc/mac.h                |   2 +-
  hw/scsi/scsi-generic.c      |   2 +-
  include/block/aio.h         |  12 ++--
  include/block/block.h       |  36 +++++------
  include/block/block_int.h   |  30 ++++-----
  include/block/blockjob.h    |   4 +-
Quoted 8 lines
  include/block/thread-pool.h |   4 +-
  include/hw/scsi/scsi.h      |   2 +-
  include/monitor/monitor.h   |   4 +-
  include/sysemu/dma.h        |  26 ++++----
  monitor.c                   |   6 +-
  tests/test-thread-pool.c    |   2 +-
  thread-pool.c               |   8 +--
  47 files changed, 353 insertions(+), 354 deletions(-)
Reviewed-by on v3 11/23
#49 lore raw

Re: [Qemu-devel] [PATCH v3 11/23] block: Rename BlockDriverAIOCB* to BlockAIOCB*

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 5 lines

I'll use BlockDriverAIOCB with block backends shortly, and the name is going to fit badly there. It's a block layer thing anyway, not just a block driver thing.

#50 lore raw

PATCH v3 12/23 virtio-blk: Drop redundant VirtIOBlock member conf

In reply to Markus Armbruster

Commit 12c5674 turned it into a pointer to member blk.conf.

---
 hw/block/virtio-blk.c          | 28 ++++++++++++++--------------
 include/hw/virtio/virtio-blk.h |  1 -
 2 files changed, 14 insertions(+), 15 deletions(-)
hw/block/virtio-blk.c +14 -14
index 38ad38f..5943af5 100644
@@ -298,7 +298,7 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
     if (sector & dev->sector_mask) {
         return false;
     }
-    if (size % dev->conf->logical_block_size) {
+    if (size % dev->blk.conf.logical_block_size) {
         return false;
     }
     bdrv_get_geometry(dev->bs, &total_sectors);
@@ -519,19 +519,20 @@ static void virtio_blk_reset(VirtIODevice *vdev)
 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
+    BlockConf *conf = &s->blk.conf;
     struct virtio_blk_config blkcfg;
     uint64_t capacity;
-    int blk_size = s->conf->logical_block_size;
+    int blk_size = conf->logical_block_size;
 
     bdrv_get_geometry(s->bs, &capacity);
     memset(&blkcfg, 0, sizeof(blkcfg));
     virtio_stq_p(vdev, &blkcfg.capacity, capacity);
     virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
-    virtio_stw_p(vdev, &blkcfg.cylinders, s->conf->cyls);
+    virtio_stw_p(vdev, &blkcfg.cylinders, conf->cyls);
     virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
-    virtio_stw_p(vdev, &blkcfg.min_io_size, s->conf->min_io_size / blk_size);
-    virtio_stw_p(vdev, &blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
-    blkcfg.heads = s->conf->heads;
+    virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size);
+    virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size);
+    blkcfg.heads = conf->heads;
     /*
      * We must ensure that the block device capacity is a multiple of
      * the logical block size. If that is not the case, let's use
@@ -543,13 +544,13 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
      * divided by 512 - instead it is the amount of blk_size blocks
      * per track (cylinder).
      */
-    if (bdrv_getlength(s->bs) /  s->conf->heads / s->conf->secs % blk_size) {
-        blkcfg.sectors = s->conf->secs & ~s->sector_mask;
+    if (bdrv_getlength(s->bs) /  conf->heads / conf->secs % blk_size) {
+        blkcfg.sectors = conf->secs & ~s->sector_mask;
     } else {
-        blkcfg.sectors = s->conf->secs;
+        blkcfg.sectors = conf->secs;
     }
     blkcfg.size_max = 0;
-    blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
+    blkcfg.physical_block_exp = get_physical_block_exp(&s->blk.conf);
     blkcfg.alignment_offset = 0;
     blkcfg.wce = bdrv_enable_write_cache(s->bs);
     memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
@@ -756,9 +757,8 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
                 sizeof(struct virtio_blk_config));
 
     s->bs = blk->conf.bs;
-    s->conf = &blk->conf;
     s->rq = NULL;
-    s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
+    s->sector_mask = (s->blk.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1;
 
     s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
     s->complete_request = virtio_blk_complete_request;
@@ -777,11 +777,11 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
-    bdrv_set_guest_block_size(s->bs, s->conf->logical_block_size);
+    bdrv_set_guest_block_size(s->bs, s->blk.conf.logical_block_size);
 
     bdrv_iostatus_enable(s->bs);
 
-    add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
+    add_boot_device_path(s->blk.conf.bootindex, dev, "/disk@0,0");
 }
 
 static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp)
include/hw/virtio/virtio-blk.h +0 -1
index cf61154..18967c8 100644
@@ -125,7 +125,6 @@ typedef struct VirtIOBlock {
     VirtQueue *vq;
     void *rq;
     QEMUBH *bh;
-    BlockConf *conf;
     VirtIOBlkConf blk;
     unsigned short sector_mask;
     bool original_wce;
Signature · 1 line
1.9.3
Reviewed-by on v3 12/23
#51 lore raw

Re: [Qemu-devel] [PATCH v3 12/23] virtio-blk: Drop redundant VirtIOBlock member conf

Quoted 105 lines · Markus Armbruster

Commit 12c5674 turned it into a pointer to member blk.conf.

---
 hw/block/virtio-blk.c          | 28 ++++++++++++++--------------
 include/hw/virtio/virtio-blk.h |  1 -
 2 files changed, 14 insertions(+), 15 deletions(-)
hw/block/virtio-blk.c +14 -14
index 38ad38f..5943af5 100644
@@ -298,7 +298,7 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
     if (sector & dev->sector_mask) {
         return false;
     }
-    if (size % dev->conf->logical_block_size) {
+    if (size % dev->blk.conf.logical_block_size) {
         return false;
     }
     bdrv_get_geometry(dev->bs, &total_sectors);
@@ -519,19 +519,20 @@ static void virtio_blk_reset(VirtIODevice *vdev)
 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
+    BlockConf *conf = &s->blk.conf;
     struct virtio_blk_config blkcfg;
     uint64_t capacity;
-    int blk_size = s->conf->logical_block_size;
+    int blk_size = conf->logical_block_size;
 
     bdrv_get_geometry(s->bs, &capacity);
     memset(&blkcfg, 0, sizeof(blkcfg));
     virtio_stq_p(vdev, &blkcfg.capacity, capacity);
     virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
-    virtio_stw_p(vdev, &blkcfg.cylinders, s->conf->cyls);
+    virtio_stw_p(vdev, &blkcfg.cylinders, conf->cyls);
     virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
-    virtio_stw_p(vdev, &blkcfg.min_io_size, s->conf->min_io_size / blk_size);
-    virtio_stw_p(vdev, &blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
-    blkcfg.heads = s->conf->heads;
+    virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size);
+    virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size);
+    blkcfg.heads = conf->heads;
     /*
      * We must ensure that the block device capacity is a multiple of
      * the logical block size. If that is not the case, let's use
@@ -543,13 +544,13 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
      * divided by 512 - instead it is the amount of blk_size blocks
      * per track (cylinder).
      */
-    if (bdrv_getlength(s->bs) /  s->conf->heads / s->conf->secs % blk_size) {
-        blkcfg.sectors = s->conf->secs & ~s->sector_mask;
+    if (bdrv_getlength(s->bs) /  conf->heads / conf->secs % blk_size) {
+        blkcfg.sectors = conf->secs & ~s->sector_mask;
     } else {
-        blkcfg.sectors = s->conf->secs;
+        blkcfg.sectors = conf->secs;
     }
     blkcfg.size_max = 0;
-    blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
+    blkcfg.physical_block_exp = get_physical_block_exp(&s->blk.conf);
     blkcfg.alignment_offset = 0;
     blkcfg.wce = bdrv_enable_write_cache(s->bs);
     memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
@@ -756,9 +757,8 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
                 sizeof(struct virtio_blk_config));
 
     s->bs = blk->conf.bs;
-    s->conf = &blk->conf;
     s->rq = NULL;
-    s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
+    s->sector_mask = (s->blk.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1;
 
     s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
     s->complete_request = virtio_blk_complete_request;
@@ -777,11 +777,11 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
-    bdrv_set_guest_block_size(s->bs, s->conf->logical_block_size);
+    bdrv_set_guest_block_size(s->bs, s->blk.conf.logical_block_size);
 
     bdrv_iostatus_enable(s->bs);
 
-    add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
+    add_boot_device_path(s->blk.conf.bootindex, dev, "/disk@0,0");
 }
 
 static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp)
include/hw/virtio/virtio-blk.h +0 -1
index cf61154..18967c8 100644
@@ -125,7 +125,6 @@ typedef struct VirtIOBlock {
     VirtQueue *vq;
     void *rq;
     QEMUBH *bh;
-    BlockConf *conf;
     VirtIOBlkConf blk;
     unsigned short sector_mask;
     bool original_wce;
Signature · 1 line
1.9.3

Look good

Reviewed-by on v3 12/23
#52 lore raw

Re: [Qemu-devel] [PATCH v3 12/23] virtio-blk: Drop redundant VirtIOBlock member conf

In reply to Markus Armbruster
Quoted 52 lines · Markus Armbruster

Commit 12c5674 turned it into a pointer to member blk.conf.

---
  hw/block/virtio-blk.c          | 28 ++++++++++++++--------------
  include/hw/virtio/virtio-blk.h |  1 -
  2 files changed, 14 insertions(+), 15 deletions(-)
hw/block/virtio-blk.c +7 -7
index 38ad38f..5943af5 100644
@@ -298,7 +298,7 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
      if (sector & dev->sector_mask) {
          return false;
      }
-    if (size % dev->conf->logical_block_size) {
+    if (size % dev->blk.conf.logical_block_size) {
          return false;
      }
      bdrv_get_geometry(dev->bs, &total_sectors);
@@ -519,19 +519,20 @@ static void virtio_blk_reset(VirtIODevice *vdev)
  static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
  {
      VirtIOBlock *s = VIRTIO_BLK(vdev);
+    BlockConf *conf = &s->blk.conf;
      struct virtio_blk_config blkcfg;
      uint64_t capacity;
-    int blk_size = s->conf->logical_block_size;
+    int blk_size = conf->logical_block_size;
 
      bdrv_get_geometry(s->bs, &capacity);
      memset(&blkcfg, 0, sizeof(blkcfg));
      virtio_stq_p(vdev, &blkcfg.capacity, capacity);
      virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
-    virtio_stw_p(vdev, &blkcfg.cylinders, s->conf->cyls);
+    virtio_stw_p(vdev, &blkcfg.cylinders, conf->cyls);
      virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
-    virtio_stw_p(vdev, &blkcfg.min_io_size, s->conf->min_io_size / blk_size);
-    virtio_stw_p(vdev, &blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
-    blkcfg.heads = s->conf->heads;
+    virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size);
+    virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size);
+    blkcfg.heads = conf->heads;
      /*
       * We must ensure that the block device capacity is a multiple of
       * the logical block size. If that is not the case, let's use
@@ -543,13 +544,13 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
       * divided by 512 - instead it is the amount of blk_size blocks
       * per track (cylinder).
       */
-    if (bdrv_getlength(s->bs) /  s->conf->heads / s->conf->secs % blk_size) {

hw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) · line 553

Quoted 10 lines
hw/block/virtio-blk.c +4 -3
-        blkcfg.sectors = s->conf->secs & ~s->sector_mask;
+    if (bdrv_getlength(s->bs) /  conf->heads / conf->secs % blk_size) {
+        blkcfg.sectors = conf->secs & ~s->sector_mask;
      } else {
-        blkcfg.sectors = s->conf->secs;
+        blkcfg.sectors = conf->secs;
      }
      blkcfg.size_max = 0;
-    blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
+    blkcfg.physical_block_exp = get_physical_block_exp(&s->blk.conf);

Is there a reason for you not using "conf" instead of "&s->blk.conf" here?

Of course, it's not wrong, so with the one or the other:

#53 lore raw

Re: [Qemu-devel] [PATCH v3 12/23] virtio-blk: Drop redundant VirtIOBlock member conf

Quoted 65 lines · Max Reitz
Quoted 51 lines · Markus Armbruster

Commit 12c5674 turned it into a pointer to member blk.conf.

---
  hw/block/virtio-blk.c          | 28 ++++++++++++++--------------
  include/hw/virtio/virtio-blk.h |  1 -
  2 files changed, 14 insertions(+), 15 deletions(-)
hw/block/virtio-blk.c +7 -7
index 38ad38f..5943af5 100644
@@ -298,7 +298,7 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
      if (sector & dev->sector_mask) {
          return false;
      }
-    if (size % dev->conf->logical_block_size) {
+    if (size % dev->blk.conf.logical_block_size) {
          return false;
      }
      bdrv_get_geometry(dev->bs, &total_sectors);
@@ -519,19 +519,20 @@ static void virtio_blk_reset(VirtIODevice *vdev)
  static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
  {
      VirtIOBlock *s = VIRTIO_BLK(vdev);
+    BlockConf *conf = &s->blk.conf;
      struct virtio_blk_config blkcfg;
      uint64_t capacity;
-    int blk_size = s->conf->logical_block_size;
+    int blk_size = conf->logical_block_size;
        bdrv_get_geometry(s->bs, &capacity);
      memset(&blkcfg, 0, sizeof(blkcfg));
      virtio_stq_p(vdev, &blkcfg.capacity, capacity);
      virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
-    virtio_stw_p(vdev, &blkcfg.cylinders, s->conf->cyls);
+    virtio_stw_p(vdev, &blkcfg.cylinders, conf->cyls);
      virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
-    virtio_stw_p(vdev, &blkcfg.min_io_size, s->conf->min_io_size / blk_size);
-    virtio_stw_p(vdev, &blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
-    blkcfg.heads = s->conf->heads;
+    virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size);
+    virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size);
+    blkcfg.heads = conf->heads;
      /*
       * We must ensure that the block device capacity is a multiple of
       * the logical block size. If that is not the case, let's use
@@ -543,13 +544,13 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
       * divided by 512 - instead it is the amount of blk_size blocks
       * per track (cylinder).
       */
-    if (bdrv_getlength(s->bs) /  s->conf->heads / s->conf->secs % blk_size) {

hw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) · line 553

Quoted 10 lines
hw/block/virtio-blk.c +4 -3
-        blkcfg.sectors = s->conf->secs & ~s->sector_mask;
+    if (bdrv_getlength(s->bs) /  conf->heads / conf->secs % blk_size) {
+        blkcfg.sectors = conf->secs & ~s->sector_mask;
      } else {
-        blkcfg.sectors = s->conf->secs;
+        blkcfg.sectors = conf->secs;
      }
      blkcfg.size_max = 0;
-    blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
+    blkcfg.physical_block_exp = get_physical_block_exp(&s->blk.conf);

Is there a reason for you not using "conf" instead of "&s->blk.conf" here?

Quoted 1 line

Of course, it's not wrong, so with the one or the other:

Looks like an editing accident to me. I'll clean it up in v4.

Quoted 1 line

Thanks!

#55 lore raw

PATCH v3 13/23 virtio-blk: Rename VirtIOBlkConf variables to conf

In reply to Markus Armbruster

This is consistent with how VirtIOFOOConf variables are named elsewhere, and makes blk available for BlockBackend variables.

---
 hw/block/dataplane/virtio-blk.c | 33 +++++++++++++-------------
 hw/block/dataplane/virtio-blk.h |  2 +-
 hw/block/virtio-blk.c           | 52 ++++++++++++++++++++---------------------
 include/hw/virtio/virtio-blk.h  |  2 +-
 4 files changed, 45 insertions(+), 44 deletions(-)
hw/block/dataplane/virtio-blk.c +17 -16
index 5458f9d..bd250df 100644
@@ -30,7 +30,7 @@ struct VirtIOBlockDataPlane {
     bool stopping;
     bool disabled;
 
-    VirtIOBlkConf *blk;
+    VirtIOBlkConf *conf;
 
     VirtIODevice *vdev;
     Vring vring;                    /* virtqueue vring */
@@ -94,7 +94,7 @@ static void handle_notify(EventNotifier *e)
     VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
 
     event_notifier_test_and_clear(&s->host_notifier);
-    bdrv_io_plug(s->blk->conf.bs);
+    bdrv_io_plug(s->conf->conf.bs);
     for (;;) {
         MultiReqBuffer mrb = {
             .num_writes = 0,
@@ -120,7 +120,7 @@ static void handle_notify(EventNotifier *e)
             virtio_blk_handle_request(req, &mrb);
         }
 
-        virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
+        virtio_submit_multiwrite(s->conf->conf.bs, &mrb);
 
         if (likely(ret == -EAGAIN)) { /* vring emptied */
             /* Re-enable guest->host notifies and stop processing the vring.
@@ -133,11 +133,11 @@ static void handle_notify(EventNotifier *e)
             break;
         }
     }
-    bdrv_io_unplug(s->blk->conf.bs);
+    bdrv_io_unplug(s->conf->conf.bs);
 }
 
 /* Context: QEMU global mutex held */
-void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
+void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
                                   VirtIOBlockDataPlane **dataplane,
                                   Error **errp)
 {
@@ -148,7 +148,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
 
     *dataplane = NULL;
 
-    if (!blk->data_plane && !blk->iothread) {
+    if (!conf->data_plane && !conf->iothread) {
         return;
     }
 
@@ -163,7 +163,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
     /* If dataplane is (re-)enabled while the guest is running there could be
      * block jobs that can conflict.
      */
-    if (bdrv_op_is_blocked(blk->conf.bs, BLOCK_OP_TYPE_DATAPLANE, &local_err)) {
+    if (bdrv_op_is_blocked(conf->conf.bs, BLOCK_OP_TYPE_DATAPLANE,
+                           &local_err)) {
         error_setg(errp, "cannot start dataplane thread: %s",
                    error_get_pretty(local_err));
         error_free(local_err);
@@ -172,10 +173,10 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
 
     s = g_new0(VirtIOBlockDataPlane, 1);
     s->vdev = vdev;
-    s->blk = blk;
+    s->conf = conf;
 
-    if (blk->iothread) {
-        s->iothread = blk->iothread;
+    if (conf->iothread) {
+        s->iothread = conf->iothread;
         object_ref(OBJECT(s->iothread));
     } else {
         /* Create per-device IOThread if none specified.  This is for
@@ -192,9 +193,9 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
     s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);
 
     error_setg(&s->blocker, "block device is in use by data plane");
-    bdrv_op_block_all(blk->conf.bs, s->blocker);
-    bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker);
-    bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
+    bdrv_op_block_all(conf->conf.bs, s->blocker);
+    bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker);
+    bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
 
     *dataplane = s;
 }
@@ -207,7 +208,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
     }
 
     virtio_blk_data_plane_stop(s);
-    bdrv_op_unblock_all(s->blk->conf.bs, s->blocker);
+    bdrv_op_unblock_all(s->conf->conf.bs, s->blocker);
     error_free(s->blocker);
     object_unref(OBJECT(s->iothread));
     qemu_bh_delete(s->bh);
@@ -262,7 +263,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
     s->started = true;
     trace_virtio_blk_data_plane_start(s);
 
-    bdrv_set_aio_context(s->blk->conf.bs, s->ctx);
+    bdrv_set_aio_context(s->conf->conf.bs, s->ctx);
 
     /* Kick right away to begin processing requests already in vring */
     event_notifier_set(virtio_queue_get_host_notifier(vq));
@@ -308,7 +309,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
     aio_set_event_notifier(s->ctx, &s->host_notifier, NULL);
 
     /* Drain and switch bs back to the QEMU main loop */
-    bdrv_set_aio_context(s->blk->conf.bs, qemu_get_aio_context());
+    bdrv_set_aio_context(s->conf->conf.bs, qemu_get_aio_context());
 
     aio_context_release(s->ctx);
 
hw/block/dataplane/virtio-blk.h +1 -1
index 1750c99..c88d40e 100644
@@ -19,7 +19,7 @@
 
 typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane;
 
-void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
+void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
                                   VirtIOBlockDataPlane **dataplane,
                                   Error **errp);
 void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s);
hw/block/virtio-blk.c +26 -26

150 lines not on this page · raw message

include/hw/virtio/virtio-blk.h +1 -1
index 18967c8..6f8f59e 100644
@@ -125,7 +125,7 @@ typedef struct VirtIOBlock {
     VirtQueue *vq;
     void *rq;
     QEMUBH *bh;
-    VirtIOBlkConf blk;
+    VirtIOBlkConf conf;
     unsigned short sector_mask;
     bool original_wce;
     VMChangeStateEntry *change;
Signature · 1 line
1.9.3
Reviewed-by on v3 13/23
#56 lore raw

Re: [Qemu-devel] [PATCH v3 13/23] virtio-blk: Rename VirtIOBlkConf variables to conf

hw/block/virtio-blk.c static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, · line 301

Quoted 2 lines
hw/block/virtio-blk.c +1 -1
-    if (size % dev->blk.conf.logical_block_size) {
+    if (size % dev->conf.conf.logical_block_size) {

This look strange (conf.conf)

Anyway this seems correct.

#57 lore raw

Re: [Qemu-devel] [PATCH v3 13/23] virtio-blk: Rename VirtIOBlkConf variables to conf

Quoted 4 lines · Benoît Canet

hw/block/virtio-blk.c static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, · line 301

Quoted 2 lines
hw/block/virtio-blk.c +1 -1
-    if (size % dev->blk.conf.logical_block_size) {
+    if (size % dev->conf.conf.logical_block_size) {

This look strange (conf.conf)

Yeah, it does. I picked conf anyway, for consistency with the existing similar members of sibling structs VirtIOSCSICommon and VirtIORNG.

Quoted 3 lines

Anyway this seems correct.

Thanks!

Reviewed-by on v3 13/23
#58 lore raw

Re: [Qemu-devel] [PATCH v3 13/23] virtio-blk: Rename VirtIOBlkConf variables to conf

In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster

This is consistent with how VirtIOFOOConf variables are named elsewhere, and makes blk available for BlockBackend variables.

---
  hw/block/dataplane/virtio-blk.c | 33 +++++++++++++-------------
  hw/block/dataplane/virtio-blk.h |  2 +-
  hw/block/virtio-blk.c           | 52 ++++++++++++++++++++---------------------
  include/hw/virtio/virtio-blk.h  |  2 +-
  4 files changed, 45 insertions(+), 44 deletions(-)
#60 lore raw

PATCH v3 14/23 hw: Convert from BlockDriverState to BlockBackend, mostly

In reply to Markus Armbruster

Just four uses of BlockDriverState are left:

* The Xen paravirtual block device backend (xen_disk.c) opens images itself when set up via xenbus, bypassing blockdev.c. I figure it should go through qmp_blockdev_add() instead.

* Device model "usb-storage" prompts for keys. No other device model does, and this one probably shouldn't do it, either.

* ide_issue_trim_cb() uses bdrv_aio_discard() instead of blk_aio_discard() because it fishes its backend out of a BlockAIOCB, which has only the BlockDriverState.

* PC87312State has an unused BlockDriverState[] member.

The next two commits take care of the latter two.

---
 block/block-backend.c                    | 257 +++++++++++++++++++++++++++++++
 blockdev.c                               |  19 +--
 dma-helpers.c                            |  61 ++++----
 hw/arm/collie.c                          |   5 +-
 hw/arm/gumstix.c                         |   5 +-
 hw/arm/highbank.c                        |   2 +-
 hw/arm/mainstone.c                       |   2 +-
 hw/arm/musicpal.c                        |  10 +-
 hw/arm/nseries.c                         |   3 +-
 hw/arm/omap1.c                           |   2 +-
 hw/arm/omap2.c                           |   2 +-
 hw/arm/omap_sx1.c                        |   5 +-
 hw/arm/pxa2xx.c                          |   4 +-
 hw/arm/realview.c                        |   2 +-
 hw/arm/spitz.c                           |   4 +-
 hw/arm/tosa.c                            |   3 +-
 hw/arm/versatilepb.c                     |   3 +-
 hw/arm/vexpress.c                        |   3 +-
 hw/arm/xilinx_zynq.c                     |   3 +-
 hw/arm/z2.c                              |   3 +-
 hw/block/block.c                         |   7 +-
 hw/block/dataplane/virtio-blk.c          |  24 +--
 hw/block/fdc.c                           |  78 +++++-----
 hw/block/hd-geometry.c                   |  24 +--
 hw/block/m25p80.c                        |  28 ++--
 hw/block/nand.c                          |  50 +++---
 hw/block/nvme.c                          |  19 +--
 hw/block/onenand.c                       |  67 ++++----
 hw/block/pflash_cfi01.c                  |  24 +--
 hw/block/pflash_cfi02.c                  |  24 +--
 hw/block/virtio-blk.c                    |  95 ++++++------
 hw/block/xen_disk.c                      |  83 +++++-----
 hw/core/qdev-properties-system.c         |  26 ++--
 hw/core/qdev-properties.c                |   2 +-
 hw/cris/axis_dev88.c                     |   3 +-
 hw/display/tc6393xb.c                    |   2 +-
 hw/i386/pc.c                             |   2 +-
 hw/i386/pc_piix.c                        |   2 +-
 hw/i386/pc_sysfw.c                       |   9 +-
 hw/i386/xen/xen_platform.c               |   5 +-
 hw/ide/ahci.c                            |  31 ++--
 hw/ide/atapi.c                           |  33 ++--
 hw/ide/cmd646.c                          |   2 +-
 hw/ide/core.c                            | 186 +++++++++++-----------
 hw/ide/ich.c                             |   2 +-
 hw/ide/internal.h                        |   6 +-
 hw/ide/isa.c                             |   2 +-
 hw/ide/macio.c                           |  50 +++---
 hw/ide/microdrive.c                      |   4 +-
 hw/ide/mmio.c                            |   2 +-
 hw/ide/pci.c                             |   4 +-
 hw/ide/piix.c                            |   9 +-
 hw/ide/qdev.c                            |  11 +-
 hw/ide/via.c                             |   2 +-
 hw/isa/pc87312.c                         |   4 +-
 hw/lm32/lm32_boards.c                    |   5 +-
 hw/lm32/milkymist.c                      |   3 +-
 hw/microblaze/petalogix_ml605_mmu.c      |   3 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |   3 +-
 hw/mips/mips_fulong2e.c                  |   2 +-
 hw/mips/mips_jazz.c                      |   2 +-
 hw/mips/mips_malta.c                     |   6 +-
 hw/mips/mips_r4k.c                       |   3 +-
 hw/nvram/spapr_nvram.c                   |  17 +-
 hw/pci/pci-hotplug-old.c                 |   5 +-
 hw/ppc/mac_newworld.c                    |   2 +-
 hw/ppc/mac_oldworld.c                    |   2 +-
 hw/ppc/ppc405_boards.c                   |  26 ++--
 hw/ppc/prep.c                            |   2 +-
 hw/ppc/spapr.c                           |   4 +-
 hw/ppc/virtex_ml507.c                    |   3 +-
 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                       |   8 +-
 hw/scsi/scsi-disk.c                      | 186 +++++++++++-----------
 hw/scsi/scsi-generic.c                   |  39 ++---
 hw/sd/milkymist-memcard.c                |   8 +-
 hw/sd/omap_mmc.c                         |   8 +-
 hw/sd/pl181.c                            |   2 +-
 hw/sd/pxa2xx_mmci.c                      |   4 +-
 hw/sd/sd.c                               |  60 ++++----
 hw/sd/sdhci.c                            |   2 +-
 hw/sd/ssi-sd.c                           |   2 +-
 hw/sh4/r2d.c                             |   3 +-
 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                     |  17 +-
 hw/virtio/virtio-pci.c                   |   2 +-
 hw/xen/xen_devconfig.c                   |   1 +
 hw/xenpv/xen_machine_pv.c                |   2 +-
 hw/xtensa/xtfpga.c                       |   3 +-
 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/qdev-properties.h             |   8 +-
 include/hw/scsi/scsi.h                   |   4 +-
 include/hw/sd.h                          |   2 +-
 include/hw/virtio/virtio-blk.h           |   7 +-
 include/qemu/typedefs.h                  |   1 +
 include/sysemu/block-backend.h           |  75 +++++++++
 include/sysemu/blockdev.h                |   5 +-
 include/sysemu/dma.h                     |  24 +--
 trace-events                             |   8 +-
 108 files changed, 1126 insertions(+), 810 deletions(-)
block/block-backend.c +257 -0
index 7fd832d..5f796b4 100644
@@ -235,3 +235,260 @@ void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk)
         bdrv_make_anon(blk->bs);
     }
 }
+
+void blk_iostatus_enable(BlockBackend *blk)
+{
+    bdrv_iostatus_enable(blk->bs);
+}
+
+int blk_attach_dev(BlockBackend *blk, void *dev)
+{
+    return bdrv_attach_dev(blk->bs, dev);
+}
+
+void blk_attach_dev_nofail(BlockBackend *blk, void *dev)
+{
+    bdrv_attach_dev_nofail(blk->bs, dev);
+}
+
+void blk_detach_dev(BlockBackend *blk, void *dev)
+{
+    bdrv_detach_dev(blk->bs, dev);
+}
+
+void *blk_get_attached_dev(BlockBackend *blk)
+{
+    return bdrv_get_attached_dev(blk->bs);
+}
+
+void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque)
+{
+    bdrv_set_dev_ops(blk->bs, ops, opaque);
+}
+
+int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+             int nb_sectors)
+{
+    return bdrv_read(blk->bs, sector_num, buf, nb_sectors);
+}
+
+int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+                         int nb_sectors)
+{
+    return bdrv_read_unthrottled(blk->bs, sector_num, buf, nb_sectors);
+}
+
+int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
+              int nb_sectors)
+{
+    return bdrv_write(blk->bs, sector_num, buf, nb_sectors);
+}
+
+BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
+                                 int nb_sectors, BdrvRequestFlags flags,
+                                 BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_write_zeroes(blk->bs, sector_num, nb_sectors, flags,
+                                 cb, opaque);
+}
+
+int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
+{
+    return bdrv_pread(blk->bs, offset, buf, count);
+}
+
+int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count)
+{
+    return bdrv_pwrite(blk->bs, offset, buf, count);
+}
+
+int64_t blk_getlength(BlockBackend *blk)
+{
+    return bdrv_getlength(blk->bs);
+}
+
+void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)
+{
+    bdrv_get_geometry(blk->bs, nb_sectors_ptr);
+}
+
+BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num,
+                          QEMUIOVector *iov, int nb_sectors,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_readv(blk->bs, sector_num, iov, nb_sectors, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num,
+                           QEMUIOVector *iov, int nb_sectors,
+                           BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_writev(blk->bs, sector_num, iov, nb_sectors, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_flush(BlockBackend *blk,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_flush(blk->bs, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_discard(BlockBackend *blk,
+                            int64_t sector_num, int nb_sectors,
+                            BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_discard(blk->bs, sector_num, nb_sectors, cb, opaque);
+}
+
+void blk_aio_cancel(BlockAIOCB *acb)
+{
+    bdrv_aio_cancel(acb);
+}
+
+int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs)
+{
+    return bdrv_aio_multiwrite(blk->bs, reqs, num_reqs);
+}
+
+int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
+{
+    return bdrv_ioctl(blk->bs, req, buf);
+}
+
+BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_ioctl(blk->bs, req, buf, cb, opaque);
+}
+
+int blk_flush(BlockBackend *blk)
+{
+    return bdrv_flush(blk->bs);
+}
+
+int blk_flush_all(void)
+{
+    return bdrv_flush_all();
+}
+
+void blk_drain_all(void)
+{
+    bdrv_drain_all();
+}
+
+BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read)
+{
+    return bdrv_get_on_error(blk->bs, is_read);
+}
+
+BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
+                                      int error)
+{
+    return bdrv_get_error_action(blk->bs, is_read, error);
+}
+
+void blk_error_action(BlockBackend *blk, BlockErrorAction action,
+                      bool is_read, int error)
+{
+    bdrv_error_action(blk->bs, action, is_read, error);
+}
+
+int blk_is_read_only(BlockBackend *blk)
+{
+    return bdrv_is_read_only(blk->bs);
+}
+
+int blk_is_sg(BlockBackend *blk)
+{
+    return bdrv_is_sg(blk->bs);
+}
+
+int blk_enable_write_cache(BlockBackend *blk)
+{
+    return bdrv_enable_write_cache(blk->bs);
+}
+
+void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
+{
+    bdrv_set_enable_write_cache(blk->bs, wce);
+}
+
+int blk_is_inserted(BlockBackend *blk)
+{
+    return bdrv_is_inserted(blk->bs);
+}
+
+void blk_lock_medium(BlockBackend *blk, bool locked)
+{
+    bdrv_lock_medium(blk->bs, locked);
+}
+
+void blk_eject(BlockBackend *blk, bool eject_flag)
+{
+    bdrv_eject(blk->bs, eject_flag);
+}
+
+int blk_get_flags(BlockBackend *blk)
+{
+    return bdrv_get_flags(blk->bs);
+}
+
+void blk_set_guest_block_size(BlockBackend *blk, int align)
+{
+    bdrv_set_guest_block_size(blk->bs, align);
+}
+
+void *blk_blockalign(BlockBackend *blk, size_t size)
+{
+    return qemu_blockalign(blk ? blk->bs : NULL, size);
+}
+
+bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp)
+{
+    return bdrv_op_is_blocked(blk->bs, op, errp);
+}
+
+void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason)
+{
+    bdrv_op_unblock(blk->bs, op, reason);
+}
+
+void blk_op_block_all(BlockBackend *blk, Error *reason)
+{
+    bdrv_op_block_all(blk->bs, reason);
+}
+
+void blk_op_unblock_all(BlockBackend *blk, Error *reason)
+{
+    bdrv_op_unblock_all(blk->bs, reason);
+}
+
+AioContext *blk_get_aio_context(BlockBackend *blk)
+{
+    return bdrv_get_aio_context(blk->bs);
+}
+
+void blk_set_aio_context(BlockBackend *blk, AioContext *new_context)
+{
+    bdrv_set_aio_context(blk->bs, new_context);
+}
+
+void blk_io_plug(BlockBackend *blk)
+{
+    bdrv_io_plug(blk->bs);
+}
+
+void blk_io_unplug(BlockBackend *blk)
+{
+    bdrv_io_unplug(blk->bs);
+}
+
+BlockAcctStats *blk_get_stats(BlockBackend *blk)
+{
+    return bdrv_get_stats(blk->bs);
+}
+
+void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
+                  BlockCompletionFunc *cb, void *opaque)
+{
+    return qemu_aio_get(aiocb_info, blk_bs(blk), cb, opaque);
+}
blockdev.c +3 -16
index 49496b6..e87bf4b 100644
@@ -85,10 +85,10 @@ static const int if_max_devs[IF_COUNT] = {
  * automatic deletion, and generic qdev code calls blockdev_auto_del()
  * when deletion is actually safe.
  */
-void blockdev_mark_auto_del(BlockDriverState *bs)
+void blockdev_mark_auto_del(BlockBackend *blk)
 {
-    BlockBackend *blk = bs->blk;
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
+    BlockDriverState *bs = blk_bs(blk);
 
     if (dinfo && !dinfo->enable_auto_del) {
         return;
@@ -102,9 +102,8 @@ void blockdev_mark_auto_del(BlockDriverState *bs)
     }
 }
 
-void blockdev_auto_del(BlockDriverState *bs)
+void blockdev_auto_del(BlockBackend *blk)
 {
-    BlockBackend *blk = bs->blk;
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
 
     if (dinfo && dinfo->auto_del) {
@@ -200,18 +199,6 @@ DriveInfo *drive_get_next(BlockInterfaceType type)
     return drive_get(type, 0, next_block_unit[type]++);
 }
 
-DriveInfo *drive_get_by_blockdev(BlockDriverState *bs)
-{
-    BlockBackend *blk;
-
-    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
-        if (blk_bs(blk) == bs) {
-            return blk_legacy_dinfo(blk);
-        }
-    }
-    return NULL;
-}
-
 static void bdrv_format_print(void *opaque, const char *name)
 {
     error_printf(" %s", name);
dma-helpers.c +31 -30

157 lines not on this page · raw message

hw/arm/collie.c +2 -3
index 0247290..6c9b82f 100644
@@ -16,7 +16,6 @@
 #include "hw/arm/arm.h"
 #include "hw/block/flash.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 
 static struct arm_boot_info collie_binfo = {
@@ -42,12 +41,12 @@ static void collie_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x02000000,
-                    dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                    dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                     (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     dinfo = drive_get(IF_PFLASH, 0, 1);
     pflash_cfi01_register(SA_CS1, NULL, "collie.fl2", 0x02000000,
-                    dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                    dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                     (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     sysbus_create_simple("scoop", 0x40800000, NULL);
hw/arm/gumstix.c +2 -3
index 49f9339..8103278 100644
@@ -41,7 +41,6 @@
 #include "hw/devices.h"
 #include "hw/boards.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
 
@@ -72,7 +71,7 @@ static void connex_init(MachineState *machine)
     be = 0;
 #endif
     if (!pflash_cfi01_register(0x00000000, NULL, "connext.rom", connex_rom,
-                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                sector_len, connex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
@@ -110,7 +109,7 @@ static void verdex_init(MachineState *machine)
     be = 0;
 #endif
     if (!pflash_cfi01_register(0x00000000, NULL, "verdex.rom", verdex_rom,
-                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                sector_len, verdex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
hw/arm/highbank.c +1 -1
index fa61e5f..30f744a 100644
@@ -24,7 +24,7 @@
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 #include "qemu/error-report.h"
 
hw/arm/mainstone.c +1 -1
index a4a25b5..0da02a6 100644
@@ -149,7 +149,7 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
         if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
                                    i ? "mainstone.flash1" : "mainstone.flash0",
                                    MAINSTONE_FLASH,
-                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   blk_by_legacy_dinfo(dinfo),
                                    sector_len, MAINSTONE_FLASH / sector_len,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory.\n");
hw/arm/musicpal.c +4 -6
index 77ad4eb..3712de6 100644
@@ -18,12 +18,10 @@
 #include "hw/char/serial.h"
 #include "qemu/timer.h"
 #include "hw/ptimer.h"
-#include "block/block.h"
 #include "hw/block/flash.h"
 #include "ui/console.h"
 #include "hw/i2c/i2c.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "ui/pixel_ops.h"
 
@@ -1633,9 +1631,9 @@ static void musicpal_init(MachineState *machine)
     /* Register flash */
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (dinfo) {
-        BlockDriverState *bs = blk_bs(blk_by_legacy_dinfo(dinfo));
+        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
 
-        flash_size = bdrv_getlength(bs);
+        flash_size = blk_getlength(blk);
         if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 &&
             flash_size != 32*1024*1024) {
             fprintf(stderr, "Invalid flash image size\n");
@@ -1650,14 +1648,14 @@ static void musicpal_init(MachineState *machine)
 #ifdef TARGET_WORDS_BIGENDIAN
         pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
                               "musicpal.flash", flash_size,
-                              bs, 0x10000, (flash_size + 0xffff) >> 16,
+                              blk, 0x10000, (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 1);
 #else
         pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
                               "musicpal.flash", flash_size,
-                              bs, 0x10000, (flash_size + 0xffff) >> 16,
+                              blk, 0x10000, (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 0);
hw/arm/nseries.c +1 -2
index 2536078..c7ebaa6 100644
@@ -32,7 +32,6 @@
 #include "hw/bt.h"
 #include "hw/loader.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 
@@ -175,7 +174,7 @@ static void n8x0_nand_setup(struct n800_s *s)
     dinfo = drive_get(IF_MTD, 0, 0);
     if (dinfo) {
         qdev_prop_set_drive_nofail(s->nand, "drive",
-                                   blk_bs(blk_by_legacy_dinfo(dinfo)));
+                                   blk_by_legacy_dinfo(dinfo));
     }
     qdev_init_nofail(s->nand);
     sysbus_connect_irq(SYS_BUS_DEVICE(s->nand), 0,
hw/arm/omap1.c +1 -1
index 74dac49..abb183c 100644
@@ -3980,7 +3980,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
         exit(1);
     }
     s->mmc = omap_mmc_init(0xfffb7800, system_memory,
-                           blk_bs(blk_by_legacy_dinfo(dinfo)),
+                           blk_by_legacy_dinfo(dinfo),
                            qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN),
                            &s->drq[OMAP_DMA_MMC_TX],
                     omap_findclk(s, "mmc_ck"));
hw/arm/omap2.c +1 -1
index 0b6a95e..b083ebe 100644
@@ -2463,7 +2463,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
         exit(1);
     }
     s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9),
-                    blk_bs(blk_by_legacy_dinfo(dinfo)),
+                    blk_by_legacy_dinfo(dinfo),
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_24XX_MMC_IRQ),
                     &s->drq[OMAP24XX_DMA_MMC1_TX],
                     omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
hw/arm/omap_sx1.c +2 -3
index 0a4e740..671e02c 100644
@@ -32,7 +32,6 @@
 #include "hw/arm/arm.h"
 #include "hw/block/flash.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "sysemu/qtest.h"
 #include "exec/address-spaces.h"
 
@@ -155,7 +154,7 @@ static void sx1_init(MachineState *machine, const int version)
     if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
         if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
                                    "omap_sx1.flash0-1", flash_size,
-                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   blk_by_legacy_dinfo(dinfo),
                                    sector_size, flash_size / sector_size,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
@@ -179,7 +178,7 @@ static void sx1_init(MachineState *machine, const int version)
 
         if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
                                    "omap_sx1.flash1-1", flash1_size,
-                                   blk_bs(blk_by_legacy_dinfo(dinfo)),
+                                   blk_by_legacy_dinfo(dinfo),
                                    sector_size, flash1_size / sector_size,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
hw/arm/pxa2xx.c +2 -2
index 6b7abe1..693dfec 100644
@@ -2087,7 +2087,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
         exit(1);
     }
     s->mmc = pxa2xx_mmci_init(address_space, 0x41100000,
-                    blk_bs(blk_by_legacy_dinfo(dinfo)),
+                    blk_by_legacy_dinfo(dinfo),
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_MMC),
                     qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_MMCI),
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
@@ -2220,7 +2220,7 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)
         exit(1);
     }
     s->mmc = pxa2xx_mmci_init(address_space, 0x41100000,
-                    blk_bs(blk_by_legacy_dinfo(dinfo)),
+                    blk_by_legacy_dinfo(dinfo),
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_MMC),
                     qdev_get_gpio_in(s->dma, PXA2XX_RX_RQ_MMCI),
                     qdev_get_gpio_in(s->dma, PXA2XX_TX_RQ_MMCI));
hw/arm/realview.c +1 -1
index 8bd3ff6..af65aa4 100644
@@ -16,7 +16,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/i2c/i2c.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 #include "qemu/error-report.h"
 
hw/arm/spitz.c +1 -3
index ff12f9b..a16831c 100644
@@ -22,11 +22,9 @@
 #include "hw/devices.h"
 #include "hw/arm/sharpsl.h"
 #include "ui/console.h"
-#include "block/block.h"
 #include "audio/audio.h"
 #include "hw/boards.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 
@@ -171,7 +169,7 @@ static int sl_nand_init(SysBusDevice *dev)
 
     s->ctl = 0;
     nand = drive_get(IF_MTD, 0, 0);
-    s->nand = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
+    s->nand = nand_init(nand ? blk_by_legacy_dinfo(nand) : NULL,
                         s->manf_id, s->chip_id);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &sl_ops, s, "sl", 0x40);
hw/arm/tosa.c +1 -2
index 6c574bc..73572eb 100644
@@ -17,11 +17,10 @@
 #include "hw/devices.h"
 #include "hw/arm/sharpsl.h"
 #include "hw/pcmcia.h"
-#include "block/block.h"
 #include "hw/boards.h"
 #include "hw/i2c/i2c.h"
 #include "hw/ssi.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 
hw/arm/versatilepb.c +1 -2
index 2ff46b0..e6ef0a2 100644
@@ -16,7 +16,6 @@
 #include "hw/i2c/i2c.h"
 #include "hw/boards.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "hw/block/flash.h"
 
@@ -340,7 +339,7 @@ static void versatile_init(MachineState *machine, int board_id)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, NULL, "versatile.flash",
                           VERSATILE_FLASH_SIZE,
-                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           VERSATILE_FLASH_SECT_SIZE,
                           VERSATILE_FLASH_SIZE / VERSATILE_FLASH_SECT_SIZE,
                           4, 0x0089, 0x0018, 0x0000, 0x0, 0)) {
hw/arm/vexpress.c +1 -2
index 828228c..7cbd13f 100644
@@ -31,7 +31,6 @@
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "hw/block/flash.h"
 #include "sysemu/device_tree.h"
 #include "qemu/error-report.h"
@@ -493,7 +492,7 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
     DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
 
     if (di && qdev_prop_set_drive(dev, "drive",
-                                  blk_bs(blk_by_legacy_dinfo(di)))) {
+                                  blk_by_legacy_dinfo(di))) {
         abort();
     }
 
hw/arm/xilinx_zynq.c +1 -2
index 415344f..b590392 100644
@@ -23,7 +23,6 @@
 #include "hw/boards.h"
 #include "hw/block/flash.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "hw/loader.h"
 #include "hw/ssi.h"
 #include "qemu/error-report.h"
@@ -165,7 +164,7 @@ static void zynq_init(MachineState *machine)
 
     /* AMD */
     pflash_cfi02_register(0xe2000000, NULL, "zynq.pflash", FLASH_SIZE,
-                          dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                          dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           FLASH_SECTOR_SIZE,
                           FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
                           1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa,
hw/arm/z2.c +1 -2
index 9b38a2b..1735547 100644
@@ -21,7 +21,6 @@
 #include "sysemu/sysemu.h"
 #include "hw/block/flash.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "ui/console.h"
 #include "audio/audio.h"
 #include "exec/address-spaces.h"
@@ -337,7 +336,7 @@ static void z2_init(MachineState *machine)
 
     if (!pflash_cfi01_register(Z2_FLASH_BASE,
                                NULL, "z2.flash0", Z2_FLASH_SIZE,
-                               dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
+                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                sector_len, Z2_FLASH_SIZE / sector_len,
                                4, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
hw/block/block.c +4 -3
index b6a6dc6..0666dd3 100644
@@ -8,6 +8,7 @@
  */
 
 #include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "hw/block/block.h"
 #include "qemu/error-report.h"
 
@@ -17,7 +18,7 @@ void blkconf_serial(BlockConf *conf, char **serial)
 
     if (!*serial) {
         /* try to fall back to value set with legacy -drive serial=... */
-        dinfo = drive_get_by_blockdev(conf->bs);
+        dinfo = blk_legacy_dinfo(conf->blk);
         *serial = g_strdup(dinfo->serial);
     }
 }
@@ -30,7 +31,7 @@ void blkconf_geometry(BlockConf *conf, int *ptrans,
 
     if (!conf->cyls && !conf->heads && !conf->secs) {
         /* try to fall back to value set with legacy -drive cyls=... */
-        dinfo = drive_get_by_blockdev(conf->bs);
+        dinfo = blk_legacy_dinfo(conf->blk);
         conf->cyls  = dinfo->cyls;
         conf->heads = dinfo->heads;
         conf->secs  = dinfo->secs;
@@ -39,7 +40,7 @@ void blkconf_geometry(BlockConf *conf, int *ptrans,
         }
     }
     if (!conf->cyls && !conf->heads && !conf->secs) {
-        hd_geometry_guess(conf->bs,
+        hd_geometry_guess(conf->blk,
                           &conf->cyls, &conf->heads, &conf->secs,
                           ptrans);
     } else if (ptrans && *ptrans == BIOS_ATA_TRANSLATION_AUTO) {
hw/block/dataplane/virtio-blk.c +12 -12
index bd250df..45b1164 100644
@@ -17,7 +17,7 @@
 #include "qemu/thread.h"
 #include "qemu/error-report.h"
 #include "hw/virtio/dataplane/vring.h"
-#include "block/block.h"
+#include "sysemu/block-backend.h"
 #include "hw/virtio/virtio-blk.h"
 #include "virtio-blk.h"
 #include "block/aio.h"
@@ -94,7 +94,7 @@ static void handle_notify(EventNotifier *e)
     VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
 
     event_notifier_test_and_clear(&s->host_notifier);
-    bdrv_io_plug(s->conf->conf.bs);
+    blk_io_plug(s->conf->conf.blk);
     for (;;) {
         MultiReqBuffer mrb = {
             .num_writes = 0,
@@ -120,7 +120,7 @@ static void handle_notify(EventNotifier *e)
             virtio_blk_handle_request(req, &mrb);
         }
 
-        virtio_submit_multiwrite(s->conf->conf.bs, &mrb);
+        virtio_submit_multiwrite(s->conf->conf.blk, &mrb);
 
         if (likely(ret == -EAGAIN)) { /* vring emptied */
             /* Re-enable guest->host notifies and stop processing the vring.
@@ -133,7 +133,7 @@ static void handle_notify(EventNotifier *e)
             break;
         }
     }
-    bdrv_io_unplug(s->conf->conf.bs);
+    blk_io_unplug(s->conf->conf.blk);
 }
 
 /* Context: QEMU global mutex held */
@@ -163,8 +163,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
     /* If dataplane is (re-)enabled while the guest is running there could be
      * block jobs that can conflict.
      */
-    if (bdrv_op_is_blocked(conf->conf.bs, BLOCK_OP_TYPE_DATAPLANE,
-                           &local_err)) {
+    if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE,
+                          &local_err)) {
         error_setg(errp, "cannot start dataplane thread: %s",
                    error_get_pretty(local_err));
         error_free(local_err);
@@ -193,9 +193,9 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
     s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);
 
     error_setg(&s->blocker, "block device is in use by data plane");
-    bdrv_op_block_all(conf->conf.bs, s->blocker);
-    bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker);
-    bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
+    blk_op_block_all(conf->conf.blk, s->blocker);
+    blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_RESIZE, s->blocker);
+    blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
 
     *dataplane = s;
 }
@@ -208,7 +208,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
     }
 
     virtio_blk_data_plane_stop(s);
-    bdrv_op_unblock_all(s->conf->conf.bs, s->blocker);
+    blk_op_unblock_all(s->conf->conf.blk, s->blocker);
     error_free(s->blocker);
     object_unref(OBJECT(s->iothread));
     qemu_bh_delete(s->bh);
@@ -263,7 +263,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
     s->started = true;
     trace_virtio_blk_data_plane_start(s);
 
-    bdrv_set_aio_context(s->conf->conf.bs, s->ctx);
+    blk_set_aio_context(s->conf->conf.blk, s->ctx);
 
     /* Kick right away to begin processing requests already in vring */
     event_notifier_set(virtio_queue_get_host_notifier(vq));
@@ -309,7 +309,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
     aio_set_event_notifier(s->ctx, &s->host_notifier, NULL);
 
     /* Drain and switch bs back to the QEMU main loop */
-    bdrv_set_aio_context(s->conf->conf.bs, qemu_get_aio_context());
+    blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context());
 
     aio_context_release(s->ctx);
 
hw/block/fdc.c +38 -40

219 lines not on this page · raw message

hw/block/hd-geometry.c +12 -12
index 6feb4f8..6fcf74d 100644
@@ -30,7 +30,7 @@
  * THE SOFTWARE.
  */
 
-#include "block/block.h"
+#include "sysemu/block-backend.h"
 #include "hw/block/block.h"
 #include "trace.h"
 
@@ -49,7 +49,7 @@ struct partition {
 
 /* try to guess the disk logical geometry from the MSDOS partition table.
    Return 0 if OK, -1 if could not guess */
-static int guess_disk_lchs(BlockDriverState *bs,
+static int guess_disk_lchs(BlockBackend *blk,
                            int *pcylinders, int *pheads, int *psectors)
 {
     uint8_t buf[BDRV_SECTOR_SIZE];
@@ -58,14 +58,14 @@ static int guess_disk_lchs(BlockDriverState *bs,
     uint32_t nr_sects;
     uint64_t nb_sectors;
 
-    bdrv_get_geometry(bs, &nb_sectors);
+    blk_get_geometry(blk, &nb_sectors);
 
     /**
      * The function will be invoked during startup not only in sync I/O mode,
      * but also in async I/O mode. So the I/O throttling function has to
      * be disabled temporarily here, not permanently.
      */
-    if (bdrv_read_unthrottled(bs, 0, buf, 1) < 0) {
+    if (blk_read_unthrottled(blk, 0, buf, 1) < 0) {
         return -1;
     }
     /* test msdos magic */
@@ -90,20 +90,20 @@ static int guess_disk_lchs(BlockDriverState *bs,
             *pheads = heads;
             *psectors = sectors;
             *pcylinders = cylinders;
-            trace_hd_geometry_lchs_guess(bs, cylinders, heads, sectors);
+            trace_hd_geometry_lchs_guess(blk, cylinders, heads, sectors);
             return 0;
         }
     }
     return -1;
 }
 
-static void guess_chs_for_size(BlockDriverState *bs,
+static void guess_chs_for_size(BlockBackend *blk,
                 uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs)
 {
     uint64_t nb_sectors;
     int cylinders;
 
-    bdrv_get_geometry(bs, &nb_sectors);
+    blk_get_geometry(blk, &nb_sectors);
 
     cylinders = nb_sectors / (16 * 63);
     if (cylinders > 16383) {
@@ -116,21 +116,21 @@ static void guess_chs_for_size(BlockDriverState *bs,
     *psecs = 63;
 }
 
-void hd_geometry_guess(BlockDriverState *bs,
+void hd_geometry_guess(BlockBackend *blk,
                        uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
                        int *ptrans)
 {
     int cylinders, heads, secs, translation;
 
-    if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
+    if (guess_disk_lchs(blk, &cylinders, &heads, &secs) < 0) {
         /* no LCHS guess: use a standard physical disk geometry  */
-        guess_chs_for_size(bs, pcyls, pheads, psecs);
+        guess_chs_for_size(blk, pcyls, pheads, psecs);
         translation = hd_bios_chs_auto_trans(*pcyls, *pheads, *psecs);
     } else if (heads > 16) {
         /* LCHS guess with heads > 16 means that a BIOS LBA
            translation was active, so a standard physical disk
            geometry is OK */
-        guess_chs_for_size(bs, pcyls, pheads, psecs);
+        guess_chs_for_size(blk, pcyls, pheads, psecs);
         translation = *pcyls * *pheads <= 131072
             ? BIOS_ATA_TRANSLATION_LARGE
             : BIOS_ATA_TRANSLATION_LBA;
@@ -146,7 +146,7 @@ void hd_geometry_guess(BlockDriverState *bs,
     if (ptrans) {
         *ptrans = translation;
     }
-    trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation);
+    trace_hd_geometry_guess(blk, *pcyls, *pheads, *psecs, translation);
 }
 
 int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs)
hw/block/m25p80.c +14 -14
index 78280a8..ff1106b 100644
@@ -246,7 +246,7 @@ typedef struct Flash {
 
     uint32_t r;
 
-    BlockDriverState *bdrv;
+    BlockBackend *blk;
 
     uint8_t *storage;
     uint32_t size;
@@ -280,7 +280,7 @@ typedef struct M25P80Class {
 #define M25P80_GET_CLASS(obj) \
      OBJECT_GET_CLASS(M25P80Class, (obj), TYPE_M25P80)
 
-static void bdrv_sync_complete(void *opaque, int ret)
+static void blk_sync_complete(void *opaque, int ret)
 {
     /* do nothing. Masters do not directly interact with the backing store,
      * only the working copy so no mutexing required.
@@ -289,20 +289,20 @@ static void bdrv_sync_complete(void *opaque, int ret)
 
 static void flash_sync_page(Flash *s, int page)
 {
-    int bdrv_sector, nb_sectors;
+    int blk_sector, nb_sectors;
     QEMUIOVector iov;
 
-    if (!s->bdrv || bdrv_is_read_only(s->bdrv)) {
+    if (!s->blk || blk_is_read_only(s->blk)) {
         return;
     }
 
-    bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE;
+    blk_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE;
     nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE);
     qemu_iovec_init(&iov, 1);
-    qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE,
+    qemu_iovec_add(&iov, s->storage + blk_sector * BDRV_SECTOR_SIZE,
                    nb_sectors * BDRV_SECTOR_SIZE);
-    bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors, bdrv_sync_complete,
-                    NULL);
+    blk_aio_writev(s->blk, blk_sector, &iov, nb_sectors, blk_sync_complete,
+                   NULL);
 }
 
 static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
@@ -310,7 +310,7 @@ static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
     int64_t start, end, nb_sectors;
     QEMUIOVector iov;
 
-    if (!s->bdrv || bdrv_is_read_only(s->bdrv)) {
+    if (!s->blk || blk_is_read_only(s->blk)) {
         return;
     }
 
@@ -321,7 +321,7 @@ static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
     qemu_iovec_init(&iov, 1);
     qemu_iovec_add(&iov, s->storage + (start * BDRV_SECTOR_SIZE),
                                         nb_sectors * BDRV_SECTOR_SIZE);
-    bdrv_aio_writev(s->bdrv, start, &iov, nb_sectors, bdrv_sync_complete, NULL);
+    blk_aio_writev(s->blk, start, &iov, nb_sectors, blk_sync_complete, NULL);
 }
 
 static void flash_erase(Flash *s, int offset, FlashCMD cmd)
@@ -621,17 +621,17 @@ static int m25p80_init(SSISlave *ss)
 
     s->size = s->pi->sector_size * s->pi->n_sectors;
     s->dirty_page = -1;
-    s->storage = qemu_blockalign(s->bdrv, s->size);
+    s->storage = blk_blockalign(s->blk, s->size);
 
     dinfo = drive_get_next(IF_MTD);
 
     if (dinfo) {
         DB_PRINT_L(0, "Binding to IF_MTD drive\n");
-        s->bdrv = blk_bs(blk_by_legacy_dinfo(dinfo));
+        s->blk = blk_by_legacy_dinfo(dinfo);
 
         /* FIXME: Move to late init */
-        if (bdrv_read(s->bdrv, 0, s->storage, DIV_ROUND_UP(s->size,
-                                                    BDRV_SECTOR_SIZE))) {
+        if (blk_read(s->blk, 0, s->storage,
+                     DIV_ROUND_UP(s->size, BDRV_SECTOR_SIZE))) {
             fprintf(stderr, "Failed to initialize SPI flash!\n");
             return 1;
         }
hw/block/nand.c +25 -25

167 lines not on this page · raw message

hw/block/nvme.c +10 -9
index b010c9b..40c4793 100644
@@ -24,6 +24,7 @@
 #include <hw/hw.h>
 #include <hw/pci/msix.h>
 #include <hw/pci/pci.h>
+#include "sysemu/block-backend.h"
 
 #include "nvme.h"
 
@@ -197,7 +198,7 @@ static void nvme_rw_cb(void *opaque, int ret)
     NvmeCtrl *n = sq->ctrl;
     NvmeCQueue *cq = n->cq[sq->cqid];
 
-    block_acct_done(bdrv_get_stats(n->conf.bs), &req->acct);
+    block_acct_done(blk_get_stats(n->conf.blk), &req->acct);
     if (!ret) {
         req->status = NVME_SUCCESS;
     } else {
@@ -231,11 +232,11 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
     }
     assert((nlb << data_shift) == req->qsg.size);
 
-    dma_acct_start(n->conf.bs, &req->acct, &req->qsg, is_write ?
-        BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
+    dma_acct_start(n->conf.blk, &req->acct, &req->qsg,
+                   is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
     req->aiocb = is_write ?
-        dma_bdrv_write(n->conf.bs, &req->qsg, aio_slba, nvme_rw_cb, req) :
-        dma_bdrv_read(n->conf.bs, &req->qsg, aio_slba, nvme_rw_cb, req);
+        dma_blk_write(n->conf.blk, &req->qsg, aio_slba, nvme_rw_cb, req) :
+        dma_blk_read(n->conf.blk, &req->qsg, aio_slba, nvme_rw_cb, req);
 
     return NVME_NO_COMPLETE;
 }
@@ -288,7 +289,7 @@ static uint16_t nvme_del_sq(NvmeCtrl *n, NvmeCmd *cmd)
     while (!QTAILQ_EMPTY(&sq->out_req_list)) {
         req = QTAILQ_FIRST(&sq->out_req_list);
         assert(req->aiocb);
-        bdrv_aio_cancel(req->aiocb);
+        blk_aio_cancel(req->aiocb);
     }
     if (!nvme_check_cqid(n, sq->cqid)) {
         cq = n->cq[sq->cqid];
@@ -563,7 +564,7 @@ static void nvme_clear_ctrl(NvmeCtrl *n)
         }
     }
 
-    bdrv_flush(n->conf.bs);
+    blk_flush(n->conf.blk);
     n->bar.cc = 0;
 }
 
@@ -748,11 +749,11 @@ static int nvme_init(PCIDevice *pci_dev)
     int64_t bs_size;
     uint8_t *pci_conf;
 
-    if (!(n->conf.bs)) {
+    if (!n->conf.blk) {
         return -1;
     }
 
-    bs_size = bdrv_getlength(n->conf.bs);
+    bs_size = blk_getlength(n->conf.blk);
     if (bs_size < 0) {
         return -1;
     }
hw/block/onenand.c +35 -32

172 lines not on this page · raw message

hw/block/pflash_cfi01.c +12 -12
index 1346541..89d380e 100644
@@ -38,7 +38,7 @@
 
 #include "hw/hw.h"
 #include "hw/block/flash.h"
-#include "block/block.h"
+#include "sysemu/block-backend.h"
 #include "qemu/timer.h"
 #include "qemu/bitops.h"
 #include "exec/address-spaces.h"
@@ -69,7 +69,7 @@ struct pflash_t {
     SysBusDevice parent_obj;
     /*< public >*/
 
-    BlockDriverState *bs;
+    BlockBackend *blk;
     uint32_t nb_blocs;
     uint64_t sector_len;
     uint8_t bank_width;
@@ -395,13 +395,13 @@ static void pflash_update(pflash_t *pfl, int offset,
                           int size)
 {
     int offset_end;
-    if (pfl->bs) {
+    if (pfl->blk) {
         offset_end = offset + size;
         /* round to sectors */
         offset = offset >> 9;
         offset_end = (offset_end + 511) >> 9;
-        bdrv_write(pfl->bs, offset, pfl->storage + (offset << 9),
-                   offset_end - offset);
+        blk_write(pfl->blk, offset, pfl->storage + (offset << 9),
+                  offset_end - offset);
     }
 }
 
@@ -784,9 +784,9 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
     pfl->storage = memory_region_get_ram_ptr(&pfl->mem);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
 
-    if (pfl->bs) {
+    if (pfl->blk) {
         /* read the initial flash content */
-        ret = bdrv_read(pfl->bs, 0, pfl->storage, total_len >> 9);
+        ret = blk_read(pfl->blk, 0, pfl->storage, total_len >> 9);
 
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
@@ -795,8 +795,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    if (pfl->bs) {
-        pfl->ro = bdrv_is_read_only(pfl->bs);
+    if (pfl->blk) {
+        pfl->ro = blk_is_read_only(pfl->blk);
     } else {
         pfl->ro = 0;
     }
@@ -898,7 +898,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
 }
 
 static Property pflash_cfi01_properties[] = {
-    DEFINE_PROP_DRIVE("drive", struct pflash_t, bs),
+    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
     /* num-blocks is the number of blocks actually visible to the guest,
      * ie the total size of the device divided by the sector length.
      * If we're emulating flash devices wired in parallel the actual
@@ -962,14 +962,14 @@ type_init(pflash_cfi01_register_types)
 pflash_t *pflash_cfi01_register(hwaddr base,
                                 DeviceState *qdev, const char *name,
                                 hwaddr size,
-                                BlockDriverState *bs,
+                                BlockBackend *blk,
                                 uint32_t sector_len, int nb_blocs,
                                 int bank_width, uint16_t id0, uint16_t id1,
                                 uint16_t id2, uint16_t id3, int be)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
 
-    if (bs && qdev_prop_set_drive(dev, "drive", bs)) {
+    if (blk && qdev_prop_set_drive(dev, "drive", blk)) {
         abort();
     }
     qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
hw/block/pflash_cfi02.c +12 -12
index 01011cf..8513a17 100644
@@ -38,7 +38,7 @@
 #include "hw/hw.h"
 #include "hw/block/flash.h"
 #include "qemu/timer.h"
-#include "block/block.h"
+#include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 #include "qemu/host-utils.h"
 #include "hw/sysbus.h"
@@ -63,7 +63,7 @@ struct pflash_t {
     SysBusDevice parent_obj;
     /*< public >*/
 
-    BlockDriverState *bs;
+    BlockBackend *blk;
     uint32_t sector_len;
     uint32_t nb_blocs;
     uint32_t chip_len;
@@ -249,13 +249,13 @@ static void pflash_update(pflash_t *pfl, int offset,
                           int size)
 {
     int offset_end;
-    if (pfl->bs) {
+    if (pfl->blk) {
         offset_end = offset + size;
         /* round to sectors */
         offset = offset >> 9;
         offset_end = (offset_end + 511) >> 9;
-        bdrv_write(pfl->bs, offset, pfl->storage + (offset << 9),
-                   offset_end - offset);
+        blk_write(pfl->blk, offset, pfl->storage + (offset << 9),
+                  offset_end - offset);
     }
 }
 
@@ -618,9 +618,9 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
     vmstate_register_ram(&pfl->orig_mem, DEVICE(pfl));
     pfl->storage = memory_region_get_ram_ptr(&pfl->orig_mem);
     pfl->chip_len = chip_len;
-    if (pfl->bs) {
+    if (pfl->blk) {
         /* read the initial flash content */
-        ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9);
+        ret = blk_read(pfl->blk, 0, pfl->storage, chip_len >> 9);
         if (ret < 0) {
             vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl));
             error_setg(errp, "failed to read the initial flash content");
@@ -632,8 +632,8 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
     pfl->rom_mode = 1;
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
 
-    if (pfl->bs) {
-        pfl->ro = bdrv_is_read_only(pfl->bs);
+    if (pfl->blk) {
+        pfl->ro = blk_is_read_only(pfl->blk);
     } else {
         pfl->ro = 0;
     }
@@ -722,7 +722,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
 }
 
 static Property pflash_cfi02_properties[] = {
-    DEFINE_PROP_DRIVE("drive", struct pflash_t, bs),
+    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
     DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
     DEFINE_PROP_UINT32("sector-length", struct pflash_t, sector_len, 0),
     DEFINE_PROP_UINT8("width", struct pflash_t, width, 0),
@@ -763,7 +763,7 @@ type_init(pflash_cfi02_register_types)
 pflash_t *pflash_cfi02_register(hwaddr base,
                                 DeviceState *qdev, const char *name,
                                 hwaddr size,
-                                BlockDriverState *bs, uint32_t sector_len,
+                                BlockBackend *blk, uint32_t sector_len,
                                 int nb_blocs, int nb_mappings, int width,
                                 uint16_t id0, uint16_t id1,
                                 uint16_t id2, uint16_t id3,
@@ -772,7 +772,7 @@ pflash_t *pflash_cfi02_register(hwaddr base,
 {
     DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH02);
 
-    if (bs && qdev_prop_set_drive(dev, "drive", bs)) {
+    if (blk && qdev_prop_set_drive(dev, "drive", blk)) {
         abort();
     }
     qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
hw/block/virtio-blk.c +49 -46

282 lines not on this page · raw message

hw/block/xen_disk.c +41 -42

163 lines not on this page · raw message

hw/core/qdev-properties-system.c +13 -13
index ae0900f..f77b22a 100644
@@ -13,6 +13,7 @@
 #include "net/net.h"
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
 #include "hw/block/block.h"
 #include "net/hub.h"
@@ -68,16 +69,16 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
 
 static int parse_drive(DeviceState *dev, const char *str, void **ptr)
 {
-    BlockDriverState *bs;
+    BlockBackend *blk;
 
-    bs = bdrv_find(str);
-    if (bs == NULL) {
+    blk = blk_by_name(str);
+    if (!blk) {
         return -ENOENT;
     }
-    if (bdrv_attach_dev(bs, dev) < 0) {
+    if (blk_attach_dev(blk, dev) < 0) {
         return -EEXIST;
     }
-    *ptr = bs;
+    *ptr = blk;
     return 0;
 }
 
@@ -85,17 +86,17 @@ static void release_drive(Object *obj, const char *name, void *opaque)
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
+    BlockBackend **ptr = qdev_get_prop_ptr(dev, prop);
 
     if (*ptr) {
-        bdrv_detach_dev(*ptr, dev);
+        blk_detach_dev(*ptr, dev);
         blockdev_auto_del(*ptr);
     }
 }
 
 static char *print_drive(void *ptr)
 {
-    return g_strdup(bdrv_get_device_name(ptr));
+    return g_strdup(blk_name(ptr));
 }
 
 static void get_drive(Object *obj, Visitor *v, void *opaque,
@@ -335,12 +336,11 @@ PropertyInfo qdev_prop_vlan = {
 };
 
 int qdev_prop_set_drive(DeviceState *dev, const char *name,
-                        BlockDriverState *value)
+                        BlockBackend *value)
 {
     Error *err = NULL;
-    const char *bdrv_name = value ? bdrv_get_device_name(value) : "";
-    object_property_set_str(OBJECT(dev), bdrv_name,
-                            name, &err);
+    object_property_set_str(OBJECT(dev),
+                            value ? blk_name(value) : "", name, &err);
     if (err) {
         qerror_report_err(err);
         error_free(err);
@@ -350,7 +350,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name,
 }
 
 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name,
-                                BlockDriverState *value)
+                                BlockBackend *value)
 {
     if (qdev_prop_set_drive(dev, name, value) < 0) {
         exit(1);
hw/core/qdev-properties.c +1 -1
index 3d12560..931a48c 100644
@@ -1,7 +1,7 @@
 #include "net/net.h"
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "hw/block/block.h"
 #include "net/hub.h"
 #include "qapi/visitor.h"
hw/cris/axis_dev88.c +1 -2
index 417702a..0479196 100644
@@ -31,7 +31,6 @@
 #include "elf.h"
 #include "boot.h"
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
 
@@ -285,7 +284,7 @@ void axisdev88_init(MachineState *machine)
 
       /* Attach a NAND flash to CS1.  */
     nand = drive_get(IF_MTD, 0, 0);
-    nand_state.nand = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
+    nand_state.nand = nand_init(nand ? blk_by_legacy_dinfo(nand) : NULL,
                                 NAND_MFR_STMICRO, 0x39);
     memory_region_init_io(&nand_state.iomem, NULL, &nand_ops, &nand_state,
                           "nand", 0x05000000);
hw/display/tc6393xb.c +1 -1
index 576f319..4306adc 100644
@@ -577,7 +577,7 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq)
     s->sub_irqs = qemu_allocate_irqs(tc6393xb_sub_irq, s, TC6393XB_NR_IRQS);
 
     nand = drive_get(IF_MTD, 0, 0);
-    s->flash = nand_init(nand ? blk_bs(blk_by_legacy_dinfo(nand)) : NULL,
+    s->flash = nand_init(nand ? blk_by_legacy_dinfo(nand) : NULL,
                          NAND_MFR_TOSHIBA, 0x76);
 
     memory_region_init_io(&s->iomem, NULL, &tc6393xb_ops, s, "tc6393xb", 0x10000);
hw/i386/pc.c +1 -1
index 77b6782..0a281e0 100644
@@ -44,7 +44,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_i386.h"
 #include "hw/xen/xen.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "hw/block/block.h"
 #include "ui/qemu-spice.h"
 #include "exec/memory.h"
hw/i386/pc_piix.c +1 -1
index 103d756..000b34a 100644
@@ -41,7 +41,7 @@
 #include "hw/sysbus.h"
 #include "hw/cpu/icc_bus.h"
 #include "sysemu/arch_init.h"
-#include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include "hw/i2c/smbus.h"
 #include "hw/xen/xen.h"
 #include "exec/memory.h"
hw/i386/pc_sysfw.c +4 -5
index 9bf22b6..75913c5 100644
@@ -24,7 +24,6 @@
  */
 
 #include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "qemu/error-report.h"
 #include "hw/sysbus.h"
 #include "hw/hw.h"
@@ -104,7 +103,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
 {
     int unit;
     DriveInfo *pflash_drv;
-    BlockDriverState *bdrv;
+    BlockBackend *blk;
     int64_t size;
     char *fatal_errmsg = NULL;
     hwaddr phys_addr = 0x100000000ULL;
@@ -120,8 +119,8 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
          (unit < FLASH_MAP_UNIT_MAX &&
           (pflash_drv = drive_get(IF_PFLASH, 0, unit)) != NULL);
          ++unit) {
-        bdrv = blk_bs(blk_by_legacy_dinfo(pflash_drv));
-        size = bdrv_getlength(bdrv);
+        blk = blk_by_legacy_dinfo(pflash_drv);
+        size = blk_getlength(blk);
         if (size < 0) {
             fatal_errmsg = g_strdup_printf("failed to get backing file size");
         } else if (size == 0) {
@@ -157,7 +156,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
         /* pflash_cfi01_register() creates a deep copy of the name */
         snprintf(name, sizeof name, "system.flash%d", unit);
         system_flash = pflash_cfi01_register(phys_addr, NULL /* qdev */, name,
-                                             size, bdrv, sector_size,
+                                             size, blk, sector_size,
                                              size >> sector_bits,
                                              1      /* width */,
                                              0x0000 /* id0 */,
hw/i386/xen/xen_platform.c +3 -2
index 8bb18b4..28b324a 100644
@@ -34,6 +34,7 @@
 #include "hw/xen/xen_backend.h"
 #include "trace.h"
 #include "exec/address-spaces.h"
+#include "sysemu/block-backend.h"
 
 #include <xenguest.h>
 
@@ -132,8 +133,8 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v
            devices, and bit 2 the non-primary-master IDE devices. */
         if (val & UNPLUG_ALL_IDE_DISKS) {
             DPRINTF("unplug disks\n");
-            bdrv_drain_all();
-            bdrv_flush_all();
+            blk_drain_all();
+            blk_flush_all();
             pci_unplug_disks(pci_dev->bus);
         }
         if (val & UNPLUG_ALL_NICS) {
hw/ide/ahci.c +16 -15
index f301fe1..aa16212 100644
@@ -28,6 +28,7 @@
 #include <hw/sysbus.h>
 
 #include "monitor/monitor.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/dma.h"
 #include "internal.h"
 #include <hw/ide/pci.h>
@@ -85,7 +86,7 @@ static uint32_t  ahci_port_read(AHCIState *s, int port, int offset)
         val = pr->sig;
         break;
     case PORT_SCR_STAT:
-        if (s->dev[port].port.ifs[0].bs) {
+        if (s->dev[port].port.ifs[0].blk) {
             val = SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP |
                   SATA_SCR_SSTATUS_SPD_GEN1 | SATA_SCR_SSTATUS_IPM_ACTIVE;
         } else {
@@ -501,7 +502,7 @@ static void ahci_reset_port(AHCIState *s, int port)
     d->init_d2h_sent = false;
 
     ide_state = &s->dev[port].port.ifs[0];
-    if (!ide_state->bs) {
+    if (!ide_state->blk) {
         return;
     }
 
@@ -513,11 +514,11 @@ static void ahci_reset_port(AHCIState *s, int port)
         }
 
         if (ncq_tfs->aiocb) {
-            bdrv_aio_cancel(ncq_tfs->aiocb);
+            blk_aio_cancel(ncq_tfs->aiocb);
             ncq_tfs->aiocb = NULL;
         }
 
-        /* Maybe we just finished the request thanks to bdrv_aio_cancel() */
+        /* Maybe we just finished the request thanks to blk_aio_cancel() */
         if (!ncq_tfs->used) {
             continue;
         }
@@ -527,7 +528,7 @@ static void ahci_reset_port(AHCIState *s, int port)
     }
 
     s->dev[port].port_state = STATE_RUN;
-    if (!ide_state->bs) {
+    if (!ide_state->blk) {
         s->dev[port].port_regs.sig = 0;
         ide_state->status = SEEK_STAT | WRERR_STAT;
     } else if (ide_state->drive_kind == IDE_CD) {
@@ -809,7 +810,7 @@ static void ncq_cb(void *opaque, int ret)
     DPRINTF(ncq_tfs->drive->port_no, "NCQ transfer tag %d finished\n",
             ncq_tfs->tag);
 
-    block_acct_done(bdrv_get_stats(ncq_tfs->drive->port.ifs[0].bs),
+    block_acct_done(blk_get_stats(ncq_tfs->drive->port.ifs[0].blk),
                     &ncq_tfs->acct);
     qemu_sglist_destroy(&ncq_tfs->sglist);
     ncq_tfs->used = 0;
@@ -860,11 +861,11 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
             DPRINTF(port, "tag %d aio read %"PRId64"\n",
                     ncq_tfs->tag, ncq_tfs->lba);
 
-            dma_acct_start(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct,
+            dma_acct_start(ncq_tfs->drive->port.ifs[0].blk, &ncq_tfs->acct,
                            &ncq_tfs->sglist, BLOCK_ACCT_READ);
-            ncq_tfs->aiocb = dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs,
-                                           &ncq_tfs->sglist, ncq_tfs->lba,
-                                           ncq_cb, ncq_tfs);
+            ncq_tfs->aiocb = dma_blk_read(ncq_tfs->drive->port.ifs[0].blk,
+                                          &ncq_tfs->sglist, ncq_tfs->lba,
+                                          ncq_cb, ncq_tfs);
             break;
         case WRITE_FPDMA_QUEUED:
             DPRINTF(port, "NCQ writing %d sectors to LBA %"PRId64", tag %d\n",
@@ -873,11 +874,11 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
             DPRINTF(port, "tag %d aio write %"PRId64"\n",
                     ncq_tfs->tag, ncq_tfs->lba);
 
-            dma_acct_start(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct,
+            dma_acct_start(ncq_tfs->drive->port.ifs[0].blk, &ncq_tfs->acct,
                            &ncq_tfs->sglist, BLOCK_ACCT_WRITE);
-            ncq_tfs->aiocb = dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs,
-                                            &ncq_tfs->sglist, ncq_tfs->lba,
-                                            ncq_cb, ncq_tfs);
+            ncq_tfs->aiocb = dma_blk_write(ncq_tfs->drive->port.ifs[0].blk,
+                                           &ncq_tfs->sglist, ncq_tfs->lba,
+                                           ncq_cb, ncq_tfs);
             break;
         default:
             DPRINTF(port, "error: tried to process non-NCQ command as NCQ\n");
@@ -926,7 +927,7 @@ static int handle_cmd(AHCIState *s, int port, int slot)
     /* The device we are working for */
     ide_state = &s->dev[port].port.ifs[0];
 
-    if (!ide_state->bs) {
+    if (!ide_state->blk) {
         DPRINTF(port, "error: guest accessed unused port");
         goto out;
     }
hw/ide/atapi.c +17 -16
index 6d52cda..78446de 100644
@@ -25,6 +25,7 @@
 
 #include "hw/ide/internal.h"
 #include "hw/scsi/scsi.h"
+#include "sysemu/block-backend.h"
 
 static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret);
 
@@ -110,16 +111,16 @@ static int cd_read_sector(IDEState *s, int lba, uint8_t *buf, int sector_size)
 
     switch(sector_size) {
     case 2048:
-        block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+        block_acct_start(blk_get_stats(s->blk), &s->acct,
                          4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
-        ret = bdrv_read(s->bs, (int64_t)lba << 2, buf, 4);
-        block_acct_done(bdrv_get_stats(s->bs), &s->acct);
+        ret = blk_read(s->blk, (int64_t)lba << 2, buf, 4);
+        block_acct_done(blk_get_stats(s->blk), &s->acct);
         break;
     case 2352:
-        block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+        block_acct_start(blk_get_stats(s->blk), &s->acct,
                          4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
-        ret = bdrv_read(s->bs, (int64_t)lba << 2, buf + 16, 4);
-        block_acct_done(bdrv_get_stats(s->bs), &s->acct);
+        ret = blk_read(s->blk, (int64_t)lba << 2, buf + 16, 4);
+        block_acct_done(blk_get_stats(s->blk), &s->acct);
         if (ret < 0)
             return ret;
         cd_data_to_raw(buf, lba);
@@ -255,7 +256,7 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int max_size)
     s->io_buffer_index = 0;
 
     if (s->atapi_dma) {
-        block_acct_start(bdrv_get_stats(s->bs), &s->acct, size,
+        block_acct_start(blk_get_stats(s->blk), &s->acct, size,
                          BLOCK_ACCT_READ);
         s->status = READY_STAT | SEEK_STAT | DRQ_STAT;
         ide_start_dma(s, ide_atapi_cmd_read_dma_cb);
@@ -351,13 +352,13 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
     s->bus->dma->iov.iov_len = n * 4 * 512;
     qemu_iovec_init_external(&s->bus->dma->qiov, &s->bus->dma->iov, 1);
 
-    s->bus->dma->aiocb = bdrv_aio_readv(s->bs, (int64_t)s->lba << 2,
+    s->bus->dma->aiocb = blk_aio_readv(s->blk, (int64_t)s->lba << 2,
                                        &s->bus->dma->qiov, n * 4,
                                        ide_atapi_cmd_read_dma_cb, s);
     return;
 
 eot:
-    block_acct_done(bdrv_get_stats(s->bs), &s->acct);
+    block_acct_done(blk_get_stats(s->blk), &s->acct);
     ide_set_inactive(s, false);
 }
 
@@ -372,7 +373,7 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
     s->io_buffer_size = 0;
     s->cd_sector_size = sector_size;
 
-    block_acct_start(bdrv_get_stats(s->bs), &s->acct, s->packet_transfer_size,
+    block_acct_start(blk_get_stats(s->blk), &s->acct, s->packet_transfer_size,
                      BLOCK_ACCT_READ);
 
     /* XXX: check if BUSY_STAT should be set */
@@ -505,7 +506,7 @@ static unsigned int event_status_media(IDEState *s,
     media_status = 0;
     if (s->tray_open) {
         media_status = MS_TRAY_OPEN;
-    } else if (bdrv_is_inserted(s->bs)) {
+    } else if (blk_is_inserted(s->blk)) {
         media_status = MS_MEDIA_PRESENT;
     }
 
@@ -801,7 +802,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
 static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
 {
     s->tray_locked = buf[4] & 1;
-    bdrv_lock_medium(s->bs, buf[4] & 1);
+    blk_lock_medium(s->blk, buf[4] & 1);
     ide_atapi_cmd_ok(s);
 }
 
@@ -885,14 +886,14 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
 
     if (loej) {
         if (!start && !s->tray_open && s->tray_locked) {
-            sense = bdrv_is_inserted(s->bs)
+            sense = blk_is_inserted(s->blk)
                 ? NOT_READY : ILLEGAL_REQUEST;
             ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
             return;
         }
 
         if (s->tray_open != !start) {
-            bdrv_eject(s->bs, !start);
+            blk_eject(s->blk, !start);
             s->tray_open = !start;
         }
     }
@@ -1126,7 +1127,7 @@ void ide_atapi_cmd(IDEState *s)
      * states rely on this behavior.
      */
     if (!(atapi_cmd_table[s->io_buffer[0]].flags & ALLOW_UA) &&
-        !s->tray_open && bdrv_is_inserted(s->bs) && s->cdrom_changed) {
+        !s->tray_open && blk_is_inserted(s->blk) && s->cdrom_changed) {
 
         if (s->cdrom_changed == 1) {
             ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
@@ -1141,7 +1142,7 @@ void ide_atapi_cmd(IDEState *s)
 
     /* Report a Not Ready condition if appropriate for the command */
     if ((atapi_cmd_table[s->io_buffer[0]].flags & CHECK_READY) &&
-        (!media_present(s) || !bdrv_is_inserted(s->bs)))
+        (!media_present(s) || !blk_is_inserted(s->blk)))
     {
         ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
         return;
hw/ide/cmd646.c +1 -1
index 91048f2..c8b0322 100644
@@ -26,7 +26,7 @@
 #include <hw/i386/pc.h>
 #include <hw/pci/pci.h>
 #include <hw/isa/isa.h>
-#include "block/block.h"
+#include "sysemu/block-backend.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
 
hw/ide/core.c +98 -88

409 lines not on this page · raw message

hw/ide/ich.c +1 -1
index a2f1639..6351363 100644

Lines of this file are not shown. View the raw message.

hw/ide/internal.h +3 -3
index 9314c80..68ac610 100644

Lines of this file are not shown. View the raw message.

hw/ide/isa.c +1 -1
index 4cbcb1c..b084162 100644

Lines of this file are not shown. View the raw message.

hw/ide/macio.c +25 -25

50 lines not on this page · raw message

hw/ide/microdrive.c +2 -2
index 15671b8..ed85185 100644

Lines of this file are not shown. View the raw message.

hw/ide/mmio.c +1 -1
index 334c8cc..b6ce62a 100644

Lines of this file are not shown. View the raw message.

hw/ide/pci.c +2 -2
index 6ff1c58..2dad50e 100644

Lines of this file are not shown. View the raw message.

hw/ide/piix.c +4 -5
index c6c256f..61958c6 100644

Lines of this file are not shown. View the raw message.

hw/ide/qdev.c +5 -6
index 75e8eb3..4818334 100644

Lines of this file are not shown. View the raw message.

hw/ide/via.c +1 -1
index 89d27b4..4d8089d 100644

Lines of this file are not shown. View the raw message.

hw/isa/pc87312.c +2 -2
index b691a0c..40a1106 100644

Lines of this file are not shown. View the raw message.

hw/lm32/lm32_boards.c +2 -3
index 2a1d3de..af0abdb 100644

Lines of this file are not shown. View the raw message.

hw/lm32/milkymist.c +1 -2
index 8411895..256c102 100644

Lines of this file are not shown. View the raw message.

hw/microblaze/petalogix_ml605_mmu.c +1 -2
index 8c0532d..48c264b 100644

Lines of this file are not shown. View the raw message.

hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -2
index c3fd743..84f6e74 100644

Lines of this file are not shown. View the raw message.

hw/mips/mips_fulong2e.c +1 -1
index be286da..60c8104 100644

Lines of this file are not shown. View the raw message.

hw/mips/mips_jazz.c +1 -1
index 6c31cb8..3f33093 100644

Lines of this file are not shown. View the raw message.

hw/mips/mips_malta.c +3 -3
index 6d81cbf..b48b7a9 100644

Lines of this file are not shown. View the raw message.

hw/mips/mips_r4k.c +1 -2
index f07fe6b..82ee641 100644

Lines of this file are not shown. View the raw message.

hw/nvram/spapr_nvram.c +9 -8
index 6a72ef4..10b5b2e 100644

Lines of this file are not shown. View the raw message.

hw/pci/pci-hotplug-old.c +2 -3
index e4d51de..23c80ca 100644

Lines of this file are not shown. View the raw message.

hw/ppc/mac_newworld.c +1 -1
index 1626db4..b407202 100644

Lines of this file are not shown. View the raw message.

hw/ppc/mac_oldworld.c +1 -1
index be9a194..c3f34b3 100644

Lines of this file are not shown. View the raw message.

hw/ppc/ppc405_boards.c +13 -13
index aeae450..1dcea77 100644

Lines of this file are not shown. View the raw message.

hw/ppc/prep.c +1 -1
index f0ef1af..37c582b 100644

Lines of this file are not shown. View the raw message.

hw/ppc/spapr.c +1 -3
index a577812..78fb927 100644

Lines of this file are not shown. View the raw message.

hw/ppc/virtex_ml507.c +1 -2
index a0ce447..6ebd5be 100644

Lines of this file are not shown. View the raw message.

hw/s390x/s390-virtio-bus.c +1 -1
index 6b6fb61..81cf22a 100644

Lines of this file are not shown. View the raw message.

hw/s390x/s390-virtio.c +1 -1
index 9c61246..b7ab774 100644

Lines of this file are not shown. View the raw message.

hw/s390x/virtio-ccw.c +1 -1
index 33a1d86..6339f82 100644

Lines of this file are not shown. View the raw message.

hw/scsi/megasas.c +6 -9
index eedc992..36a04f3 100644

Lines of this file are not shown. View the raw message.

hw/scsi/scsi-bus.c +4 -4
index f5156ae..869d616 100644

Lines of this file are not shown. View the raw message.

hw/scsi/scsi-disk.c +94 -92

186 lines not on this page · raw message

hw/scsi/scsi-generic.c +21 -18
index 5301886..ff2f920 100644

Lines of this file are not shown. View the raw message.

hw/sd/milkymist-memcard.c +4 -4
index 501aa3a..9661eaf 100644

Lines of this file are not shown. View the raw message.

hw/sd/omap_mmc.c +4 -4
index 6c92149..86c477d 100644

Lines of this file are not shown. View the raw message.

hw/sd/pl181.c +1 -1
index 0501d40..e704b6e 100644

Lines of this file are not shown. View the raw message.

hw/sd/pxa2xx_mmci.c +2 -2
index b9d8b1a..ac3ab39 100644

Lines of this file are not shown. View the raw message.

hw/sd/sd.c +30 -30

60 lines not on this page · raw message

hw/sd/sdhci.c +1 -1
index 0b7d754..b380050 100644

Lines of this file are not shown. View the raw message.

hw/sd/ssi-sd.c +1 -1
index 6ae99e4..a71fbca 100644

Lines of this file are not shown. View the raw message.

hw/sh4/r2d.c +1 -2
index 80ac132..12f44d2 100644

Lines of this file are not shown. View the raw message.

hw/sparc/sun4m.c +1 -1
index 78f87a2..99b061f 100644

Lines of this file are not shown. View the raw message.

hw/sparc64/sun4u.c +1 -1
index 9c77e18..d104e54 100644

Lines of this file are not shown. View the raw message.

hw/tpm/tpm_tis.c +1 -1
index 82747ee..c0e7cd7 100644

Lines of this file are not shown. View the raw message.

hw/tricore/tricore_testboard.c +1 -1
index 605de86..eeb4922 100644

Lines of this file are not shown. View the raw message.

hw/usb/dev-storage.c +9 -8
index 0d6e7c6..a2b4810 100644

Lines of this file are not shown. View the raw message.

hw/virtio/virtio-pci.c +1 -1
index ddb5da1..28ddc73 100644

Lines of this file are not shown. View the raw message.

hw/xen/xen_devconfig.c +1 -0
index fa998ef..e138dbb 100644

Lines of this file are not shown. View the raw message.

hw/xenpv/xen_machine_pv.c +1 -1
index 3150064..2e545d2 100644

Lines of this file are not shown. View the raw message.

hw/xtensa/xtfpga.c +1 -2
index 4ac1cef..0100c31 100644

Lines of this file are not shown. View the raw message.

include/hw/arm/omap.h +2 -2
index b9655ee..0ad5fb8 100644

Lines of this file are not shown. View the raw message.

include/hw/arm/pxa.h +1 -1
index c507906..259b852 100644

Lines of this file are not shown. View the raw message.

include/hw/block/block.h +3 -3
index 3a01488..c128589 100644

Lines of this file are not shown. View the raw message.

include/hw/block/flash.h +3 -3
index 920d759..50ccbbc 100644

Lines of this file are not shown. View the raw message.

include/hw/qdev-properties.h +5 -3
index 77fe3a1..e560647 100644

Lines of this file are not shown. View the raw message.

include/hw/scsi/scsi.h +2 -2
index e3e27cb..444e450 100644

Lines of this file are not shown. View the raw message.

include/hw/sd.h +1 -1
index d9b97e4..79adb5b 100644

Lines of this file are not shown. View the raw message.

include/hw/virtio/virtio-blk.h +3 -4
index 6f8f59e..f1b46e7 100644

Lines of this file are not shown. View the raw message.

include/qemu/typedefs.h +1 -0
index 198da2e..8b3f352 100644

Lines of this file are not shown. View the raw message.

include/sysemu/block-backend.h +75 -0

75 lines not on this page · raw message

include/sysemu/blockdev.h +2 -3
index 75f6ac6..f66b89a 100644

Lines of this file are not shown. View the raw message.

include/sysemu/dma.h +12 -12
index bcff53a..15f997b 100644

Lines of this file are not shown. View the raw message.

trace-events +4 -4
index fb58963..74829f4 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.3

Part of the diff is not shown here. View the raw message.

Reviewed-by on v3 14/23
#61 lore raw

Re: [Qemu-devel] [PATCH v3 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly

Quoted 128 lines · Markus Armbruster

Just four uses of BlockDriverState are left:

* The Xen paravirtual block device backend (xen_disk.c) opens images itself when set up via xenbus, bypassing blockdev.c. I figure it should go through qmp_blockdev_add() instead.

* Device model "usb-storage" prompts for keys. No other device model does, and this one probably shouldn't do it, either.

* ide_issue_trim_cb() uses bdrv_aio_discard() instead of blk_aio_discard() because it fishes its backend out of a BlockAIOCB, which has only the BlockDriverState.

* PC87312State has an unused BlockDriverState[] member.

The next two commits take care of the latter two.

---
  block/block-backend.c                    | 257 +++++++++++++++++++++++++++++++
  blockdev.c                               |  19 +--
  dma-helpers.c                            |  61 ++++----
  hw/arm/collie.c                          |   5 +-
  hw/arm/gumstix.c                         |   5 +-
  hw/arm/highbank.c                        |   2 +-
  hw/arm/mainstone.c                       |   2 +-
  hw/arm/musicpal.c                        |  10 +-
  hw/arm/nseries.c                         |   3 +-
  hw/arm/omap1.c                           |   2 +-
  hw/arm/omap2.c                           |   2 +-
  hw/arm/omap_sx1.c                        |   5 +-
  hw/arm/pxa2xx.c                          |   4 +-
  hw/arm/realview.c                        |   2 +-
  hw/arm/spitz.c                           |   4 +-
  hw/arm/tosa.c                            |   3 +-
  hw/arm/versatilepb.c                     |   3 +-
  hw/arm/vexpress.c                        |   3 +-
  hw/arm/xilinx_zynq.c                     |   3 +-
  hw/arm/z2.c                              |   3 +-
  hw/block/block.c                         |   7 +-
  hw/block/dataplane/virtio-blk.c          |  24 +--
  hw/block/fdc.c                           |  78 +++++-----
  hw/block/hd-geometry.c                   |  24 +--
  hw/block/m25p80.c                        |  28 ++--
  hw/block/nand.c                          |  50 +++---
  hw/block/nvme.c                          |  19 +--
  hw/block/onenand.c                       |  67 ++++----
  hw/block/pflash_cfi01.c                  |  24 +--
  hw/block/pflash_cfi02.c                  |  24 +--
  hw/block/virtio-blk.c                    |  95 ++++++------
  hw/block/xen_disk.c                      |  83 +++++-----
  hw/core/qdev-properties-system.c         |  26 ++--
  hw/core/qdev-properties.c                |   2 +-
  hw/cris/axis_dev88.c                     |   3 +-
  hw/display/tc6393xb.c                    |   2 +-
  hw/i386/pc.c                             |   2 +-
  hw/i386/pc_piix.c                        |   2 +-
  hw/i386/pc_sysfw.c                       |   9 +-
  hw/i386/xen/xen_platform.c               |   5 +-
  hw/ide/ahci.c                            |  31 ++--
  hw/ide/atapi.c                           |  33 ++--
  hw/ide/cmd646.c                          |   2 +-
  hw/ide/core.c                            | 186 +++++++++++-----------
  hw/ide/ich.c                             |   2 +-
  hw/ide/internal.h                        |   6 +-
  hw/ide/isa.c                             |   2 +-
  hw/ide/macio.c                           |  50 +++---
  hw/ide/microdrive.c                      |   4 +-
  hw/ide/mmio.c                            |   2 +-
  hw/ide/pci.c                             |   4 +-
  hw/ide/piix.c                            |   9 +-
  hw/ide/qdev.c                            |  11 +-
  hw/ide/via.c                             |   2 +-
  hw/isa/pc87312.c                         |   4 +-
  hw/lm32/lm32_boards.c                    |   5 +-
  hw/lm32/milkymist.c                      |   3 +-
  hw/microblaze/petalogix_ml605_mmu.c      |   3 +-
  hw/microblaze/petalogix_s3adsp1800_mmu.c |   3 +-
  hw/mips/mips_fulong2e.c                  |   2 +-
  hw/mips/mips_jazz.c                      |   2 +-
  hw/mips/mips_malta.c                     |   6 +-
  hw/mips/mips_r4k.c                       |   3 +-
  hw/nvram/spapr_nvram.c                   |  17 +-
  hw/pci/pci-hotplug-old.c                 |   5 +-
  hw/ppc/mac_newworld.c                    |   2 +-
  hw/ppc/mac_oldworld.c                    |   2 +-
  hw/ppc/ppc405_boards.c                   |  26 ++--
  hw/ppc/prep.c                            |   2 +-
  hw/ppc/spapr.c                           |   4 +-
  hw/ppc/virtex_ml507.c                    |   3 +-
  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                       |   8 +-
  hw/scsi/scsi-disk.c                      | 186 +++++++++++-----------
  hw/scsi/scsi-generic.c                   |  39 ++---
  hw/sd/milkymist-memcard.c                |   8 +-
  hw/sd/omap_mmc.c                         |   8 +-
  hw/sd/pl181.c                            |   2 +-
  hw/sd/pxa2xx_mmci.c                      |   4 +-
  hw/sd/sd.c                               |  60 ++++----
  hw/sd/sdhci.c                            |   2 +-
  hw/sd/ssi-sd.c                           |   2 +-
  hw/sh4/r2d.c                             |   3 +-
  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                     |  17 +-
  hw/virtio/virtio-pci.c                   |   2 +-
  hw/xen/xen_devconfig.c                   |   1 +
  hw/xenpv/xen_machine_pv.c                |   2 +-
  hw/xtensa/xtfpga.c                       |   3 +-
  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/qdev-properties.h             |   8 +-
  include/hw/scsi/scsi.h                   |   4 +-
  include/hw/sd.h                          |   2 +-
  include/hw/virtio/virtio-blk.h           |   7 +-
  include/qemu/typedefs.h                  |   1 +
  include/sysemu/block-backend.h           |  75 +++++++++
  include/sysemu/blockdev.h                |   5 +-
  include/sysemu/dma.h                     |  24 +--
  trace-events                             |   8 +-
  108 files changed, 1126 insertions(+), 810 deletions(-)

[snip]

Quoted 5 lines
include/sysemu/dma.h +0 -0
index bcff53a..15f997b 100644

include/sysemu/dma.h void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len); · line 202

Quoted 9 lines
include/sysemu/dma.h +3 -3
@@ -197,24 +197,24 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len);
  void qemu_sglist_destroy(QEMUSGList *qsg);
  #endif
 
-typedef BlockAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num,
-                              QEMUIOVector *iov, int nb_sectors,
-                              BlockCompletionFunc *cb, void *opaque);
+typedef BlockAIOCB *DMAIOFunc(BlockBackend *blk, int64_t sector_num,
+                                 QEMUIOVector *iov, int nb_sectors,
+                                 BlockCompletionFunc *cb, void *opaque);

This breaks the alignment.

There are a couple files touched by this patch where the only change is to replace '#include "sysemu/blockdev.h"' and '#include "block/block.h"' by '#include "sysemu/block-backend.h"' (in xen_devconfig.c you actually just add the latter and don't remove the former). Although I don't understand the purpose of this and it seems a mechanical artifact to me, it certainly won't be hurt anyone. I suppose it's because including block-backend.h is more correct than the other two (as I can read from your TODO in block-backend.h).

Anyway, with the alignment not broken:

#62 lore raw

Re: [Qemu-devel] [PATCH v3 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly

Quoted 141 lines · Max Reitz
Quoted 128 lines · Markus Armbruster

Just four uses of BlockDriverState are left:

* The Xen paravirtual block device backend (xen_disk.c) opens images itself when set up via xenbus, bypassing blockdev.c. I figure it should go through qmp_blockdev_add() instead.

* Device model "usb-storage" prompts for keys. No other device model does, and this one probably shouldn't do it, either.

* ide_issue_trim_cb() uses bdrv_aio_discard() instead of blk_aio_discard() because it fishes its backend out of a BlockAIOCB, which has only the BlockDriverState.

* PC87312State has an unused BlockDriverState[] member.

The next two commits take care of the latter two.

---
  block/block-backend.c                    | 257 +++++++++++++++++++++++++++++++
  blockdev.c                               |  19 +--
  dma-helpers.c                            |  61 ++++----
  hw/arm/collie.c                          |   5 +-
  hw/arm/gumstix.c                         |   5 +-
  hw/arm/highbank.c                        |   2 +-
  hw/arm/mainstone.c                       |   2 +-
  hw/arm/musicpal.c                        |  10 +-
  hw/arm/nseries.c                         |   3 +-
  hw/arm/omap1.c                           |   2 +-
  hw/arm/omap2.c                           |   2 +-
  hw/arm/omap_sx1.c                        |   5 +-
  hw/arm/pxa2xx.c                          |   4 +-
  hw/arm/realview.c                        |   2 +-
  hw/arm/spitz.c                           |   4 +-
  hw/arm/tosa.c                            |   3 +-
  hw/arm/versatilepb.c                     |   3 +-
  hw/arm/vexpress.c                        |   3 +-
  hw/arm/xilinx_zynq.c                     |   3 +-
  hw/arm/z2.c                              |   3 +-
  hw/block/block.c                         |   7 +-
  hw/block/dataplane/virtio-blk.c          |  24 +--
  hw/block/fdc.c                           |  78 +++++-----
  hw/block/hd-geometry.c                   |  24 +--
  hw/block/m25p80.c                        |  28 ++--
  hw/block/nand.c                          |  50 +++---
  hw/block/nvme.c                          |  19 +--
  hw/block/onenand.c                       |  67 ++++----
  hw/block/pflash_cfi01.c                  |  24 +--
  hw/block/pflash_cfi02.c                  |  24 +--
  hw/block/virtio-blk.c                    |  95 ++++++------
  hw/block/xen_disk.c                      |  83 +++++-----
  hw/core/qdev-properties-system.c         |  26 ++--
  hw/core/qdev-properties.c                |   2 +-
  hw/cris/axis_dev88.c                     |   3 +-
  hw/display/tc6393xb.c                    |   2 +-
  hw/i386/pc.c                             |   2 +-
  hw/i386/pc_piix.c                        |   2 +-
  hw/i386/pc_sysfw.c                       |   9 +-
  hw/i386/xen/xen_platform.c               |   5 +-
  hw/ide/ahci.c                            |  31 ++--
  hw/ide/atapi.c                           |  33 ++--
  hw/ide/cmd646.c                          |   2 +-
  hw/ide/core.c                            | 186 +++++++++++-----------
  hw/ide/ich.c                             |   2 +-
  hw/ide/internal.h                        |   6 +-
  hw/ide/isa.c                             |   2 +-
  hw/ide/macio.c                           |  50 +++---
  hw/ide/microdrive.c                      |   4 +-
  hw/ide/mmio.c                            |   2 +-
  hw/ide/pci.c                             |   4 +-
  hw/ide/piix.c                            |   9 +-
  hw/ide/qdev.c                            |  11 +-
  hw/ide/via.c                             |   2 +-
  hw/isa/pc87312.c                         |   4 +-
  hw/lm32/lm32_boards.c                    |   5 +-
  hw/lm32/milkymist.c                      |   3 +-
  hw/microblaze/petalogix_ml605_mmu.c      |   3 +-
  hw/microblaze/petalogix_s3adsp1800_mmu.c |   3 +-
  hw/mips/mips_fulong2e.c                  |   2 +-
  hw/mips/mips_jazz.c                      |   2 +-
  hw/mips/mips_malta.c                     |   6 +-
  hw/mips/mips_r4k.c                       |   3 +-
  hw/nvram/spapr_nvram.c                   |  17 +-
  hw/pci/pci-hotplug-old.c                 |   5 +-
  hw/ppc/mac_newworld.c                    |   2 +-
  hw/ppc/mac_oldworld.c                    |   2 +-
  hw/ppc/ppc405_boards.c                   |  26 ++--
  hw/ppc/prep.c                            |   2 +-
  hw/ppc/spapr.c                           |   4 +-
  hw/ppc/virtex_ml507.c                    |   3 +-
  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                       |   8 +-
  hw/scsi/scsi-disk.c                      | 186 +++++++++++-----------
  hw/scsi/scsi-generic.c                   |  39 ++---
  hw/sd/milkymist-memcard.c                |   8 +-
  hw/sd/omap_mmc.c                         |   8 +-
  hw/sd/pl181.c                            |   2 +-
  hw/sd/pxa2xx_mmci.c                      |   4 +-
  hw/sd/sd.c                               |  60 ++++----
  hw/sd/sdhci.c                            |   2 +-
  hw/sd/ssi-sd.c                           |   2 +-
  hw/sh4/r2d.c                             |   3 +-
  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                     |  17 +-
  hw/virtio/virtio-pci.c                   |   2 +-
  hw/xen/xen_devconfig.c                   |   1 +
  hw/xenpv/xen_machine_pv.c                |   2 +-
  hw/xtensa/xtfpga.c                       |   3 +-
  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/qdev-properties.h             |   8 +-
  include/hw/scsi/scsi.h                   |   4 +-
  include/hw/sd.h                          |   2 +-
  include/hw/virtio/virtio-blk.h           |   7 +-
  include/qemu/typedefs.h                  |   1 +
  include/sysemu/block-backend.h           |  75 +++++++++
  include/sysemu/blockdev.h                |   5 +-
  include/sysemu/dma.h                     |  24 +--
  trace-events                             |   8 +-
  108 files changed, 1126 insertions(+), 810 deletions(-)

[snip]

Quoted 9 lines
include/sysemu/dma.h +0 -0
index bcff53a..15f997b 100644
@@ -197,24 +197,24 @@ void qemu_sglist_add(QEMUSGList *qsg,
 dma_addr_t base, dma_addr_t len);
  void qemu_sglist_destroy(QEMUSGList *qsg);
  #endif
  -typedef BlockAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t
Quoted 8 lines

include/sysemu/dma.h void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len); · line 202

Quoted 6 lines
include/sysemu/dma.h +3 -2
 sector_num,
-                              QEMUIOVector *iov, int nb_sectors,
-                              BlockCompletionFunc *cb, void *opaque);
+typedef BlockAIOCB *DMAIOFunc(BlockBackend *blk, int64_t sector_num,
+                                 QEMUIOVector *iov, int nb_sectors,
+                                 BlockCompletionFunc *cb, void *opaque);

This breaks the alignment.

Will fix.

Quoted 8 lines

There are a couple files touched by this patch where the only change is to replace '#include "sysemu/blockdev.h"' and '#include "block/block.h"' by '#include "sysemu/block-backend.h"' (in xen_devconfig.c you actually just add the latter and don't remove the former). Although I don't understand the purpose of this and it seems a mechanical artifact to me, it certainly won't be hurt anyone. I suppose it's because including block-backend.h is more correct than the other two (as I can read from your TODO in block-backend.h).

We want hw to use the block layer only through the BlockBackend API. That means including block-backend-h, not blockdev.h or block.h, let alone block_int.h. This patch moves us a bit closer to this goal.

I'll explain in the commit message.

Quoted 3 lines

Anyway, with the alignment not broken:

Thanks!

#63 lore raw

Re: [Qemu-devel] [PATCH v3 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 13 lines

Just four uses of BlockDriverState are left:

* The Xen paravirtual block device backend (xen_disk.c) opens images itself when set up via xenbus, bypassing blockdev.c. I figure it should go through qmp_blockdev_add() instead.

* Device model "usb-storage" prompts for keys. No other device model does, and this one probably shouldn't do it, either.

* ide_issue_trim_cb() uses bdrv_aio_discard() instead of blk_aio_discard() because it fishes its backend out of a BlockAIOCB, which has only the BlockDriverState.

Quoted 5 lines

* PC87312State has an unused BlockDriverState[] member.

The next two commits take care of the latter two.

Okay. This patch gives us a chance to have a look at each of the functions that we'll expose in the BlockBackend layer.

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 242

Quoted 13 lines
block/block-backend.c +5 -0
index 7fd832d..5f796b4 100644
@@ -235,3 +235,260 @@ void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk)
         bdrv_make_anon(blk->bs);
     }
 }
+
+void blk_iostatus_enable(BlockBackend *blk)
+{
+    bdrv_iostatus_enable(blk->bs);
+}

Even at the end of the series, iostatus (i.e. rerror/werror handling) is still at the BDS level. I think our earlier conclusion was that it's really a BB thing, so I would expect it to be implemented in block-backend.c with no calls into block.c.

Is this on your todo list?

Quoted 14 lines
block/block-backend.c +14 -0
+int blk_attach_dev(BlockBackend *blk, void *dev)
+{
+    return bdrv_attach_dev(blk->bs, dev);
+}
+
+void blk_attach_dev_nofail(BlockBackend *blk, void *dev)
+{
+    bdrv_attach_dev_nofail(blk->bs, dev);
+}
+
+void blk_detach_dev(BlockBackend *blk, void *dev)
+{
+    bdrv_detach_dev(blk->bs, dev);
+}

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 267

Quoted 10 lines
block/block-backend.c +10 -0
+
+void *blk_get_attached_dev(BlockBackend *blk)
+{
+    return bdrv_get_attached_dev(blk->bs);
+}
+
+void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque)
+{
+    bdrv_set_dev_ops(blk->bs, ops, opaque);
+}

At the end of the series, all of these are BB-only code. Good.

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 279

Quoted 11 lines
block/block-backend.c +11 -0
+int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+             int nb_sectors)
+{
+    return bdrv_read(blk->bs, sector_num, buf, nb_sectors);
+}
+
+int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+                         int nb_sectors)
+{
+    return bdrv_read_unthrottled(blk->bs, sector_num, buf, nb_sectors);
+}

This one is a hack that I'd rather see disappear. Unrelated to this series, though.

Quoted 13 lines
block/block-backend.c +13 -0
+int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
+              int nb_sectors)
+{
+    return bdrv_write(blk->bs, sector_num, buf, nb_sectors);
+}
+
+BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
+                                 int nb_sectors, BdrvRequestFlags flags,
+                                 BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_write_zeroes(blk->bs, sector_num, nb_sectors, flags,
+                                 cb, opaque);
+}

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 303

Quoted 10 lines
block/block-backend.c +10 -0
+
+int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
+{
+    return bdrv_pread(blk->bs, offset, buf, count);
+}
+
+int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count)
+{
+    return bdrv_pwrite(blk->bs, offset, buf, count);
+}

Any particular reason for the ordering of the functions here? Is this just how they were in block.c? I would have expected all read function and all write functions in one place.

Quoted 79 lines
block/block-backend.c +78 -0
+int64_t blk_getlength(BlockBackend *blk)
+{
+    return bdrv_getlength(blk->bs);
+}
+
+void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)
+{
+    bdrv_get_geometry(blk->bs, nb_sectors_ptr);
+}
+
+BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num,
+                          QEMUIOVector *iov, int nb_sectors,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_readv(blk->bs, sector_num, iov, nb_sectors, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num,
+                           QEMUIOVector *iov, int nb_sectors,
+                           BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_writev(blk->bs, sector_num, iov, nb_sectors, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_flush(BlockBackend *blk,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_flush(blk->bs, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_discard(BlockBackend *blk,
+                            int64_t sector_num, int nb_sectors,
+                            BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_discard(blk->bs, sector_num, nb_sectors, cb, opaque);
+}
+
+void blk_aio_cancel(BlockAIOCB *acb)
+{
+    bdrv_aio_cancel(acb);
+}
+
+int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs)
+{
+    return bdrv_aio_multiwrite(blk->bs, reqs, num_reqs);
+}
+
+int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
+{
+    return bdrv_ioctl(blk->bs, req, buf);
+}
+
+BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_ioctl(blk->bs, req, buf, cb, opaque);
+}
+
+int blk_flush(BlockBackend *blk)
+{
+    return bdrv_flush(blk->bs);
+}
+
+int blk_flush_all(void)
+{
+    return bdrv_flush_all();
+}
+
+void blk_drain_all(void)
+{
+    bdrv_drain_all();
+}
 
+BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read)
+{
+    return bdrv_get_on_error(blk->bs, is_read);
+}
+
+BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 393

Quoted 10 lines
block/block-backend.c +10 -0
+                                      int error)
+{
+    return bdrv_get_error_action(blk->bs, is_read, error);
+}
+
+void blk_error_action(BlockBackend *blk, BlockErrorAction action,
+                      bool is_read, int error)
+{
+    bdrv_error_action(blk->bs, action, is_read, error);
+}

Like iostatus, this probably should be a BB-only thing in the end.

Quoted 36 lines
block/block-backend.c +36 -0
+int blk_is_read_only(BlockBackend *blk)
+{
+    return bdrv_is_read_only(blk->bs);
+}
+
+int blk_is_sg(BlockBackend *blk)
+{
+    return bdrv_is_sg(blk->bs);
+}
+
+int blk_enable_write_cache(BlockBackend *blk)
+{
+    return bdrv_enable_write_cache(blk->bs);
+}
+
+void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
+{
+    bdrv_set_enable_write_cache(blk->bs, wce);
+}
+
+int blk_is_inserted(BlockBackend *blk)
+{
+    return bdrv_is_inserted(blk->bs);
+}
+
+void blk_lock_medium(BlockBackend *blk, bool locked)
+{
+    bdrv_lock_medium(blk->bs, locked);
+}
+
+void blk_eject(BlockBackend *blk, bool eject_flag)
+{
+    bdrv_eject(blk->bs, eject_flag);
+}
+
+int blk_get_flags(BlockBackend *blk)

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 440

Quoted 10 lines
block/block-backend.c +10 -0
+{
+    return bdrv_get_flags(blk->bs);
+}
+
+void blk_set_guest_block_size(BlockBackend *blk, int align)
+{
+    bdrv_set_guest_block_size(blk->bs, align);
+}
+
+void *blk_blockalign(BlockBackend *blk, size_t size)

Perhaps better blk_memalign?

Quoted 44 lines
block/block-backend.c +44 -0
+{
+    return qemu_blockalign(blk ? blk->bs : NULL, size);
+}
+
+bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp)
+{
+    return bdrv_op_is_blocked(blk->bs, op, errp);
+}
+
+void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason)
+{
+    bdrv_op_unblock(blk->bs, op, reason);
+}
+
+void blk_op_block_all(BlockBackend *blk, Error *reason)
+{
+    bdrv_op_block_all(blk->bs, reason);
+}
+
+void blk_op_unblock_all(BlockBackend *blk, Error *reason)
+{
+    bdrv_op_unblock_all(blk->bs, reason);
+}
+
+AioContext *blk_get_aio_context(BlockBackend *blk)
+{
+    return bdrv_get_aio_context(blk->bs);
+}
+
+void blk_set_aio_context(BlockBackend *blk, AioContext *new_context)
+{
+    bdrv_set_aio_context(blk->bs, new_context);
+}
+
+void blk_io_plug(BlockBackend *blk)
+{
+    bdrv_io_plug(blk->bs);
+}
+
+void blk_io_unplug(BlockBackend *blk)
+{
+    bdrv_io_unplug(blk->bs);
+}
+

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 494

Quoted 10 lines
block/block-backend.c +10 -0
+BlockAcctStats *blk_get_stats(BlockBackend *blk)
+{
+    return bdrv_get_stats(blk->bs);
+}
+
+void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
+                  BlockCompletionFunc *cb, void *opaque)
+{
+    return qemu_aio_get(aiocb_info, blk_bs(blk), cb, opaque);
+}

There are a few more in this list that look dubious, but this patch series isn't the right place to discuss them.

Found nothing noteworthy in the rest of the patch, though I only quickly scanned it, so that wasn't thorough enough for a R-b.

Kevin

#64 lore raw

Re: [Qemu-devel] [PATCH v3 14/23] hw: Convert from BlockDriverState to BlockBackend, mostly

Quoted 14 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 13 lines

Just four uses of BlockDriverState are left:

* The Xen paravirtual block device backend (xen_disk.c) opens images itself when set up via xenbus, bypassing blockdev.c. I figure it should go through qmp_blockdev_add() instead.

* Device model "usb-storage" prompts for keys. No other device model does, and this one probably shouldn't do it, either.

* ide_issue_trim_cb() uses bdrv_aio_discard() instead of blk_aio_discard() because it fishes its backend out of a BlockAIOCB, which has only the BlockDriverState.

Quoted 8 lines
Quoted 5 lines

* PC87312State has an unused BlockDriverState[] member.

The next two commits take care of the latter two.

Okay. This patch gives us a chance to have a look at each of the functions that we'll expose in the BlockBackend layer.

Yes. I really like how BlockBackend separates the API meant for use within the block layer from the one for its users, such as device models.

Quoted 19 lines

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 242

Quoted 13 lines
block/block-backend.c +5 -0
index 7fd832d..5f796b4 100644
@@ -235,3 +235,260 @@ void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk)
         bdrv_make_anon(blk->bs);
     }
 }
+
+void blk_iostatus_enable(BlockBackend *blk)
+{
+    bdrv_iostatus_enable(blk->bs);
+}

Even at the end of the series, iostatus (i.e. rerror/werror handling) is still at the BDS level. I think our earlier conclusion was that it's really a BB thing, so I would expect it to be implemented in block-backend.c with no calls into block.c.

Quoted 1 line

Is this on your todo list?

Definitely. Anything touched by bdrv_move_feature_fields() is a candidate for lifting from BDS into BB.

This series lifts almost nothing.

Quoted 18 lines
Quoted 18 lines
block/block-backend.c +18 -0
+int blk_attach_dev(BlockBackend *blk, void *dev)
+{
+    return bdrv_attach_dev(blk->bs, dev);
+}
+
+void blk_attach_dev_nofail(BlockBackend *blk, void *dev)
+{
+    bdrv_attach_dev_nofail(blk->bs, dev);
+}
+
+void blk_detach_dev(BlockBackend *blk, void *dev)
+{
+    bdrv_detach_dev(blk->bs, dev);
+}
+
+void *blk_get_attached_dev(BlockBackend *blk)
+{
+    return bdrv_get_attached_dev(blk->bs);
Quoted 8 lines

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 267

Quoted 6 lines
block/block-backend.c +6 -0
+}
+
+void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque)
+{
+    bdrv_set_dev_ops(blk->bs, ops, opaque);
+}

At the end of the series, all of these are BB-only code. Good.

Yes. I included lifting this part to have at least one meaningful example above and beyond the bare minimum of name.

Quoted 6 lines
Quoted 6 lines
block/block-backend.c +6 -0
+int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+             int nb_sectors)
+{
+    return bdrv_read(blk->bs, sector_num, buf, nb_sectors);
+}
+
Quoted 8 lines

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 279

Quoted 5 lines
block/block-backend.c +5 -0
+int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+                         int nb_sectors)
+{
+    return bdrv_read_unthrottled(blk->bs, sector_num, buf, nb_sectors);
+}

This one is a hack that I'd rather see disappear. Unrelated to this series, though.

Okay :)

Quoted 19 lines
Quoted 19 lines
block/block-backend.c +19 -0
+int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
+              int nb_sectors)
+{
+    return bdrv_write(blk->bs, sector_num, buf, nb_sectors);
+}
+
+BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
+                                 int nb_sectors, BdrvRequestFlags flags,
+                                 BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_write_zeroes(blk->bs, sector_num, nb_sectors, flags,
+                                 cb, opaque);
+}
+
+int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
+{
+    return bdrv_pread(blk->bs, offset, buf, count);
+}
+
Quoted 8 lines

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 303

Quoted 4 lines
block/block-backend.c +4 -0
+int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count)
+{
+    return bdrv_pwrite(blk->bs, offset, buf, count);
+}

Any particular reason for the ordering of the functions here? Is this just how they were in block.c? I would have expected all read function and all write functions in one place.

Yes, same order. I'm quite happy to put them in any order you like.

Quoted 84 lines
Quoted 84 lines
block/block-backend.c +53 -0
+int64_t blk_getlength(BlockBackend *blk)
+{
+    return bdrv_getlength(blk->bs);
+}
+
+void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)
+{
+    bdrv_get_geometry(blk->bs, nb_sectors_ptr);
+}
+
+BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num,
+                          QEMUIOVector *iov, int nb_sectors,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_readv(blk->bs, sector_num, iov, nb_sectors, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num,
+                           QEMUIOVector *iov, int nb_sectors,
+                           BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_writev(blk->bs, sector_num, iov, nb_sectors, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_flush(BlockBackend *blk,
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_flush(blk->bs, cb, opaque);
+}
+
+BlockAIOCB *blk_aio_discard(BlockBackend *blk,
+                            int64_t sector_num, int nb_sectors,
+                            BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_discard(blk->bs, sector_num, nb_sectors, cb, opaque);
+}
+
+void blk_aio_cancel(BlockAIOCB *acb)
+{
+    bdrv_aio_cancel(acb);
+}
+
+int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs)
+{
+    return bdrv_aio_multiwrite(blk->bs, reqs, num_reqs);
+}
+
+int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
+{
+    return bdrv_ioctl(blk->bs, req, buf);
+}
+
+BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req,

void *buf,

block/block-backend.c +29 -0
+                          BlockCompletionFunc *cb, void *opaque)
+{
+    return bdrv_aio_ioctl(blk->bs, req, buf, cb, opaque);
+}
+
+int blk_flush(BlockBackend *blk)
+{
+    return bdrv_flush(blk->bs);
+}
+
+int blk_flush_all(void)
+{
+    return bdrv_flush_all();
+}
+
+void blk_drain_all(void)
+{
+    bdrv_drain_all();
+}
 
+BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read)
+{
+    return bdrv_get_on_error(blk->bs, is_read);
+}
+
+BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
+                                      int error)
+{
+    return bdrv_get_error_action(blk->bs, is_read, error);
+}
Quoted 8 lines

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 393

Quoted 6 lines
block/block-backend.c +6 -0
+
+void blk_error_action(BlockBackend *blk, BlockErrorAction action,
+                      bool is_read, int error)
+{
+    bdrv_error_action(blk->bs, action, is_read, error);
+}

Like iostatus, this probably should be a BB-only thing in the end.

Like iostatus, it's touched by bdrv_move_feature_fields().

Quoted 40 lines
Quoted 40 lines
block/block-backend.c +40 -0
+int blk_is_read_only(BlockBackend *blk)
+{
+    return bdrv_is_read_only(blk->bs);
+}
+
+int blk_is_sg(BlockBackend *blk)
+{
+    return bdrv_is_sg(blk->bs);
+}
+
+int blk_enable_write_cache(BlockBackend *blk)
+{
+    return bdrv_enable_write_cache(blk->bs);
+}
+
+void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
+{
+    bdrv_set_enable_write_cache(blk->bs, wce);
+}
+
+int blk_is_inserted(BlockBackend *blk)
+{
+    return bdrv_is_inserted(blk->bs);
+}
+
+void blk_lock_medium(BlockBackend *blk, bool locked)
+{
+    bdrv_lock_medium(blk->bs, locked);
+}
+
+void blk_eject(BlockBackend *blk, bool eject_flag)
+{
+    bdrv_eject(blk->bs, eject_flag);
+}
+
+int blk_get_flags(BlockBackend *blk)
+{
+    return bdrv_get_flags(blk->bs);
+}
+
Quoted 8 lines

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 440

Quoted 6 lines
block/block-backend.c +6 -0
+void blk_set_guest_block_size(BlockBackend *blk, int align)
+{
+    bdrv_set_guest_block_size(blk->bs, align);
+}
+
+void *blk_blockalign(BlockBackend *blk, size_t size)

Perhaps better blk_memalign?

Well, the actual alignment comes from bdrv_opt_mem_align(blk->bs).

Quoted 58 lines
Quoted 44 lines
block/block-backend.c +44 -0
+{
+    return qemu_blockalign(blk ? blk->bs : NULL, size);
+}
+
+bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp)
+{
+    return bdrv_op_is_blocked(blk->bs, op, errp);
+}
+
+void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason)
+{
+    bdrv_op_unblock(blk->bs, op, reason);
+}
+
+void blk_op_block_all(BlockBackend *blk, Error *reason)
+{
+    bdrv_op_block_all(blk->bs, reason);
+}
+
+void blk_op_unblock_all(BlockBackend *blk, Error *reason)
+{
+    bdrv_op_unblock_all(blk->bs, reason);
+}
+
+AioContext *blk_get_aio_context(BlockBackend *blk)
+{
+    return bdrv_get_aio_context(blk->bs);
+}
+
+void blk_set_aio_context(BlockBackend *blk, AioContext *new_context)
+{
+    bdrv_set_aio_context(blk->bs, new_context);
+}
+
+void blk_io_plug(BlockBackend *blk)
+{
+    bdrv_io_plug(blk->bs);
+}
+
+void blk_io_unplug(BlockBackend *blk)
+{
+    bdrv_io_unplug(blk->bs);
+}
+

block/block-backend.c void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk) · line 494

Quoted 10 lines
block/block-backend.c +10 -0
+BlockAcctStats *blk_get_stats(BlockBackend *blk)
+{
+    return bdrv_get_stats(blk->bs);
+}
+
+void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
+                  BlockCompletionFunc *cb, void *opaque)
+{
+    return qemu_aio_get(aiocb_info, blk_bs(blk), cb, opaque);
+}

There are a few more in this list that look dubious, but this patch series isn't the right place to discuss them.

Quoted 2 lines

Found nothing noteworthy in the rest of the patch, though I only quickly scanned it, so that wasn't thorough enough for a R-b.

Thanks anyway!

#65 lore raw

PATCH v3 15/23 ide: Complete conversion from BlockDriverState to BlockBackend

In reply to Markus Armbruster

Add a BlockBackend member to TrimAIOCB, so ide_issue_trim_cb() can use blk_aio_discard() instead of bdrv_aio_discard().

---
 hw/ide/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ide/core.c +4 -2
index f02ce4a..23964a2 100644
@@ -362,6 +362,7 @@ static void ide_set_signature(IDEState *s)
 
 typedef struct TrimAIOCB {
     BlockAIOCB common;
+    BlockBackend *blk;
     QEMUBH *bh;
     int ret;
     QEMUIOVector *qiov;
@@ -423,8 +424,8 @@ static void ide_issue_trim_cb(void *opaque, int ret)
                 }
 
                 /* Got an entry! Submit and exit.  */
-                iocb->aiocb = bdrv_aio_discard(iocb->common.bs, sector, count,
-                                               ide_issue_trim_cb, opaque);
+                iocb->aiocb = blk_aio_discard(iocb->blk, sector, count,
+                                              ide_issue_trim_cb, opaque);
                 return;
             }
 
@@ -448,6 +449,7 @@ BlockAIOCB *ide_issue_trim(BlockBackend *blk,
     TrimAIOCB *iocb;
 
     iocb = blk_aio_get(&trim_aiocb_info, blk, cb, opaque);
+    iocb->blk = blk;
     iocb->bh = qemu_bh_new(ide_trim_bh_cb, iocb);
     iocb->ret = 0;
     iocb->qiov = qiov;
Signature · 1 line
1.9.3
Reviewed-by on v3 15/23
#66 lore raw

Re: [Qemu-devel] [PATCH v3 15/23] ide: Complete conversion from BlockDriverState to BlockBackend

Quoted 7 lines · Markus Armbruster

Add a BlockBackend member to TrimAIOCB, so ide_issue_trim_cb() can use blk_aio_discard() instead of bdrv_aio_discard().

---
  hw/ide/core.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
#68 lore raw

PATCH v3 16/23 pc87312: Drop unused members of PC87312State

In reply to Markus Armbruster
---
 include/hw/isa/pc87312.h | 3 ---
 1 file changed, 3 deletions(-)
include/hw/isa/pc87312.h +0 -3
index befc8bd..bf74470 100644
@@ -47,13 +47,10 @@ typedef struct PC87312State {
 
     struct {
         ISADevice *dev;
-        BlockDriverState *drive[2];
-        uint32_t base;
     } fdc;
 
     struct {
         ISADevice *dev;
-        uint32_t base;
     } ide;
 
     MemoryRegion io;
Signature · 1 line
1.9.3
Reviewed-by on v3 16/23
#69 lore raw

Re: [Qemu-devel] [PATCH v3 16/23] pc87312: Drop unused members of PC87312State

Quoted 26 lines · Markus Armbruster
---
 include/hw/isa/pc87312.h | 3 ---
 1 file changed, 3 deletions(-)
include/hw/isa/pc87312.h +0 -3
index befc8bd..bf74470 100644
@@ -47,13 +47,10 @@ typedef struct PC87312State {
 
     struct {
         ISADevice *dev;
-        BlockDriverState *drive[2];
-        uint32_t base;
     } fdc;
 
     struct {
         ISADevice *dev;
-        uint32_t base;
     } ide;
 
     MemoryRegion io;
Signature · 1 line
1.9.3
#72 lore raw

PATCH v3 17/23 blockdev: Drop superfluous DriveInfo member id

In reply to Markus Armbruster
---
 block/block-backend.c     | 1 -
 blockdev.c                | 3 +--
 include/sysemu/blockdev.h | 1 -
 3 files changed, 1 insertion(+), 4 deletions(-)
block/block-backend.c +0 -1
index 5f796b4..141a31b 100644
@@ -104,7 +104,6 @@ static void drive_info_del(DriveInfo *dinfo)
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
     }
-    g_free(dinfo->id);
     g_free(dinfo->serial);
     g_free(dinfo);
 }
blockdev.c +1 -2
index e87bf4b..2def256 100644
@@ -458,7 +458,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     }
 
     dinfo = g_malloc0(sizeof(*dinfo));
-    dinfo->id = g_strdup(qemu_opts_id(opts));
     blk_set_legacy_dinfo(blk, dinfo);
 
     if (!file || !*file) {
@@ -492,7 +491,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     if (ret < 0) {
         error_setg(errp, "could not open disk image %s: %s",
-                   file ?: dinfo->id, error_get_pretty(error));
+                   file ?: blk_name(blk), error_get_pretty(error));
         error_free(error);
         goto err;
     }
include/sysemu/blockdev.h +0 -1
index f66b89a..27a40d5 100644
@@ -30,7 +30,6 @@ typedef enum {
 } BlockInterfaceType;
 
 struct DriveInfo {
-    char *id;
     const char *devaddr;
     BlockInterfaceType type;
     int bus;
Signature · 1 line
1.9.3
Reviewed-by on v3 17/23
#73 lore raw

Re: [Qemu-devel] [PATCH v3 17/23] blockdev: Drop superfluous DriveInfo member id

Quoted 55 lines · Markus Armbruster
---
 block/block-backend.c     | 1 -
 blockdev.c                | 3 +--
 include/sysemu/blockdev.h | 1 -
 3 files changed, 1 insertion(+), 4 deletions(-)
block/block-backend.c +0 -1
index 5f796b4..141a31b 100644
@@ -104,7 +104,6 @@ static void drive_info_del(DriveInfo *dinfo)
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
     }
-    g_free(dinfo->id);
     g_free(dinfo->serial);
     g_free(dinfo);
 }
blockdev.c +1 -2
index e87bf4b..2def256 100644
@@ -458,7 +458,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     }
 
     dinfo = g_malloc0(sizeof(*dinfo));
-    dinfo->id = g_strdup(qemu_opts_id(opts));
     blk_set_legacy_dinfo(blk, dinfo);
 
     if (!file || !*file) {
@@ -492,7 +491,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     if (ret < 0) {
         error_setg(errp, "could not open disk image %s: %s",
-                   file ?: dinfo->id, error_get_pretty(error));
+                   file ?: blk_name(blk), error_get_pretty(error));
         error_free(error);
         goto err;
     }
include/sysemu/blockdev.h +0 -1
index f66b89a..27a40d5 100644
@@ -30,7 +30,6 @@ typedef enum {
 } BlockInterfaceType;
 
 struct DriveInfo {
-    char *id;
     const char *devaddr;
     BlockInterfaceType type;
     int bus;
Signature · 1 line
1.9.3
#76 lore raw

PATCH v3 18/23 blockdev: Fix blockdev-add not to create IDE drive (0, 0)

In reply to Markus Armbruster

blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.

Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though.

Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one.

A few places assume a block backend always has a DriveInfo. Fix them up.

---
 block/block-backend.c |  4 +---
 blockdev.c            | 10 ++--------
 hw/block/block.c      | 16 ++++++++++------
 hw/ide/qdev.c         |  2 +-
 hw/scsi/scsi-disk.c   |  2 +-
 5 files changed, 15 insertions(+), 19 deletions(-)
block/block-backend.c +1 -3
index 141a31b..b55f0b4 100644
@@ -101,9 +101,7 @@ static void drive_info_del(DriveInfo *dinfo)
     if (!dinfo) {
         return;
     }
-    if (dinfo->opts) {
-        qemu_opts_del(dinfo->opts);
-    }
+    qemu_opts_del(dinfo->opts);
     g_free(dinfo->serial);
     g_free(dinfo);
 }
blockdev.c +2 -8
index 2def256..0d99be0 100644
@@ -285,7 +285,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     int on_read_error, on_write_error;
     BlockBackend *blk;
     BlockDriverState *bs;
-    DriveInfo *dinfo;
     ThrottleConfig cfg;
     int snapshot = 0;
     bool copy_on_read;
@@ -457,9 +456,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
         bdrv_set_io_limits(bs, &cfg);
     }
 
-    dinfo = g_malloc0(sizeof(*dinfo));
-    blk_set_legacy_dinfo(blk, dinfo);
-
     if (!file || !*file) {
         if (has_driver_specific_opts) {
             file = NULL;
@@ -903,21 +899,19 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* Set legacy DriveInfo fields */
-    dinfo = blk_legacy_dinfo(blk);
+    dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->enable_auto_del = true;
     dinfo->opts = all_opts;
-
     dinfo->cyls = cyls;
     dinfo->heads = heads;
     dinfo->secs = secs;
     dinfo->trans = translation;
-
     dinfo->type = type;
     dinfo->bus = bus_id;
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
-
     dinfo->serial = g_strdup(serial);
+    blk_set_legacy_dinfo(blk, dinfo);
 
     switch(type) {
     case IF_IDE:
hw/block/block.c +10 -6
index 0666dd3..a625773 100644
@@ -19,7 +19,9 @@ void blkconf_serial(BlockConf *conf, char **serial)
     if (!*serial) {
         /* try to fall back to value set with legacy -drive serial=... */
         dinfo = blk_legacy_dinfo(conf->blk);
-        *serial = g_strdup(dinfo->serial);
+        if (dinfo) {
+            *serial = g_strdup(dinfo->serial);
+        }
     }
 }
 
@@ -32,11 +34,13 @@ void blkconf_geometry(BlockConf *conf, int *ptrans,
     if (!conf->cyls && !conf->heads && !conf->secs) {
         /* try to fall back to value set with legacy -drive cyls=... */
         dinfo = blk_legacy_dinfo(conf->blk);
-        conf->cyls  = dinfo->cyls;
-        conf->heads = dinfo->heads;
-        conf->secs  = dinfo->secs;
-        if (ptrans) {
-            *ptrans = dinfo->trans;
+        if (dinfo) {
+            conf->cyls  = dinfo->cyls;
+            conf->heads = dinfo->heads;
+            conf->secs  = dinfo->secs;
+            if (ptrans) {
+                *ptrans = dinfo->trans;
+            }
         }
     }
     if (!conf->cyls && !conf->heads && !conf->secs) {
hw/ide/qdev.c +1 -1
index 4818334..a74c81e 100644
@@ -206,7 +206,7 @@ static int ide_drive_initfn(IDEDevice *dev)
 {
     DriveInfo *dinfo = blk_legacy_dinfo(dev->conf.blk);
 
-    return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD);
+    return ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD);
 }
 
 #define DEFINE_IDE_DEV_PROPERTIES()                     \
hw/scsi/scsi-disk.c +1 -1
index b0bca48..9deef1a 100644
@@ -2336,7 +2336,7 @@ static void scsi_disk_realize(SCSIDevice *dev, Error **errp)
     }
 
     dinfo = blk_legacy_dinfo(dev->conf.blk);
-    if (dinfo->media_cd) {
+    if (dinfo && dinfo->media_cd) {
         scsi_cd_realize(dev, errp);
     } else {
         scsi_hd_realize(dev, errp);
Signature · 1 line
1.9.3
Reviewed-by on v3 18/23
#78 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

In reply to Markus Armbruster
Quoted 14 lines · Markus Armbruster

blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.

Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though.

Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one.

A few places assume a block backend always has a DriveInfo. Fix them up.

Quoted 8 lines
---
  block/block-backend.c |  4 +---
  blockdev.c            | 10 ++--------
  hw/block/block.c      | 16 ++++++++++------
  hw/ide/qdev.c         |  2 +-
  hw/scsi/scsi-disk.c   |  2 +-
  5 files changed, 15 insertions(+), 19 deletions(-)
#79 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 28 lines

blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.

Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though.

Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one.

A few places assume a block backend always has a DriveInfo. Fix them up.

---
 block/block-backend.c |  4 +---
 blockdev.c            | 10 ++--------
 hw/block/block.c      | 16 ++++++++++------
 hw/ide/qdev.c         |  2 +-
 hw/scsi/scsi-disk.c   |  2 +-
 5 files changed, 15 insertions(+), 19 deletions(-)
block/block-backend.c +0 -0
index 141a31b..b55f0b4 100644

block/block-backend.c static void drive_info_del(DriveInfo *dinfo) · line 107

Quoted 10 lines
block/block-backend.c +1 -3
@@ -101,9 +101,7 @@ static void drive_info_del(DriveInfo *dinfo)
     if (!dinfo) {
         return;
     }
-    if (dinfo->opts) {
-        qemu_opts_del(dinfo->opts);
-    }
+    qemu_opts_del(dinfo->opts);
     g_free(dinfo->serial);
     g_free(dinfo);
 }

Doesn't look directly related?

Quoted 33 lines
blockdev.c +1 -6
index 2def256..0d99be0 100644
@@ -285,7 +285,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     int on_read_error, on_write_error;
     BlockBackend *blk;
     BlockDriverState *bs;
-    DriveInfo *dinfo;
     ThrottleConfig cfg;
     int snapshot = 0;
     bool copy_on_read;
@@ -457,9 +456,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
         bdrv_set_io_limits(bs, &cfg);
     }
 
-    dinfo = g_malloc0(sizeof(*dinfo));
-    blk_set_legacy_dinfo(blk, dinfo);
-
     if (!file || !*file) {
         if (has_driver_specific_opts) {
             file = NULL;
@@ -903,21 +899,19 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* Set legacy DriveInfo fields */
-    dinfo = blk_legacy_dinfo(blk);
+    dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->enable_auto_del = true;
     dinfo->opts = all_opts;
-
     dinfo->cyls = cyls;
     dinfo->heads = heads;

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 914

Quoted 10 lines
blockdev.c +1 -2
     dinfo->secs = secs;
     dinfo->trans = translation;
-
     dinfo->type = type;
     dinfo->bus = bus_id;
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
-
     dinfo->serial = g_strdup(serial);
+    blk_set_legacy_dinfo(blk, dinfo);

You don't like the grouping?

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 917

Quoted 2 lines
blockdev.c +0 -0
     switch(type) {
     case IF_IDE:

Kevin

#80 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

Quoted 33 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 32 lines

blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.

Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though.

Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one.

A few places assume a block backend always has a DriveInfo. Fix them up.

---
 block/block-backend.c |  4 +---
 blockdev.c            | 10 ++--------
 hw/block/block.c      | 16 ++++++++++------
 hw/ide/qdev.c         |  2 +-
 hw/scsi/scsi-disk.c   |  2 +-
 5 files changed, 15 insertions(+), 19 deletions(-)
block/block-backend.c +0 -1
index 141a31b..b55f0b4 100644
@@ -101,9 +101,7 @@ static void drive_info_del(DriveInfo *dinfo)
     if (!dinfo) {
         return;
     }
-    if (dinfo->opts) {
Quoted 8 lines

block/block-backend.c static void drive_info_del(DriveInfo *dinfo) · line 107

Quoted 6 lines
block/block-backend.c +1 -2
-        qemu_opts_del(dinfo->opts);
-    }
+    qemu_opts_del(dinfo->opts);
     g_free(dinfo->serial);
     g_free(dinfo);
 }

Doesn't look directly related?

I'll split it off.

Quoted 37 lines
Quoted 37 lines
blockdev.c +1 -7
index 2def256..0d99be0 100644
@@ -285,7 +285,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
     int on_read_error, on_write_error;
     BlockBackend *blk;
     BlockDriverState *bs;
-    DriveInfo *dinfo;
     ThrottleConfig cfg;
     int snapshot = 0;
     bool copy_on_read;
@@ -457,9 +456,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
         bdrv_set_io_limits(bs, &cfg);
     }
 
-    dinfo = g_malloc0(sizeof(*dinfo));
-    blk_set_legacy_dinfo(blk, dinfo);
-
     if (!file || !*file) {
         if (has_driver_specific_opts) {
             file = NULL;
@@ -903,21 +899,19 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* Set legacy DriveInfo fields */
-    dinfo = blk_legacy_dinfo(blk);
+    dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->enable_auto_del = true;
     dinfo->opts = all_opts;
-
     dinfo->cyls = cyls;
     dinfo->heads = heads;
     dinfo->secs = secs;
     dinfo->trans = translation;
-
     dinfo->type = type;
Quoted 8 lines

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 914

Quoted 6 lines
blockdev.c +1 -1
     dinfo->bus = bus_id;
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
-
     dinfo->serial = g_strdup(serial);
+    blk_set_legacy_dinfo(blk, dinfo);

You don't like the grouping?

No, because the comment appears as if it applied only to the first group.

This is how this spot looks at the end of the series:

    /* Set legacy DriveInfo fields */
    dinfo = g_malloc0(sizeof(*dinfo));
    dinfo->opts = all_opts;
    dinfo->cyls = cyls;
    dinfo->heads = heads;
    dinfo->secs = secs;
    dinfo->trans = translation;
    dinfo->type = type;
    dinfo->bus = bus_id;
    dinfo->unit = unit_id;
    dinfo->devaddr = devaddr;
    dinfo->serial = g_strdup(serial);
    blk_set_legacy_dinfo(blk, dinfo);

Could do this instead:

    dinfo = g_malloc0(sizeof(*dinfo));
    dinfo->opts = all_opts;

    dinfo->cyls = cyls;
    dinfo->heads = heads;
    dinfo->secs = secs;
    dinfo->trans = translation;

    dinfo->type = type;
    dinfo->bus = bus_id;
    dinfo->unit = unit_id;
    dinfo->devaddr = devaddr;
    dinfo->serial = g_strdup(serial);

    blk_set_legacy_dinfo(blk, dinfo);

The comment is next to useless anyway. Got a preference?

Quoted 2 lines
Quoted 2 lines
blockdev.c +0 -0
     switch(type) {
     case IF_IDE:
#81 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

Am 29.09.2014 um 15:05 hat Markus Armbruster geschrieben:

Quoted 64 lines
Quoted 16 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 15 lines
blockdev.c +1 -3
@@ -903,21 +899,19 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* Set legacy DriveInfo fields */
-    dinfo = blk_legacy_dinfo(blk);
+    dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->enable_auto_del = true;
     dinfo->opts = all_opts;
-
     dinfo->cyls = cyls;
     dinfo->heads = heads;
     dinfo->secs = secs;
     dinfo->trans = translation;
-
     dinfo->type = type;
Quoted 8 lines

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 914

Quoted 6 lines
blockdev.c +1 -1
     dinfo->bus = bus_id;
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
-
     dinfo->serial = g_strdup(serial);
+    blk_set_legacy_dinfo(blk, dinfo);

You don't like the grouping?

No, because the comment appears as if it applied only to the first group.

This is how this spot looks at the end of the series:

    /* Set legacy DriveInfo fields */
    dinfo = g_malloc0(sizeof(*dinfo));
    dinfo->opts = all_opts;
    dinfo->cyls = cyls;
    dinfo->heads = heads;
    dinfo->secs = secs;
    dinfo->trans = translation;
    dinfo->type = type;
    dinfo->bus = bus_id;
    dinfo->unit = unit_id;
    dinfo->devaddr = devaddr;
    dinfo->serial = g_strdup(serial);
    blk_set_legacy_dinfo(blk, dinfo);

Could do this instead:

    dinfo = g_malloc0(sizeof(*dinfo));
    dinfo->opts = all_opts;

    dinfo->cyls = cyls;
    dinfo->heads = heads;
    dinfo->secs = secs;
    dinfo->trans = translation;

    dinfo->type = type;
    dinfo->bus = bus_id;
    dinfo->unit = unit_id;
    dinfo->devaddr = devaddr;
    dinfo->serial = g_strdup(serial);

    blk_set_legacy_dinfo(blk, dinfo);
Quoted 1 line

The comment is next to useless anyway. Got a preference?

The reason why it's there is that I like to use comments to give "headlines" to the blocks of code. In drive_new(), I can only read the comments without looking at the code and understand what functionality is implemented at a high level.

So for me the "headline" is valid until the next one appears (except that this is the last one) and it's good as it is today. Your taste differs, as it seems.

If I have to choose between your two alternatives, I'll reluctantly vote for removing the empty lines, because making it part of the "Actual block device init" block by removing the comment makes even less sense.

Kevin

#82 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

Quoted 73 lines · Kevin Wolf

Am 29.09.2014 um 15:05 hat Markus Armbruster geschrieben:

Quoted 65 lines
Quoted 17 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 16 lines
blockdev.c +1 -3
@@ -903,21 +899,19 @@ DriveInfo *drive_new(QemuOpts *all_opts,
 BlockInterfaceType block_default_type)
     }
 
     /* Set legacy DriveInfo fields */
-    dinfo = blk_legacy_dinfo(blk);
+    dinfo = g_malloc0(sizeof(*dinfo));
     dinfo->enable_auto_del = true;
     dinfo->opts = all_opts;
-
     dinfo->cyls = cyls;
     dinfo->heads = heads;
     dinfo->secs = secs;
     dinfo->trans = translation;
-
     dinfo->type = type;
Quoted 8 lines

blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 914

Quoted 6 lines
blockdev.c +1 -1
     dinfo->bus = bus_id;
     dinfo->unit = unit_id;
     dinfo->devaddr = devaddr;
-
     dinfo->serial = g_strdup(serial);
+    blk_set_legacy_dinfo(blk, dinfo);

You don't like the grouping?

No, because the comment appears as if it applied only to the first group.

This is how this spot looks at the end of the series:

    /* Set legacy DriveInfo fields */
    dinfo = g_malloc0(sizeof(*dinfo));
    dinfo->opts = all_opts;
    dinfo->cyls = cyls;
    dinfo->heads = heads;
    dinfo->secs = secs;
    dinfo->trans = translation;
    dinfo->type = type;
    dinfo->bus = bus_id;
    dinfo->unit = unit_id;
    dinfo->devaddr = devaddr;
    dinfo->serial = g_strdup(serial);
    blk_set_legacy_dinfo(blk, dinfo);

Could do this instead:

    dinfo = g_malloc0(sizeof(*dinfo));
    dinfo->opts = all_opts;

    dinfo->cyls = cyls;
    dinfo->heads = heads;
    dinfo->secs = secs;
    dinfo->trans = translation;

    dinfo->type = type;
    dinfo->bus = bus_id;
    dinfo->unit = unit_id;
    dinfo->devaddr = devaddr;
    dinfo->serial = g_strdup(serial);

    blk_set_legacy_dinfo(blk, dinfo);
Quoted 1 line

The comment is next to useless anyway. Got a preference?

The reason why it's there is that I like to use comments to give "headlines" to the blocks of code. In drive_new(), I can only read the comments without looking at the code and understand what functionality is implemented at a high level.

Quoted 7 lines

So for me the "headline" is valid until the next one appears (except that this is the last one) and it's good as it is today. Your taste differs, as it seems.

If I have to choose between your two alternatives, I'll reluctantly vote for removing the empty lines, because making it part of the "Actual block device init" block by removing the comment makes even less sense.

Okay, you care for the headline comment and the grouping more than I dislike them, so I'll keep them both.

#83 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines

blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.

Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though.

Quoted 7 lines

Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one.

A few places assume a block backend always has a DriveInfo. Fix them up.

I think I would change the subject line to describe that blockdev-add devices don't get a DriveInfo any more. The IF_IDE = 0 bug is real, but probably not the most important part of this patch.

As you already mentioned, you need to squash in some parts of patch 19 for this to be correct (the changed if conditions in do_drive_del and blockdev_mark_auto_del). You may still leave patch 19 for the removal of enable_auto_del if you like, or squash in the whole patch.

Kevin

#84 lore raw

Re: [Qemu-devel] [PATCH v3 18/23] blockdev: Fix blockdev-add not to create IDE drive (0, 0)

Quoted 17 lines · Kevin Wolf

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 8 lines

blockdev_init() always creates a DriveInfo, but only drive_new() fills it in. qmp_blockdev_add() leaves it blank. This results in a drive with type = IF_IDE, bus = 0, unit = 0. Screwed up in commit ee13ed1c.

Board initialization code looking for IDE drive (0,0) can pick up one of these bogus drives. Not sure whether getting the QMP command executed early enough is likely in practice, though.

Quoted 7 lines

Fix by creating DriveInfo in drive_new(). Block backends created by blockdev-add don't get one.

A few places assume a block backend always has a DriveInfo. Fix them up.

Quoted 8 lines

I think I would change the subject line to describe that blockdev-add devices don't get a DriveInfo any more. The IF_IDE = 0 bug is real, but probably not the most important part of this patch.

As you already mentioned, you need to squash in some parts of patch 19 for this to be correct (the changed if conditions in do_drive_del and blockdev_mark_auto_del). You may still leave patch 19 for the removal of enable_auto_del if you like, or squash in the whole patch.

I'll see how the reworked pair of patches turns out, then think about the subject line.

#85 lore raw

PATCH v3 19/23 blockdev: Drop DriveInfo member enable_auto_del

In reply to Markus Armbruster

Commit 2d246f0 introduced DriveInfo member enable_auto_del to distinguish DriveInfo created via drive_new() from DriveInfo created via qmp_blockdev_add(). The latter no longer exist. Drop enable_auto_del.

---
 blockdev.c                | 11 +++--------
 include/sysemu/blockdev.h |  1 -
 2 files changed, 3 insertions(+), 9 deletions(-)
blockdev.c +3 -8
index 0d99be0..e218c59 100644
@@ -90,16 +90,14 @@ void blockdev_mark_auto_del(BlockBackend *blk)
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
     BlockDriverState *bs = blk_bs(blk);
 
-    if (dinfo && !dinfo->enable_auto_del) {
+    if (!dinfo) {
         return;
     }
 
     if (bs->job) {
         block_job_cancel(bs->job);
     }
-    if (dinfo) {
-        dinfo->auto_del = 1;
-    }
+    dinfo->auto_del = 1;
 }
 
 void blockdev_auto_del(BlockBackend *blk)
@@ -900,7 +898,6 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 
     /* Set legacy DriveInfo fields */
     dinfo = g_malloc0(sizeof(*dinfo));
-    dinfo->enable_auto_del = true;
     dinfo->opts = all_opts;
     dinfo->cyls = cyls;
     dinfo->heads = heads;
@@ -1716,7 +1713,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     const char *id = qdict_get_str(qdict, "id");
     BlockBackend *blk;
     BlockDriverState *bs;
-    DriveInfo *dinfo;
     AioContext *aio_context;
     Error *local_err = NULL;
 
@@ -1727,8 +1723,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     }
     bs = blk_bs(blk);
 
-    dinfo = blk_legacy_dinfo(blk);
-    if (dinfo && !dinfo->enable_auto_del) {
+    if (!blk_legacy_dinfo(blk)) {
         error_report("Deleting device added with blockdev-add"
                      " is not supported");
         return -1;
include/sysemu/blockdev.h +0 -1
index 27a40d5..2129d81 100644
@@ -35,7 +35,6 @@ struct DriveInfo {
     int bus;
     int unit;
     int auto_del;               /* see blockdev_mark_auto_del() */
-    bool enable_auto_del;       /* Only for legacy drive_new() */
     int media_cd;
     int cyls, heads, secs, trans;
     QemuOpts *opts;
Signature · 1 line
1.9.3
Reviewed-by on v3 19/23
#87 lore raw

Re: [Qemu-devel] [PATCH v3 19/23] blockdev: Drop DriveInfo member enable_auto_del

In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster

Commit 2d246f0 introduced DriveInfo member enable_auto_del to distinguish DriveInfo created via drive_new() from DriveInfo created via qmp_blockdev_add(). The latter no longer exist. Drop enable_auto_del.

---
  blockdev.c                | 11 +++--------
  include/sysemu/blockdev.h |  1 -
  2 files changed, 3 insertions(+), 9 deletions(-)

I would've liked some comment somewhere about DriveInfo's presence corresponding with the drive having been created through drive_new(), but I can live without, too.

Quoted 4 lines
blockdev.c +0 -0
index 0d99be0..e218c59 100644

[snip]

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1729

Quoted 10 lines
blockdev.c +1 -2
@@ -1727,8 +1723,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
      }
      bs = blk_bs(blk);
 
-    dinfo = blk_legacy_dinfo(blk);
-    if (dinfo && !dinfo->enable_auto_del) {
+    if (!blk_legacy_dinfo(blk)) {
          error_report("Deleting device added with blockdev-add"
                       " is not supported");
          return -1;

This doesn't look like a 1-to-1 correspondence. Before this patch, if DriveInfo was not present, the condition was false (actually, it was always false, which is the reason for this patch). Now it's true. It seems like the behavior is now correct but wasn't before... I guess this means patch 18 should be fixed?

However, for this patch:

#88 lore raw

Re: [Qemu-devel] [PATCH v3 19/23] blockdev: Drop DriveInfo member enable_auto_del

Quoted 12 lines · Max Reitz
Quoted 10 lines · Markus Armbruster

Commit 2d246f0 introduced DriveInfo member enable_auto_del to distinguish DriveInfo created via drive_new() from DriveInfo created via qmp_blockdev_add(). The latter no longer exist. Drop enable_auto_del.

---
  blockdev.c                | 11 +++--------
  include/sysemu/blockdev.h |  1 -
  2 files changed, 3 insertions(+), 9 deletions(-)
Quoted 3 lines

I would've liked some comment somewhere about DriveInfo's presence corresponding with the drive having been created through drive_new(), but I can live without, too.

Fair request. I could squash the following into PATCH 18:

block/block-backend.c +1 -1
index 5646628..5e4ecd7 100644
@@ -22,7 +22,7 @@ struct BlockBackend {
     char *name;
     int refcnt;
     BlockDriverState *bs;
-    DriveInfo *legacy_dinfo;
+    DriveInfo *legacy_dinfo;    /* null unless created by drive_new() */
     QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
 
     void *dev;                  /* attached device model, if any */
Quoted 7 lines
Quoted 4 lines
blockdev.c +0 -0
index 0d99be0..e218c59 100644

[snip]

Quoted 15 lines

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1729

Quoted 9 lines
blockdev.c +1 -1
@@ -1727,8 +1723,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
      }
      bs = blk_bs(blk);
  -    dinfo = blk_legacy_dinfo(blk);
-    if (dinfo && !dinfo->enable_auto_del) {
+    if (!blk_legacy_dinfo(blk)) {
          error_report("Deleting device added with blockdev-add"
                       " is not supported");
          return -1;

This doesn't look like a 1-to-1 correspondence. Before this patch, if DriveInfo was not present, the condition was false (actually, it was always false, which is the reason for this patch). Now it's true. It seems like the behavior is now correct but wasn't before... I guess this means patch 18 should be fixed?

PATCH 18 is broken. See also my reply to Fam on v2 of this patch.

Quoted 3 lines

However, for this patch:

Thanks!

#89 lore raw

Re: [Qemu-devel] [PATCH v3 19/23] blockdev: Drop DriveInfo member enable_auto_del

Quoted 23 lines · Markus Armbruster
Quoted 6 lines · Max Reitz
Quoted 5 lines · Markus Armbruster

Commit 2d246f0 introduced DriveInfo member enable_auto_del to distinguish DriveInfo created via drive_new() from DriveInfo created via qmp_blockdev_add(). The latter no longer exist. Drop enable_auto_del.

Quoted 8 lines
Quoted 5 lines
---
   blockdev.c                | 11 +++--------
   include/sysemu/blockdev.h |  1 -
   2 files changed, 3 insertions(+), 9 deletions(-)

I would've liked some comment somewhere about DriveInfo's presence corresponding with the drive having been created through drive_new(), but I can live without, too.

Fair request. I could squash the following into PATCH 18:

block/block-backend.c +0 -0
index 5646628..5e4ecd7 100644

block/block-backend.c struct BlockBackend { · line 28

Quoted 8 lines
block/block-backend.c +1 -1
@@ -22,7 +22,7 @@ struct BlockBackend {
      char *name;
      int refcnt;
      BlockDriverState *bs;
-    DriveInfo *legacy_dinfo;
+    DriveInfo *legacy_dinfo;    /* null unless created by drive_new() */
      QTAILQ_ENTRY(BlockBackend) link; /* for blk_backends */
 
      void *dev;                  /* attached device model, if any */

Yes, that would be nice, thank you!

Quoted 20 lines
Quoted 6 lines
Quoted 4 lines
blockdev.c +0 -0
index 0d99be0..e218c59 100644

[snip]

Quoted 14 lines

blockdev.c int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 1729

Quoted 9 lines
blockdev.c +1 -1
@@ -1727,8 +1723,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
       }
       bs = blk_bs(blk);
   -    dinfo = blk_legacy_dinfo(blk);
-    if (dinfo && !dinfo->enable_auto_del) {
+    if (!blk_legacy_dinfo(blk)) {
           error_report("Deleting device added with blockdev-add"
                        " is not supported");
           return -1;

This doesn't look like a 1-to-1 correspondence. Before this patch, if DriveInfo was not present, the condition was false (actually, it was always false, which is the reason for this patch). Now it's true. It seems like the behavior is now correct but wasn't before... I guess this means patch 18 should be fixed?

Quoted 1 line

PATCH 18 is broken. See also my reply to Fam on v2 of this patch.

Hm, okay. Fine with me. I don't object to squashing 19 into 18, either.

Max

Quoted 4 lines
Quoted 3 lines

However, for this patch:

Thanks!

#90 lore raw

PATCH v3 20/23 block/qapi: Convert qmp_query_block() to BlockBackend

In reply to Markus Armbruster

Much more command code needs conversion. I start with this one because it's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.

While there, give bdrv_query_info() internal linkage.

---
 block/qapi.c         | 15 ++++++++-------
 include/block/qapi.h |  3 ---
 2 files changed, 8 insertions(+), 10 deletions(-)
block/qapi.c +8 -7
index d071ee5..fca981d 100644
@@ -28,6 +28,7 @@
 #include "qapi-visit.h"
 #include "qapi/qmp-output-visitor.h"
 #include "qapi/qmp/types.h"
+#include "sysemu/block-backend.h"
 #ifdef __linux__
 #include <linux/fs.h>
 #include <sys/ioctl.h>
@@ -264,15 +265,15 @@ void bdrv_query_image_info(BlockDriverState *bs,
 }
 
 /* @p_info will be set only on success. */
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp)
+static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
+                            Error **errp)
 {
     BlockInfo *info = g_malloc0(sizeof(*info));
+    BlockDriverState *bs = blk_bs(blk);
     BlockDriverState *bs0;
     ImageInfo **p_image_info;
     Error *local_err = NULL;
-    info->device = g_strdup(bdrv_get_device_name(bs));
+    info->device = g_strdup(blk_name(blk));
     info->type = g_strdup("unknown");
     info->locked = bdrv_dev_is_medium_locked(bs);
     info->removable = bdrv_dev_has_removable_media(bs);
@@ -360,12 +361,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 BlockInfoList *qmp_query_block(Error **errp)
 {
     BlockInfoList *head = NULL, **p_next = &head;
-    BlockDriverState *bs = NULL;
+    BlockBackend *blk;
     Error *local_err = NULL;
 
-     while ((bs = bdrv_next(bs))) {
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
         BlockInfoList *info = g_malloc0(sizeof(*info));
-        bdrv_query_info(bs, &info->value, &local_err);
+        bdrv_query_info(blk, &info->value, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
             goto err;
include/block/qapi.h +0 -3
index 0374546..168d788 100644
@@ -36,9 +36,6 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
 void bdrv_query_image_info(BlockDriverState *bs,
                            ImageInfo **p_info,
                            Error **errp);
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp);
 
 void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
                         QEMUSnapshotInfo *sn);
Signature · 1 line
1.9.3
Reviewed-by on v3 20/23
#91 lore raw

Re: [Qemu-devel] [PATCH v3 20/23] block/qapi: Convert qmp_query_block() to BlockBackend

Quoted 77 lines · Markus Armbruster

Much more command code needs conversion. I start with this one because it's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.

While there, give bdrv_query_info() internal linkage.

---
 block/qapi.c         | 15 ++++++++-------
 include/block/qapi.h |  3 ---
 2 files changed, 8 insertions(+), 10 deletions(-)
block/qapi.c +8 -7
index d071ee5..fca981d 100644
@@ -28,6 +28,7 @@
 #include "qapi-visit.h"
 #include "qapi/qmp-output-visitor.h"
 #include "qapi/qmp/types.h"
+#include "sysemu/block-backend.h"
 #ifdef __linux__
 #include <linux/fs.h>
 #include <sys/ioctl.h>
@@ -264,15 +265,15 @@ void bdrv_query_image_info(BlockDriverState *bs,
 }
 
 /* @p_info will be set only on success. */
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp)
+static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
+                            Error **errp)
 {
     BlockInfo *info = g_malloc0(sizeof(*info));
+    BlockDriverState *bs = blk_bs(blk);
     BlockDriverState *bs0;
     ImageInfo **p_image_info;
     Error *local_err = NULL;
-    info->device = g_strdup(bdrv_get_device_name(bs));
+    info->device = g_strdup(blk_name(blk));
     info->type = g_strdup("unknown");
     info->locked = bdrv_dev_is_medium_locked(bs);
     info->removable = bdrv_dev_has_removable_media(bs);
@@ -360,12 +361,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 BlockInfoList *qmp_query_block(Error **errp)
 {
     BlockInfoList *head = NULL, **p_next = &head;
-    BlockDriverState *bs = NULL;
+    BlockBackend *blk;
     Error *local_err = NULL;
 
-     while ((bs = bdrv_next(bs))) {
+    for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
         BlockInfoList *info = g_malloc0(sizeof(*info));
-        bdrv_query_info(bs, &info->value, &local_err);
+        bdrv_query_info(blk, &info->value, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
             goto err;
include/block/qapi.h +0 -3
index 0374546..168d788 100644
@@ -36,9 +36,6 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
 void bdrv_query_image_info(BlockDriverState *bs,
                            ImageInfo **p_info,
                            Error **errp);
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp);
 
 void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
                         QEMUSnapshotInfo *sn);
Signature · 1 line
1.9.3
Reviewed-by on v3 20/23
#92 lore raw

Re: [Qemu-devel] [PATCH v3 20/23] block/qapi: Convert qmp_query_block() to BlockBackend

In reply to Markus Armbruster
Quoted 11 lines · Markus Armbruster

Much more command code needs conversion. I start with this one because it's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.

While there, give bdrv_query_info() internal linkage.

---
  block/qapi.c         | 15 ++++++++-------
  include/block/qapi.h |  3 ---
  2 files changed, 8 insertions(+), 10 deletions(-)
Reviewed-by on v3 20/23
#93 lore raw

Re: [Qemu-devel] [PATCH v3 20/23] block/qapi: Convert qmp_query_block() to BlockBackend

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 7 lines

Much more command code needs conversion. I start with this one because it's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.

While there, give bdrv_query_info() internal linkage.

#94 lore raw

PATCH v3 21/23 blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend

In reply to Markus Armbruster

Much more command code needs conversion. I'm converting these now because they's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.

---
 blockdev.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
blockdev.c +12 -8
index e218c59..e115bde 100644
@@ -1502,8 +1502,10 @@ exit:
 }
 
 
-static void eject_device(BlockDriverState *bs, int force, Error **errp)
+static void eject_device(BlockBackend *blk, int force, Error **errp)
 {
+    BlockDriverState *bs = blk_bs(blk);
+
     if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) {
         return;
     }
@@ -1527,15 +1529,15 @@ static void eject_device(BlockDriverState *bs, int force, Error **errp)
 
 void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
 {
-    BlockDriverState *bs;
+    BlockBackend *blk;
 
-    bs = bdrv_find(device);
-    if (!bs) {
+    blk = blk_by_name(device);
+    if (!blk) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, device);
         return;
     }
 
-    eject_device(bs, force, errp);
+    eject_device(blk, force, errp);
 }
 
 void qmp_block_passwd(bool has_device, const char *device,
@@ -1594,16 +1596,18 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
 void qmp_change_blockdev(const char *device, const char *filename,
                          const char *format, Error **errp)
 {
+    BlockBackend *blk;
     BlockDriverState *bs;
     BlockDriver *drv = NULL;
     int bdrv_flags;
     Error *err = NULL;
 
-    bs = bdrv_find(device);
-    if (!bs) {
+    blk = blk_by_name(device);
+    if (!blk) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, device);
         return;
     }
+    bs = blk_bs(blk);
 
     if (format) {
         drv = bdrv_find_whitelisted_format(format, bs->read_only);
@@ -1613,7 +1617,7 @@ void qmp_change_blockdev(const char *device, const char *filename,
         }
     }
 
-    eject_device(bs, 0, &err);
+    eject_device(blk, 0, &err);
     if (err) {
         error_propagate(errp, err);
         return;
Signature · 1 line
1.9.3
Reviewed-by on v3 21/23
#95 lore raw

Re: [Qemu-devel] [PATCH v3 21/23] blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend

Quoted 78 lines · Markus Armbruster

Much more command code needs conversion. I'm converting these now because they's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.

---
 blockdev.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
blockdev.c +12 -8
index e218c59..e115bde 100644
@@ -1502,8 +1502,10 @@ exit:
 }
 
 
-static void eject_device(BlockDriverState *bs, int force, Error **errp)
+static void eject_device(BlockBackend *blk, int force, Error **errp)
 {
+    BlockDriverState *bs = blk_bs(blk);
+
     if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) {
         return;
     }
@@ -1527,15 +1529,15 @@ static void eject_device(BlockDriverState *bs, int force, Error **errp)
 
 void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
 {
-    BlockDriverState *bs;
+    BlockBackend *blk;
 
-    bs = bdrv_find(device);
-    if (!bs) {
+    blk = blk_by_name(device);
+    if (!blk) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, device);
         return;
     }
 
-    eject_device(bs, force, errp);
+    eject_device(blk, force, errp);
 }
 
 void qmp_block_passwd(bool has_device, const char *device,
@@ -1594,16 +1596,18 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
 void qmp_change_blockdev(const char *device, const char *filename,
                          const char *format, Error **errp)
 {
+    BlockBackend *blk;
     BlockDriverState *bs;
     BlockDriver *drv = NULL;
     int bdrv_flags;
     Error *err = NULL;
 
-    bs = bdrv_find(device);
-    if (!bs) {
+    blk = blk_by_name(device);
+    if (!blk) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, device);
         return;
     }
+    bs = blk_bs(blk);
 
     if (format) {
         drv = bdrv_find_whitelisted_format(format, bs->read_only);
@@ -1613,7 +1617,7 @@ void qmp_change_blockdev(const char *device, const char *filename,
         }
     }
 
-    eject_device(bs, 0, &err);
+    eject_device(blk, 0, &err);
     if (err) {
         error_propagate(errp, err);
         return;
Signature · 1 line
1.9.3
Reviewed-by on v3 21/23
#96 lore raw

Re: [Qemu-devel] [PATCH v3 21/23] blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend

In reply to Markus Armbruster
Quoted 2 lines · Markus Armbruster

Much more command code needs conversion. I'm converting these now because they's using bdrv_dev_* functions, which I'm about to lift

Either this is again some phrase I haven't yet picked up or it should be "they're". ;-)

Quoted 6 lines

into BlockBackend.

---
  blockdev.c | 20 ++++++++++++--------
  1 file changed, 12 insertions(+), 8 deletions(-)

With that fixed (or alternatively another Wikipedia or Wiktionary reference):

#97 lore raw

Re: [Qemu-devel] [PATCH v3 21/23] blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend

Quoted 6 lines · Max Reitz
Quoted 2 lines · Markus Armbruster

Much more command code needs conversion. I'm converting these now because they's using bdrv_dev_* functions, which I'm about to lift

Either this is again some phrase I haven't yet picked up or it should be "they're". ;-)

Nah, this is actually me trying to think and write at the same time :)

I'll fix it.

Quoted 11 lines
Quoted 6 lines

into BlockBackend.

---
  blockdev.c | 20 ++++++++++++--------
  1 file changed, 12 insertions(+), 8 deletions(-)

With that fixed (or alternatively another Wikipedia or Wiktionary reference):

Thanks!

Reviewed-by on v3 21/23
#98 lore raw

Re: [Qemu-devel] [PATCH v3 21/23] blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend

In reply to Markus Armbruster

Am 16.09.2014 um 20:12 hat Markus Armbruster geschrieben:

Quoted 5 lines

Much more command code needs conversion. I'm converting these now because they's using bdrv_dev_* functions, which I'm about to lift into BlockBackend.