diff options
author | Markus Armbruster <armbru@redhat.com> | 2014-10-07 13:59:18 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-10-20 14:02:25 +0200 |
commit | 4be746345f13e99e468c60acbd3a355e8183e3ce (patch) | |
tree | 16509218f940129beb113cf3b1be158c3501ec1d /hw/scsi | |
parent | 2a30307f709e6a395d23cf94837e9aae15f8e8fa (diff) |
hw: Convert from BlockDriverState to BlockBackend, mostly
Device models should access their block backends only through the
block-backend.h API. Convert them, and drop direct includes of
inappropriate headers.
Just four uses of BlockDriverState are left:
* The Xen paravirtual block device backend (xen_disk.c) opens images
itself when set up via xenbus, bypassing blockdev.c. I figure it
should go through qmp_blockdev_add() instead.
* Device model "usb-storage" prompts for keys. No other device model
does, and this one probably shouldn't do it, either.
* ide_issue_trim_cb() uses bdrv_aio_discard() instead of
blk_aio_discard() because it fishes its backend out of a BlockAIOCB,
which has only the BlockDriverState.
* PC87312State has an unused BlockDriverState[] member.
The next two commits take care of the latter two.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw/scsi')
-rw-r--r-- | hw/scsi/megasas.c | 15 | ||||
-rw-r--r-- | hw/scsi/scsi-bus.c | 12 | ||||
-rw-r--r-- | hw/scsi/scsi-disk.c | 182 | ||||
-rw-r--r-- | hw/scsi/scsi-generic.c | 35 | ||||
-rw-r--r-- | hw/scsi/virtio-scsi-dataplane.c | 3 | ||||
-rw-r--r-- | hw/scsi/virtio-scsi.c | 15 |
6 files changed, 133 insertions, 129 deletions
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index eedc9922a7..36a04f31bb 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 b4bbd9ca4d..af7707cf27 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -222,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) { @@ -230,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) { @@ -243,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; @@ -271,7 +271,7 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp) continue; } qemu_opts_loc_restore(dinfo->opts); - scsi_bus_legacy_add_drive(bus, blk_bs(blk_by_legacy_dinfo(dinfo)), + 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)); @@ -1754,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); } } @@ -1768,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 ae9e08dd13..300ba01045 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,14 +2302,14 @@ 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); + dinfo = blk_legacy_dinfo(dev->conf.blk); if (dinfo->media_cd) { scsi_cd_realize(dev, errp); } else { @@ -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 4177c5357e..f2e53afd09 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,7 +142,7 @@ done: scsi_req_unref(&r->req); } -static int execute_command(BlockDriverState *bdrv, +static int execute_command(BlockBackend *blk, SCSIGenericReq *r, int direction, BlockCompletionFunc *complete) { @@ -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 b778e051f8..48dcfd2852 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 8547ea0475..a1725b8f48 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; } } |