diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2014-10-22 16:39:49 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2014-10-22 16:39:49 +0100 |
commit | 8f4699d873bef81cec95db6da53d4c33f8caf4b9 (patch) | |
tree | 249e2a7bb71c26b66643162f98e2659d83c79d4d /hw | |
parent | 895b810c1220fff7fb5cca5c428b881b6e30f0ac (diff) | |
parent | 84ebe3755f88be4c3733e997641fafd050a58810 (diff) | |
download | hqemu-8f4699d873bef81cec95db6da53d4c33f8caf4b9.zip hqemu-8f4699d873bef81cec95db6da53d4c33f8caf4b9.tar.gz |
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block patches
# gpg: Signature made Mon 20 Oct 2014 13:04:09 BST using RSA key ID C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
* remotes/kevin/tags/for-upstream: (28 commits)
block: Make device model's references to BlockBackend strong
block: Lift device model API into BlockBackend
blockdev: Convert qmp_eject(), qmp_change_blockdev() to BlockBackend
block/qapi: Convert qmp_query_block() to BlockBackend
blockdev: Fix blockdev-add not to create DriveInfo
blockdev: Drop superfluous DriveInfo member id
pc87312: Drop unused members of PC87312State
ide: Complete conversion from BlockDriverState to BlockBackend
hw: Convert from BlockDriverState to BlockBackend, mostly
virtio-blk: Rename VirtIOBlkConf variables to conf
virtio-blk: Drop redundant VirtIOBlock member conf
block: Rename BlockDriverCompletionFunc to BlockCompletionFunc
block: Rename BlockDriverAIOCB* to BlockAIOCB*
block: Eliminate DriveInfo member bdrv, use blk_by_legacy_dinfo()
block: Merge BlockBackend and BlockDriverState name spaces
block: Eliminate BlockDriverState member device_name[]
block: Eliminate bdrv_iterate(), use bdrv_next()
blockdev: Eliminate drive_del()
block: Make BlockBackend own its BlockDriverState
block: Code motion to get rid of stubs/blockdev.c
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
100 files changed, 881 insertions, 795 deletions
diff --git a/hw/arm/collie.c b/hw/arm/collie.c index ed7851f..6c9b82f 100644 --- a/hw/arm/collie.c +++ b/hw/arm/collie.c @@ -15,7 +15,7 @@ #include "strongarm.h" #include "hw/arm/arm.h" #include "hw/block/flash.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" static struct arm_boot_info collie_binfo = { @@ -41,13 +41,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_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_by_legacy_dinfo(dinfo) : NULL, + (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0); sysbus_create_simple("scoop", 0x40800000, NULL); diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c index 3f8465e..8103278 100644 --- a/hw/arm/gumstix.c +++ b/hw/arm/gumstix.c @@ -40,7 +40,7 @@ #include "hw/block/flash.h" #include "hw/devices.h" #include "hw/boards.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "sysemu/qtest.h" @@ -71,7 +71,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_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 +109,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_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"); diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index fa61e5f..30f744a 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -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" diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c index 2f1d618..0da02a6 100644 --- a/hw/arm/mainstone.c +++ b/hw/arm/mainstone.c @@ -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_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); } diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index c541455..3712de6 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -18,11 +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/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "ui/pixel_ops.h" @@ -1632,7 +1631,9 @@ static void musicpal_init(MachineState *machine) /* Register flash */ dinfo = drive_get(IF_PFLASH, 0, 0); if (dinfo) { - flash_size = bdrv_getlength(dinfo->bdrv); + BlockBackend *blk = blk_by_legacy_dinfo(dinfo); + + 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"); @@ -1647,16 +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, - dinfo->bdrv, 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, - dinfo->bdrv, 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); diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c index 4f092d6..c7ebaa6 100644 --- a/hw/arm/nseries.c +++ b/hw/arm/nseries.c @@ -31,7 +31,7 @@ #include "hw/hw.h" #include "hw/bt.h" #include "hw/loader.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/sysbus.h" #include "exec/address-spaces.h" @@ -172,8 +172,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_by_legacy_dinfo(dinfo)); } qdev_init_nofail(s->nand); sysbus_connect_irq(SYS_BUS_DEVICE(s->nand), 0, diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index 306cf17..abb183c 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -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_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")); diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index d6e19ae..b083ebe 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -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_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")); diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c index 320b39c..671e02c 100644 --- a/hw/arm/omap_sx1.c +++ b/hw/arm/omap_sx1.c @@ -31,7 +31,7 @@ #include "hw/boards.h" #include "hw/arm/arm.h" #include "hw/block/flash.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "sysemu/qtest.h" #include "exec/address-spaces.h" @@ -154,8 +154,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_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 +178,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_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); diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c index 7d306fb..693dfec 100644 --- a/hw/arm/pxa2xx.c +++ b/hw/arm/pxa2xx.c @@ -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_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_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)); diff --git a/hw/arm/realview.c b/hw/arm/realview.c index 8bd3ff6..af65aa4 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -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" diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c index 9260896..a16831c 100644 --- a/hw/arm/spitz.c +++ b/hw/arm/spitz.c @@ -22,10 +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/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/sysbus.h" #include "exec/address-spaces.h" @@ -170,7 +169,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_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); diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c index 6c574bc..73572eb 100644 --- a/hw/arm/tosa.c +++ b/hw/arm/tosa.c @@ -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" diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c index 7696be1..e6ef0a2 100644 --- a/hw/arm/versatilepb.c +++ b/hw/arm/versatilepb.c @@ -15,7 +15,7 @@ #include "hw/pci/pci.h" #include "hw/i2c/i2c.h" #include "hw/boards.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "hw/block/flash.h" @@ -338,7 +338,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_by_legacy_dinfo(dinfo) : NULL, VERSATILE_FLASH_SECT_SIZE, VERSATILE_FLASH_SIZE / VERSATILE_FLASH_SECT_SIZE, 4, 0x0089, 0x0018, 0x0000, 0x0, 0)) { diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index aed218f..7cbd13f 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -30,7 +30,7 @@ #include "hw/boards.h" #include "hw/loader.h" #include "exec/address-spaces.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/block/flash.h" #include "sysemu/device_tree.h" #include "qemu/error-report.h" @@ -491,7 +491,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_by_legacy_dinfo(di))) { abort(); } diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8c6b171..8ea592e 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -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_by_legacy_dinfo(dinfo))) { abort(); } diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c index ad85c7a..b590392 100644 --- a/hw/arm/xilinx_zynq.c +++ b/hw/arm/xilinx_zynq.c @@ -22,7 +22,7 @@ #include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/block/flash.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/loader.h" #include "hw/ssi.h" #include "qemu/error-report.h" @@ -164,7 +164,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_by_legacy_dinfo(dinfo) : NULL, + FLASH_SECTOR_SIZE, FLASH_SIZE/FLASH_SECTOR_SIZE, 1, 1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa, 0); diff --git a/hw/arm/z2.c b/hw/arm/z2.c index 36b3b50..1735547 100644 --- a/hw/arm/z2.c +++ b/hw/arm/z2.c @@ -20,7 +20,7 @@ #include "hw/boards.h" #include "sysemu/sysemu.h" #include "hw/block/flash.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "ui/console.h" #include "audio/audio.h" #include "exec/address-spaces.h" @@ -336,9 +336,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_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); } diff --git a/hw/block/block.c b/hw/block/block.c index b6a6dc6..a625773 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -8,6 +8,7 @@ */ #include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/block/block.h" #include "qemu/error-report.h" @@ -17,8 +18,10 @@ 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); - *serial = g_strdup(dinfo->serial); + dinfo = blk_legacy_dinfo(conf->blk); + if (dinfo) { + *serial = g_strdup(dinfo->serial); + } } } @@ -30,16 +33,18 @@ 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); - conf->cyls = dinfo->cyls; - conf->heads = dinfo->heads; - conf->secs = dinfo->secs; - if (ptrans) { - *ptrans = dinfo->trans; + dinfo = blk_legacy_dinfo(conf->blk); + 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) { - 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) { diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 5458f9d..45b1164 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -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" @@ -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); + 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->blk->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,11 +133,11 @@ static void handle_notify(EventNotifier *e) break; } } - bdrv_io_unplug(s->blk->conf.bs); + blk_io_unplug(s->conf->conf.blk); } /* 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 (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); @@ -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); + 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; } @@ -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); + blk_op_unblock_all(s->conf->conf.blk, 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); + 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)); @@ -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()); + blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context()); aio_context_release(s->ctx); diff --git a/hw/block/dataplane/virtio-blk.h b/hw/block/dataplane/virtio-blk.h index 1750c99..c88d40e 100644 --- a/hw/block/dataplane/virtio-blk.h +++ b/hw/block/dataplane/virtio-blk.h @@ -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); diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 34c1d8f..739a03e 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -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" @@ -113,7 +114,7 @@ static const FDFormat fd_formats[] = { { FDRIVE_DRV_NONE, -1, -1, 0, 0, }, }; -static void pick_geometry(BlockDriverState *bs, int *nb_heads, +static void pick_geometry(BlockBackend *blk, int *nb_heads, int *max_track, int *last_sect, FDriveType drive_in, FDriveType *drive, FDriveRate *rate) @@ -122,7 +123,7 @@ static void pick_geometry(BlockDriverState *bs, int *nb_heads, uint64_t nb_sectors, size; int i, first_match, match; - bdrv_get_geometry(bs, &nb_sectors); + blk_get_geometry(blk, &nb_sectors); match = -1; first_match = -1; for (i = 0; ; i++) { @@ -175,7 +176,7 @@ typedef enum FDiskFlags { typedef struct FDrive { FDCtrl *fdctrl; - BlockDriverState *bs; + BlockBackend *blk; /* Drive status */ FDriveType drive; uint8_t perpendicular; /* 2.88 MB access mode */ @@ -260,7 +261,7 @@ static int fd_seek(FDrive *drv, uint8_t head, uint8_t track, uint8_t sect, #endif drv->head = head; if (drv->track != track) { - if (drv->bs != NULL && bdrv_is_inserted(drv->bs)) { + if (drv->blk != NULL && blk_is_inserted(drv->blk)) { drv->media_changed = 0; } ret = 1; @@ -269,7 +270,7 @@ static int fd_seek(FDrive *drv, uint8_t head, uint8_t track, uint8_t sect, drv->sect = sect; } - if (drv->bs == NULL || !bdrv_is_inserted(drv->bs)) { + if (drv->blk == NULL || !blk_is_inserted(drv->blk)) { ret = 2; } @@ -291,11 +292,11 @@ static void fd_revalidate(FDrive *drv) FDriveRate rate; FLOPPY_DPRINTF("revalidate\n"); - if (drv->bs != NULL) { - ro = bdrv_is_read_only(drv->bs); - pick_geometry(drv->bs, &nb_heads, &max_track, + if (drv->blk != NULL) { + ro = blk_is_read_only(drv->blk); + pick_geometry(drv->blk, &nb_heads, &max_track, &last_sect, drv->drive, &drive, &rate); - if (!bdrv_is_inserted(drv->bs)) { + if (!blk_is_inserted(drv->blk)) { FLOPPY_DPRINTF("No disk in drive\n"); } else { FLOPPY_DPRINTF("Floppy disk (%d h %d t %d s) %s\n", nb_heads, @@ -665,7 +666,7 @@ static bool fdrive_media_changed_needed(void *opaque) { FDrive *drive = opaque; - return (drive->bs != NULL && drive->media_changed != 1); + return (drive->blk != NULL && drive->media_changed != 1); } static const VMStateDescription vmstate_fdrive_media_changed = { @@ -910,8 +911,9 @@ static void fdctrl_reset(FDCtrl *fdctrl, int do_irq) /* Initialise controller */ fdctrl->sra = 0; fdctrl->srb = 0xc0; - if (!fdctrl->drives[1].bs) + if (!fdctrl->drives[1].blk) { fdctrl->sra |= FD_SRA_nDRV2; + } fdctrl->cur_drv = 0; fdctrl->dor = FD_DOR_nRESET; fdctrl->dor |= (fdctrl->dma_chann != -1) ? FD_DOR_DMAEN : 0; @@ -1403,7 +1405,7 @@ static int fdctrl_transfer_handler (void *opaque, int nchan, status2 = FD_SR2_SNS; if (dma_len > fdctrl->data_len) dma_len = fdctrl->data_len; - if (cur_drv->bs == NULL) { + if (cur_drv->blk == NULL) { if (fdctrl->data_dir == FD_DIR_WRITE) fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); else @@ -1424,8 +1426,8 @@ static int fdctrl_transfer_handler (void *opaque, int nchan, if (fdctrl->data_dir != FD_DIR_WRITE || len < FD_SECTOR_LEN || rel_pos != 0) { /* READ & SCAN commands and realign to a sector for WRITE */ - if (bdrv_read(cur_drv->bs, fd_sector(cur_drv), - fdctrl->fifo, 1) < 0) { + if (blk_read(cur_drv->blk, fd_sector(cur_drv), + fdctrl->fifo, 1) < 0) { FLOPPY_DPRINTF("Floppy: error getting sector %d\n", fd_sector(cur_drv)); /* Sure, image size is too small... */ @@ -1452,8 +1454,8 @@ static int fdctrl_transfer_handler (void *opaque, int nchan, DMA_read_memory (nchan, fdctrl->fifo + rel_pos, fdctrl->data_pos, len); - if (bdrv_write(cur_drv->bs, fd_sector(cur_drv), - fdctrl->fifo, 1) < 0) { + if (blk_write(cur_drv->blk, fd_sector(cur_drv), + fdctrl->fifo, 1) < 0) { FLOPPY_DPRINTF("error writing sector %d\n", fd_sector(cur_drv)); fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); @@ -1528,7 +1530,8 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl) fd_sector(cur_drv)); return 0; } - if (bdrv_read(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) { + if (blk_read(cur_drv->blk, fd_sector(cur_drv), fdctrl->fifo, 1) + < 0) { FLOPPY_DPRINTF("error getting sector %d\n", fd_sector(cur_drv)); /* Sure, image size is too small... */ @@ -1597,8 +1600,8 @@ static void fdctrl_format_sector(FDCtrl *fdctrl) break; } memset(fdctrl->fifo, 0, FD_SECTOR_LEN); - if (cur_drv->bs == NULL || - bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) { + if (cur_drv->blk == NULL || + blk_write(cur_drv->blk, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) { FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv)); fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); } else { @@ -1988,7 +1991,8 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value) if (pos == FD_SECTOR_LEN - 1 || fdctrl->data_pos == fdctrl->data_len) { cur_drv = get_cur_drv(fdctrl); - if (bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) { + if (blk_write(cur_drv->blk, fd_sector(cur_drv), fdctrl->fifo, 1) + < 0) { FLOPPY_DPRINTF("error writing sector %d\n", fd_sector(cur_drv)); return; @@ -2076,12 +2080,12 @@ static void fdctrl_connect_drives(FDCtrl *fdctrl, Error **errp) drive = &fdctrl->drives[i]; drive->fdctrl = fdctrl; - if (drive->bs) { - if (bdrv_get_on_error(drive->bs, 0) != BLOCKDEV_ON_ERROR_ENOSPC) { + if (drive->blk) { + if (blk_get_on_error(drive->blk, 0) != BLOCKDEV_ON_ERROR_ENOSPC) { error_setg(errp, "fdc doesn't support drive option werror"); return; } - if (bdrv_get_on_error(drive->bs, 1) != BLOCKDEV_ON_ERROR_REPORT) { + if (blk_get_on_error(drive->blk, 1) != BLOCKDEV_ON_ERROR_REPORT) { error_setg(errp, "fdc doesn't support drive option rerror"); return; } @@ -2089,8 +2093,8 @@ static void fdctrl_connect_drives(FDCtrl *fdctrl, Error **errp) fd_init(drive); fdctrl_change_cb(drive, 0); - if (drive->bs) { - bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive); + if (drive->blk) { + blk_set_dev_ops(drive->blk, &fdctrl_block_ops, drive); } } } @@ -2107,10 +2111,10 @@ 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_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_by_legacy_dinfo(fds[1])); } qdev_init_nofail(dev); @@ -2130,10 +2134,10 @@ 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_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_by_legacy_dinfo(fds[1])); } qdev_init_nofail(dev); sbd = SYS_BUS_DEVICE(dev); @@ -2149,7 +2153,7 @@ 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_by_legacy_dinfo(fds[0])); } qdev_init_nofail(dev); sys = SYSBUS_FDC(dev); @@ -2286,8 +2290,8 @@ static Property isa_fdc_properties[] = { DEFINE_PROP_UINT32("iobase", FDCtrlISABus, iobase, 0x3f0), DEFINE_PROP_UINT32("irq", FDCtrlISABus, irq, 6), DEFINE_PROP_UINT32("dma", FDCtrlISABus, dma, 2), - DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs), - DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs), + DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].blk), + DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].blk), DEFINE_PROP_BIT("check_media_rate", FDCtrlISABus, state.check_media_rate, 0, true), DEFINE_PROP_END_OF_LIST(), @@ -2336,8 +2340,8 @@ static const VMStateDescription vmstate_sysbus_fdc ={ }; static Property sysbus_fdc_properties[] = { - DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.drives[0].bs), - DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.drives[1].bs), + DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.drives[0].blk), + DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.drives[1].blk), DEFINE_PROP_END_OF_LIST(), }; @@ -2357,7 +2361,7 @@ static const TypeInfo sysbus_fdc_info = { }; static Property sun4m_fdc_properties[] = { - DEFINE_PROP_DRIVE("drive", FDCtrlSysBus, state.drives[0].bs), + DEFINE_PROP_DRIVE("drive", FDCtrlSysBus, state.drives[0].blk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c index 6feb4f8..6fcf74d 100644 --- a/hw/block/hd-geometry.c +++ b/hw/block/hd-geometry.c @@ -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) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 5893773..ff1106b 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -22,6 +22,7 @@ */ #include "hw/hw.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/ssi.h" @@ -245,7 +246,7 @@ typedef struct Flash { uint32_t r; - BlockDriverState *bdrv; + BlockBackend *blk; uint8_t *storage; uint32_t size; @@ -279,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. @@ -288,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) @@ -309,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; } @@ -320,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) @@ -620,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 && dinfo->bdrv) { + if (dinfo) { DB_PRINT_L(0, "Binding to IF_MTD drive\n"); - s->bdrv = dinfo->bdrv; + 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; } diff --git a/hw/block/nand.c b/hw/block/nand.c index 38eefd4..1882a0c 100644 --- a/hw/block/nand.c +++ b/hw/block/nand.c @@ -20,7 +20,7 @@ # include "hw/hw.h" # include "hw/block/flash.h" -# include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/qdev.h" #include "qemu/error-report.h" @@ -61,7 +61,7 @@ struct NANDFlashState { int size, pages; int page_shift, oob_shift, erase_shift, addr_shift; uint8_t *storage; - BlockDriverState *bdrv; + BlockBackend *blk; int mem_oob; uint8_t cle, ale, ce, wp, gnd; @@ -400,12 +400,12 @@ static void nand_realize(DeviceState *dev, Error **errp) pagesize = 1 << s->oob_shift; s->mem_oob = 1; - if (s->bdrv) { - if (bdrv_is_read_only(s->bdrv)) { + if (s->blk) { + if (blk_is_read_only(s->blk)) { error_setg(errp, "Can't use a read-only drive"); return; } - if (bdrv_getlength(s->bdrv) >= + if (blk_getlength(s->blk) >= (s->pages << s->page_shift) + (s->pages << s->oob_shift)) { pagesize = 0; s->mem_oob = 0; @@ -424,7 +424,7 @@ static void nand_realize(DeviceState *dev, Error **errp) static Property nand_properties[] = { DEFINE_PROP_UINT8("manufacturer_id", NANDFlashState, manf_id, 0), DEFINE_PROP_UINT8("chip_id", NANDFlashState, chip_id, 0), - DEFINE_PROP_DRIVE("drive", NANDFlashState, bdrv), + DEFINE_PROP_DRIVE("drive", NANDFlashState, blk), DEFINE_PROP_END_OF_LIST(), }; @@ -624,7 +624,7 @@ uint32_t nand_getbuswidth(DeviceState *dev) return s->buswidth << 3; } -DeviceState *nand_init(BlockDriverState *bdrv, int manf_id, int chip_id) +DeviceState *nand_init(BlockBackend *blk, int manf_id, int chip_id) { DeviceState *dev; @@ -634,8 +634,8 @@ DeviceState *nand_init(BlockDriverState *bdrv, int manf_id, int chip_id) dev = DEVICE(object_new(TYPE_NAND)); qdev_prop_set_uint8(dev, "manufacturer_id", manf_id); qdev_prop_set_uint8(dev, "chip_id", chip_id); - if (bdrv) { - qdev_prop_set_drive_nofail(dev, "drive", bdrv); + if (blk) { + qdev_prop_set_drive_nofail(dev, "drive", blk); } qdev_init_nofail(dev); @@ -654,14 +654,14 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) if (PAGE(s->addr) >= s->pages) return; - if (!s->bdrv) { + if (!s->blk) { mem_and(s->storage + PAGE_START(s->addr) + (s->addr & PAGE_MASK) + s->offset, s->io, s->iolen); } else if (s->mem_oob) { sector = SECTOR(s->addr); off = (s->addr & PAGE_MASK) + s->offset; soff = SECTOR_OFFSET(s->addr); - if (bdrv_read(s->bdrv, sector, iobuf, PAGE_SECTORS) < 0) { + if (blk_read(s->blk, sector, iobuf, PAGE_SECTORS) < 0) { printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); return; } @@ -673,21 +673,21 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) MIN(OOB_SIZE, off + s->iolen - PAGE_SIZE)); } - if (bdrv_write(s->bdrv, sector, iobuf, PAGE_SECTORS) < 0) { + if (blk_write(s->blk, sector, iobuf, PAGE_SECTORS) < 0) { printf("%s: write error in sector %" PRIu64 "\n", __func__, sector); } } else { off = PAGE_START(s->addr) + (s->addr & PAGE_MASK) + s->offset; sector = off >> 9; soff = off & 0x1ff; - if (bdrv_read(s->bdrv, sector, iobuf, PAGE_SECTORS + 2) < 0) { + if (blk_read(s->blk, sector, iobuf, PAGE_SECTORS + 2) < 0) { printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); return; } mem_and(iobuf + soff, s->io, s->iolen); - if (bdrv_write(s->bdrv, sector, iobuf, PAGE_SECTORS + 2) < 0) { + if (blk_write(s->blk, sector, iobuf, PAGE_SECTORS + 2) < 0) { printf("%s: write error in sector %" PRIu64 "\n", __func__, sector); } } @@ -705,7 +705,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) return; } - if (!s->bdrv) { + if (!s->blk) { memset(s->storage + PAGE_START(addr), 0xff, (PAGE_SIZE + OOB_SIZE) << s->erase_shift); } else if (s->mem_oob) { @@ -714,17 +714,17 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) i = SECTOR(addr); page = SECTOR(addr + (ADDR_SHIFT + s->erase_shift)); for (; i < page; i ++) - if (bdrv_write(s->bdrv, i, iobuf, 1) < 0) { + if (blk_write(s->blk, i, iobuf, 1) < 0) { printf("%s: write error in sector %" PRIu64 "\n", __func__, i); } } else { addr = PAGE_START(addr); page = addr >> 9; - if (bdrv_read(s->bdrv, page, iobuf, 1) < 0) { + if (blk_read(s->blk, page, iobuf, 1) < 0) { printf("%s: read error in sector %" PRIu64 "\n", __func__, page); } memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1); - if (bdrv_write(s->bdrv, page, iobuf, 1) < 0) { + if (blk_write(s->blk, page, iobuf, 1) < 0) { printf("%s: write error in sector %" PRIu64 "\n", __func__, page); } @@ -732,18 +732,18 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) i = (addr & ~0x1ff) + 0x200; for (addr += ((PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; i < addr; i += 0x200) { - if (bdrv_write(s->bdrv, i >> 9, iobuf, 1) < 0) { + if (blk_write(s->blk, i >> 9, iobuf, 1) < 0) { printf("%s: write error in sector %" PRIu64 "\n", __func__, i >> 9); } } page = i >> 9; - if (bdrv_read(s->bdrv, page, iobuf, 1) < 0) { + if (blk_read(s->blk, page, iobuf, 1) < 0) { printf("%s: read error in sector %" PRIu64 "\n", __func__, page); } memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1); - if (bdrv_write(s->bdrv, page, iobuf, 1) < 0) { + if (blk_write(s->blk, page, iobuf, 1) < 0) { printf("%s: write error in sector %" PRIu64 "\n", __func__, page); } } @@ -756,9 +756,9 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, return; } - if (s->bdrv) { + if (s->blk) { if (s->mem_oob) { - if (bdrv_read(s->bdrv, SECTOR(addr), s->io, PAGE_SECTORS) < 0) { + if (blk_read(s->blk, SECTOR(addr), s->io, PAGE_SECTORS) < 0) { printf("%s: read error in sector %" PRIu64 "\n", __func__, SECTOR(addr)); } @@ -767,8 +767,8 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, OOB_SIZE); s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset; } else { - if (bdrv_read(s->bdrv, PAGE_START(addr) >> 9, - s->io, (PAGE_SECTORS + 2)) < 0) { + if (blk_read(s->blk, PAGE_START(addr) >> 9, + s->io, (PAGE_SECTORS + 2)) < 0) { printf("%s: read error in sector %" PRIu64 "\n", __func__, PAGE_START(addr) >> 9); } diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 9a95f75..b6263dc 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -26,6 +26,7 @@ #include <hw/pci/pci.h> #include "sysemu/sysemu.h" #include "qapi/visitor.h" +#include "sysemu/block-backend.h" #include "nvme.h" @@ -199,7 +200,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 { @@ -233,11 +234,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; } @@ -290,7 +291,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]; @@ -565,7 +566,7 @@ static void nvme_clear_ctrl(NvmeCtrl *n) } } - bdrv_flush(n->conf.bs); + blk_flush(n->conf.blk); n->bar.cc = 0; } @@ -750,11 +751,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; } diff --git a/hw/block/nvme.h b/hw/block/nvme.h index bd8fc3e..993c511 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -636,7 +636,7 @@ typedef struct NvmeAsyncEvent { typedef struct NvmeRequest { struct NvmeSQueue *sq; - BlockDriverAIOCB *aiocb; + BlockAIOCB *aiocb; uint16_t status; NvmeCqe cqe; BlockAcctCookie acct; diff --git a/hw/block/onenand.c b/hw/block/onenand.c index e48e585..348630d 100644 --- a/hw/block/onenand.c +++ b/hw/block/onenand.c @@ -22,6 +22,7 @@ #include "hw/hw.h" #include "hw/block/flash.h" #include "hw/irq.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "exec/memory.h" #include "exec/address-spaces.h" @@ -49,8 +50,8 @@ typedef struct OneNANDState { hwaddr base; qemu_irq intr; qemu_irq rdy; - BlockDriverState *bdrv; - BlockDriverState *bdrv_cur; + BlockBackend *blk; + BlockBackend *blk_cur; uint8_t *image; uint8_t *otp; uint8_t *current; @@ -213,7 +214,7 @@ static void onenand_reset(OneNANDState *s, int cold) s->wpstatus = 0x0002; s->cycle = 0; s->otpmode = 0; - s->bdrv_cur = s->bdrv; + s->blk_cur = s->blk; s->current = s->image; s->secs_cur = s->secs; @@ -221,7 +222,7 @@ static void onenand_reset(OneNANDState *s, int cold) /* Lock the whole flash */ memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks); - if (s->bdrv_cur && bdrv_read(s->bdrv_cur, 0, s->boot[0], 8) < 0) { + if (s->blk_cur && blk_read(s->blk_cur, 0, s->boot[0], 8) < 0) { hw_error("%s: Loading the BootRAM failed.\n", __func__); } } @@ -237,10 +238,11 @@ static void onenand_system_reset(DeviceState *dev) static inline int onenand_load_main(OneNANDState *s, int sec, int secn, void *dest) { - if (s->bdrv_cur) - return bdrv_read(s->bdrv_cur, sec, dest, secn) < 0; - else if (sec + secn > s->secs_cur) + if (s->blk_cur) { + return blk_read(s->blk_cur, sec, dest, secn) < 0; + } else if (sec + secn > s->secs_cur) { return 1; + } memcpy(dest, s->current + (sec << 9), secn << 9); @@ -256,9 +258,9 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, uint32_t size = (uint32_t)secn * 512; const uint8_t *sp = (const uint8_t *)src; uint8_t *dp = 0; - if (s->bdrv_cur) { + if (s->blk_cur) { dp = g_malloc(size); - if (!dp || bdrv_read(s->bdrv_cur, sec, dp, secn) < 0) { + if (!dp || blk_read(s->blk_cur, sec, dp, secn) < 0) { result = 1; } } else { @@ -273,11 +275,11 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, for (i = 0; i < size; i++) { dp[i] &= sp[i]; } - if (s->bdrv_cur) { - result = bdrv_write(s->bdrv_cur, sec, dp, secn) < 0; + if (s->blk_cur) { + result = blk_write(s->blk_cur, sec, dp, secn) < 0; } } - if (dp && s->bdrv_cur) { + if (dp && s->blk_cur) { g_free(dp); } } @@ -290,14 +292,16 @@ static inline int onenand_load_spare(OneNANDState *s, int sec, int secn, { uint8_t buf[512]; - if (s->bdrv_cur) { - if (bdrv_read(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) + if (s->blk_cur) { + if (blk_read(s->blk_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) { return 1; + } memcpy(dest, buf + ((sec & 31) << 4), secn << 4); - } else if (sec + secn > s->secs_cur) + } else if (sec + secn > s->secs_cur) { return 1; - else + } else { memcpy(dest, s->current + (s->secs_cur << 9) + (sec << 4), secn << 4); + } return 0; } @@ -309,11 +313,10 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, if (secn > 0) { const uint8_t *sp = (const uint8_t *)src; uint8_t *dp = 0, *dpp = 0; - if (s->bdrv_cur) { + if (s->blk_cur) { dp = g_malloc(512); - if (!dp || bdrv_read(s->bdrv_cur, - s->secs_cur + (sec >> 5), - dp, 1) < 0) { + if (!dp + || blk_read(s->blk_cur, s->secs_cur + (sec >> 5), dp, 1) < 0) { result = 1; } else { dpp = dp + ((sec & 31) << 4); @@ -330,9 +333,9 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, for (i = 0; i < (secn << 4); i++) { dpp[i] &= sp[i]; } - if (s->bdrv_cur) { - result = bdrv_write(s->bdrv_cur, s->secs_cur + (sec >> 5), - dp, 1) < 0; + if (s->blk_cur) { + result = blk_write(s->blk_cur, s->secs_cur + (sec >> 5), + dp, 1) < 0; } } g_free(dp); @@ -354,16 +357,16 @@ static inline int onenand_erase(OneNANDState *s, int sec, int num) } memset(blankbuf, 0xff, 512); for (; num > 0; num--, sec++) { - if (s->bdrv_cur) { + if (s->blk_cur) { int erasesec = s->secs_cur + (sec >> 5); - if (bdrv_write(s->bdrv_cur, sec, blankbuf, 1) < 0) { + if (blk_write(s->blk_cur, sec, blankbuf, 1) < 0) { goto fail; } - if (bdrv_read(s->bdrv_cur, erasesec, tmpbuf, 1) < 0) { + if (blk_read(s->blk_cur, erasesec, tmpbuf, 1) < 0) { goto fail; } memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4); - if (bdrv_write(s->bdrv_cur, erasesec, tmpbuf, 1) < 0) { + if (blk_write(s->blk_cur, erasesec, tmpbuf, 1) < 0) { goto fail; } } else { @@ -576,7 +579,7 @@ static void onenand_command(OneNANDState *s) case 0x65: /* OTP Access */ s->intstatus |= ONEN_INT; - s->bdrv_cur = NULL; + s->blk_cur = NULL; s->current = s->otp; s->secs_cur = 1 << (BLOCK_SHIFT - 9); s->addr[ONEN_BUF_BLOCK] = 0; @@ -776,15 +779,15 @@ static int onenand_initfn(SysBusDevice *sbd) ? (1 << (6 + ((s->id.dev >> 4) & 7))) : 0; memory_region_init_io(&s->iomem, OBJECT(s), &onenand_ops, s, "onenand", 0x10000 << s->shift); - if (!s->bdrv) { + if (!s->blk) { s->image = memset(g_malloc(size + (size >> 5)), 0xff, size + (size >> 5)); } else { - if (bdrv_is_read_only(s->bdrv)) { + if (blk_is_read_only(s->blk)) { error_report("Can't use a read-only drive"); return -1; } - s->bdrv_cur = s->bdrv; + s->blk_cur = s->blk; } s->otp = memset(g_malloc((64 + 2) << PAGE_SHIFT), 0xff, (64 + 2) << PAGE_SHIFT); @@ -815,7 +818,7 @@ static Property onenand_properties[] = { DEFINE_PROP_UINT16("device_id", OneNANDState, id.dev, 0), DEFINE_PROP_UINT16("version_id", OneNANDState, id.ver, 0), DEFINE_PROP_INT32("shift", OneNANDState, shift, 0), - DEFINE_PROP_DRIVE("drive", OneNANDState, bdrv), + DEFINE_PROP_DRIVE("drive", OneNANDState, blk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 1346541..89d380e 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -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); diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 01011cf..8513a17 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -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); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 1fa9770..b19b102 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -16,6 +16,7 @@ #include "qemu/error-report.h" #include "trace.h" #include "hw/block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/virtio/virtio-blk.h" #include "dataplane/virtio-blk.h" @@ -64,7 +65,8 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, bool is_read) { - BlockErrorAction action = bdrv_get_error_action(req->dev->bs, is_read, error); + BlockErrorAction action = blk_get_error_action(req->dev->blk, + is_read, error); VirtIOBlock *s = req->dev; if (action == BLOCK_ERROR_ACTION_STOP) { @@ -72,11 +74,11 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, s->rq = req; } else if (action == BLOCK_ERROR_ACTION_REPORT) { virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); - block_acct_done(bdrv_get_stats(s->bs), &req->acct); + block_acct_done(blk_get_stats(s->blk), &req->acct); virtio_blk_free_request(req); } - bdrv_error_action(s->bs, action, is_read, error); + blk_error_action(s->blk, action, is_read, error); return action != BLOCK_ERROR_ACTION_IGNORE; } @@ -94,7 +96,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret) } virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); - block_acct_done(bdrv_get_stats(req->dev->bs), &req->acct); + block_acct_done(blk_get_stats(req->dev->blk), &req->acct); virtio_blk_free_request(req); } @@ -109,7 +111,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret) } virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); - block_acct_done(bdrv_get_stats(req->dev->bs), &req->acct); + block_acct_done(blk_get_stats(req->dev->blk), &req->acct); virtio_blk_free_request(req); } @@ -155,7 +157,7 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk, */ scsi = (void *)elem->in_sg[elem->in_num - 2].iov_base; - if (!blk->blk.scsi) { + if (!blk->conf.scsi) { status = VIRTIO_BLK_S_UNSUPP; goto fail; } @@ -209,7 +211,7 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk, hdr.sbp = elem->in_sg[elem->in_num - 3].iov_base; hdr.mx_sb_len = elem->in_sg[elem->in_num - 3].iov_len; - status = bdrv_ioctl(blk->bs, SG_IO, &hdr); + status = blk_ioctl(blk->blk, SG_IO, &hdr); if (status) { status = VIRTIO_BLK_S_UNSUPP; goto fail; @@ -255,7 +257,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req) virtio_blk_free_request(req); } -void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb) +void virtio_submit_multiwrite(BlockBackend *blk, MultiReqBuffer *mrb) { int i, ret; @@ -263,7 +265,7 @@ void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb) return; } - ret = bdrv_aio_multiwrite(bs, mrb->blkreq, mrb->num_writes); + ret = blk_aio_multiwrite(blk, mrb->blkreq, mrb->num_writes); if (ret != 0) { for (i = 0; i < mrb->num_writes; i++) { if (mrb->blkreq[i].error) { @@ -277,14 +279,14 @@ void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb) static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) { - block_acct_start(bdrv_get_stats(req->dev->bs), &req->acct, 0, + block_acct_start(blk_get_stats(req->dev->blk), &req->acct, 0, BLOCK_ACCT_FLUSH); /* * Make sure all outstanding writes are posted to the backing device. */ - virtio_submit_multiwrite(req->dev->bs, mrb); - bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); + virtio_submit_multiwrite(req->dev->blk, mrb); + blk_aio_flush(req->dev->blk, virtio_blk_flush_complete, req); } static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, @@ -296,10 +298,10 @@ 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->conf.conf.logical_block_size) { return false; } - bdrv_get_geometry(dev->bs, &total_sectors); + blk_get_geometry(dev->blk, &total_sectors); if (sector > total_sectors || nb_sectors > total_sectors - sector) { return false; } @@ -321,11 +323,11 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) return; } - block_acct_start(bdrv_get_stats(req->dev->bs), &req->acct, req->qiov.size, + block_acct_start(blk_get_stats(req->dev->blk), &req->acct, req->qiov.size, BLOCK_ACCT_WRITE); if (mrb->num_writes == 32) { - virtio_submit_multiwrite(req->dev->bs, mrb); + virtio_submit_multiwrite(req->dev->blk, mrb); } blkreq = &mrb->blkreq[mrb->num_writes]; @@ -353,11 +355,11 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req) return; } - block_acct_start(bdrv_get_stats(req->dev->bs), &req->acct, req->qiov.size, + block_acct_start(blk_get_stats(req->dev->blk), &req->acct, req->qiov.size, BLOCK_ACCT_READ); - bdrv_aio_readv(req->dev->bs, sector, &req->qiov, - req->qiov.size / BDRV_SECTOR_SIZE, - virtio_blk_rw_complete, req); + blk_aio_readv(req->dev->blk, sector, &req->qiov, + req->qiov.size / BDRV_SECTOR_SIZE, + virtio_blk_rw_complete, req); } void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) @@ -405,7 +407,7 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) * NB: per existing s/n string convention the string is * terminated by '\0' only when shorter than buffer. */ - const char *serial = s->blk.serial ? s->blk.serial : ""; + const char *serial = s->conf.serial ? s->conf.serial : ""; size_t size = MIN(strlen(serial) + 1, MIN(iov_size(in_iov, in_num), VIRTIO_BLK_ID_BYTES)); @@ -445,7 +447,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) virtio_blk_handle_request(req, &mrb); } - virtio_submit_multiwrite(s->bs, &mrb); + virtio_submit_multiwrite(s->blk, &mrb); /* * FIXME: Want to check for completions before returning to guest mode, @@ -473,7 +475,7 @@ static void virtio_blk_dma_restart_bh(void *opaque) req = next; } - virtio_submit_multiwrite(s->bs, &mrb); + virtio_submit_multiwrite(s->blk, &mrb); } static void virtio_blk_dma_restart_cb(void *opaque, int running, @@ -486,7 +488,7 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running, } if (!s->bh) { - s->bh = aio_bh_new(bdrv_get_aio_context(s->blk.conf.bs), + s->bh = aio_bh_new(blk_get_aio_context(s->conf.conf.blk), virtio_blk_dma_restart_bh, s); qemu_bh_schedule(s->bh); } @@ -504,8 +506,8 @@ static void virtio_blk_reset(VirtIODevice *vdev) * This should cancel pending requests, but can't do nicely until there * are per-device request lists. */ - bdrv_drain_all(); - bdrv_set_enable_write_cache(s->bs, s->original_wce); + blk_drain_all(); + blk_set_enable_write_cache(s->blk, s->original_wce); } /* coalesce internal state, copy to pci i/o region 0 @@ -513,19 +515,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->conf.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); + blk_get_geometry(s->blk, &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 @@ -537,15 +540,15 @@ 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 (blk_getlength(s->blk) / 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(conf); blkcfg.alignment_offset = 0; - blkcfg.wce = bdrv_enable_write_cache(s->bs); + blkcfg.wce = blk_enable_write_cache(s->blk); memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); } @@ -556,9 +559,9 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) memcpy(&blkcfg, config, sizeof(blkcfg)); - aio_context_acquire(bdrv_get_aio_context(s->bs)); - bdrv_set_enable_write_cache(s->bs, blkcfg.wce != 0); - aio_context_release(bdrv_get_aio_context(s->bs)); + aio_context_acquire(blk_get_aio_context(s->blk)); + blk_set_enable_write_cache(s->blk, blkcfg.wce != 0); + aio_context_release(blk_get_aio_context(s->blk)); } static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) @@ -571,14 +574,15 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) features |= (1 << VIRTIO_BLK_F_BLK_SIZE); features |= (1 << VIRTIO_BLK_F_SCSI); - if (s->blk.config_wce) { + if (s->conf.config_wce) { features |= (1 << VIRTIO_BLK_F_CONFIG_WCE); } - if (bdrv_enable_write_cache(s->bs)) + if (blk_enable_write_cache(s->blk)) { features |= (1 << VIRTIO_BLK_F_WCE); - - if (bdrv_is_read_only(s->bs)) + } + if (blk_is_read_only(s->blk)) { features |= 1 << VIRTIO_BLK_F_RO; + } return features; } @@ -612,13 +616,13 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) * Guest writes 1 to the WCE configuration field (writeback mode) * Guest sets DRIVER_OK bit in status field * - * s->bs would erroneously be placed in writethrough mode. + * s->blk would erroneously be placed in writethrough mode. */ if (!(features & (1 << VIRTIO_BLK_F_CONFIG_WCE))) { - aio_context_acquire(bdrv_get_aio_context(s->bs)); - bdrv_set_enable_write_cache(s->bs, - !!(features & (1 << VIRTIO_BLK_F_WCE))); - aio_context_release(bdrv_get_aio_context(s->bs)); + aio_context_acquire(blk_get_aio_context(s->blk)); + blk_set_enable_write_cache(s->blk, + !!(features & (1 << VIRTIO_BLK_F_WCE))); + aio_context_release(blk_get_aio_context(s->blk)); } } @@ -707,8 +711,8 @@ static void virtio_blk_migration_state_changed(Notifier *notifier, void *data) if (s->dataplane) { return; } - bdrv_drain_all(); /* complete in-flight non-dataplane requests */ - virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->blk, + blk_drain_all(); /* complete in-flight non-dataplane requests */ + virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->conf, &s->dataplane, &err); if (err != NULL) { error_report("%s", error_get_pretty(err)); @@ -721,22 +725,22 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOBlock *s = VIRTIO_BLK(dev); - VirtIOBlkConf *blk = &(s->blk); + VirtIOBlkConf *conf = &s->conf; Error *err = NULL; static int virtio_blk_id; - if (!blk->conf.bs) { + if (!conf->conf.blk) { error_setg(errp, "drive property not set"); return; } - if (!bdrv_is_inserted(blk->conf.bs)) { + if (!blk_is_inserted(conf->conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); return; } - blkconf_serial(&blk->conf, &blk->serial); - s->original_wce = bdrv_enable_write_cache(blk->conf.bs); - blkconf_geometry(&blk->conf, NULL, 65535, 255, 255, &err); + blkconf_serial(&conf->conf, &conf->serial); + s->original_wce = blk_enable_write_cache(conf->conf.blk); + blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, &err); if (err) { error_propagate(errp, err); return; @@ -745,14 +749,13 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config)); - s->bs = blk->conf.bs; - s->conf = &blk->conf; + s->blk = conf->conf.blk; s->rq = NULL; - s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; + s->sector_mask = (s->conf.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; - virtio_blk_data_plane_create(vdev, blk, &s->dataplane, &err); + virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err); if (err != NULL) { error_propagate(errp, err); virtio_cleanup(vdev); @@ -764,10 +767,10 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); 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); + blk_set_dev_ops(s->blk, &virtio_block_ops, s); + blk_set_guest_block_size(s->blk, s->conf.conf.logical_block_size); - bdrv_iostatus_enable(s->bs); + blk_iostatus_enable(s->blk); } static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) @@ -780,7 +783,7 @@ static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) s->dataplane = NULL; qemu_del_vm_change_state_handler(s->change); unregister_savevm(dev, "virtio-blk", s); - blockdev_mark_auto_del(s->bs); + blockdev_mark_auto_del(s->blk); virtio_cleanup(vdev); } @@ -789,23 +792,23 @@ static void virtio_blk_instance_init(Object *obj) VirtIOBlock *s = VIRTIO_BLK(obj); object_property_add_link(obj, "iothread", TYPE_IOTHREAD, - (Object **)&s->blk.iothread, + (Object **)&s->conf.iothread, qdev_prop_allow_set_link_before_realize, OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL); - device_add_bootindex_property(obj, &s->blk.conf.bootindex, + device_add_bootindex_property(obj, &s->conf.conf.bootindex, "bootindex", "/disk@0,0", DEVICE(obj), NULL); } static Property virtio_blk_properties[] = { - DEFINE_BLOCK_PROPERTIES(VirtIOBlock, blk.conf), - DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, blk.conf), - DEFINE_PROP_STRING("serial", VirtIOBlock, blk.serial), - DEFINE_PROP_BIT("config-wce", VirtIOBlock, blk.config_wce, 0, true), + DEFINE_BLOCK_PROPERTIES(VirtIOBlock, conf.conf), + DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf), + DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial), + DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true), #ifdef __linux__ - DEFINE_PROP_BIT("scsi", VirtIOBlock, blk.scsi, 0, true), + DEFINE_PROP_BIT("scsi", VirtIOBlock, conf.scsi, 0, true), #endif - DEFINE_PROP_BIT("x-data-plane", VirtIOBlock, blk.data_plane, 0, false), + DEFINE_PROP_BIT("x-data-plane", VirtIOBlock, conf.data_plane, 0, false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 0d27ab1..231e9a7 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -39,6 +39,7 @@ #include "hw/xen/xen_backend.h" #include "xen_blkif.h" #include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" /* ------------------------------------------------------------- */ @@ -122,7 +123,7 @@ struct XenBlkDev { /* qemu block driver */ DriveInfo *dinfo; - BlockDriverState *bs; + BlockBackend *blk; QEMUBH *bh; }; @@ -479,7 +480,7 @@ static void qemu_aio_complete(void *opaque, int ret) if (ioreq->postsync) { ioreq->postsync = 0; ioreq->aio_inflight++; - bdrv_aio_flush(ioreq->blkdev->bs, qemu_aio_complete, ioreq); + blk_aio_flush(ioreq->blkdev->blk, qemu_aio_complete, ioreq); return; } @@ -493,7 +494,7 @@ static void qemu_aio_complete(void *opaque, int ret) break; } case BLKIF_OP_READ: - block_acct_done(bdrv_get_stats(ioreq->blkdev->bs), &ioreq->acct); + block_acct_done(blk_get_stats(ioreq->blkdev->blk), &ioreq->acct); break; case BLKIF_OP_DISCARD: default: @@ -512,18 +513,18 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) ioreq->aio_inflight++; if (ioreq->presync) { - bdrv_aio_flush(ioreq->blkdev->bs, qemu_aio_complete, ioreq); + blk_aio_flush(ioreq->blkdev->blk, qemu_aio_complete, ioreq); return 0; } switch (ioreq->req.operation) { case BLKIF_OP_READ: - block_acct_start(bdrv_get_stats(blkdev->bs), &ioreq->acct, + block_acct_start(blk_get_stats(blkdev->blk), &ioreq->acct, ioreq->v.size, BLOCK_ACCT_READ); ioreq->aio_inflight++; - bdrv_aio_readv(blkdev->bs, ioreq->start / BLOCK_SIZE, - &ioreq->v, ioreq->v.size / BLOCK_SIZE, - qemu_aio_complete, ioreq); + blk_aio_readv(blkdev->blk, ioreq->start / BLOCK_SIZE, + &ioreq->v, ioreq->v.size / BLOCK_SIZE, + qemu_aio_complete, ioreq); break; case BLKIF_OP_WRITE: case BLKIF_OP_FLUSH_DISKCACHE: @@ -531,18 +532,18 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) break; } - block_acct_start(bdrv_get_stats(blkdev->bs), &ioreq->acct, + block_acct_start(blk_get_stats(blkdev->blk), &ioreq->acct, ioreq->v.size, BLOCK_ACCT_WRITE); ioreq->aio_inflight++; - bdrv_aio_writev(blkdev->bs, ioreq->start / BLOCK_SIZE, - &ioreq->v, ioreq->v.size / BLOCK_SIZE, - qemu_aio_complete, ioreq); + blk_aio_writev(blkdev->blk, ioreq->start / BLOCK_SIZE, + &ioreq->v, ioreq->v.size / BLOCK_SIZE, + qemu_aio_complete, ioreq); break; case BLKIF_OP_DISCARD: { struct blkif_request_discard *discard_req = (void *)&ioreq->req; ioreq->aio_inflight++; - bdrv_aio_discard(blkdev->bs, + blk_aio_discard(blkdev->blk, discard_req->sector_number, discard_req->nr_sectors, qemu_aio_complete, ioreq); break; @@ -854,44 +855,49 @@ 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; + BlockDriverState *bs; /* 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); - if (!blkdev->bs) { + blk = blk_new_with_bs(blkdev->dev, NULL); + if (!blk) { return -1; } + blkdev->blk = blk; + bs = blk_bs(blk); drv = bdrv_find_whitelisted_format(blkdev->fileproto, readonly); - if (bdrv_open(&blkdev->bs, blkdev->filename, NULL, NULL, qflags, + if (bdrv_open(&bs, blkdev->filename, NULL, NULL, qflags, drv, &local_err) != 0) { xen_be_printf(&blkdev->xendev, 0, "error: %s\n", error_get_pretty(local_err)); error_free(local_err); - bdrv_unref(blkdev->bs); - blkdev->bs = NULL; + blk_unref(blk); + blkdev->blk = NULL; return -1; } + assert(bs == blk_bs(blk)); } 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; - if (bdrv_is_read_only(blkdev->bs) && !readonly) { + blkdev->blk = blk_by_legacy_dinfo(blkdev->dinfo); + if (blk_is_read_only(blkdev->blk) && !readonly) { xen_be_printf(&blkdev->xendev, 0, "Unexpected read-only drive"); - blkdev->bs = NULL; + blkdev->blk = NULL; return -1; } - /* blkdev->bs is not create by us, we get a reference - * so we can bdrv_unref() unconditionally */ - bdrv_ref(blkdev->bs); + /* blkdev->blk is not create by us, we get a reference + * so we can blk_unref() unconditionally */ + blk_ref(blkdev->blk); } - bdrv_attach_dev_nofail(blkdev->bs, blkdev); - blkdev->file_size = bdrv_getlength(blkdev->bs); + blk_attach_dev_nofail(blkdev->blk, blkdev); + blkdev->file_size = blk_getlength(blkdev->blk); if (blkdev->file_size < 0) { - xen_be_printf(&blkdev->xendev, 1, "bdrv_getlength: %d (%s) | drv %s\n", + xen_be_printf(&blkdev->xendev, 1, "blk_getlength: %d (%s) | drv %s\n", (int)blkdev->file_size, strerror(-blkdev->file_size), - bdrv_get_format_name(blkdev->bs) ?: "-"); + bdrv_get_format_name(blk_bs(blkdev->blk)) ?: "-"); blkdev->file_size = 0; } @@ -982,10 +988,10 @@ static void blk_disconnect(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); - if (blkdev->bs) { - bdrv_detach_dev(blkdev->bs, blkdev); - bdrv_unref(blkdev->bs); - blkdev->bs = NULL; + if (blkdev->blk) { + blk_detach_dev(blkdev->blk, blkdev); + blk_unref(blkdev->blk); + blkdev->blk = NULL; } xen_be_unbind_evtchn(&blkdev->xendev); @@ -1001,7 +1007,7 @@ static int blk_free(struct XenDevice *xendev) struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); struct ioreq *ioreq; - if (blkdev->bs || blkdev->sring) { + if (blkdev->blk || blkdev->sring) { blk_disconnect(xendev); } diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index f2bd954..65901ef 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -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); diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 2ed995f..2e47f70 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -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" diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c index 2fb3aa8..0479196 100644 --- a/hw/cris/axis_dev88.c +++ b/hw/cris/axis_dev88.c @@ -30,7 +30,7 @@ #include "hw/loader.h" #include "elf.h" #include "boot.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "sysemu/qtest.h" @@ -284,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 ? nand->bdrv : 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); diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c index c19c055..4306adc 100644 --- a/hw/display/tc6393xb.c +++ b/hw/display/tc6393xb.c @@ -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_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); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d045e8b..61aba9f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -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" diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 4384633..91a20cb 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -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" diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index bbe367a..75913c5 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -23,7 +23,7 @@ * THE SOFTWARE. */ -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "qemu/error-report.h" #include "hw/sysbus.h" #include "hw/hw.h" @@ -103,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; @@ -119,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 = pflash_drv->bdrv; - 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) { @@ -156,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 */, diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 8bb18b4..28b324a 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -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) { diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 063730e..70958e3 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -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> @@ -84,7 +85,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) { pr->sig = 0; ide_state->status = SEEK_STAT | WRERR_STAT; } else if (ide_state->drive_kind == IDE_CD) { @@ -826,7 +827,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; @@ -877,11 +878,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", @@ -890,11 +891,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"); @@ -943,7 +944,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; } @@ -1122,7 +1123,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); diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index e223258..e8ea34a 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -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; diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 10218df..c63b7e5 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -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); @@ -254,7 +255,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); @@ -350,13 +351,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); } @@ -371,7 +372,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 */ @@ -504,7 +505,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; } @@ -800,7 +801,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); } @@ -884,14 +885,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; } } @@ -1125,7 +1126,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); @@ -1140,7 +1141,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; diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index 91048f2..c8b0322 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -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" diff --git a/hw/ide/core.c b/hw/ide/core.c index ae85428..44e3d50 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -31,7 +31,7 @@ #include "sysemu/sysemu.h" #include "sysemu/dma.h" #include "hw/block/block.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include <hw/ide/internal.h> @@ -158,10 +158,11 @@ static void ide_identify(IDEState *s) put_le16(p + 84, (1 << 14) | 0); } /* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */ - if (bdrv_enable_write_cache(s->bs)) - put_le16(p + 85, (1 << 14) | (1 << 5) | 1); - else - put_le16(p + 85, (1 << 14) | 1); + if (blk_enable_write_cache(s->blk)) { + put_le16(p + 85, (1 << 14) | (1 << 5) | 1); + } else { + put_le16(p + 85, (1 << 14) | 1); + } /* 13=flush_cache_ext,12=flush_cache,10=lba48 */ put_le16(p + 86, (1 << 13) | (1 <<12) | (1 << 10)); /* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */ @@ -350,7 +351,7 @@ static void ide_set_signature(IDEState *s) if (s->drive_kind == IDE_CD) { s->lcyl = 0x14; s->hcyl = 0xeb; - } else if (s->bs) { + } else if (s->blk) { s->lcyl = 0; s->hcyl = 0; } else { @@ -360,15 +361,16 @@ static void ide_set_signature(IDEState *s) } typedef struct TrimAIOCB { - BlockDriverAIOCB common; + BlockAIOCB common; + BlockBackend *blk; 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); @@ -379,7 +381,7 @@ static void trim_aio_cancel(BlockDriverAIOCB *acb) iocb->ret = -ECANCELED; if (iocb->aiocb) { - bdrv_aio_cancel_async(iocb->aiocb); + blk_aio_cancel_async(iocb->aiocb); iocb->aiocb = NULL; } } @@ -420,8 +422,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; } @@ -438,13 +440,14 @@ static void ide_issue_trim_cb(void *opaque, int ret) } } -BlockDriverAIOCB *ide_issue_trim(BlockDriverState *bs, +BlockAIOCB *ide_issue_trim(BlockBackend *blk, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, - BlockDriverCompletionFunc *cb, void *opaque) + BlockCompletionFunc *cb, void *opaque) { TrimAIOCB *iocb; - iocb = qemu_aio_get(&trim_aiocb_info, bs, cb, opaque); + 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; @@ -551,7 +554,7 @@ static bool ide_sect_range_ok(IDEState *s, { uint64_t total_sectors; - bdrv_get_geometry(s->bs, &total_sectors); + blk_get_geometry(s->blk, &total_sectors); if (sector > total_sectors || nb_sectors > total_sectors - sector) { return false; } @@ -569,7 +572,7 @@ static void ide_sector_read_cb(void *opaque, int ret) if (ret == -ECANCELED) { return; } - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + block_acct_done(blk_get_stats(s->blk), &s->acct); if (ret != 0) { if (ide_handle_rw_error(s, -ret, IDE_RETRY_PIO | IDE_RETRY_READ)) { @@ -625,10 +628,10 @@ void ide_sector_read(IDEState *s) s->iov.iov_len = n * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&s->qiov, &s->iov, 1); - block_acct_start(bdrv_get_stats(s->bs), &s->acct, + block_acct_start(blk_get_stats(s->blk), &s->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ); - s->pio_aiocb = bdrv_aio_readv(s->bs, sector_num, &s->qiov, n, - ide_sector_read_cb, s); + s->pio_aiocb = blk_aio_readv(s->blk, sector_num, &s->qiov, n, + ide_sector_read_cb, s); } static void dma_buf_commit(IDEState *s) @@ -655,7 +658,7 @@ void ide_dma_error(IDEState *s) static int ide_handle_rw_error(IDEState *s, int error, int op) { bool is_read = (op & IDE_RETRY_READ) != 0; - BlockErrorAction action = bdrv_get_error_action(s->bs, is_read, error); + BlockErrorAction action = blk_get_error_action(s->blk, is_read, error); if (action == BLOCK_ERROR_ACTION_STOP) { s->bus->dma->ops->set_unit(s->bus->dma, s->unit); @@ -668,7 +671,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) ide_rw_error(s); } } - bdrv_error_action(s->bs, action, is_read, error); + blk_error_action(s->blk, action, is_read, error); return action != BLOCK_ERROR_ACTION_IGNORE; } @@ -744,24 +747,24 @@ void ide_dma_cb(void *opaque, int ret) switch (s->dma_cmd) { case IDE_DMA_READ: - s->bus->dma->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num, - ide_dma_cb, s); + s->bus->dma->aiocb = dma_blk_read(s->blk, &s->sg, sector_num, + ide_dma_cb, s); break; case IDE_DMA_WRITE: - s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num, - ide_dma_cb, s); + s->bus->dma->aiocb = dma_blk_write(s->blk, &s->sg, sector_num, + ide_dma_cb, s); break; case IDE_DMA_TRIM: - s->bus->dma->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num, - ide_issue_trim, ide_dma_cb, s, - DMA_DIRECTION_TO_DEVICE); + s->bus->dma->aiocb = dma_blk_io(s->blk, &s->sg, sector_num, + ide_issue_trim, ide_dma_cb, s, + DMA_DIRECTION_TO_DEVICE); break; } return; eot: if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) { - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + block_acct_done(blk_get_stats(s->blk), &s->acct); } ide_set_inactive(s, stay_active); } @@ -775,11 +778,11 @@ static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd) switch (dma_cmd) { case IDE_DMA_READ: - block_acct_start(bdrv_get_stats(s->bs), &s->acct, + block_acct_start(blk_get_stats(s->blk), &s->acct, s->nsector * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ); break; case IDE_DMA_WRITE: - block_acct_start(bdrv_get_stats(s->bs), &s->acct, + block_acct_start(blk_get_stats(s->blk), &s->acct, s->nsector * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE); break; default: @@ -789,7 +792,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); @@ -810,7 +813,7 @@ static void ide_sector_write_cb(void *opaque, int ret) if (ret == -ECANCELED) { return; } - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + block_acct_done(blk_get_stats(s->blk), &s->acct); s->pio_aiocb = NULL; s->status &= ~BUSY_STAT; @@ -877,10 +880,10 @@ void ide_sector_write(IDEState *s) s->iov.iov_len = n * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&s->qiov, &s->iov, 1); - block_acct_start(bdrv_get_stats(s->bs), &s->acct, + block_acct_start(blk_get_stats(s->blk), &s->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ); - s->pio_aiocb = bdrv_aio_writev(s->bs, sector_num, &s->qiov, n, - ide_sector_write_cb, s); + s->pio_aiocb = blk_aio_writev(s->blk, sector_num, &s->qiov, n, + ide_sector_write_cb, s); } static void ide_flush_cb(void *opaque, int ret) @@ -899,8 +902,8 @@ static void ide_flush_cb(void *opaque, int ret) } } - if (s->bs) { - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + if (s->blk) { + block_acct_done(blk_get_stats(s->blk), &s->acct); } s->status = READY_STAT | SEEK_STAT; ide_cmd_done(s); @@ -909,14 +912,14 @@ static void ide_flush_cb(void *opaque, int ret) void ide_flush_cache(IDEState *s) { - if (s->bs == NULL) { + if (s->blk == NULL) { ide_flush_cb(s, 0); return; } s->status |= BUSY_STAT; - block_acct_start(bdrv_get_stats(s->bs), &s->acct, 0, BLOCK_ACCT_FLUSH); - s->pio_aiocb = bdrv_aio_flush(s->bs, ide_flush_cb, s); + block_acct_start(blk_get_stats(s->blk), &s->acct, 0, BLOCK_ACCT_FLUSH); + s->pio_aiocb = blk_aio_flush(s->blk, ide_flush_cb, s); } static void ide_cfata_metadata_inquiry(IDEState *s) @@ -979,7 +982,7 @@ static void ide_cd_change_cb(void *opaque, bool load) uint64_t nb_sectors; s->tray_open = !load; - bdrv_get_geometry(s->bs, &nb_sectors); + blk_get_geometry(s->blk, &nb_sectors); s->nb_sectors = nb_sectors; /* @@ -1113,7 +1116,7 @@ static bool cmd_data_set_management(IDEState *s, uint8_t cmd) { switch (s->feature) { case DSM_TRIM: - if (s->bs) { + if (s->blk) { ide_sector_start_dma(s, IDE_DMA_TRIM); return false; } @@ -1126,7 +1129,7 @@ static bool cmd_data_set_management(IDEState *s, uint8_t cmd) static bool cmd_identify(IDEState *s, uint8_t cmd) { - if (s->bs && s->drive_kind != IDE_CD) { + if (s->blk && s->drive_kind != IDE_CD) { if (s->drive_kind != IDE_CFATA) { ide_identify(s); } else { @@ -1176,7 +1179,7 @@ static bool cmd_read_multiple(IDEState *s, uint8_t cmd) { bool lba48 = (cmd == WIN_MULTREAD_EXT); - if (!s->bs || !s->mult_sectors) { + if (!s->blk || !s->mult_sectors) { ide_abort_command(s); return true; } @@ -1192,7 +1195,7 @@ static bool cmd_write_multiple(IDEState *s, uint8_t cmd) bool lba48 = (cmd == WIN_MULTWRITE_EXT); int n; - if (!s->bs || !s->mult_sectors) { + if (!s->blk || !s->mult_sectors) { ide_abort_command(s); return true; } @@ -1220,7 +1223,7 @@ static bool cmd_read_pio(IDEState *s, uint8_t cmd) return true; } - if (!s->bs) { + if (!s->blk) { ide_abort_command(s); return true; } @@ -1236,7 +1239,7 @@ static bool cmd_write_pio(IDEState *s, uint8_t cmd) { bool lba48 = (cmd == WIN_WRITE_EXT); - if (!s->bs) { + if (!s->blk) { ide_abort_command(s); return true; } @@ -1256,7 +1259,7 @@ static bool cmd_read_dma(IDEState *s, uint8_t cmd) { bool lba48 = (cmd == WIN_READDMA_EXT); - if (!s->bs) { + if (!s->blk) { ide_abort_command(s); return true; } @@ -1271,7 +1274,7 @@ static bool cmd_write_dma(IDEState *s, uint8_t cmd) { bool lba48 = (cmd == WIN_WRITEDMA_EXT); - if (!s->bs) { + if (!s->blk) { ide_abort_command(s); return true; } @@ -1322,7 +1325,7 @@ static bool cmd_set_features(IDEState *s, uint8_t cmd) { uint16_t *identify_data; - if (!s->bs) { + if (!s->blk) { ide_abort_command(s); return true; } @@ -1330,12 +1333,12 @@ static bool cmd_set_features(IDEState *s, uint8_t cmd) /* XXX: valid for CDROM ? */ switch (s->feature) { case 0x02: /* write cache enable */ - bdrv_set_enable_write_cache(s->bs, true); + blk_set_enable_write_cache(s->blk, true); identify_data = (uint16_t *)s->identify_data; put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1); return true; case 0x82: /* write cache disable */ - bdrv_set_enable_write_cache(s->bs, false); + blk_set_enable_write_cache(s->blk, false); identify_data = (uint16_t *)s->identify_data; put_le16(identify_data + 85, (1 << 14) | 1); ide_flush_cache(s); @@ -1802,8 +1805,9 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) #endif s = idebus_active_if(bus); /* ignore commands to non existent slave */ - if (s != bus->ifs && !s->bs) + if (s != bus->ifs && !s->blk) { return; + } /* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET) @@ -1848,59 +1852,66 @@ uint32_t ide_ioport_read(void *opaque, uint32_t addr1) ret = 0xff; break; case 1: - if ((!bus->ifs[0].bs && !bus->ifs[1].bs) || - (s != bus->ifs && !s->bs)) + if ((!bus->ifs[0].blk && !bus->ifs[1].blk) || + (s != bus->ifs && !s->blk)) { ret = 0; - else if (!hob) + } else if (!hob) { ret = s->error; - else + } else { ret = s->hob_feature; + } break; case 2: - if (!bus->ifs[0].bs && !bus->ifs[1].bs) + if (!bus->ifs[0].blk && !bus->ifs[1].blk) { ret = 0; - else if (!hob) + } else if (!hob) { ret = s->nsector & 0xff; - else + } else { ret = s->hob_nsector; + } break; case 3: - if (!bus->ifs[0].bs && !bus->ifs[1].bs) + if (!bus->ifs[0].blk && !bus->ifs[1].blk) { ret = 0; - else if (!hob) + } else if (!hob) { ret = s->sector; - else + } else { ret = s->hob_sector; + } break; case 4: - if (!bus->ifs[0].bs && !bus->ifs[1].bs) + if (!bus->ifs[0].blk && !bus->ifs[1].blk) { ret = 0; - else if (!hob) + } else if (!hob) { ret = s->lcyl; - else + } else { ret = s->hob_lcyl; + } break; case 5: - if (!bus->ifs[0].bs && !bus->ifs[1].bs) + if (!bus->ifs[0].blk && !bus->ifs[1].blk) { ret = 0; - else if (!hob) + } else if (!hob) { ret = s->hcyl; - else + } else { ret = s->hob_hcyl; + } break; case 6: - if (!bus->ifs[0].bs && !bus->ifs[1].bs) + if (!bus->ifs[0].blk && !bus->ifs[1].blk) { ret = 0; - else + } else { ret = s->select; + } break; default: case 7: - if ((!bus->ifs[0].bs && !bus->ifs[1].bs) || - (s != bus->ifs && !s->bs)) + if ((!bus->ifs[0].blk && !bus->ifs[1].blk) || + (s != bus->ifs && !s->blk)) { ret = 0; - else + } else { ret = s->status; + } qemu_irq_lower(bus->irq); break; } @@ -1916,11 +1927,12 @@ uint32_t ide_status_read(void *opaque, uint32_t addr) IDEState *s = idebus_active_if(bus); int ret; - if ((!bus->ifs[0].bs && !bus->ifs[1].bs) || - (s != bus->ifs && !s->bs)) + if ((!bus->ifs[0].blk && !bus->ifs[1].blk) || + (s != bus->ifs && !s->blk)) { ret = 0; - else + } else { ret = s->status; + } #ifdef DEBUG_IDE printf("ide: read status addr=0x%x val=%02x\n", addr, ret); #endif @@ -2081,7 +2093,7 @@ static void ide_reset(IDEState *s) #endif if (s->pio_aiocb) { - bdrv_aio_cancel(s->pio_aiocb); + blk_aio_cancel(s->pio_aiocb); s->pio_aiocb = NULL; } @@ -2145,7 +2157,7 @@ void ide_bus_reset(IDEBus *bus) #ifdef DEBUG_AIO printf("aio_cancel\n"); #endif - bdrv_aio_cancel(bus->dma->aiocb); + blk_aio_cancel(bus->dma->aiocb); bus->dma->aiocb = NULL; } @@ -2174,7 +2186,7 @@ static void ide_resize_cb(void *opaque) return; } - bdrv_get_geometry(s->bs, &nb_sectors); + blk_get_geometry(s->blk, &nb_sectors); s->nb_sectors = nb_sectors; /* Update the identify data buffer. */ @@ -2198,7 +2210,7 @@ static const BlockDevOps ide_hd_block_ops = { .resize_cb = ide_resize_cb, }; -int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, +int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind, const char *version, const char *serial, const char *model, uint64_t wwn, uint32_t cylinders, uint32_t heads, uint32_t secs, @@ -2206,10 +2218,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, { uint64_t nb_sectors; - s->bs = bs; + s->blk = blk; s->drive_kind = kind; - bdrv_get_geometry(bs, &nb_sectors); + blk_get_geometry(blk, &nb_sectors); s->cylinders = cylinders; s->heads = heads; s->sectors = secs; @@ -2223,18 +2235,18 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, s->smart_errors = 0; s->smart_selftest_count = 0; if (kind == IDE_CD) { - bdrv_set_dev_ops(bs, &ide_cd_block_ops, s); - bdrv_set_guest_block_size(bs, 2048); + blk_set_dev_ops(blk, &ide_cd_block_ops, s); + blk_set_guest_block_size(blk, 2048); } else { - if (!bdrv_is_inserted(s->bs)) { + if (!blk_is_inserted(s->blk)) { error_report("Device needs media, but drive is empty"); return -1; } - if (bdrv_is_read_only(bs)) { + if (blk_is_read_only(blk)) { error_report("Can't use a read-only drive"); return -1; } - bdrv_set_dev_ops(bs, &ide_hd_block_ops, s); + blk_set_dev_ops(blk, &ide_hd_block_ops, s); } if (serial) { pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial); @@ -2265,7 +2277,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, } ide_reset(s); - bdrv_iostatus_enable(bs); + blk_iostatus_enable(blk); return 0; } @@ -2282,7 +2294,7 @@ static void ide_init1(IDEBus *bus, int unit) s->io_buffer = qemu_memalign(2048, s->io_buffer_total_len); memset(s->io_buffer, 0, s->io_buffer_total_len); - s->smart_selftest_data = qemu_blockalign(s->bs, 512); + s->smart_selftest_data = blk_blockalign(s->blk, 512); memset(s->smart_selftest_data, 0, 512); s->sector_write_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, @@ -2377,7 +2389,7 @@ static int ide_drive_post_load(void *opaque, int version_id) IDEState *s = opaque; if (s->identify_set) { - bdrv_set_enable_write_cache(s->bs, !!(s->identify_data[85] & (1 << 5))); + blk_set_enable_write_cache(s->blk, !!(s->identify_data[85] & (1 << 5))); } return 0; } diff --git a/hw/ide/ich.c b/hw/ide/ich.c index 8eb77a1..fb1d095 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -65,7 +65,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/dma.h" #include <hw/ide/pci.h> diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 5c19f79..68ac610 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -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); @@ -373,7 +373,7 @@ struct IDEState { /* set for lba48 access */ uint8_t lba48; - BlockDriverState *bs; + BlockBackend *blk; char version[9]; /* ATAPI specific */ struct unreported_events events; @@ -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); @@ -537,7 +537,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr); void ide_data_writel(void *opaque, uint32_t addr, uint32_t val); uint32_t ide_data_readl(void *opaque, uint32_t addr); -int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, +int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind, const char *version, const char *serial, const char *model, uint64_t wwn, uint32_t cylinders, uint32_t heads, uint32_t secs, @@ -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(BlockBackend *blk, 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); diff --git a/hw/ide/isa.c b/hw/ide/isa.c index 4cbcb1c..b084162 100644 --- a/hw/ide/isa.c +++ b/hw/ide/isa.c @@ -25,7 +25,7 @@ #include <hw/hw.h> #include <hw/i386/pc.h> #include <hw/isa/isa.h> -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/dma.h" #include <hw/ide/internal.h> diff --git a/hw/ide/macio.c b/hw/ide/macio.c index cefc85c..9a55407 100644 --- a/hw/ide/macio.c +++ b/hw/ide/macio.c @@ -25,7 +25,7 @@ #include "hw/hw.h" #include "hw/ppc/mac.h" #include "hw/ppc/mac_dbdma.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/dma.h" #include <hw/ide/internal.h> @@ -134,7 +134,7 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret) MACIO_DPRINTF("precopying unaligned %d bytes to %#" HWADDR_PRIx "\n", unaligned, io->addr + io->len - unaligned); - bdrv_read(s->bs, sector_num + nsector, io->remainder, 1); + blk_read(s->blk, sector_num + nsector, io->remainder, 1); cpu_physical_memory_write(io->addr + io->len - unaligned, io->remainder, unaligned); @@ -164,14 +164,14 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret) (s->lba << 2) + (s->io_buffer_index >> 9), s->packet_transfer_size, s->dma_cmd); - m->aiocb = dma_bdrv_read(s->bs, &s->sg, - (int64_t)(s->lba << 2) + (s->io_buffer_index >> 9), - pmac_ide_atapi_transfer_cb, io); + m->aiocb = dma_blk_read(s->blk, &s->sg, + (int64_t)(s->lba << 2) + (s->io_buffer_index >> 9), + pmac_ide_atapi_transfer_cb, io); return; done: MACIO_DPRINTF("done DMA\n"); - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + block_acct_done(blk_get_stats(s->blk), &s->acct); io->dma_end(opaque); } @@ -254,8 +254,8 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) qemu_iovec_reset(&io->iov); qemu_iovec_add(&io->iov, io->remainder, 0x200); - m->aiocb = bdrv_aio_writev(s->bs, sector_num - 1, &io->iov, 1, - pmac_ide_transfer_cb, io); + m->aiocb = blk_aio_writev(s->blk, sector_num - 1, &io->iov, 1, + pmac_ide_transfer_cb, io); } } @@ -294,8 +294,8 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) qemu_iovec_reset(&io->iov); qemu_iovec_add(&io->iov, io->remainder, 0x200); - m->aiocb = bdrv_aio_readv(s->bs, sector_num + nsector, &io->iov, 1, - pmac_ide_transfer_cb, io); + m->aiocb = blk_aio_readv(s->blk, sector_num + nsector, &io->iov, 1, + pmac_ide_transfer_cb, io); break; case IDE_DMA_WRITE: /* cache the contents in our io struct */ @@ -333,17 +333,17 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) switch (s->dma_cmd) { case IDE_DMA_READ: - m->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num, - pmac_ide_transfer_cb, io); + m->aiocb = dma_blk_read(s->blk, &s->sg, sector_num, + pmac_ide_transfer_cb, io); break; case IDE_DMA_WRITE: - m->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num, - pmac_ide_transfer_cb, io); + m->aiocb = dma_blk_write(s->blk, &s->sg, sector_num, + pmac_ide_transfer_cb, io); break; case IDE_DMA_TRIM: - m->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num, - ide_issue_trim, pmac_ide_transfer_cb, io, - DMA_DIRECTION_TO_DEVICE); + m->aiocb = dma_blk_io(s->blk, &s->sg, sector_num, + ide_issue_trim, pmac_ide_transfer_cb, io, + DMA_DIRECTION_TO_DEVICE); break; } @@ -352,7 +352,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) done: if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) { - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + block_acct_done(blk_get_stats(s->blk), &s->acct); } io->dma_end(io); } @@ -370,7 +370,7 @@ static void pmac_ide_transfer(DBDMA_io *io) /* Handle non-block ATAPI DMA transfers */ if (s->lba == -1) { s->io_buffer_size = MIN(io->len, s->packet_transfer_size); - block_acct_start(bdrv_get_stats(s->bs), &s->acct, s->io_buffer_size, + block_acct_start(blk_get_stats(s->blk), &s->acct, s->io_buffer_size, BLOCK_ACCT_READ); MACIO_DPRINTF("non-block ATAPI DMA transfer size: %d\n", s->io_buffer_size); @@ -382,12 +382,12 @@ static void pmac_ide_transfer(DBDMA_io *io) m->dma_active = false; MACIO_DPRINTF("end of non-block ATAPI DMA transfer\n"); - block_acct_done(bdrv_get_stats(s->bs), &s->acct); + block_acct_done(blk_get_stats(s->blk), &s->acct); io->dma_end(io); return; } - block_acct_start(bdrv_get_stats(s->bs), &s->acct, io->len, + block_acct_start(blk_get_stats(s->blk), &s->acct, io->len, BLOCK_ACCT_READ); pmac_ide_atapi_transfer_cb(io, 0); return; @@ -395,11 +395,11 @@ static void pmac_ide_transfer(DBDMA_io *io) switch (s->dma_cmd) { case IDE_DMA_READ: - block_acct_start(bdrv_get_stats(s->bs), &s->acct, io->len, + block_acct_start(blk_get_stats(s->blk), &s->acct, io->len, BLOCK_ACCT_READ); break; case IDE_DMA_WRITE: - block_acct_start(bdrv_get_stats(s->bs), &s->acct, io->len, + block_acct_start(blk_get_stats(s->blk), &s->acct, io->len, BLOCK_ACCT_WRITE); break; default: @@ -415,7 +415,7 @@ static void pmac_ide_flush(DBDMA_io *io) MACIOIDEState *m = io->opaque; if (m->aiocb) { - bdrv_drain_all(); + blk_drain_all(); } } @@ -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); diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c index 15671b8..ed85185 100644 --- a/hw/ide/microdrive.c +++ b/hw/ide/microdrive.c @@ -25,7 +25,7 @@ #include <hw/hw.h> #include <hw/i386/pc.h> #include <hw/pcmcia.h> -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/dma.h" #include <hw/ide/internal.h> @@ -247,7 +247,7 @@ static uint16_t md_common_read(PCMCIACardState *card, uint32_t at) return ide_ioport_read(&s->bus, 0x1); case 0xe: /* Alternate Status */ ifs = idebus_active_if(&s->bus); - if (ifs->bs) { + if (ifs->blk) { return ifs->status; } else { return 0; diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c index 334c8cc..b6ce62a 100644 --- a/hw/ide/mmio.c +++ b/hw/ide/mmio.c @@ -24,7 +24,7 @@ */ #include "hw/hw.h" #include "hw/sysbus.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/dma.h" #include <hw/ide/internal.h> diff --git a/hw/ide/pci.c b/hw/ide/pci.c index 2397f35..2dad50e 100644 --- a/hw/ide/pci.c +++ b/hw/ide/pci.c @@ -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/dma.h" #include <hw/ide/pci.h> @@ -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); @@ -302,7 +302,7 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val) * aio operation with preadv/pwritev. */ if (bm->bus->dma->aiocb) { - bdrv_drain_all(); + blk_drain_all(); assert(bm->bus->dma->aiocb == NULL); } bm->status &= ~BM_STATUS_DMAING; diff --git a/hw/ide/pci.h b/hw/ide/pci.h index 517711f..2e9314a 100644 --- a/hw/ide/pci.h +++ b/hw/ide/pci.h @@ -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; diff --git a/hw/ide/piix.c b/hw/ide/piix.c index 49e78a7..574b9c1 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -27,7 +27,7 @@ #include <hw/i386/pc.h> #include <hw/pci/pci.h> #include <hw/isa/isa.h> -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "sysemu/sysemu.h" #include "sysemu/dma.h" @@ -178,12 +178,13 @@ 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); + BlockBackend *blk = blk_by_legacy_dinfo(di); + DeviceState *ds = blk_get_attached_dev(blk); if (ds) { - bdrv_detach_dev(di->bdrv, ds); + blk_detach_dev(blk, ds); } - pci_ide->bus[di->bus].ifs[di->unit].bs = NULL; - drive_del(di); + pci_ide->bus[di->bus].ifs[di->unit].blk = NULL; + blk_unref(blk); } } qdev_reset_all(DEVICE(dev)); diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 9814ef0..b4f096e 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -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" @@ -72,7 +73,7 @@ static int ide_qdev_init(DeviceState *qdev) IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev); IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus); - if (!dev->conf.bs) { + if (!dev->conf.blk) { error_report("No drive specified"); goto err; } @@ -117,7 +118,7 @@ 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_by_legacy_dinfo(drive)); qdev_init_nofail(dev); return DO_UPCAST(IDEDevice, qdev, dev); } @@ -127,7 +128,7 @@ int ide_get_geometry(BusState *bus, int unit, { IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit]; - if (s->drive_kind != IDE_HD || !s->bs) { + if (s->drive_kind != IDE_HD || !s->blk) { return -1; } @@ -172,7 +173,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) } } - if (ide_init_drive(s, dev->conf.bs, kind, + if (ide_init_drive(s, dev->conf.blk, kind, dev->version, dev->serial, dev->model, dev->wwn, dev->conf.cyls, dev->conf.heads, dev->conf.secs, dev->chs_trans) < 0) { @@ -249,9 +250,9 @@ static int ide_cd_initfn(IDEDevice *dev) static int ide_drive_initfn(IDEDevice *dev) { - DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs); + 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() \ diff --git a/hw/ide/via.c b/hw/ide/via.c index 89d27b4..4d8089d 100644 --- a/hw/ide/via.c +++ b/hw/ide/via.c @@ -27,7 +27,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" diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c index 9327c53..40a1106 100644 --- a/hw/isa/pc87312.c +++ b/hw/isa/pc87312.c @@ -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_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_by_legacy_dinfo(drive)); } qdev_init_nofail(d); s->fdc.dev = isa; diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c index 5ae6cad..af0abdb 100644 --- a/hw/lm32/lm32_boards.c +++ b/hw/lm32/lm32_boards.c @@ -23,7 +23,7 @@ #include "hw/devices.h" #include "hw/boards.h" #include "hw/loader.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "elf.h" #include "lm32_hwsetup.h" #include "lm32.h" @@ -119,9 +119,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_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 +222,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_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); diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c index c8832f0..256c102 100644 --- a/hw/lm32/milkymist.c +++ b/hw/lm32/milkymist.c @@ -26,7 +26,7 @@ #include "hw/boards.h" #include "hw/loader.h" #include "elf.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "milkymist-hw.h" #include "lm32.h" #include "exec/address-spaces.h" @@ -126,9 +126,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_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); diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c index fcb51bc..48c264b 100644 --- a/hw/microblaze/petalogix_ml605_mmu.c +++ b/hw/microblaze/petalogix_ml605_mmu.c @@ -32,7 +32,7 @@ #include "sysemu/sysemu.h" #include "hw/devices.h" #include "hw/boards.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/char/serial.h" #include "exec/address-spaces.h" #include "hw/ssi.h" @@ -113,8 +113,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_by_legacy_dinfo(dinfo) : NULL, + (64 * 1024), FLASH_SIZE >> 16, 2, 0x89, 0x18, 0x0000, 0x0, 0); diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c index 8e0fca9..84f6e74 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -30,7 +30,7 @@ #include "sysemu/sysemu.h" #include "hw/devices.h" #include "hw/boards.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "boot.h" @@ -94,8 +94,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_by_legacy_dinfo(dinfo) : NULL, + (64 * 1024), FLASH_SIZE >> 16, 1, 0x89, 0x18, 0x0000, 0x0, 1); dev = qdev_create(NULL, "xlnx.xps-intc"); diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index 29cd708..6a9ebfa 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -25,7 +25,7 @@ #include "net/net.h" #include "hw/boards.h" #include "hw/i2c/smbus.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "hw/block/flash.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c index 6c31cb8..3f33093 100644 --- a/hw/mips/mips_jazz.c +++ b/hw/mips/mips_jazz.c @@ -39,7 +39,7 @@ #include "hw/timer/mc146818rtc.h" #include "hw/timer/i8254.h" #include "hw/audio/pcspk.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "hw/sysbus.h" #include "exec/address-spaces.h" #include "sysemu/qtest.h" diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index e8e075c..5845158 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -29,7 +29,7 @@ #include "net/net.h" #include "hw/boards.h" #include "hw/i2c/smbus.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "hw/block/flash.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" @@ -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 */ @@ -1032,11 +1033,12 @@ void mips_malta_init(MachineState *machine) printf("Register parallel flash %d size " TARGET_FMT_lx " at " "addr %08llx '%s' %x\n", fl_idx, bios_size, FLASH_ADDRESS, - bdrv_get_device_name(dinfo->bdrv), fl_sectors); + blk_name(dinfo->bdrv), fl_sectors); } #endif fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios", - BIOS_SIZE, dinfo ? dinfo->bdrv : NULL, + BIOS_SIZE, + dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, 65536, fl_sectors, 4, 0x0000, 0x0000, 0x0000, 0x0000, be); bios = pflash_cfi01_get_memory(fl); diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c index 93606a4..a7fe0ce 100644 --- a/hw/mips/mips_r4k.c +++ b/hw/mips/mips_r4k.c @@ -24,7 +24,7 @@ #include "elf.h" #include "hw/timer/mc146818rtc.h" #include "hw/timer/i8254.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "sysemu/qtest.h" @@ -241,8 +241,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_by_legacy_dinfo(dinfo), + sector_len, mips_rom / sector_len, 4, 0, 0, 0, 0, be)) { fprintf(stderr, "qemu: Error registering flash memory.\n"); } diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c index 6a72ef4..10b5b2e 100644 --- a/hw/nvram/spapr_nvram.c +++ b/hw/nvram/spapr_nvram.c @@ -24,6 +24,7 @@ #include <libfdt.h> +#include "sysemu/block-backend.h" #include "sysemu/device_tree.h" #include "hw/sysbus.h" #include "hw/ppc/spapr.h" @@ -33,7 +34,7 @@ typedef struct sPAPRNVRAM { VIOsPAPRDevice sdev; uint32_t size; uint8_t *buf; - BlockDriverState *drive; + BlockBackend *blk; } sPAPRNVRAM; #define TYPE_VIO_SPAPR_NVRAM "spapr-nvram" @@ -77,8 +78,8 @@ static void rtas_nvram_fetch(PowerPCCPU *cpu, sPAPREnvironment *spapr, } membuf = cpu_physical_memory_map(buffer, &len, 1); - if (nvram->drive) { - alen = bdrv_pread(nvram->drive, offset, membuf, len); + if (nvram->blk) { + alen = blk_pread(nvram->blk, offset, membuf, len); } else { assert(nvram->buf); @@ -122,8 +123,8 @@ static void rtas_nvram_store(PowerPCCPU *cpu, sPAPREnvironment *spapr, } membuf = cpu_physical_memory_map(buffer, &len, 0); - if (nvram->drive) { - alen = bdrv_pwrite(nvram->drive, offset, membuf, len); + if (nvram->blk) { + alen = blk_pwrite(nvram->blk, offset, membuf, len); } else { assert(nvram->buf); @@ -140,8 +141,8 @@ static int spapr_nvram_init(VIOsPAPRDevice *dev) { sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(dev); - if (nvram->drive) { - nvram->size = bdrv_getlength(nvram->drive); + if (nvram->blk) { + nvram->size = blk_getlength(nvram->blk); } else { nvram->size = DEFAULT_NVRAM_SIZE; nvram->buf = g_malloc0(nvram->size); @@ -168,7 +169,7 @@ static int spapr_nvram_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off) static Property spapr_nvram_properties[] = { DEFINE_SPAPR_PROPERTIES(sPAPRNVRAM, sdev), - DEFINE_PROP_DRIVE("drive", sPAPRNVRAM, drive), + DEFINE_PROP_DRIVE("drive", sPAPRNVRAM, blk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c index 6ab28b7..0c09c72 100644 --- a/hw/pci/pci-hotplug-old.c +++ b/hw/pci/pci-hotplug-old.c @@ -33,7 +33,7 @@ #include "hw/scsi/scsi.h" #include "hw/virtio/virtio-blk.h" #include "qemu/config-file.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "qapi/error.h" static int pci_read_devaddr(Monitor *mon, const char *addr, @@ -127,8 +127,10 @@ 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, &local_err); + scsidev = scsi_bus_legacy_add_drive(scsibus, + blk_by_legacy_dinfo(dinfo), + dinfo->unit, false, -1, NULL, + &local_err); if (!scsidev) { error_report("%s", error_get_pretty(local_err)); error_free(local_err); @@ -250,7 +252,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_by_legacy_dinfo(dinfo)) < 0) { object_unparent(OBJECT(dev)); dev = NULL; break; diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h index aff2b9a..8bdba30 100644 --- a/hw/ppc/mac.h +++ b/hw/ppc/mac.h @@ -131,7 +131,7 @@ typedef struct MACIOIDEState { MemoryRegion mem; IDEBus bus; - BlockDriverAIOCB *aiocb; + BlockAIOCB *aiocb; IDEDMA dma; void *dbdma; bool dma_active; diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index 4094beb..89aee71 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -65,7 +65,7 @@ #include "sysemu/kvm.h" #include "kvm_ppc.h" #include "hw/usb.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "hw/sysbus.h" diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index ebd87fb..32c21a4 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -40,7 +40,7 @@ #include "elf.h" #include "sysemu/kvm.h" #include "kvm_ppc.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #define MAX_IDE_BUS 2 diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c index 18a4ec5..1dcea77 100644 --- a/hw/ppc/ppc405_boards.c +++ b/hw/ppc/ppc405_boards.c @@ -28,11 +28,12 @@ #include "hw/block/flash.h" #include "sysemu/sysemu.h" #include "sysemu/qtest.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "hw/boards.h" #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); + BlockBackend *blk = blk_by_legacy_dinfo(dinfo); + + bios_size = blk_getlength(blk); 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); + blk_name(blk), fl_sectors); #endif pflash_cfi02_register((uint32_t)(-bios_size), NULL, "ef405ep.bios", bios_size, - dinfo->bdrv, 65536, fl_sectors, 1, + blk, 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); + BlockBackend *blk = blk_by_legacy_dinfo(dinfo); + + bios_size = blk_getlength(blk); /* 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); + blk_name(blk), fl_sectors); #endif pflash_cfi02_register((uint32_t)(-bios_size), NULL, "taihu_405ep.bios", bios_size, - dinfo->bdrv, 65536, fl_sectors, 1, + blk, 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); + BlockBackend *blk = blk_by_legacy_dinfo(dinfo); + + bios_size = blk_getlength(blk); /* 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)); + blk_name(blk)); #endif pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size, - dinfo->bdrv, 65536, fl_sectors, 1, + blk, 65536, fl_sectors, 1, 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA, 1); fl_idx++; diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index 9f484cd..dd8433d 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -38,7 +38,7 @@ #include "hw/loader.h" #include "hw/timer/mc146818rtc.h" #include "hw/isa/pc87312.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "sysemu/arch_init.h" #include "sysemu/qtest.h" #include "exec/address-spaces.h" diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 2becc9f..45764a7 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -29,7 +29,7 @@ #include "hw/fw-path-provider.h" #include "elf.h" #include "net/net.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "kvm_ppc.h" @@ -925,7 +925,7 @@ 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_by_legacy_dinfo(dinfo)); } qdev_init_nofail(dev); diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index 0de5148..6ebd5be 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -39,7 +39,7 @@ #include "hw/ppc/ppc4xx.h" #include "ppc405.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "qapi/qmp/qerror.h" #define EPAPR_MAGIC (0x45504150) @@ -227,8 +227,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_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]; diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c index 29ecdb4..2059874 100644 --- a/hw/s390x/s390-virtio-bus.c +++ b/hw/s390x/s390-virtio-bus.c @@ -18,7 +18,7 @@ */ #include "hw/hw.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/sysemu.h" #include "hw/boards.h" #include "monitor/monitor.h" diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index af0004a..c215cd8 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -22,7 +22,7 @@ */ #include "hw/hw.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" #include "net/net.h" diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index f5ec946..1c0d913 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -10,7 +10,7 @@ */ #include "hw/hw.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" #include "net/net.h" diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index eedc992..36a04f3 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -21,6 +21,7 @@ #include "hw/hw.h" #include "hw/pci/pci.h" #include "sysemu/dma.h" +#include "sysemu/block-backend.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "qemu/iov.h" @@ -976,7 +977,6 @@ static int megasas_pd_get_info_submit(SCSIDevice *sdev, int lun, { struct mfi_pd_info *info = cmd->iov_buf; size_t dcmd_size = sizeof(struct mfi_pd_info); - BlockConf *conf = &sdev->conf; uint64_t pd_size; uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF); uint8_t cmdbuf[6]; @@ -1037,7 +1037,7 @@ static int megasas_pd_get_info_submit(SCSIDevice *sdev, int lun, info->ref.v.device_id = cpu_to_le16(sdev_id); info->state.ddf.pd_type = cpu_to_le16(MFI_PD_DDF_TYPE_IN_VD| MFI_PD_DDF_TYPE_INTF_SAS); - bdrv_get_geometry(conf->bs, &pd_size); + blk_get_geometry(sdev->conf.blk, &pd_size); info->raw_size = cpu_to_le64(pd_size); info->non_coerced_size = cpu_to_le64(pd_size); info->coerced_size = cpu_to_le64(pd_size); @@ -1100,13 +1100,12 @@ static int megasas_dcmd_ld_get_list(MegasasState *s, MegasasCmd *cmd) } QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { SCSIDevice *sdev = DO_UPCAST(SCSIDevice, qdev, kid->child); - BlockConf *conf = &sdev->conf; if (num_ld_disks >= max_ld_disks) { break; } /* Logical device size is in blocks */ - bdrv_get_geometry(conf->bs, &ld_size); + blk_get_geometry(sdev->conf.blk, &ld_size); info.ld_list[num_ld_disks].ld.v.target_id = sdev->id; info.ld_list[num_ld_disks].ld.v.lun_id = sdev->lun; info.ld_list[num_ld_disks].state = MFI_LD_STATE_OPTIMAL; @@ -1144,7 +1143,6 @@ static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun, uint8_t cdb[6]; SCSIRequest *req; ssize_t len, resid; - BlockConf *conf = &sdev->conf; uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF); uint64_t ld_size; @@ -1177,7 +1175,7 @@ static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun, info->ld_config.params.num_drives = 1; info->ld_config.params.is_consistent = 1; /* Logical device size is in blocks */ - bdrv_get_geometry(conf->bs, &ld_size); + blk_get_geometry(sdev->conf.blk, &ld_size); info->size = cpu_to_le64(ld_size); memset(info->ld_config.span, 0, sizeof(info->ld_config.span)); info->ld_config.span[0].start_block = 0; @@ -1261,7 +1259,6 @@ static int megasas_dcmd_cfg_read(MegasasState *s, MegasasCmd *cmd) QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { SCSIDevice *sdev = DO_UPCAST(SCSIDevice, qdev, kid->child); - BlockConf *conf = &sdev->conf; uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (sdev->lun & 0xFF); struct mfi_array *array; struct mfi_ld_config *ld; @@ -1269,7 +1266,7 @@ static int megasas_dcmd_cfg_read(MegasasState *s, MegasasCmd *cmd) int i; array = (struct mfi_array *)(data + array_offset); - bdrv_get_geometry(conf->bs, &pd_size); + blk_get_geometry(sdev->conf.blk, &pd_size); array->size = cpu_to_le64(pd_size); array->num_drives = 1; array->array_ref = cpu_to_le16(sdev_id); @@ -1340,7 +1337,7 @@ static int megasas_dcmd_get_properties(MegasasState *s, MegasasCmd *cmd) static int megasas_cache_flush(MegasasState *s, MegasasCmd *cmd) { - bdrv_drain_all(); + blk_drain_all(); return MFI_STAT_OK; } diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 022a524..af7707c 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -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" @@ -221,7 +222,7 @@ static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp) } /* handle legacy '-drive if=scsi,...' cmd line args */ -SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, +SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, int unit, bool removable, int bootindex, const char *serial, Error **errp) { @@ -229,7 +230,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, DeviceState *dev; Error *err = NULL; - driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk"; + driver = blk_is_sg(blk) ? "scsi-generic" : "scsi-disk"; dev = qdev_create(&bus->qbus, driver); qdev_prop_set_uint32(dev, "scsi-id", unit); if (bootindex >= 0) { @@ -242,7 +243,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, if (serial && object_property_find(OBJECT(dev), "serial", NULL)) { qdev_prop_set_string(dev, "serial", serial); } - if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) { + if (qdev_prop_set_drive(dev, "drive", blk) < 0) { error_setg(errp, "Setting drive property failed"); object_unparent(OBJECT(dev)); return NULL; @@ -270,8 +271,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_by_legacy_dinfo(dinfo), + unit, false, -1, NULL, &err); if (err != NULL) { error_report("%s", error_get_pretty(err)); error_propagate(errp, err); @@ -1753,7 +1754,7 @@ void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier) scsi_req_dequeue(req); req->io_canceled = true; if (req->aiocb) { - bdrv_aio_cancel_async(req->aiocb); + blk_aio_cancel_async(req->aiocb); } } @@ -1767,7 +1768,7 @@ void scsi_req_cancel(SCSIRequest *req) scsi_req_dequeue(req); req->io_canceled = true; if (req->aiocb) { - bdrv_aio_cancel(req->aiocb); + blk_aio_cancel(req->aiocb); } } diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index ae9e08d..010eefd 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -33,6 +33,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0) #include "hw/scsi/scsi.h" #include "block/scsi.h" #include "sysemu/sysemu.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/block/block.h" #include "sysemu/dma.h" @@ -111,7 +112,7 @@ static uint32_t scsi_init_iovec(SCSIDiskReq *r, size_t size) if (!r->iov.iov_base) { r->buflen = size; - r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen); + r->iov.iov_base = blk_blockalign(s->qdev.conf.blk, r->buflen); } r->iov.iov_len = MIN(r->sector_count * 512, r->buflen); qemu_iovec_init_external(&r->qiov, &r->iov, 1); @@ -166,7 +167,7 @@ static void scsi_aio_complete(void *opaque, int ret) assert(r->req.aiocb != NULL); r->req.aiocb = NULL; - block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct); + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); goto done; @@ -220,9 +221,9 @@ static void scsi_write_do_fua(SCSIDiskReq *r) } if (scsi_is_cmd_fua(&r->req.cmd)) { - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, BLOCK_ACCT_FLUSH); - r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r); + r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete, r); return; } @@ -239,7 +240,7 @@ static void scsi_dma_complete_noio(void *opaque, int ret) if (r->req.aiocb != NULL) { r->req.aiocb = NULL; - block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct); + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); } if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); @@ -281,7 +282,7 @@ static void scsi_read_complete(void * opaque, int ret) assert(r->req.aiocb != NULL); r->req.aiocb = NULL; - block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct); + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); goto done; @@ -313,7 +314,7 @@ static void scsi_do_read(void *opaque, int ret) if (r->req.aiocb != NULL) { r->req.aiocb = NULL; - block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct); + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); } if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); @@ -330,16 +331,16 @@ static void scsi_do_read(void *opaque, int ret) scsi_req_ref(&r->req); if (r->req.sg) { - dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BLOCK_ACCT_READ); + dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_READ); r->req.resid -= r->req.sg->size; - r->req.aiocb = dma_bdrv_read(s->qdev.conf.bs, r->req.sg, r->sector, - scsi_dma_complete, r); + r->req.aiocb = dma_blk_read(s->qdev.conf.blk, r->req.sg, r->sector, + scsi_dma_complete, r); } else { n = scsi_init_iovec(r, SCSI_DMA_BUF_SIZE); - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ); - r->req.aiocb = bdrv_aio_readv(s->qdev.conf.bs, r->sector, &r->qiov, n, - scsi_read_complete, r); + r->req.aiocb = blk_aio_readv(s->qdev.conf.blk, r->sector, &r->qiov, n, + scsi_read_complete, r); } done: @@ -379,9 +380,9 @@ static void scsi_read_data(SCSIRequest *req) first = !r->started; r->started = true; if (first && scsi_is_cmd_fua(&r->req.cmd)) { - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, BLOCK_ACCT_FLUSH); - r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_do_read, r); + r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_do_read, r); } else { scsi_do_read(r, 0); } @@ -398,7 +399,8 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error) { bool is_read = (r->req.cmd.xfer == SCSI_XFER_FROM_DEV); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); - BlockErrorAction action = bdrv_get_error_action(s->qdev.conf.bs, is_read, error); + BlockErrorAction action = blk_get_error_action(s->qdev.conf.blk, + is_read, error); if (action == BLOCK_ERROR_ACTION_REPORT) { switch (error) { @@ -419,7 +421,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error) break; } } - bdrv_error_action(s->qdev.conf.bs, action, is_read, error); + blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action == BLOCK_ERROR_ACTION_STOP) { scsi_req_retry(&r->req); } @@ -434,7 +436,7 @@ static void scsi_write_complete(void * opaque, int ret) if (r->req.aiocb != NULL) { r->req.aiocb = NULL; - block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct); + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); } if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); @@ -502,16 +504,16 @@ static void scsi_write_data(SCSIRequest *req) } if (r->req.sg) { - dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BLOCK_ACCT_WRITE); + dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_WRITE); r->req.resid -= r->req.sg->size; - r->req.aiocb = dma_bdrv_write(s->qdev.conf.bs, r->req.sg, r->sector, - scsi_dma_complete, r); + r->req.aiocb = dma_blk_write(s->qdev.conf.blk, r->req.sg, r->sector, + scsi_dma_complete, r); } else { n = r->qiov.size / 512; - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE); - r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, r->sector, &r->qiov, n, - scsi_write_complete, r); + r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, r->sector, &r->qiov, n, + scsi_write_complete, r); } } @@ -578,7 +580,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) case 0x83: /* Device identification page, mandatory */ { - const char *str = s->serial ?: bdrv_get_device_name(s->qdev.conf.bs); + const char *str = s->serial ?: blk_name(s->qdev.conf.blk); int max_len = s->serial ? 20 : 255 - 8; int id_len = strlen(str); @@ -739,10 +741,10 @@ static inline bool media_is_dvd(SCSIDiskState *s) if (s->qdev.type != TYPE_ROM) { return false; } - if (!bdrv_is_inserted(s->qdev.conf.bs)) { + if (!blk_is_inserted(s->qdev.conf.blk)) { return false; } - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); return nb_sectors > CD_MAX_SECTORS; } @@ -752,10 +754,10 @@ static inline bool media_is_cd(SCSIDiskState *s) if (s->qdev.type != TYPE_ROM) { return false; } - if (!bdrv_is_inserted(s->qdev.conf.bs)) { + if (!blk_is_inserted(s->qdev.conf.blk)) { return false; } - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); return nb_sectors <= CD_MAX_SECTORS; } @@ -816,7 +818,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r, } if (format != 0xff) { - if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) { + if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) { scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); return -1; } @@ -838,7 +840,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r, if (layer != 0) { goto fail; } - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); outbuf[4] = 1; /* DVD-ROM, part version 1 */ outbuf[5] = 0xf; /* 120mm disc, minimum rate unspecified */ @@ -893,7 +895,7 @@ static int scsi_event_status_media(SCSIDiskState *s, uint8_t *outbuf) media_status = 0; if (s->tray_open) { media_status = MS_TRAY_OPEN; - } else if (bdrv_is_inserted(s->qdev.conf.bs)) { + } else if (blk_is_inserted(s->qdev.conf.blk)) { media_status = MS_MEDIA_PRESENT; } @@ -1091,7 +1093,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, case MODE_PAGE_CACHING: length = 0x12; if (page_control == 1 || /* Changeable Values */ - bdrv_enable_write_cache(s->qdev.conf.bs)) { + blk_enable_write_cache(s->qdev.conf.blk)) { p[0] = 4; /* WCE */ } break; @@ -1172,7 +1174,7 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) if (s->qdev.type == TYPE_DISK) { dev_specific_param = s->features & (1 << SCSI_DISK_F_DPOFUA) ? 0x10 : 0; - if (bdrv_is_read_only(s->qdev.conf.bs)) { + if (blk_is_read_only(s->qdev.conf.blk)) { dev_specific_param |= 0x80; /* Readonly. */ } } else { @@ -1194,7 +1196,7 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) p += 8; } - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); if (!dbd && nb_sectors) { if (r->req.cmd.buf[0] == MODE_SENSE) { outbuf[3] = 8; /* Block descriptor length */ @@ -1257,7 +1259,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf) msf = req->cmd.buf[1] & 2; format = req->cmd.buf[2] & 0xf; start_track = req->cmd.buf[6]; - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, format, msf >> 1); nb_sectors /= s->qdev.blocksize / 512; switch (format) { @@ -1297,14 +1299,14 @@ static int scsi_disk_emulate_start_stop(SCSIDiskReq *r) if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && loej) { if (!start && !s->tray_open && s->tray_locked) { scsi_check_condition(r, - bdrv_is_inserted(s->qdev.conf.bs) + blk_is_inserted(s->qdev.conf.blk) ? SENSE_CODE(ILLEGAL_REQ_REMOVAL_PREVENTED) : SENSE_CODE(NOT_READY_REMOVAL_PREVENTED)); return -1; } if (s->tray_open != !start) { - bdrv_eject(s->qdev.conf.bs, !start); + blk_eject(s->qdev.conf.blk, !start); s->tray_open = !start; } } @@ -1371,7 +1373,7 @@ static void scsi_disk_apply_mode_select(SCSIDiskState *s, int page, uint8_t *p) { switch (page) { case MODE_PAGE_CACHING: - bdrv_set_enable_write_cache(s->qdev.conf.bs, (p[0] & 4) != 0); + blk_set_enable_write_cache(s->qdev.conf.blk, (p[0] & 4) != 0); break; default: @@ -1474,12 +1476,12 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, uint8_t *inbuf) return; } } - if (!bdrv_enable_write_cache(s->qdev.conf.bs)) { + if (!blk_enable_write_cache(s->qdev.conf.blk)) { /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, BLOCK_ACCT_FLUSH); - r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r); + r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete, r); return; } @@ -1548,10 +1550,10 @@ static void scsi_unmap_complete(void *opaque, int ret) goto done; } - r->req.aiocb = bdrv_aio_discard(s->qdev.conf.bs, - sector_num * (s->qdev.blocksize / 512), - nb_sectors * (s->qdev.blocksize / 512), - scsi_unmap_complete, data); + r->req.aiocb = blk_aio_discard(s->qdev.conf.blk, + sector_num * (s->qdev.blocksize / 512), + nb_sectors * (s->qdev.blocksize / 512), + scsi_unmap_complete, data); data->count--; data->inbuf += 16; return; @@ -1589,7 +1591,7 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf) goto invalid_param_len; } - if (bdrv_is_read_only(s->qdev.conf.bs)) { + if (blk_is_read_only(s->qdev.conf.blk)) { scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED)); return; } @@ -1628,7 +1630,7 @@ static void scsi_write_same_complete(void *opaque, int ret) assert(r->req.aiocb != NULL); r->req.aiocb = NULL; - block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct); + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); goto done; @@ -1644,11 +1646,11 @@ static void scsi_write_same_complete(void *opaque, int ret) data->sector += data->iov.iov_len / 512; data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len); if (data->iov.iov_len) { - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, data->iov.iov_len, BLOCK_ACCT_WRITE); - r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector, - &data->qiov, data->iov.iov_len / 512, - scsi_write_same_complete, data); + r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, data->sector, + &data->qiov, data->iov.iov_len / 512, + scsi_write_same_complete, data); return; } @@ -1675,7 +1677,7 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf) return; } - if (bdrv_is_read_only(s->qdev.conf.bs)) { + if (blk_is_read_only(s->qdev.conf.blk)) { scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED)); return; } @@ -1689,13 +1691,13 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf) /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, nb_sectors * s->qdev.blocksize, BLOCK_ACCT_WRITE); - r->req.aiocb = bdrv_aio_write_zeroes(s->qdev.conf.bs, - r->req.cmd.lba * (s->qdev.blocksize / 512), - nb_sectors * (s->qdev.blocksize / 512), - flags, scsi_aio_complete, r); + r->req.aiocb = blk_aio_write_zeroes(s->qdev.conf.blk, + r->req.cmd.lba * (s->qdev.blocksize / 512), + nb_sectors * (s->qdev.blocksize / 512), + flags, scsi_aio_complete, r); return; } @@ -1704,7 +1706,8 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf) data->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); data->nb_sectors = nb_sectors * (s->qdev.blocksize / 512); data->iov.iov_len = MIN(data->nb_sectors * 512, SCSI_WRITE_SAME_MAX); - data->iov.iov_base = buf = qemu_blockalign(s->qdev.conf.bs, data->iov.iov_len); + data->iov.iov_base = buf = blk_blockalign(s->qdev.conf.blk, + data->iov.iov_len); qemu_iovec_init_external(&data->qiov, &data->iov, 1); for (i = 0; i < data->iov.iov_len; i += s->qdev.blocksize) { @@ -1712,11 +1715,11 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf) } scsi_req_ref(&r->req); - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, data->iov.iov_len, BLOCK_ACCT_WRITE); - r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector, - &data->qiov, data->iov.iov_len / 512, - scsi_write_same_complete, data); + r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, data->sector, + &data->qiov, data->iov.iov_len / 512, + scsi_write_same_complete, data); } static void scsi_disk_emulate_write_data(SCSIRequest *req) @@ -1785,7 +1788,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) break; default: - if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) { + if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) { scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); return 0; } @@ -1806,7 +1809,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) r->buflen = MAX(4096, req->cmd.xfer); if (!r->iov.iov_base) { - r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen); + r->iov.iov_base = blk_blockalign(s->qdev.conf.blk, r->buflen); } buflen = req->cmd.xfer; @@ -1814,7 +1817,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) memset(outbuf, 0, r->buflen); switch (req->cmd.buf[0]) { case TEST_UNIT_READY: - assert(!s->tray_open && bdrv_is_inserted(s->qdev.conf.bs)); + assert(!s->tray_open && blk_is_inserted(s->qdev.conf.blk)); break; case INQUIRY: buflen = scsi_disk_emulate_inquiry(req, outbuf); @@ -1862,12 +1865,12 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) break; case ALLOW_MEDIUM_REMOVAL: s->tray_locked = req->cmd.buf[4] & 1; - bdrv_lock_medium(s->qdev.conf.bs, req->cmd.buf[4] & 1); + blk_lock_medium(s->qdev.conf.blk, req->cmd.buf[4] & 1); break; case READ_CAPACITY_10: /* The normal LEN field for this command is zero. */ memset(outbuf, 0, 8); - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); if (!nb_sectors) { scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY)); return 0; @@ -1936,7 +1939,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) if ((req->cmd.buf[1] & 31) == SAI_READ_CAPACITY_16) { DPRINTF("SAI READ CAPACITY(16)\n"); memset(outbuf, 0, req->cmd.xfer); - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); if (!nb_sectors) { scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY)); return 0; @@ -1977,9 +1980,9 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) case SYNCHRONIZE_CACHE: /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); - block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0, + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, BLOCK_ACCT_FLUSH); - r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r); + r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete, r); return 0; case SEEK_10: DPRINTF("Seek(10) (sector %" PRId64 ")\n", r->req.cmd.lba); @@ -2053,7 +2056,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf) command = buf[0]; - if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) { + if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) { scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); return 0; } @@ -2081,7 +2084,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf) case WRITE_VERIFY_10: case WRITE_VERIFY_12: case WRITE_VERIFY_16: - if (bdrv_is_read_only(s->qdev.conf.bs)) { + if (blk_is_read_only(s->qdev.conf.blk)) { scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED)); return 0; } @@ -2124,7 +2127,7 @@ static void scsi_disk_reset(DeviceState *dev) scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET)); - bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); + blk_get_geometry(s->qdev.conf.blk, &nb_sectors); nb_sectors /= s->qdev.blocksize / 512; if (nb_sectors) { nb_sectors--; @@ -2140,7 +2143,7 @@ static void scsi_unrealize(SCSIDevice *dev, Error **errp) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); scsi_device_purge_requests(&s->qdev, SENSE_CODE(NO_SENSE)); - blockdev_mark_auto_del(s->qdev.conf.bs); + blockdev_mark_auto_del(s->qdev.conf.blk); } static void scsi_disk_resize_cb(void *opaque) @@ -2223,13 +2226,13 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); Error *err = NULL; - if (!s->qdev.conf.bs) { + if (!s->qdev.conf.blk) { error_setg(errp, "drive property not set"); return; } if (!(s->features & (1 << SCSI_DISK_F_REMOVABLE)) && - !bdrv_is_inserted(s->qdev.conf.bs)) { + !blk_is_inserted(s->qdev.conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); return; } @@ -2255,20 +2258,20 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) s->vendor = g_strdup("QEMU"); } - if (bdrv_is_sg(s->qdev.conf.bs)) { + if (blk_is_sg(s->qdev.conf.blk)) { error_setg(errp, "unwanted /dev/sg*"); return; } if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && !(s->features & (1 << SCSI_DISK_F_NO_REMOVABLE_DEVOPS))) { - bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_removable_block_ops, s); + blk_set_dev_ops(s->qdev.conf.blk, &scsi_disk_removable_block_ops, s); } else { - bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s); + blk_set_dev_ops(s->qdev.conf.blk, &scsi_disk_block_ops, s); } - bdrv_set_guest_block_size(s->qdev.conf.bs, s->qdev.blocksize); + blk_set_guest_block_size(s->qdev.conf.blk, s->qdev.blocksize); - bdrv_iostatus_enable(s->qdev.conf.bs); + blk_iostatus_enable(s->qdev.conf.blk); } static void scsi_hd_realize(SCSIDevice *dev, Error **errp) @@ -2299,15 +2302,15 @@ static void scsi_disk_realize(SCSIDevice *dev, Error **errp) DriveInfo *dinfo; Error *local_err = NULL; - if (!dev->conf.bs) { + if (!dev->conf.blk) { scsi_realize(dev, &local_err); assert(local_err); error_propagate(errp, local_err); return; } - dinfo = drive_get_by_blockdev(dev->conf.bs); - if (dinfo->media_cd) { + dinfo = blk_legacy_dinfo(dev->conf.blk); + if (dinfo && dinfo->media_cd) { scsi_cd_realize(dev, errp); } else { scsi_hd_realize(dev, errp); @@ -2406,7 +2409,6 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun, #ifdef __linux__ static int get_device_type(SCSIDiskState *s) { - BlockDriverState *bdrv = s->qdev.conf.bs; uint8_t cmd[16]; uint8_t buf[36]; uint8_t sensebuf[8]; @@ -2429,7 +2431,7 @@ static int get_device_type(SCSIDiskState *s) io_header.sbp = sensebuf; io_header.timeout = 6000; /* XXX */ - ret = bdrv_ioctl(bdrv, SG_IO, &io_header); + ret = blk_ioctl(s->qdev.conf.blk, SG_IO, &io_header); if (ret < 0 || io_header.driver_status || io_header.host_status) { return -1; } @@ -2446,13 +2448,13 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) int sg_version; int rc; - if (!s->qdev.conf.bs) { + if (!s->qdev.conf.blk) { error_setg(errp, "drive property not set"); return; } /* check we are using a driver managing SG_IO (version 3 and after) */ - rc = bdrv_ioctl(s->qdev.conf.bs, SG_GET_VERSION_NUM, &sg_version); + rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); if (rc < 0) { error_setg(errp, "cannot get SG_IO version number: %s. " "Is this a SCSI device?", @@ -2511,7 +2513,7 @@ static bool scsi_block_is_passthrough(SCSIDiskState *s, uint8_t *buf) * ones (such as WRITE SAME or EXTENDED COPY, etc.). So, without * O_DIRECT everything must go through SG_IO. */ - if (!(bdrv_get_flags(s->qdev.conf.bs) & BDRV_O_NOCACHE)) { + if (!(blk_get_flags(s->qdev.conf.blk) & BDRV_O_NOCACHE)) { break; } @@ -2660,7 +2662,7 @@ static const TypeInfo scsi_cd_info = { #ifdef __linux__ static Property scsi_block_properties[] = { - DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.bs), + DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 84a1d5b..f2e53af 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -14,6 +14,7 @@ #include "qemu-common.h" #include "qemu/error-report.h" #include "hw/scsi/scsi.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #ifdef __linux__ @@ -141,9 +142,9 @@ done: scsi_req_unref(&r->req); } -static int execute_command(BlockDriverState *bdrv, +static int execute_command(BlockBackend *blk, SCSIGenericReq *r, int direction, - BlockDriverCompletionFunc *complete) + BlockCompletionFunc *complete) { r->io_header.interface_id = 'S'; r->io_header.dxfer_direction = direction; @@ -157,7 +158,7 @@ static int execute_command(BlockDriverState *bdrv, r->io_header.usr_ptr = r; r->io_header.flags |= SG_FLAG_DIRECT_IO; - r->req.aiocb = bdrv_aio_ioctl(bdrv, SG_IO, &r->io_header, complete, r); + r->req.aiocb = blk_aio_ioctl(blk, SG_IO, &r->io_header, complete, r); if (r->req.aiocb == NULL) { return -EIO; } @@ -193,7 +194,7 @@ static void scsi_read_complete(void * opaque, int ret) s->blocksize = ldl_be_p(&r->buf[8]); s->max_lba = ldq_be_p(&r->buf[0]); } - bdrv_set_guest_block_size(s->conf.bs, s->blocksize); + blk_set_guest_block_size(s->conf.blk, s->blocksize); scsi_req_data(&r->req, len); scsi_req_unref(&r->req); @@ -216,7 +217,8 @@ static void scsi_read_data(SCSIRequest *req) return; } - ret = execute_command(s->conf.bs, r, SG_DXFER_FROM_DEV, scsi_read_complete); + ret = execute_command(s->conf.blk, r, SG_DXFER_FROM_DEV, + scsi_read_complete); if (ret < 0) { scsi_command_complete(r, ret); } @@ -260,7 +262,7 @@ static void scsi_write_data(SCSIRequest *req) /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); - ret = execute_command(s->conf.bs, r, SG_DXFER_TO_DEV, scsi_write_complete); + ret = execute_command(s->conf.blk, r, SG_DXFER_TO_DEV, scsi_write_complete); if (ret < 0) { scsi_command_complete(r, ret); } @@ -302,7 +304,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd) r->buf = NULL; /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); - ret = execute_command(s->conf.bs, r, SG_DXFER_NONE, scsi_command_complete); + ret = execute_command(s->conf.blk, r, SG_DXFER_NONE, + scsi_command_complete); if (ret < 0) { scsi_command_complete(r, ret); return 0; @@ -327,7 +330,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd) } } -static int get_stream_blocksize(BlockDriverState *bdrv) +static int get_stream_blocksize(BlockBackend *blk) { uint8_t cmd[6]; uint8_t buf[12]; @@ -351,7 +354,7 @@ static int get_stream_blocksize(BlockDriverState *bdrv) io_header.sbp = sensebuf; io_header.timeout = 6000; /* XXX */ - ret = bdrv_ioctl(bdrv, SG_IO, &io_header); + ret = blk_ioctl(blk, SG_IO, &io_header); if (ret < 0 || io_header.driver_status || io_header.host_status) { return -1; } @@ -368,7 +371,7 @@ static void scsi_generic_reset(DeviceState *dev) static void scsi_unrealize(SCSIDevice *s, Error **errp) { scsi_device_purge_requests(s, SENSE_CODE(NO_SENSE)); - blockdev_mark_auto_del(s->conf.bs); + blockdev_mark_auto_del(s->conf.blk); } static void scsi_generic_realize(SCSIDevice *s, Error **errp) @@ -377,22 +380,22 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp) int sg_version; struct sg_scsi_id scsiid; - if (!s->conf.bs) { + if (!s->conf.blk) { error_setg(errp, "drive property not set"); return; } - if (bdrv_get_on_error(s->conf.bs, 0) != BLOCKDEV_ON_ERROR_ENOSPC) { + if (blk_get_on_error(s->conf.blk, 0) != BLOCKDEV_ON_ERROR_ENOSPC) { error_setg(errp, "Device doesn't support drive option werror"); return; } - if (bdrv_get_on_error(s->conf.bs, 1) != BLOCKDEV_ON_ERROR_REPORT) { + if (blk_get_on_error(s->conf.blk, 1) != BLOCKDEV_ON_ERROR_REPORT) { error_setg(errp, "Device doesn't support drive option rerror"); return; } /* check we are using a driver managing SG_IO (version 3 and after */ - rc = bdrv_ioctl(s->conf.bs, SG_GET_VERSION_NUM, &sg_version); + rc = blk_ioctl(s->conf.blk, SG_GET_VERSION_NUM, &sg_version); if (rc < 0) { error_setg(errp, "cannot get SG_IO version number: %s. " "Is this a SCSI device?", @@ -405,7 +408,7 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp) } /* get LUN of the /dev/sg? */ - if (bdrv_ioctl(s->conf.bs, SG_GET_SCSI_ID, &scsiid)) { + if (blk_ioctl(s->conf.blk, SG_GET_SCSI_ID, &scsiid)) { error_setg(errp, "SG_GET_SCSI_ID ioctl failed"); return; } @@ -416,7 +419,7 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp) switch (s->type) { case TYPE_TAPE: - s->blocksize = get_stream_blocksize(s->conf.bs); + s->blocksize = get_stream_blocksize(s->conf.blk); if (s->blocksize == -1) { s->blocksize = 0; } @@ -459,7 +462,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun, } static Property scsi_generic_properties[] = { - DEFINE_PROP_DRIVE("drive", SCSIDevice, conf.bs), + DEFINE_PROP_DRIVE("drive", SCSIDevice, conf.blk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c index b778e05..48dcfd2 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -13,6 +13,7 @@ #include "hw/virtio/virtio-scsi.h" #include "qemu/error-report.h" +#include "sysemu/block-backend.h" #include <hw/scsi/scsi.h> #include <block/scsi.h> #include <hw/virtio/virtio-bus.h> @@ -205,7 +206,7 @@ void virtio_scsi_dataplane_stop(VirtIOSCSI *s) aio_set_event_notifier(s->ctx, &s->cmd_vrings[i]->host_notifier, NULL); } - bdrv_drain_all(); /* ensure there are no in-flight requests */ + blk_drain_all(); /* ensure there are no in-flight requests */ aio_context_release(s->ctx); diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 8547ea0..a1725b8 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -16,6 +16,7 @@ #include "hw/virtio/virtio-scsi.h" #include "qemu/error-report.h" #include "qemu/iov.h" +#include "sysemu/block-backend.h" #include <hw/scsi/scsi.h> #include <block/scsi.h> #include <hw/virtio/virtio-bus.h> @@ -236,9 +237,9 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) int target; int ret = 0; - if (s->dataplane_started && bdrv_get_aio_context(d->conf.bs) != s->ctx) { + if (s->dataplane_started && blk_get_aio_context(d->conf.blk) != s->ctx) { aio_context_acquire(s->ctx); - bdrv_set_aio_context(d->conf.bs, s->ctx); + blk_set_aio_context(d->conf.blk, s->ctx); aio_context_release(s->ctx); } /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */ @@ -522,9 +523,9 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) virtio_scsi_complete_cmd_req(req); return false; } - if (s->dataplane_started && bdrv_get_aio_context(d->conf.bs) != s->ctx) { + if (s->dataplane_started && blk_get_aio_context(d->conf.blk) != s->ctx) { aio_context_acquire(s->ctx); - bdrv_set_aio_context(d->conf.bs, s->ctx); + blk_set_aio_context(d->conf.blk, s->ctx); aio_context_release(s->ctx); } req->sreq = scsi_req_new(d, req->req.cmd.tag, @@ -539,7 +540,7 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) return false; } scsi_req_ref(req->sreq); - bdrv_io_plug(d->conf.bs); + blk_io_plug(d->conf.blk); return true; } @@ -549,7 +550,7 @@ void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req) if (scsi_req_enqueue(sreq)) { scsi_req_continue(sreq); } - bdrv_io_unplug(sreq->dev->conf.bs); + blk_io_unplug(sreq->dev->conf.blk); scsi_req_unref(sreq); } @@ -832,7 +833,7 @@ static void virtio_scsi_migration_state_changed(Notifier *notifier, void *data) if (s->dataplane_started) { return; } - bdrv_drain_all(); /* complete in-flight non-dataplane requests */ + blk_drain_all(); /* complete in-flight non-dataplane requests */ s->dataplane_disabled = false; } } diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 2a40f92..9661eaf 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -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; + BlockBackend *blk; dinfo = drive_get_next(IF_SD); - s->card = sd_init(dinfo ? dinfo->bdrv : NULL, false); + blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + s->card = sd_init(blk, false); if (s->card == NULL) { return -1; } - s->enabled = dinfo ? bdrv_is_inserted(dinfo->bdrv) : 0; + s->enabled = blk && blk_is_inserted(blk); memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, "milkymist-memcard", R_MAX * 4); diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 6c92149..86c477d 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -574,7 +574,7 @@ static void omap_mmc_cover_cb(void *opaque, int line, int level) struct omap_mmc_s *omap_mmc_init(hwaddr base, MemoryRegion *sysmem, - BlockDriverState *bd, + BlockBackend *blk, qemu_irq irq, qemu_irq dma[], omap_clk clk) { struct omap_mmc_s *s = (struct omap_mmc_s *) @@ -592,7 +592,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base, memory_region_add_subregion(sysmem, base, &s->iomem); /* Instantiate the storage */ - s->card = sd_init(bd, false); + s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); } @@ -601,7 +601,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base, } struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, - BlockDriverState *bd, qemu_irq irq, qemu_irq dma[], + BlockBackend *blk, qemu_irq irq, qemu_irq dma[], omap_clk fclk, omap_clk iclk) { struct omap_mmc_s *s = (struct omap_mmc_s *) @@ -620,7 +620,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, omap_l4_attach(ta, 0, &s->iomem); /* Instantiate the storage */ - s->card = sd_init(bd, false); + s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); } diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index 462558b..e704b6e 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -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_by_legacy_dinfo(dinfo) : NULL, false); if (s->card == NULL) { return -1; } diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c index b9d8b1a..ac3ab39 100644 --- a/hw/sd/pxa2xx_mmci.c +++ b/hw/sd/pxa2xx_mmci.c @@ -523,7 +523,7 @@ static int pxa2xx_mmci_load(QEMUFile *f, void *opaque, int version_id) PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, hwaddr base, - BlockDriverState *bd, qemu_irq irq, + BlockBackend *blk, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma) { PXA2xxMMCIState *s; @@ -538,7 +538,7 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, memory_region_add_subregion(sysmem, base, &s->iomem); /* Instantiate the actual storage */ - s->card = sd_init(bd, false); + s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); } @@ -30,7 +30,7 @@ */ #include "hw/hw.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "hw/sd.h" #include "qemu/bitmap.h" @@ -110,7 +110,7 @@ struct SDState { uint8_t data[512]; qemu_irq readonly_cb; qemu_irq inserted_cb; - BlockDriverState *bdrv; + BlockBackend *blk; uint8_t *buf; bool enable; @@ -389,13 +389,13 @@ static inline uint64_t sd_addr_to_wpnum(uint64_t addr) return addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT); } -static void sd_reset(SDState *sd, BlockDriverState *bdrv) +static void sd_reset(SDState *sd, BlockBackend *blk) { uint64_t size; uint64_t sect; - if (bdrv) { - bdrv_get_geometry(bdrv, §); + if (blk) { + blk_get_geometry(blk, §); } else { sect = 0; } @@ -412,11 +412,11 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) sd_set_cardstatus(sd); sd_set_sdstatus(sd); - sd->bdrv = bdrv; + sd->blk = blk; if (sd->wp_groups) g_free(sd->wp_groups); - sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : false; + sd->wp_switch = blk ? blk_is_read_only(blk) : false; sd->wpgrps_size = sect; sd->wp_groups = bitmap_new(sd->wpgrps_size); memset(sd->function_group, 0, sizeof(sd->function_group)); @@ -432,9 +432,9 @@ static void sd_cardchange(void *opaque, bool load) { SDState *sd = opaque; - qemu_set_irq(sd->inserted_cb, bdrv_is_inserted(sd->bdrv)); - if (bdrv_is_inserted(sd->bdrv)) { - sd_reset(sd, sd->bdrv); + qemu_set_irq(sd->inserted_cb, blk_is_inserted(sd->blk)); + if (blk_is_inserted(sd->blk)) { + sd_reset(sd, sd->blk); qemu_set_irq(sd->readonly_cb, sd->wp_switch); } } @@ -479,23 +479,23 @@ static const VMStateDescription sd_vmstate = { whether card should be in SSI or MMC/SD mode. It is also up to the board to ensure that ssi transfers only occur when the chip select is asserted. */ -SDState *sd_init(BlockDriverState *bs, bool is_spi) +SDState *sd_init(BlockBackend *blk, bool is_spi) { SDState *sd; - if (bs && bdrv_is_read_only(bs)) { + if (blk && blk_is_read_only(blk)) { fprintf(stderr, "sd_init: Cannot use read-only drive\n"); return NULL; } sd = (SDState *) g_malloc0(sizeof(SDState)); - sd->buf = qemu_blockalign(bs, 512); + sd->buf = blk_blockalign(blk, 512); sd->spi = is_spi; sd->enable = true; - sd_reset(sd, bs); - if (sd->bdrv) { - bdrv_attach_dev_nofail(sd->bdrv, sd); - bdrv_set_dev_ops(sd->bdrv, &sd_block_ops, sd); + sd_reset(sd, blk); + if (sd->blk) { + blk_attach_dev_nofail(sd->blk, sd); + blk_set_dev_ops(sd->blk, &sd_block_ops, sd); } vmstate_register(NULL, -1, &sd_vmstate, sd); return sd; @@ -505,8 +505,8 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) { sd->readonly_cb = readonly; sd->inserted_cb = insert; - qemu_set_irq(readonly, sd->bdrv ? bdrv_is_read_only(sd->bdrv) : 0); - qemu_set_irq(insert, sd->bdrv ? bdrv_is_inserted(sd->bdrv) : 0); + qemu_set_irq(readonly, sd->blk ? blk_is_read_only(sd->blk) : 0); + qemu_set_irq(insert, sd->blk ? blk_is_inserted(sd->blk) : 0); } static void sd_erase(SDState *sd) @@ -680,7 +680,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, default: sd->state = sd_idle_state; - sd_reset(sd, sd->bdrv); + sd_reset(sd, sd->blk); return sd->spi ? sd_r1 : sd_r0; } break; @@ -1347,7 +1347,7 @@ int sd_do_command(SDState *sd, SDRequest *req, sd_rsp_type_t rtype; int rsplen; - if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) { + if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) { return 0; } @@ -1456,7 +1456,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) DPRINTF("sd_blk_read: addr = 0x%08llx, len = %d\n", (unsigned long long) addr, len); - if (!sd->bdrv || bdrv_read(sd->bdrv, addr >> 9, sd->buf, 1) < 0) { + if (!sd->blk || blk_read(sd->blk, addr >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); return; } @@ -1464,7 +1464,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) if (end > (addr & ~511) + 512) { memcpy(sd->data, sd->buf + (addr & 511), 512 - (addr & 511)); - if (bdrv_read(sd->bdrv, end >> 9, sd->buf, 1) < 0) { + if (blk_read(sd->blk, end >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); return; } @@ -1478,29 +1478,29 @@ static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) uint64_t end = addr + len; if ((addr & 511) || len < 512) - if (!sd->bdrv || bdrv_read(sd->bdrv, addr >> 9, sd->buf, 1) < 0) { + if (!sd->blk || blk_read(sd->blk, addr >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_write: read error on host side\n"); return; } if (end > (addr & ~511) + 512) { memcpy(sd->buf + (addr & 511), sd->data, 512 - (addr & 511)); - if (bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) < 0) { + if (blk_write(sd->blk, addr >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); return; } - if (bdrv_read(sd->bdrv, end >> 9, sd->buf, 1) < 0) { + if (blk_read(sd->blk, end >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_write: read error on host side\n"); return; } memcpy(sd->buf, sd->data + 512 - (addr & 511), end & 511); - if (bdrv_write(sd->bdrv, end >> 9, sd->buf, 1) < 0) { + if (blk_write(sd->blk, end >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); } } else { memcpy(sd->buf + (addr & 511), sd->data, len); - if (!sd->bdrv || bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) < 0) { + if (!sd->blk || blk_write(sd->blk, addr >> 9, sd->buf, 1) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); } } @@ -1515,7 +1515,7 @@ void sd_write_data(SDState *sd, uint8_t value) { int i; - if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) + if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) return; if (sd->state != sd_receivingdata_state) { @@ -1641,7 +1641,7 @@ uint8_t sd_read_data(SDState *sd) uint8_t ret; int io_len; - if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) + if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) return 0x00; if (sd->state != sd_sendingdata_state) { diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index f9fe700..b380050 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -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_by_legacy_dinfo(di) : NULL, false); if (s->card == NULL) { exit(1); } diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index b012e57..a71fbca 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -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_by_legacy_dinfo(dinfo) : NULL, true); if (s->sd == NULL) { return -1; } diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c index 321379e..12f44d2 100644 --- a/hw/sh4/r2d.c +++ b/hw/sh4/r2d.c @@ -36,7 +36,7 @@ #include "hw/loader.h" #include "hw/usb.h" #include "hw/block/flash.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #define FLASH_BASE 0x00000000 @@ -290,8 +290,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_by_legacy_dinfo(dinfo) : NULL, + (16 * 1024), FLASH_SIZE >> 16, 1, 4, 0x0000, 0x0000, 0x0000, 0x0000, 0x555, 0x2aa, 0); diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 2feab35..8273199 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -40,7 +40,7 @@ #include "hw/empty_slot.h" #include "hw/loader.h" #include "elf.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "trace.h" /* diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 871a0ea..f42112c 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -38,7 +38,7 @@ #include "hw/ide.h" #include "hw/loader.h" #include "elf.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" //#define DEBUG_IRQ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 82747ee..c0e7cd7 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -21,7 +21,7 @@ #include "sysemu/tpm_backend.h" #include "tpm_int.h" -#include "block/block.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "hw/hw.h" #include "hw/i386/pc.h" diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c index 605de86..eeb4922 100644 --- a/hw/tricore/tricore_testboard.c +++ b/hw/tricore/tricore_testboard.c @@ -24,7 +24,7 @@ #include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/loader.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "exec/address-spaces.h" #include "hw/block/flash.h" #include "elf.h" diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 5bfc72c..4539733 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -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" #include "qapi/visitor.h" @@ -600,11 +601,11 @@ static const struct SCSIBusInfo usb_msd_scsi_info_bot = { static void usb_msd_realize_storage(USBDevice *dev, Error **errp) { MSDState *s = DO_UPCAST(MSDState, dev, dev); - BlockDriverState *bs = s->conf.bs; + BlockBackend *blk = s->conf.blk; SCSIDevice *scsi_dev; Error *err = NULL; - if (!bs) { + if (!blk) { error_setg(errp, "drive property not set"); return; } @@ -620,14 +621,14 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) * * The hack is probably a bad idea. */ - bdrv_detach_dev(bs, &s->dev.qdev); - s->conf.bs = NULL; + blk_detach_dev(blk, &s->dev.qdev); + s->conf.blk = NULL; usb_desc_create_serial(dev); usb_desc_init(dev); scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_storage, NULL); - scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable, + scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable, s->conf.bootindex, dev->serial, &err); if (!scsi_dev) { @@ -637,9 +638,10 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) usb_msd_handle_reset(dev); s->scsi_dev = scsi_dev; - if (bdrv_key_required(bs)) { + if (bdrv_key_required(blk_bs(blk))) { if (cur_mon) { - monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb, s); + monitor_read_bdrv_key_start(cur_mon, blk_bs(blk), + usb_msd_password_cb, s); s->dev.auto_attach = 0; } else { autostart = 0; @@ -707,7 +709,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_by_legacy_dinfo(dinfo)) < 0) { object_unparent(OBJECT(dev)); return NULL; } diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index ae7fef9..542fb9e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -29,7 +29,7 @@ #include "hw/pci/msix.h" #include "hw/loader.h" #include "sysemu/kvm.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "virtio-pci.h" #include "qemu/range.h" #include "hw/virtio/virtio-bus.h" diff --git a/hw/xen/xen_devconfig.c b/hw/xen/xen_devconfig.c index fa998ef..e138dbb 100644 --- a/hw/xen/xen_devconfig.c +++ b/hw/xen/xen_devconfig.c @@ -1,4 +1,5 @@ #include "hw/xen/xen_backend.h" +#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" /* ------------------------------------------------------------- */ diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c index 3150064..2e545d2 100644 --- a/hw/xenpv/xen_machine_pv.c +++ b/hw/xenpv/xen_machine_pv.c @@ -26,7 +26,7 @@ #include "hw/boards.h" #include "hw/xen/xen_backend.h" #include "xen_domainbuild.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" static void xen_init_pv(MachineState *machine) { diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c index ed06ff7..0100c31 100644 --- a/hw/xtensa/xtfpga.c +++ b/hw/xtensa/xtfpga.c @@ -35,7 +35,7 @@ #include "net/net.h" #include "hw/sysbus.h" #include "hw/block/flash.h" -#include "sysemu/blockdev.h" +#include "sysemu/block-backend.h" #include "sysemu/char.h" #include "sysemu/device_tree.h" #include "qemu/error-report.h" @@ -230,7 +230,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_by_legacy_dinfo(dinfo), + board->flash_sector_size, board->flash_size / board->flash_sector_size, 4, 0x0000, 0x0000, 0x0000, 0x0000, be); if (flash == NULL) { |