2012-11-14 14:39:30 +00:00
|
|
|
/*
|
|
|
|
* Dedicated thread for virtio-blk I/O processing
|
|
|
|
*
|
|
|
|
* Copyright 2012 IBM, Corp.
|
|
|
|
* Copyright 2012 Red Hat, Inc. and/or its affiliates
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-18 18:01:42 +00:00
|
|
|
#include "qemu/osdep.h"
|
2012-11-14 14:39:30 +00:00
|
|
|
#include "trace.h"
|
|
|
|
#include "qemu/iov.h"
|
|
|
|
#include "qemu/thread.h"
|
2013-02-04 10:37:52 +00:00
|
|
|
#include "qemu/error-report.h"
|
2015-01-26 16:26:42 +00:00
|
|
|
#include "hw/virtio/virtio-access.h"
|
2013-02-05 16:06:20 +00:00
|
|
|
#include "hw/virtio/dataplane/vring.h"
|
2015-01-26 16:26:42 +00:00
|
|
|
#include "hw/virtio/dataplane/vring-accessors.h"
|
2014-10-07 11:59:18 +00:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-02-05 16:06:20 +00:00
|
|
|
#include "hw/virtio/virtio-blk.h"
|
|
|
|
#include "virtio-blk.h"
|
2013-02-22 09:40:34 +00:00
|
|
|
#include "block/aio.h"
|
2013-04-24 08:21:21 +00:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2014-03-20 14:06:32 +00:00
|
|
|
#include "qom/object_interfaces.h"
|
2012-11-14 14:39:30 +00:00
|
|
|
|
|
|
|
struct VirtIOBlockDataPlane {
|
2013-09-04 12:16:15 +00:00
|
|
|
bool starting;
|
2013-01-15 16:19:38 +00:00
|
|
|
bool stopping;
|
2014-07-25 12:10:48 +00:00
|
|
|
bool disabled;
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-10-07 11:59:17 +00:00
|
|
|
VirtIOBlkConf *conf;
|
2012-11-14 14:39:30 +00:00
|
|
|
|
|
|
|
VirtIODevice *vdev;
|
|
|
|
Vring vring; /* virtqueue vring */
|
|
|
|
EventNotifier *guest_notifier; /* irq */
|
2014-07-12 04:08:53 +00:00
|
|
|
QEMUBH *bh; /* bh for guest notification */
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2016-01-29 15:36:04 +00:00
|
|
|
Notifier insert_notifier, remove_notifier;
|
|
|
|
|
2013-02-22 09:40:34 +00:00
|
|
|
/* Note that these EventNotifiers are assigned by value. This is
|
|
|
|
* fine as long as you do not call event_notifier_cleanup on them
|
|
|
|
* (because you don't own the file descriptor or handle; you just
|
|
|
|
* use it).
|
|
|
|
*/
|
2014-03-03 10:30:08 +00:00
|
|
|
IOThread *iothread;
|
2013-02-22 09:40:34 +00:00
|
|
|
AioContext *ctx;
|
|
|
|
EventNotifier host_notifier; /* doorbell */
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-05-23 13:29:43 +00:00
|
|
|
/* Operation blocker on BDS */
|
|
|
|
Error *blocker;
|
2014-06-17 06:32:09 +00:00
|
|
|
void (*saved_complete_request)(struct VirtIOBlockReq *req,
|
|
|
|
unsigned char status);
|
2012-11-14 14:39:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Raise an interrupt to signal guest, if necessary */
|
|
|
|
static void notify_guest(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
|
|
|
if (!vring_should_notify(s->vdev, &s->vring)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event_notifier_set(s->guest_notifier);
|
|
|
|
}
|
|
|
|
|
2014-07-12 04:08:53 +00:00
|
|
|
static void notify_guest_bh(void *opaque)
|
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s = opaque;
|
|
|
|
|
|
|
|
notify_guest(s);
|
|
|
|
}
|
|
|
|
|
2014-06-17 06:32:10 +00:00
|
|
|
static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)
|
2012-11-14 14:39:30 +00:00
|
|
|
{
|
2014-07-12 04:08:53 +00:00
|
|
|
VirtIOBlockDataPlane *s = req->dev->dataplane;
|
2014-06-11 04:11:49 +00:00
|
|
|
stb_p(&req->in->status, status);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2015-04-02 17:50:44 +00:00
|
|
|
vring_push(s->vdev, &req->dev->dataplane->vring, &req->elem, req->in_len);
|
2014-07-12 04:08:53 +00:00
|
|
|
|
|
|
|
/* Suppress notification to guest by BH and its scheduled
|
|
|
|
* flag because requests are completed as a batch after io
|
|
|
|
* plug & unplug is introduced, and the BH can still be
|
|
|
|
* executed in dataplane aio context even after it is
|
|
|
|
* stopped, so needn't worry about notification loss with BH.
|
|
|
|
*/
|
|
|
|
qemu_bh_schedule(s->bh);
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
2013-02-22 09:40:34 +00:00
|
|
|
static void handle_notify(EventNotifier *e)
|
2012-11-14 14:39:30 +00:00
|
|
|
{
|
2013-02-22 09:40:34 +00:00
|
|
|
VirtIOBlockDataPlane *s = container_of(e, VirtIOBlockDataPlane,
|
|
|
|
host_notifier);
|
2014-07-09 08:05:49 +00:00
|
|
|
VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2013-02-22 09:40:34 +00:00
|
|
|
event_notifier_test_and_clear(&s->host_notifier);
|
2014-10-07 11:59:18 +00:00
|
|
|
blk_io_plug(s->conf->conf.blk);
|
2012-11-14 14:39:30 +00:00
|
|
|
for (;;) {
|
2015-02-02 13:52:21 +00:00
|
|
|
MultiReqBuffer mrb = {};
|
2014-07-09 08:05:49 +00:00
|
|
|
|
2012-11-14 14:39:30 +00:00
|
|
|
/* Disable guest->host notifies to avoid unnecessary vmexits */
|
|
|
|
vring_disable_notification(s->vdev, &s->vring);
|
|
|
|
|
|
|
|
for (;;) {
|
2016-02-04 14:26:51 +00:00
|
|
|
VirtIOBlockReq *req = vring_pop(s->vdev, &s->vring,
|
|
|
|
sizeof(VirtIOBlockReq));
|
2014-07-09 08:05:49 +00:00
|
|
|
|
2016-02-04 14:26:51 +00:00
|
|
|
if (req == NULL) {
|
2012-11-14 14:39:30 +00:00
|
|
|
break; /* no more requests */
|
|
|
|
}
|
|
|
|
|
2016-02-04 14:26:51 +00:00
|
|
|
virtio_blk_init_request(vblk, req);
|
2014-07-09 08:05:49 +00:00
|
|
|
trace_virtio_blk_data_plane_process_request(s, req->elem.out_num,
|
|
|
|
req->elem.in_num,
|
|
|
|
req->elem.index);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-06-17 06:32:09 +00:00
|
|
|
virtio_blk_handle_request(req, &mrb);
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:52:21 +00:00
|
|
|
if (mrb.num_reqs) {
|
|
|
|
virtio_blk_submit_multireq(s->conf->conf.blk, &mrb);
|
|
|
|
}
|
2014-06-17 06:32:09 +00:00
|
|
|
|
2016-02-04 14:26:51 +00:00
|
|
|
if (likely(!vring_more_avail(s->vdev, &s->vring))) { /* vring emptied */
|
2012-11-14 14:39:30 +00:00
|
|
|
/* Re-enable guest->host notifies and stop processing the vring.
|
|
|
|
* But if the guest has snuck in more descriptors, keep processing.
|
|
|
|
*/
|
2016-02-14 17:17:05 +00:00
|
|
|
vring_enable_notification(s->vdev, &s->vring);
|
|
|
|
if (!vring_more_avail(s->vdev, &s->vring)) {
|
2012-11-14 14:39:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-08 14:34:55 +00:00
|
|
|
} else { /* fatal error */
|
2012-11-14 14:39:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 11:59:18 +00:00
|
|
|
blk_io_unplug(s->conf->conf.blk);
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 15:36:04 +00:00
|
|
|
static void data_plane_set_up_op_blockers(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
|
|
|
assert(!s->blocker);
|
|
|
|
error_setg(&s->blocker, "block device is in use by data plane");
|
|
|
|
blk_op_block_all(s->conf->conf.blk, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_RESIZE, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_BACKUP_SOURCE, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_CHANGE, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_COMMIT_SOURCE, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_COMMIT_TARGET, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_EJECT, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT,
|
|
|
|
s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT,
|
|
|
|
s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE,
|
|
|
|
s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_MIRROR_SOURCE, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_STREAM, s->blocker);
|
|
|
|
blk_op_unblock(s->conf->conf.blk, BLOCK_OP_TYPE_REPLACE, s->blocker);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void data_plane_remove_op_blockers(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
|
|
|
if (s->blocker) {
|
|
|
|
blk_op_unblock_all(s->conf->conf.blk, s->blocker);
|
|
|
|
error_free(s->blocker);
|
|
|
|
s->blocker = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void data_plane_blk_insert_notifier(Notifier *n, void *data)
|
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s = container_of(n, VirtIOBlockDataPlane,
|
|
|
|
insert_notifier);
|
|
|
|
assert(s->conf->conf.blk == data);
|
|
|
|
data_plane_set_up_op_blockers(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void data_plane_blk_remove_notifier(Notifier *n, void *data)
|
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s = container_of(n, VirtIOBlockDataPlane,
|
|
|
|
remove_notifier);
|
|
|
|
assert(s->conf->conf.blk == data);
|
|
|
|
data_plane_remove_op_blockers(s);
|
|
|
|
}
|
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Context: QEMU global mutex held */
|
2014-10-07 11:59:17 +00:00
|
|
|
void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
|
2013-06-07 14:18:50 +00:00
|
|
|
VirtIOBlockDataPlane **dataplane,
|
|
|
|
Error **errp)
|
2012-11-14 14:39:30 +00:00
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s;
|
2014-06-18 09:58:30 +00:00
|
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
|
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
|
|
|
*dataplane = NULL;
|
|
|
|
|
2015-12-07 10:59:27 +00:00
|
|
|
if (!conf->iothread) {
|
2013-06-07 14:18:50 +00:00
|
|
|
return;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 09:58:30 +00:00
|
|
|
/* Don't try if transport does not support notifiers. */
|
|
|
|
if (!k->set_guest_notifiers || !k->set_host_notifier) {
|
|
|
|
error_setg(errp,
|
2015-12-07 10:59:27 +00:00
|
|
|
"device is incompatible with dataplane "
|
2014-06-18 09:58:30 +00:00
|
|
|
"(transport does not support notifiers)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-29 13:02:00 +00:00
|
|
|
/* If dataplane is (re-)enabled while the guest is running there could be
|
|
|
|
* block jobs that can conflict.
|
|
|
|
*/
|
error: Use error_prepend() where it makes obvious sense
Done with this Coccinelle semantic patch
@@
expression FMT, E1, E2;
expression list ARGS;
@@
- error_setg(E1, FMT, ARGS, error_get_pretty(E2));
+ error_propagate(E1, E2);/*###*/
+ error_prepend(E1, FMT/*@@@*/, ARGS);
followed by manual cleanup, first because I can't figure out how to
make Coccinelle transform strings, and second to get rid of now
superfluous error_propagate().
We now use or propagate the original error whole instead of just its
message obtained with error_get_pretty(). This avoids suppressing its
hint (see commit 50b7b00), but I can't see how the errors touched in
this commit could come with hints. It also improves the message
printed with &error_abort when we screw up (see commit 1e9b65b).
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2015-12-18 15:35:15 +00:00
|
|
|
if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) {
|
|
|
|
error_prepend(errp, "cannot start dataplane thread: ");
|
2013-06-07 14:18:50 +00:00
|
|
|
return;
|
2013-07-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-14 14:39:30 +00:00
|
|
|
s = g_new0(VirtIOBlockDataPlane, 1);
|
|
|
|
s->vdev = vdev;
|
2014-10-07 11:59:17 +00:00
|
|
|
s->conf = conf;
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-10-07 11:59:17 +00:00
|
|
|
if (conf->iothread) {
|
|
|
|
s->iothread = conf->iothread;
|
2014-03-20 14:06:32 +00:00
|
|
|
object_ref(OBJECT(s->iothread));
|
2014-03-03 10:30:08 +00:00
|
|
|
}
|
|
|
|
s->ctx = iothread_get_aio_context(s->iothread);
|
2014-07-12 04:08:53 +00:00
|
|
|
s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);
|
2014-03-03 10:30:08 +00:00
|
|
|
|
2016-01-29 15:36:04 +00:00
|
|
|
s->insert_notifier.notify = data_plane_blk_insert_notifier;
|
|
|
|
s->remove_notifier.notify = data_plane_blk_remove_notifier;
|
|
|
|
blk_add_insert_bs_notifier(conf->conf.blk, &s->insert_notifier);
|
|
|
|
blk_add_remove_bs_notifier(conf->conf.blk, &s->remove_notifier);
|
|
|
|
|
|
|
|
data_plane_set_up_op_blockers(s);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
|
|
|
*dataplane = s;
|
|
|
|
}
|
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Context: QEMU global mutex held */
|
2012-11-14 14:39:30 +00:00
|
|
|
void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtio_blk_data_plane_stop(s);
|
2016-01-29 15:36:04 +00:00
|
|
|
data_plane_remove_op_blockers(s);
|
|
|
|
notifier_remove(&s->insert_notifier);
|
|
|
|
notifier_remove(&s->remove_notifier);
|
2014-07-12 04:08:53 +00:00
|
|
|
qemu_bh_delete(s->bh);
|
2015-07-28 16:34:07 +00:00
|
|
|
object_unref(OBJECT(s->iothread));
|
2012-11-14 14:39:30 +00:00
|
|
|
g_free(s);
|
|
|
|
}
|
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Context: QEMU global mutex held */
|
2012-11-14 14:39:30 +00:00
|
|
|
void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
2013-04-24 08:21:21 +00:00
|
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
|
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2014-07-12 04:08:52 +00:00
|
|
|
VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
|
2012-11-14 14:39:30 +00:00
|
|
|
VirtQueue *vq;
|
2014-07-25 12:10:46 +00:00
|
|
|
int r;
|
2012-11-14 14:39:30 +00:00
|
|
|
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
if (vblk->dataplane_started || s->starting) {
|
2013-09-04 12:16:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->starting = true;
|
|
|
|
|
2012-11-14 14:39:30 +00:00
|
|
|
vq = virtio_get_queue(s->vdev, 0);
|
|
|
|
if (!vring_setup(&s->vring, s->vdev, 0)) {
|
2014-07-25 12:10:47 +00:00
|
|
|
goto fail_vring;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up guest notifier (irq) */
|
2014-07-25 12:10:46 +00:00
|
|
|
r = k->set_guest_notifiers(qbus->parent, 1, true);
|
|
|
|
if (r != 0) {
|
|
|
|
fprintf(stderr, "virtio-blk failed to set guest notifier (%d), "
|
|
|
|
"ensure -enable-kvm is set\n", r);
|
2014-07-25 12:10:47 +00:00
|
|
|
goto fail_guest_notifiers;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
s->guest_notifier = virtio_queue_get_guest_notifier(vq);
|
|
|
|
|
|
|
|
/* Set up virtqueue notify */
|
2014-07-25 12:10:46 +00:00
|
|
|
r = k->set_host_notifier(qbus->parent, 0, true);
|
|
|
|
if (r != 0) {
|
|
|
|
fprintf(stderr, "virtio-blk failed to set host notifier (%d)\n", r);
|
2014-07-25 12:10:47 +00:00
|
|
|
goto fail_host_notifier;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
2013-02-22 09:40:34 +00:00
|
|
|
s->host_notifier = *virtio_queue_get_host_notifier(vq);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-07-12 04:08:52 +00:00
|
|
|
s->saved_complete_request = vblk->complete_request;
|
|
|
|
vblk->complete_request = complete_request_vring;
|
|
|
|
|
2013-09-04 12:16:15 +00:00
|
|
|
s->starting = false;
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
vblk->dataplane_started = true;
|
2012-11-14 14:39:30 +00:00
|
|
|
trace_virtio_blk_data_plane_start(s);
|
|
|
|
|
2014-10-07 11:59:18 +00:00
|
|
|
blk_set_aio_context(s->conf->conf.blk, s->ctx);
|
2014-05-08 14:34:55 +00:00
|
|
|
|
2012-11-14 14:39:30 +00:00
|
|
|
/* Kick right away to begin processing requests already in vring */
|
|
|
|
event_notifier_set(virtio_queue_get_host_notifier(vq));
|
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Get this show started by hooking up our callbacks */
|
|
|
|
aio_context_acquire(s->ctx);
|
2015-10-23 03:08:07 +00:00
|
|
|
aio_set_event_notifier(s->ctx, &s->host_notifier, true,
|
2015-10-23 03:08:05 +00:00
|
|
|
handle_notify);
|
2014-03-03 10:30:08 +00:00
|
|
|
aio_context_release(s->ctx);
|
2014-07-25 12:10:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fail_host_notifier:
|
|
|
|
k->set_guest_notifiers(qbus->parent, 1, false);
|
|
|
|
fail_guest_notifiers:
|
|
|
|
vring_teardown(&s->vring, s->vdev, 0);
|
|
|
|
fail_vring:
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
s->disabled = true;
|
2014-07-25 12:10:47 +00:00
|
|
|
s->starting = false;
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
vblk->dataplane_started = true;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Context: QEMU global mutex held */
|
2012-11-14 14:39:30 +00:00
|
|
|
void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
2013-04-24 08:21:21 +00:00
|
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
|
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2014-06-17 06:32:09 +00:00
|
|
|
VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
|
2014-07-25 12:10:48 +00:00
|
|
|
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
if (!vblk->dataplane_started || s->stopping) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-25 12:10:48 +00:00
|
|
|
|
|
|
|
/* Better luck next time. */
|
|
|
|
if (s->disabled) {
|
|
|
|
s->disabled = false;
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
vblk->dataplane_started = false;
|
2012-11-14 14:39:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-15 16:19:38 +00:00
|
|
|
s->stopping = true;
|
2014-06-17 06:32:09 +00:00
|
|
|
vblk->complete_request = s->saved_complete_request;
|
2012-11-14 14:39:30 +00:00
|
|
|
trace_virtio_blk_data_plane_stop(s);
|
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
aio_context_acquire(s->ctx);
|
|
|
|
|
|
|
|
/* Stop notifications for new requests from guest */
|
2015-10-23 03:08:07 +00:00
|
|
|
aio_set_event_notifier(s->ctx, &s->host_notifier, true, NULL);
|
2014-03-03 10:30:08 +00:00
|
|
|
|
2014-05-08 14:34:55 +00:00
|
|
|
/* Drain and switch bs back to the QEMU main loop */
|
2014-10-07 11:59:18 +00:00
|
|
|
blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context());
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
aio_context_release(s->ctx);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Sync vring state back to virtqueue so that non-dataplane request
|
|
|
|
* processing can continue when we disable the host notifier below.
|
|
|
|
*/
|
|
|
|
vring_teardown(&s->vring, s->vdev, 0);
|
|
|
|
|
|
|
|
k->set_host_notifier(qbus->parent, 0, false);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
|
|
|
/* Clean up guest notifier (irq) */
|
2013-04-24 08:21:21 +00:00
|
|
|
k->set_guest_notifiers(qbus->parent, 1, false);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 17:17:08 +00:00
|
|
|
vblk->dataplane_started = false;
|
2013-01-15 16:19:38 +00:00
|
|
|
s->stopping = false;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|