bool stopping;
bool disabled;
- VirtIOBlkConf *blk;
+ VirtIOBlkConf *conf;
VirtIODevice *vdev;
Vring vring; /* virtqueue vring */
VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
event_notifier_test_and_clear(&s->host_notifier);
- bdrv_io_plug(s->blk->conf.bs);
+ bdrv_io_plug(s->conf->conf.bs);
for (;;) {
MultiReqBuffer mrb = {
.num_writes = 0,
virtio_blk_handle_request(req, &mrb);
}
- virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
+ virtio_submit_multiwrite(s->conf->conf.bs, &mrb);
if (likely(ret == -EAGAIN)) { /* vring emptied */
/* Re-enable guest->host notifies and stop processing the vring.
break;
}
}
- bdrv_io_unplug(s->blk->conf.bs);
+ bdrv_io_unplug(s->conf->conf.bs);
}
/* Context: QEMU global mutex held */
-void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
+void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
VirtIOBlockDataPlane **dataplane,
Error **errp)
{
*dataplane = NULL;
- if (!blk->data_plane && !blk->iothread) {
+ if (!conf->data_plane && !conf->iothread) {
return;
}
/* If dataplane is (re-)enabled while the guest is running there could be
* block jobs that can conflict.
*/
- if (bdrv_op_is_blocked(blk->conf.bs, BLOCK_OP_TYPE_DATAPLANE, &local_err)) {
+ if (bdrv_op_is_blocked(conf->conf.bs, BLOCK_OP_TYPE_DATAPLANE,
+ &local_err)) {
error_setg(errp, "cannot start dataplane thread: %s",
error_get_pretty(local_err));
error_free(local_err);
s = g_new0(VirtIOBlockDataPlane, 1);
s->vdev = vdev;
- s->blk = blk;
+ s->conf = conf;
- if (blk->iothread) {
- s->iothread = blk->iothread;
+ if (conf->iothread) {
+ s->iothread = conf->iothread;
object_ref(OBJECT(s->iothread));
} else {
/* Create per-device IOThread if none specified. This is for
s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);
error_setg(&s->blocker, "block device is in use by data plane");
- bdrv_op_block_all(blk->conf.bs, s->blocker);
- bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker);
- bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
+ bdrv_op_block_all(conf->conf.bs, s->blocker);
+ bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker);
+ bdrv_op_unblock(conf->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
*dataplane = s;
}
}
virtio_blk_data_plane_stop(s);
- bdrv_op_unblock_all(s->blk->conf.bs, s->blocker);
+ bdrv_op_unblock_all(s->conf->conf.bs, s->blocker);
error_free(s->blocker);
object_unref(OBJECT(s->iothread));
qemu_bh_delete(s->bh);
s->started = true;
trace_virtio_blk_data_plane_start(s);
- bdrv_set_aio_context(s->blk->conf.bs, s->ctx);
+ bdrv_set_aio_context(s->conf->conf.bs, s->ctx);
/* Kick right away to begin processing requests already in vring */
event_notifier_set(virtio_queue_get_host_notifier(vq));
aio_set_event_notifier(s->ctx, &s->host_notifier, NULL);
/* Drain and switch bs back to the QEMU main loop */
- bdrv_set_aio_context(s->blk->conf.bs, qemu_get_aio_context());
+ bdrv_set_aio_context(s->conf->conf.bs, qemu_get_aio_context());
aio_context_release(s->ctx);
*/
scsi = (void *)elem->in_sg[elem->in_num - 2].iov_base;
- if (!blk->blk.scsi) {
+ if (!blk->conf.scsi) {
status = VIRTIO_BLK_S_UNSUPP;
goto fail;
}
if (sector & dev->sector_mask) {
return false;
}
- if (size % dev->blk.conf.logical_block_size) {
+ if (size % dev->conf.conf.logical_block_size) {
return false;
}
bdrv_get_geometry(dev->bs, &total_sectors);
* NB: per existing s/n string convention the string is
* terminated by '\0' only when shorter than buffer.
*/
- const char *serial = s->blk.serial ? s->blk.serial : "";
+ const char *serial = s->conf.serial ? s->conf.serial : "";
size_t size = MIN(strlen(serial) + 1,
MIN(iov_size(in_iov, in_num),
VIRTIO_BLK_ID_BYTES));
}
if (!s->bh) {
- s->bh = aio_bh_new(bdrv_get_aio_context(s->blk.conf.bs),
+ s->bh = aio_bh_new(bdrv_get_aio_context(s->conf.conf.bs),
virtio_blk_dma_restart_bh, s);
qemu_bh_schedule(s->bh);
}
static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);
- BlockConf *conf = &s->blk.conf;
+ BlockConf *conf = &s->conf.conf;
struct virtio_blk_config blkcfg;
uint64_t capacity;
int blk_size = conf->logical_block_size;
features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
features |= (1 << VIRTIO_BLK_F_SCSI);
- if (s->blk.config_wce) {
+ if (s->conf.config_wce) {
features |= (1 << VIRTIO_BLK_F_CONFIG_WCE);
}
if (bdrv_enable_write_cache(s->bs))
return;
}
bdrv_drain_all(); /* complete in-flight non-dataplane requests */
- virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->blk,
+ virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->conf,
&s->dataplane, &err);
if (err != NULL) {
error_report("%s", error_get_pretty(err));
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOBlock *s = VIRTIO_BLK(dev);
- VirtIOBlkConf *blk = &(s->blk);
+ VirtIOBlkConf *conf = &s->conf;
Error *err = NULL;
static int virtio_blk_id;
- if (!blk->conf.bs) {
+ if (!conf->conf.bs) {
error_setg(errp, "drive property not set");
return;
}
- if (!bdrv_is_inserted(blk->conf.bs)) {
+ if (!bdrv_is_inserted(conf->conf.bs)) {
error_setg(errp, "Device needs media, but drive is empty");
return;
}
- blkconf_serial(&blk->conf, &blk->serial);
- s->original_wce = bdrv_enable_write_cache(blk->conf.bs);
- blkconf_geometry(&blk->conf, NULL, 65535, 255, 255, &err);
+ blkconf_serial(&conf->conf, &conf->serial);
+ s->original_wce = bdrv_enable_write_cache(conf->conf.bs);
+ blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, &err);
if (err) {
error_propagate(errp, err);
return;
virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config));
- s->bs = blk->conf.bs;
+ s->bs = conf->conf.bs;
s->rq = NULL;
- s->sector_mask = (s->blk.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1;
+ s->sector_mask = (s->conf.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1;
s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
s->complete_request = virtio_blk_complete_request;
- virtio_blk_data_plane_create(vdev, blk, &s->dataplane, &err);
+ virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err);
if (err != NULL) {
error_propagate(errp, err);
virtio_cleanup(vdev);
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->blk.conf.logical_block_size);
+ bdrv_set_guest_block_size(s->bs, s->conf.conf.logical_block_size);
bdrv_iostatus_enable(s->bs);
}
VirtIOBlock *s = VIRTIO_BLK(obj);
object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
- (Object **)&s->blk.iothread,
+ (Object **)&s->conf.iothread,
qdev_prop_allow_set_link_before_realize,
OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
- device_add_bootindex_property(obj, &s->blk.conf.bootindex,
+ device_add_bootindex_property(obj, &s->conf.conf.bootindex,
"bootindex", "/disk@0,0",
DEVICE(obj), NULL);
}
static Property virtio_blk_properties[] = {
- DEFINE_BLOCK_PROPERTIES(VirtIOBlock, blk.conf),
- DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, blk.conf),
- DEFINE_PROP_STRING("serial", VirtIOBlock, blk.serial),
- DEFINE_PROP_BIT("config-wce", VirtIOBlock, blk.config_wce, 0, true),
+ DEFINE_BLOCK_PROPERTIES(VirtIOBlock, conf.conf),
+ DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf),
+ DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial),
+ DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true),
#ifdef __linux__
- DEFINE_PROP_BIT("scsi", VirtIOBlock, blk.scsi, 0, true),
+ DEFINE_PROP_BIT("scsi", VirtIOBlock, conf.scsi, 0, true),
#endif
- DEFINE_PROP_BIT("x-data-plane", VirtIOBlock, blk.data_plane, 0, false),
+ DEFINE_PROP_BIT("x-data-plane", VirtIOBlock, conf.data_plane, 0, false),
DEFINE_PROP_END_OF_LIST(),
};