aboutsummaryrefslogtreecommitdiff
path: root/hw/block/virtio-blk.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-10-07 13:59:18 +0200
committerKevin Wolf <kwolf@redhat.com>2014-10-20 14:02:25 +0200
commit4be746345f13e99e468c60acbd3a355e8183e3ce (patch)
tree16509218f940129beb113cf3b1be158c3501ec1d /hw/block/virtio-blk.c
parent2a30307f709e6a395d23cf94837e9aae15f8e8fa (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/block/virtio-blk.c')
-rw-r--r--hw/block/virtio-blk.c95
1 files changed, 49 insertions, 46 deletions
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 4dc794c2fe..b19b102b42 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);
}