diff options
Diffstat (limited to 'hw/block')
-rw-r--r-- | hw/block/block.c | 7 | ||||
-rw-r--r-- | hw/block/dataplane/virtio-blk.c | 24 | ||||
-rw-r--r-- | hw/block/fdc.c | 78 | ||||
-rw-r--r-- | hw/block/hd-geometry.c | 24 | ||||
-rw-r--r-- | hw/block/m25p80.c | 28 | ||||
-rw-r--r-- | hw/block/nand.c | 50 | ||||
-rw-r--r-- | hw/block/nvme.c | 19 | ||||
-rw-r--r-- | hw/block/onenand.c | 67 | ||||
-rw-r--r-- | hw/block/pflash_cfi01.c | 24 | ||||
-rw-r--r-- | hw/block/pflash_cfi02.c | 24 | ||||
-rw-r--r-- | hw/block/virtio-blk.c | 95 | ||||
-rw-r--r-- | hw/block/xen_disk.c | 69 |
12 files changed, 257 insertions, 252 deletions
diff --git a/hw/block/block.c b/hw/block/block.c index b6a6dc6..0666dd3 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,7 +18,7 @@ void blkconf_serial(BlockConf *conf, char **serial) if (!*serial) { /* try to fall back to value set with legacy -drive serial=... */ - dinfo = drive_get_by_blockdev(conf->bs); + dinfo = blk_legacy_dinfo(conf->blk); *serial = g_strdup(dinfo->serial); } } @@ -30,7 +31,7 @@ void blkconf_geometry(BlockConf *conf, int *ptrans, if (!conf->cyls && !conf->heads && !conf->secs) { /* try to fall back to value set with legacy -drive cyls=... */ - dinfo = drive_get_by_blockdev(conf->bs); + dinfo = blk_legacy_dinfo(conf->blk); conf->cyls = dinfo->cyls; conf->heads = dinfo->heads; conf->secs = dinfo->secs; @@ -39,7 +40,7 @@ void blkconf_geometry(BlockConf *conf, int *ptrans, } } if (!conf->cyls && !conf->heads && !conf->secs) { - hd_geometry_guess(conf->bs, + hd_geometry_guess(conf->blk, &conf->cyls, &conf->heads, &conf->secs, ptrans); } else if (ptrans && *ptrans == BIOS_ATA_TRANSLATION_AUTO) { diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index bd250df..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" @@ -94,7 +94,7 @@ static void handle_notify(EventNotifier *e) VirtIOBlock *vblk = VIRTIO_BLK(s->vdev); event_notifier_test_and_clear(&s->host_notifier); - bdrv_io_plug(s->conf->conf.bs); + blk_io_plug(s->conf->conf.blk); for (;;) { MultiReqBuffer mrb = { .num_writes = 0, @@ -120,7 +120,7 @@ static void handle_notify(EventNotifier *e) virtio_blk_handle_request(req, &mrb); } - virtio_submit_multiwrite(s->conf->conf.bs, &mrb); + virtio_submit_multiwrite(s->conf->conf.blk, &mrb); if (likely(ret == -EAGAIN)) { /* vring emptied */ /* Re-enable guest->host notifies and stop processing the vring. @@ -133,7 +133,7 @@ static void handle_notify(EventNotifier *e) break; } } - bdrv_io_unplug(s->conf->conf.bs); + blk_io_unplug(s->conf->conf.blk); } /* Context: QEMU global mutex held */ @@ -163,8 +163,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, /* If dataplane is (re-)enabled while the guest is running there could be * block jobs that can conflict. */ - if (bdrv_op_is_blocked(conf->conf.bs, BLOCK_OP_TYPE_DATAPLANE, - &local_err)) { + if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE, + &local_err)) { error_setg(errp, "cannot start dataplane thread: %s", error_get_pretty(local_err)); error_free(local_err); @@ -193,9 +193,9 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, s->bh = aio_bh_new(s->ctx, notify_guest_bh, s); error_setg(&s->blocker, "block device is in use by data plane"); - bdrv_op_block_all(conf->conf.bs, s->blocker); - bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker); - bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker); + blk_op_block_all(conf->conf.blk, s->blocker); + blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_RESIZE, s->blocker); + blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker); *dataplane = s; } @@ -208,7 +208,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s) } virtio_blk_data_plane_stop(s); - bdrv_op_unblock_all(s->conf->conf.bs, s->blocker); + blk_op_unblock_all(s->conf->conf.blk, s->blocker); error_free(s->blocker); object_unref(OBJECT(s->iothread)); qemu_bh_delete(s->bh); @@ -263,7 +263,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) s->started = true; trace_virtio_blk_data_plane_start(s); - bdrv_set_aio_context(s->conf->conf.bs, s->ctx); + blk_set_aio_context(s->conf->conf.blk, s->ctx); /* Kick right away to begin processing requests already in vring */ event_notifier_set(virtio_queue_get_host_notifier(vq)); @@ -309,7 +309,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) aio_set_event_notifier(s->ctx, &s->host_notifier, NULL); /* Drain and switch bs back to the QEMU main loop */ - bdrv_set_aio_context(s->conf->conf.bs, qemu_get_aio_context()); + blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context()); aio_context_release(s->ctx); diff --git a/hw/block/fdc.c b/hw/block/fdc.c index c25d767..739a03e 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -114,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) @@ -123,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++) { @@ -176,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 */ @@ -261,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; @@ -270,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; } @@ -292,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, @@ -666,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 = { @@ -911,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; @@ -1404,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 @@ -1425,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... */ @@ -1453,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); @@ -1529,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... */ @@ -1598,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 { @@ -1989,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; @@ -2077,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; } @@ -2090,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); } } } @@ -2108,12 +2111,10 @@ ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds) dev = DEVICE(isadev); if (fds[0]) { - qdev_prop_set_drive_nofail(dev, "driveA", - blk_bs(blk_by_legacy_dinfo(fds[0]))); + qdev_prop_set_drive_nofail(dev, "driveA", blk_by_legacy_dinfo(fds[0])); } if (fds[1]) { - qdev_prop_set_drive_nofail(dev, "driveB", - blk_bs(blk_by_legacy_dinfo(fds[1]))); + qdev_prop_set_drive_nofail(dev, "driveB", blk_by_legacy_dinfo(fds[1])); } qdev_init_nofail(dev); @@ -2133,12 +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", - blk_bs(blk_by_legacy_dinfo(fds[0]))); + qdev_prop_set_drive_nofail(dev, "driveA", blk_by_legacy_dinfo(fds[0])); } if (fds[1]) { - qdev_prop_set_drive_nofail(dev, "driveB", - blk_bs(blk_by_legacy_dinfo(fds[1]))); + qdev_prop_set_drive_nofail(dev, "driveB", blk_by_legacy_dinfo(fds[1])); } qdev_init_nofail(dev); sbd = SYS_BUS_DEVICE(dev); @@ -2154,8 +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", - blk_bs(blk_by_legacy_dinfo(fds[0]))); + qdev_prop_set_drive_nofail(dev, "drive", blk_by_legacy_dinfo(fds[0])); } qdev_init_nofail(dev); sys = SYSBUS_FDC(dev); @@ -2292,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(), @@ -2342,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(), }; @@ -2363,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 78280a8..ff1106b 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -246,7 +246,7 @@ typedef struct Flash { uint32_t r; - BlockDriverState *bdrv; + BlockBackend *blk; uint8_t *storage; uint32_t size; @@ -280,7 +280,7 @@ typedef struct M25P80Class { #define M25P80_GET_CLASS(obj) \ OBJECT_GET_CLASS(M25P80Class, (obj), TYPE_M25P80) -static void bdrv_sync_complete(void *opaque, int ret) +static void blk_sync_complete(void *opaque, int ret) { /* do nothing. Masters do not directly interact with the backing store, * only the working copy so no mutexing required. @@ -289,20 +289,20 @@ static void bdrv_sync_complete(void *opaque, int ret) static void flash_sync_page(Flash *s, int page) { - int bdrv_sector, nb_sectors; + int blk_sector, nb_sectors; QEMUIOVector iov; - if (!s->bdrv || bdrv_is_read_only(s->bdrv)) { + if (!s->blk || blk_is_read_only(s->blk)) { return; } - bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE; + blk_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE; nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE); qemu_iovec_init(&iov, 1); - qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE, + qemu_iovec_add(&iov, s->storage + blk_sector * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); - bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors, bdrv_sync_complete, - NULL); + blk_aio_writev(s->blk, blk_sector, &iov, nb_sectors, blk_sync_complete, + NULL); } static inline void flash_sync_area(Flash *s, int64_t off, int64_t len) @@ -310,7 +310,7 @@ static inline void flash_sync_area(Flash *s, int64_t off, int64_t len) int64_t start, end, nb_sectors; QEMUIOVector iov; - if (!s->bdrv || bdrv_is_read_only(s->bdrv)) { + if (!s->blk || blk_is_read_only(s->blk)) { return; } @@ -321,7 +321,7 @@ static inline void flash_sync_area(Flash *s, int64_t off, int64_t len) qemu_iovec_init(&iov, 1); qemu_iovec_add(&iov, s->storage + (start * BDRV_SECTOR_SIZE), nb_sectors * BDRV_SECTOR_SIZE); - bdrv_aio_writev(s->bdrv, start, &iov, nb_sectors, bdrv_sync_complete, NULL); + blk_aio_writev(s->blk, start, &iov, nb_sectors, blk_sync_complete, NULL); } static void flash_erase(Flash *s, int offset, FlashCMD cmd) @@ -621,17 +621,17 @@ static int m25p80_init(SSISlave *ss) s->size = s->pi->sector_size * s->pi->n_sectors; s->dirty_page = -1; - s->storage = qemu_blockalign(s->bdrv, s->size); + s->storage = blk_blockalign(s->blk, s->size); dinfo = drive_get_next(IF_MTD); if (dinfo) { DB_PRINT_L(0, "Binding to IF_MTD drive\n"); - s->bdrv = blk_bs(blk_by_legacy_dinfo(dinfo)); + s->blk = blk_by_legacy_dinfo(dinfo); /* FIXME: Move to late init */ - if (bdrv_read(s->bdrv, 0, s->storage, DIV_ROUND_UP(s->size, - BDRV_SECTOR_SIZE))) { + if (blk_read(s->blk, 0, s->storage, + DIV_ROUND_UP(s->size, BDRV_SECTOR_SIZE))) { fprintf(stderr, "Failed to initialize SPI flash!\n"); return 1; } 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/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 4dc794c..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); } @@ -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, @@ -299,7 +301,7 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, 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) @@ -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->conf.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 @@ -518,7 +520,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) uint64_t capacity; 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); @@ -538,7 +540,7 @@ 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) / conf->heads / conf->secs % blk_size) { + if (blk_getlength(s->blk) / conf->heads / conf->secs % blk_size) { blkcfg.sectors = conf->secs & ~s->sector_mask; } else { blkcfg.sectors = conf->secs; @@ -546,7 +548,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.size_max = 0; 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)); } @@ -557,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) @@ -575,11 +577,12 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) 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; } @@ -613,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)); } } @@ -708,7 +711,7 @@ static void virtio_blk_migration_state_changed(Notifier *notifier, void *data) if (s->dataplane) { return; } - bdrv_drain_all(); /* complete in-flight non-dataplane requests */ + 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) { @@ -726,17 +729,17 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) Error *err = NULL; static int virtio_blk_id; - if (!conf->conf.bs) { + if (!conf->conf.blk) { error_setg(errp, "drive property not set"); return; } - if (!bdrv_is_inserted(conf->conf.bs)) { + if (!blk_is_inserted(conf->conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); return; } blkconf_serial(&conf->conf, &conf->serial); - s->original_wce = bdrv_enable_write_cache(conf->conf.bs); + 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); @@ -746,7 +749,7 @@ 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 = conf->conf.bs; + s->blk = conf->conf.blk; s->rq = NULL; s->sector_mask = (s->conf.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1; @@ -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.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); } diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index ca4f855..231e9a7 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -123,7 +123,7 @@ struct XenBlkDev { /* qemu block driver */ DriveInfo *dinfo; - BlockDriverState *bs; + BlockBackend *blk; QEMUBH *bh; }; @@ -480,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; } @@ -494,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: @@ -513,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: @@ -532,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; @@ -857,6 +857,7 @@ static int blk_connect(struct XenDevice *xendev) 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"); @@ -864,39 +865,39 @@ static int blk_connect(struct XenDevice *xendev) if (!blk) { return -1; } - blkdev->bs = blk_bs(blk); + 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); blk_unref(blk); - blkdev->bs = NULL; + 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 = blk_bs(blk_by_legacy_dinfo(blkdev->dinfo)); - 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 */ - /* Except we don't bdrv_unref() anymore, we blk_unref(). - * Conditionally, because we can't easily blk_ref() here. - * TODO Clean this up! */ + /* 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; } @@ -987,12 +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); - if (!blkdev->dinfo) { - blk_unref(blk_by_name(blkdev->dev)); - } - 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); @@ -1008,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); } |