Skip to content

Commit

Permalink
virtio-blk: Rename VirtIOBlkConf variables to conf
Browse files Browse the repository at this point in the history
This is consistent with how VirtIOFOOConf variables are named
elsewhere, and makes blk available for BlockBackend variables.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Markus Armbruster authored and kevmw committed Oct 20, 2014
1 parent f751673 commit 2a30307
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
33 changes: 17 additions & 16 deletions hw/block/dataplane/virtio-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct VirtIOBlockDataPlane {
bool stopping;
bool disabled;

VirtIOBlkConf *blk;
VirtIOBlkConf *conf;

VirtIODevice *vdev;
Vring vring; /* virtqueue vring */
Expand Down Expand Up @@ -94,7 +94,7 @@ static void handle_notify(EventNotifier *e)
VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);

event_notifier_test_and_clear(&s->host_notifier);
bdrv_io_plug(s->blk->conf.bs);
bdrv_io_plug(s->conf->conf.bs);
for (;;) {
MultiReqBuffer mrb = {
.num_writes = 0,
Expand All @@ -120,7 +120,7 @@ static void handle_notify(EventNotifier *e)
virtio_blk_handle_request(req, &mrb);
}

virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
virtio_submit_multiwrite(s->conf->conf.bs, &mrb);

if (likely(ret == -EAGAIN)) { /* vring emptied */
/* Re-enable guest->host notifies and stop processing the vring.
Expand All @@ -133,11 +133,11 @@ static void handle_notify(EventNotifier *e)
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)
{
Expand All @@ -148,7 +148,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,

*dataplane = NULL;

if (!blk->data_plane && !blk->iothread) {
if (!conf->data_plane && !conf->iothread) {
return;
}

Expand All @@ -163,7 +163,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
/* If dataplane is (re-)enabled while the guest is running there could be
* block jobs that can conflict.
*/
if (bdrv_op_is_blocked(blk->conf.bs, BLOCK_OP_TYPE_DATAPLANE, &local_err)) {
if (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);
Expand All @@ -172,10 +173,10 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,

s = g_new0(VirtIOBlockDataPlane, 1);
s->vdev = vdev;
s->blk = blk;
s->conf = conf;

if (blk->iothread) {
s->iothread = blk->iothread;
if (conf->iothread) {
s->iothread = conf->iothread;
object_ref(OBJECT(s->iothread));
} else {
/* Create per-device IOThread if none specified. This is for
Expand All @@ -192,9 +193,9 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);

error_setg(&s->blocker, "block device is in use by data plane");
bdrv_op_block_all(blk->conf.bs, s->blocker);
bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_RESIZE, s->blocker);
bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
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;
}
Expand All @@ -207,7 +208,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
}

virtio_blk_data_plane_stop(s);
bdrv_op_unblock_all(s->blk->conf.bs, s->blocker);
bdrv_op_unblock_all(s->conf->conf.bs, s->blocker);
error_free(s->blocker);
object_unref(OBJECT(s->iothread));
qemu_bh_delete(s->bh);
Expand Down Expand Up @@ -262,7 +263,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
s->started = true;
trace_virtio_blk_data_plane_start(s);

bdrv_set_aio_context(s->blk->conf.bs, s->ctx);
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));
Expand Down Expand Up @@ -308,7 +309,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
aio_set_event_notifier(s->ctx, &s->host_notifier, NULL);

/* Drain and switch bs back to the QEMU main loop */
bdrv_set_aio_context(s->blk->conf.bs, qemu_get_aio_context());
bdrv_set_aio_context(s->conf->conf.bs, qemu_get_aio_context());

aio_context_release(s->ctx);

Expand Down
2 changes: 1 addition & 1 deletion hw/block/dataplane/virtio-blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane;

void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
VirtIOBlockDataPlane **dataplane,
Error **errp);
void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s);
Expand Down
50 changes: 25 additions & 25 deletions hw/block/virtio-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
*/
scsi = (void *)elem->in_sg[elem->in_num - 2].iov_base;

if (!blk->blk.scsi) {
if (!blk->conf.scsi) {
status = VIRTIO_BLK_S_UNSUPP;
goto fail;
}
Expand Down Expand Up @@ -296,7 +296,7 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
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);
Expand Down Expand Up @@ -405,7 +405,7 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
* NB: per existing s/n string convention the string is
* terminated by '\0' only when shorter than buffer.
*/
const char *serial = s->blk.serial ? s->blk.serial : "";
const char *serial = s->conf.serial ? s->conf.serial : "";
size_t size = MIN(strlen(serial) + 1,
MIN(iov_size(in_iov, in_num),
VIRTIO_BLK_ID_BYTES));
Expand Down Expand Up @@ -486,7 +486,7 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running,
}

if (!s->bh) {
s->bh = aio_bh_new(bdrv_get_aio_context(s->blk.conf.bs),
s->bh = aio_bh_new(bdrv_get_aio_context(s->conf.conf.bs),
virtio_blk_dma_restart_bh, s);
qemu_bh_schedule(s->bh);
}
Expand All @@ -513,7 +513,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);
BlockConf *conf = &s->blk.conf;
BlockConf *conf = &s->conf.conf;
struct virtio_blk_config blkcfg;
uint64_t capacity;
int blk_size = conf->logical_block_size;
Expand Down Expand Up @@ -572,7 +572,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
features |= (1 << VIRTIO_BLK_F_SCSI);

if (s->blk.config_wce) {
if (s->conf.config_wce) {
features |= (1 << VIRTIO_BLK_F_CONFIG_WCE);
}
if (bdrv_enable_write_cache(s->bs))
Expand Down Expand Up @@ -709,7 +709,7 @@ static void virtio_blk_migration_state_changed(Notifier *notifier, void *data)
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));
Expand All @@ -722,22 +722,22 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOBlock *s = VIRTIO_BLK(dev);
VirtIOBlkConf *blk = &(s->blk);
VirtIOBlkConf *conf = &s->conf;
Error *err = NULL;
static int virtio_blk_id;

if (!blk->conf.bs) {
if (!conf->conf.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;
Expand All @@ -746,13 +746,13 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config));

s->bs = blk->conf.bs;
s->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);
Expand All @@ -765,7 +765,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
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);
}
Expand All @@ -789,23 +789,23 @@ static void virtio_blk_instance_init(Object *obj)
VirtIOBlock *s = VIRTIO_BLK(obj);

object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
(Object **)&s->blk.iothread,
(Object **)&s->conf.iothread,
qdev_prop_allow_set_link_before_realize,
OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
device_add_bootindex_property(obj, &s->blk.conf.bootindex,
device_add_bootindex_property(obj, &s->conf.conf.bootindex,
"bootindex", "/disk@0,0",
DEVICE(obj), NULL);
}

static Property virtio_blk_properties[] = {
DEFINE_BLOCK_PROPERTIES(VirtIOBlock, blk.conf),
DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, blk.conf),
DEFINE_PROP_STRING("serial", VirtIOBlock, blk.serial),
DEFINE_PROP_BIT("config-wce", VirtIOBlock, blk.config_wce, 0, true),
DEFINE_BLOCK_PROPERTIES(VirtIOBlock, conf.conf),
DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf),
DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial),
DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true),
#ifdef __linux__
DEFINE_PROP_BIT("scsi", VirtIOBlock, blk.scsi, 0, true),
DEFINE_PROP_BIT("scsi", VirtIOBlock, conf.scsi, 0, true),
#endif
DEFINE_PROP_BIT("x-data-plane", VirtIOBlock, blk.data_plane, 0, false),
DEFINE_PROP_BIT("x-data-plane", VirtIOBlock, conf.data_plane, 0, false),
DEFINE_PROP_END_OF_LIST(),
};

Expand Down
2 changes: 1 addition & 1 deletion include/hw/virtio/virtio-blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ typedef struct VirtIOBlock {
VirtQueue *vq;
void *rq;
QEMUBH *bh;
VirtIOBlkConf blk;
VirtIOBlkConf conf;
unsigned short sector_mask;
bool original_wce;
VMChangeStateEntry *change;
Expand Down

0 comments on commit 2a30307

Please sign in to comment.