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"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 08:01:28 +00:00
|
|
|
#include "qapi/error.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"
|
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;
|
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;
|
2016-02-14 17:17:09 +00:00
|
|
|
VirtQueue *vq; /* virtqueue vring */
|
2012-11-14 14:39:30 +00:00
|
|
|
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;
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-05-23 13:29:43 +00:00
|
|
|
/* Operation blocker on BDS */
|
|
|
|
Error *blocker;
|
2012-11-14 14:39:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Raise an interrupt to signal guest, if necessary */
|
2016-02-14 17:17:09 +00:00
|
|
|
void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *s)
|
2012-11-14 14:39:30 +00:00
|
|
|
{
|
2016-02-14 17:17:09 +00:00
|
|
|
qemu_bh_schedule(s->bh);
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
|
|
|
|
2014-07-12 04:08:53 +00:00
|
|
|
static void notify_guest_bh(void *opaque)
|
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s = opaque;
|
|
|
|
|
2016-02-14 17:17:09 +00:00
|
|
|
if (!virtio_should_notify(s->vdev, s->vq)) {
|
|
|
|
return;
|
2012-11-14 14:39:30 +00:00
|
|
|
}
|
2016-02-14 17:17:09 +00:00
|
|
|
|
|
|
|
event_notifier_set(s->guest_notifier);
|
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);
|
|
|
|
}
|
|
|
|
|
2016-04-06 10:16:26 +00:00
|
|
|
static void virtio_blk_data_plane_handle_output(VirtIODevice *vdev,
|
|
|
|
VirtQueue *vq)
|
|
|
|
{
|
|
|
|
VirtIOBlock *s = (VirtIOBlock *)vdev;
|
|
|
|
|
|
|
|
assert(s->dataplane);
|
|
|
|
assert(s->dataplane_started);
|
|
|
|
|
|
|
|
virtio_blk_handle_vq(s, vq);
|
|
|
|
}
|
|
|
|
|
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);
|
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;
|
2016-02-14 17:17:09 +00:00
|
|
|
s->vq = virtio_get_queue(s->vdev, 0);
|
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
|
|
|
}
|
2016-02-14 17:17:09 +00:00
|
|
|
s->guest_notifier = virtio_queue_get_guest_notifier(s->vq);
|
2012-11-14 14:39:30 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
2014-07-12 04:08:52 +00:00
|
|
|
|
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 */
|
2016-02-14 17:17:09 +00:00
|
|
|
event_notifier_set(virtio_queue_get_host_notifier(s->vq));
|
2012-11-14 14:39:30 +00:00
|
|
|
|
2014-03-03 10:30:08 +00:00
|
|
|
/* Get this show started by hooking up our callbacks */
|
|
|
|
aio_context_acquire(s->ctx);
|
2016-04-06 10:16:26 +00:00
|
|
|
virtio_set_queue_aio(s->vq, virtio_blk_data_plane_handle_output);
|
2016-02-14 17:17:09 +00:00
|
|
|
virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, true, true);
|
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:
|
2016-04-06 10:16:23 +00:00
|
|
|
vblk->dataplane_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. */
|
2016-04-06 10:16:23 +00:00
|
|
|
if (vblk->dataplane_disabled) {
|
|
|
|
vblk->dataplane_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;
|
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 */
|
2016-02-14 17:17:09 +00:00
|
|
|
virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, false, false);
|
2016-04-06 10:16:26 +00:00
|
|
|
virtio_set_queue_aio(s->vq, 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
|
|
|
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
|
|
|
}
|