2012-11-14 18:39:30 +04: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 21:01:42 +03: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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2012-11-14 18:39:30 +04:00
|
|
|
#include "trace.h"
|
|
|
|
#include "qemu/iov.h"
|
|
|
|
#include "qemu/thread.h"
|
2013-02-04 14:37:52 +04:00
|
|
|
#include "qemu/error-report.h"
|
2015-01-26 19:26:42 +03:00
|
|
|
#include "hw/virtio/virtio-access.h"
|
2014-10-07 15:59:18 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/virtio/virtio-blk.h"
|
|
|
|
#include "virtio-blk.h"
|
2013-02-22 13:40:34 +04:00
|
|
|
#include "block/aio.h"
|
2013-04-24 12:21:21 +04:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2014-03-20 18:06:32 +04:00
|
|
|
#include "qom/object_interfaces.h"
|
2012-11-14 18:39:30 +04:00
|
|
|
|
|
|
|
struct VirtIOBlockDataPlane {
|
2013-09-04 16:16:15 +04:00
|
|
|
bool starting;
|
2013-01-15 20:19:38 +04:00
|
|
|
bool stopping;
|
2012-11-14 18:39:30 +04:00
|
|
|
|
2014-10-07 15:59:17 +04:00
|
|
|
VirtIOBlkConf *conf;
|
2012-11-14 18:39:30 +04:00
|
|
|
VirtIODevice *vdev;
|
2014-07-12 08:08:53 +04:00
|
|
|
QEMUBH *bh; /* bh for guest notification */
|
2016-06-21 15:13:11 +03:00
|
|
|
unsigned long *batch_notify_vqs;
|
2012-11-14 18:39:30 +04:00
|
|
|
|
2013-02-22 13:40:34 +04: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 14:30:08 +04:00
|
|
|
IOThread *iothread;
|
2013-02-22 13:40:34 +04:00
|
|
|
AioContext *ctx;
|
2012-11-14 18:39:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Raise an interrupt to signal guest, if necessary */
|
2016-06-21 15:13:12 +03:00
|
|
|
void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *s, VirtQueue *vq)
|
2012-11-14 18:39:30 +04:00
|
|
|
{
|
2016-06-21 15:13:12 +03:00
|
|
|
set_bit(virtio_get_queue_index(vq), s->batch_notify_vqs);
|
2016-02-14 20:17:09 +03:00
|
|
|
qemu_bh_schedule(s->bh);
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|
|
|
|
|
2014-07-12 08:08:53 +04:00
|
|
|
static void notify_guest_bh(void *opaque)
|
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s = opaque;
|
2016-06-21 15:13:11 +03:00
|
|
|
unsigned nvqs = s->conf->num_queues;
|
|
|
|
unsigned long bitmap[BITS_TO_LONGS(nvqs)];
|
|
|
|
unsigned j;
|
2014-07-12 08:08:53 +04:00
|
|
|
|
2016-06-21 15:13:11 +03:00
|
|
|
memcpy(bitmap, s->batch_notify_vqs, sizeof(bitmap));
|
|
|
|
memset(s->batch_notify_vqs, 0, sizeof(bitmap));
|
|
|
|
|
|
|
|
for (j = 0; j < nvqs; j += BITS_PER_LONG) {
|
|
|
|
unsigned long bits = bitmap[j];
|
2016-02-14 20:17:09 +03:00
|
|
|
|
2016-06-21 15:13:11 +03:00
|
|
|
while (bits != 0) {
|
|
|
|
unsigned i = j + ctzl(bits);
|
|
|
|
VirtQueue *vq = virtio_get_queue(s->vdev, i);
|
|
|
|
|
virtio: set ISR on dataplane notifications
Dataplane has been omitting forever the step of setting ISR when
an interrupt is raised. This caused little breakage, because the
specification actually says that ISR may not be updated in MSI mode.
Some versions of the Windows drivers however didn't clear MSI mode
correctly, and proceeded using polling mode (using ISR, not the used
ring index!) for crashdump and hibernation. If it were just crashdump
and hibernation it would not be a big deal, but recent releases of
Windows do not really shut down, but rather log out and hibernate to
make the next startup faster. Hence, this manifested as a more serious
hang during shutdown with e.g. Windows 8.1 and virtio-win 1.8.0 RPMs.
Newer versions fixed this, while older versions do not use MSI at all.
The failure has always been there for virtio dataplane, but it became
visible after commits 9ffe337 ("virtio-blk: always use dataplane path
if ioeventfd is active", 2016-10-30) and ad07cd6 ("virtio-scsi: always
use dataplane path if ioeventfd is active", 2016-10-30) made virtio-blk
and virtio-scsi always use the dataplane code under KVM. The good news
therefore is that it was not a bug in the patches---they were doing
exactly what they were meant for, i.e. shake out remaining dataplane bugs.
The fix is not hard, so it's worth arranging for the broken drivers.
The virtio_should_notify+event_notifier_set pair that is common to
virtio-blk and virtio-scsi dataplane is replaced with a new public
function virtio_notify_irqfd that also sets ISR. The irqfd emulation
code now need not set ISR anymore, so virtio_irq is removed.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Farhan Ali <alifm@linux.vnet.ibm.com>
Tested-by: Alex Williamson <alex.williamson@redhat.com>
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>
2016-11-18 18:07:02 +03:00
|
|
|
virtio_notify_irqfd(s->vdev, vq);
|
2016-06-21 15:13:11 +03:00
|
|
|
|
|
|
|
bits &= bits - 1; /* clear right-most bit */
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
/* Context: QEMU global mutex held */
|
2017-11-22 06:08:44 +03:00
|
|
|
bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
|
2013-06-07 18:18:50 +04:00
|
|
|
VirtIOBlockDataPlane **dataplane,
|
|
|
|
Error **errp)
|
2012-11-14 18:39:30 +04:00
|
|
|
{
|
|
|
|
VirtIOBlockDataPlane *s;
|
2014-06-18 13:58:30 +04:00
|
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
|
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2012-11-14 18:39:30 +04:00
|
|
|
|
|
|
|
*dataplane = NULL;
|
|
|
|
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
if (conf->iothread) {
|
|
|
|
if (!k->set_guest_notifiers || !k->ioeventfd_assign) {
|
|
|
|
error_setg(errp,
|
|
|
|
"device is incompatible with iothread "
|
|
|
|
"(transport does not support notifiers)");
|
2017-11-22 06:08:44 +03:00
|
|
|
return false;
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
}
|
|
|
|
if (!virtio_device_ioeventfd_enabled(vdev)) {
|
|
|
|
error_setg(errp, "ioeventfd is required for iothread");
|
2017-11-22 06:08:44 +03:00
|
|
|
return false;
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
}
|
2012-11-14 18:39:30 +04:00
|
|
|
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
/* If dataplane is (re-)enabled while the guest is running there could
|
|
|
|
* be block jobs that can conflict.
|
|
|
|
*/
|
|
|
|
if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) {
|
|
|
|
error_prepend(errp, "cannot start virtio-blk dataplane: ");
|
2017-11-22 06:08:44 +03:00
|
|
|
return false;
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
}
|
2014-06-18 13:58:30 +04:00
|
|
|
}
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
/* Don't try if transport does not support notifiers. */
|
|
|
|
if (!virtio_device_ioeventfd_enabled(vdev)) {
|
2017-11-22 06:08:44 +03:00
|
|
|
return false;
|
2013-07-29 17:02:00 +04:00
|
|
|
}
|
|
|
|
|
2012-11-14 18:39:30 +04:00
|
|
|
s = g_new0(VirtIOBlockDataPlane, 1);
|
|
|
|
s->vdev = vdev;
|
2014-10-07 15:59:17 +04:00
|
|
|
s->conf = conf;
|
2012-11-14 18:39:30 +04:00
|
|
|
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
if (conf->iothread) {
|
|
|
|
s->iothread = conf->iothread;
|
|
|
|
object_ref(OBJECT(s->iothread));
|
|
|
|
s->ctx = iothread_get_aio_context(s->iothread);
|
|
|
|
} else {
|
|
|
|
s->ctx = qemu_get_aio_context();
|
|
|
|
}
|
2014-07-12 08:08:53 +04:00
|
|
|
s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);
|
2016-06-21 15:13:11 +03:00
|
|
|
s->batch_notify_vqs = bitmap_new(conf->num_queues);
|
2014-03-03 14:30:08 +04:00
|
|
|
|
2012-11-14 18:39:30 +04:00
|
|
|
*dataplane = s;
|
2017-11-22 06:08:44 +03:00
|
|
|
|
|
|
|
return true;
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
/* Context: QEMU global mutex held */
|
2012-11-14 18:39:30 +04:00
|
|
|
void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
|
|
|
|
{
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
VirtIOBlock *vblk;
|
|
|
|
|
2012-11-14 18:39:30 +04:00
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
vblk = VIRTIO_BLK(s->vdev);
|
|
|
|
assert(!vblk->dataplane_started);
|
2016-06-21 15:13:11 +03:00
|
|
|
g_free(s->batch_notify_vqs);
|
2014-07-12 08:08:53 +04:00
|
|
|
qemu_bh_delete(s->bh);
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
if (s->iothread) {
|
|
|
|
object_unref(OBJECT(s->iothread));
|
|
|
|
}
|
2012-11-14 18:39:30 +04:00
|
|
|
g_free(s);
|
|
|
|
}
|
|
|
|
|
2017-02-09 11:40:47 +03:00
|
|
|
static bool virtio_blk_data_plane_handle_output(VirtIODevice *vdev,
|
2016-04-06 13:16:26 +03:00
|
|
|
VirtQueue *vq)
|
|
|
|
{
|
|
|
|
VirtIOBlock *s = (VirtIOBlock *)vdev;
|
|
|
|
|
|
|
|
assert(s->dataplane);
|
|
|
|
assert(s->dataplane_started);
|
|
|
|
|
2017-02-09 11:40:47 +03:00
|
|
|
return virtio_blk_handle_vq(s, vq);
|
2016-04-06 13:16:26 +03:00
|
|
|
}
|
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
/* Context: QEMU global mutex held */
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
int virtio_blk_data_plane_start(VirtIODevice *vdev)
|
2012-11-14 18:39:30 +04:00
|
|
|
{
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
VirtIOBlock *vblk = VIRTIO_BLK(vdev);
|
|
|
|
VirtIOBlockDataPlane *s = vblk->dataplane;
|
|
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vblk)));
|
2013-04-24 12:21:21 +04:00
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2016-06-21 15:13:15 +03:00
|
|
|
unsigned i;
|
|
|
|
unsigned nvqs = s->conf->num_queues;
|
2014-07-25 16:10:46 +04:00
|
|
|
int r;
|
2012-11-14 18:39:30 +04: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 20:17:08 +03:00
|
|
|
if (vblk->dataplane_started || s->starting) {
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
return 0;
|
2013-09-04 16:16:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s->starting = true;
|
2012-11-14 18:39:30 +04:00
|
|
|
|
|
|
|
/* Set up guest notifier (irq) */
|
2016-06-21 15:13:15 +03:00
|
|
|
r = k->set_guest_notifiers(qbus->parent, nvqs, true);
|
2014-07-25 16:10:46 +04:00
|
|
|
if (r != 0) {
|
|
|
|
fprintf(stderr, "virtio-blk failed to set guest notifier (%d), "
|
|
|
|
"ensure -enable-kvm is set\n", r);
|
2014-07-25 16:10:47 +04:00
|
|
|
goto fail_guest_notifiers;
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up virtqueue notify */
|
2016-06-21 15:13:15 +03:00
|
|
|
for (i = 0; i < nvqs; i++) {
|
|
|
|
r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, true);
|
|
|
|
if (r != 0) {
|
|
|
|
fprintf(stderr, "virtio-blk failed to set host notifier (%d)\n", r);
|
|
|
|
while (i--) {
|
|
|
|
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
|
|
|
|
}
|
|
|
|
goto fail_guest_notifiers;
|
|
|
|
}
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|
2014-07-12 08:08:52 +04:00
|
|
|
|
2013-09-04 16:16:15 +04: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 20:17:08 +03:00
|
|
|
vblk->dataplane_started = true;
|
2012-11-14 18:39:30 +04:00
|
|
|
trace_virtio_blk_data_plane_start(s);
|
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_set_aio_context(s->conf->conf.blk, s->ctx);
|
2014-05-08 18:34:55 +04:00
|
|
|
|
2012-11-14 18:39:30 +04:00
|
|
|
/* Kick right away to begin processing requests already in vring */
|
2016-06-21 15:13:15 +03:00
|
|
|
for (i = 0; i < nvqs; i++) {
|
|
|
|
VirtQueue *vq = virtio_get_queue(s->vdev, i);
|
|
|
|
|
|
|
|
event_notifier_set(virtio_queue_get_host_notifier(vq));
|
|
|
|
}
|
2012-11-14 18:39:30 +04:00
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
/* Get this show started by hooking up our callbacks */
|
|
|
|
aio_context_acquire(s->ctx);
|
2016-06-21 15:13:15 +03:00
|
|
|
for (i = 0; i < nvqs; i++) {
|
|
|
|
VirtQueue *vq = virtio_get_queue(s->vdev, i);
|
|
|
|
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vq, s->ctx,
|
|
|
|
virtio_blk_data_plane_handle_output);
|
|
|
|
}
|
2014-03-03 14:30:08 +04:00
|
|
|
aio_context_release(s->ctx);
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
return 0;
|
2014-07-25 16:10:47 +04:00
|
|
|
|
|
|
|
fail_guest_notifiers:
|
2016-04-06 13:16:23 +03:00
|
|
|
vblk->dataplane_disabled = true;
|
2014-07-25 16:10:47 +04: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 20:17:08 +03:00
|
|
|
vblk->dataplane_started = true;
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
return -ENOSYS;
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
/* Context: QEMU global mutex held */
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
void virtio_blk_data_plane_stop(VirtIODevice *vdev)
|
2012-11-14 18:39:30 +04:00
|
|
|
{
|
virtio-blk: always use dataplane path if ioeventfd is active
Override start_ioeventfd and stop_ioeventfd to start/stop the
whole dataplane logic. This has some positive side effects:
- no need anymore for virtio_add_queue_aio (i.e. a revert of
commit 0ff841f6d138904d514efa1d885bcaf54583852d)
- no need anymore to switch from generic ioeventfd handlers to
dataplane
It detects some errors better:
$ qemu-system-x86_64 -object iothread,id=io \
-drive id=null,file=null-aio://,if=none,format=raw \
-device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null
qemu-system-x86_64: -device virtio-blk-pci,ioeventfd=off,iothread=io,drive=null:
ioeventfd is required for iothread
while previously it would have started just fine.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
2016-10-21 23:48:09 +03:00
|
|
|
VirtIOBlock *vblk = VIRTIO_BLK(vdev);
|
|
|
|
VirtIOBlockDataPlane *s = vblk->dataplane;
|
|
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vblk));
|
2013-04-24 12:21:21 +04:00
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2016-06-21 15:13:15 +03:00
|
|
|
unsigned i;
|
|
|
|
unsigned nvqs = s->conf->num_queues;
|
2014-07-25 16:10:48 +04: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 20:17:08 +03:00
|
|
|
if (!vblk->dataplane_started || s->stopping) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-25 16:10:48 +04:00
|
|
|
|
|
|
|
/* Better luck next time. */
|
2016-04-06 13:16:23 +03: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 20:17:08 +03:00
|
|
|
vblk->dataplane_started = false;
|
2012-11-14 18:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-15 20:19:38 +04:00
|
|
|
s->stopping = true;
|
2012-11-14 18:39:30 +04:00
|
|
|
trace_virtio_blk_data_plane_stop(s);
|
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
aio_context_acquire(s->ctx);
|
|
|
|
|
|
|
|
/* Stop notifications for new requests from guest */
|
2016-06-21 15:13:15 +03:00
|
|
|
for (i = 0; i < nvqs; i++) {
|
|
|
|
VirtQueue *vq = virtio_get_queue(s->vdev, i);
|
|
|
|
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, NULL);
|
|
|
|
}
|
2014-03-03 14:30:08 +04:00
|
|
|
|
2014-05-08 18:34:55 +04:00
|
|
|
/* Drain and switch bs back to the QEMU main loop */
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context());
|
2012-11-14 18:39:30 +04:00
|
|
|
|
2014-03-03 14:30:08 +04:00
|
|
|
aio_context_release(s->ctx);
|
2012-11-14 18:39:30 +04:00
|
|
|
|
2016-06-21 15:13:15 +03:00
|
|
|
for (i = 0; i < nvqs; i++) {
|
|
|
|
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
|
|
|
|
}
|
2012-11-14 18:39:30 +04:00
|
|
|
|
|
|
|
/* Clean up guest notifier (irq) */
|
2016-06-21 15:13:15 +03:00
|
|
|
k->set_guest_notifiers(qbus->parent, nvqs, false);
|
2012-11-14 18:39:30 +04: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 20:17:08 +03:00
|
|
|
vblk->dataplane_started = false;
|
2013-01-15 20:19:38 +04:00
|
|
|
s->stopping = false;
|
2012-11-14 18:39:30 +04:00
|
|
|
}
|