2014-09-23 11:49:24 +04:00
|
|
|
/*
|
|
|
|
* Virtio SCSI dataplane
|
|
|
|
*
|
|
|
|
* Copyright Red Hat, Inc. 2014
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Fam Zheng <famz@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-26 21:17:07 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-10-21 23:48:10 +03:00
|
|
|
#include "qapi/error.h"
|
2014-09-23 11:49:24 +04:00
|
|
|
#include "hw/virtio/virtio-scsi.h"
|
|
|
|
#include "qemu/error-report.h"
|
2014-10-07 15:59:18 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2016-06-22 20:11:19 +03:00
|
|
|
#include "hw/scsi/scsi.h"
|
2017-08-22 10:23:55 +03:00
|
|
|
#include "scsi/constants.h"
|
2016-06-22 20:11:19 +03:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2014-09-23 11:49:24 +04:00
|
|
|
#include "hw/virtio/virtio-access.h"
|
|
|
|
|
|
|
|
/* Context: QEMU global mutex held */
|
2016-10-21 23:48:10 +03:00
|
|
|
void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)
|
2014-09-23 11:49:24 +04:00
|
|
|
{
|
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
2016-10-21 23:48:10 +03:00
|
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
|
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2014-09-23 11:49:24 +04:00
|
|
|
|
2016-10-21 23:48:10 +03:00
|
|
|
if (vs->conf.iothread) {
|
|
|
|
if (!k->set_guest_notifiers || !k->ioeventfd_assign) {
|
|
|
|
error_setg(errp,
|
|
|
|
"device is incompatible with iothread "
|
|
|
|
"(transport does not support notifiers)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!virtio_device_ioeventfd_enabled(vdev)) {
|
|
|
|
error_setg(errp, "ioeventfd is required for iothread");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->ctx = iothread_get_aio_context(vs->conf.iothread);
|
|
|
|
} else {
|
|
|
|
if (!virtio_device_ioeventfd_enabled(vdev)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->ctx = qemu_get_aio_context();
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-09 11:40:47 +03:00
|
|
|
static bool virtio_scsi_data_plane_handle_cmd(VirtIODevice *vdev,
|
2016-04-06 13:16:27 +03:00
|
|
|
VirtQueue *vq)
|
|
|
|
{
|
2020-12-17 18:00:38 +03:00
|
|
|
bool progress = false;
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
2016-04-06 13:16:27 +03:00
|
|
|
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
virtio_scsi_acquire(s);
|
2020-12-17 18:00:38 +03:00
|
|
|
if (!s->dataplane_fenced) {
|
|
|
|
assert(s->ctx && s->dataplane_started);
|
|
|
|
progress = virtio_scsi_handle_cmd_vq(s, vq);
|
|
|
|
}
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
virtio_scsi_release(s);
|
|
|
|
return progress;
|
2016-04-06 13:16:27 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 11:40:47 +03:00
|
|
|
static bool virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev,
|
2016-04-06 13:16:27 +03:00
|
|
|
VirtQueue *vq)
|
|
|
|
{
|
2020-12-17 18:00:38 +03:00
|
|
|
bool progress = false;
|
2016-04-06 13:16:27 +03:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
virtio_scsi_acquire(s);
|
2020-12-17 18:00:38 +03:00
|
|
|
if (!s->dataplane_fenced) {
|
|
|
|
assert(s->ctx && s->dataplane_started);
|
|
|
|
progress = virtio_scsi_handle_ctrl_vq(s, vq);
|
|
|
|
}
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
virtio_scsi_release(s);
|
|
|
|
return progress;
|
2016-04-06 13:16:27 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 11:40:47 +03:00
|
|
|
static bool virtio_scsi_data_plane_handle_event(VirtIODevice *vdev,
|
2016-04-06 13:16:27 +03:00
|
|
|
VirtQueue *vq)
|
|
|
|
{
|
2020-12-17 18:00:38 +03:00
|
|
|
bool progress = false;
|
2016-04-06 13:16:27 +03:00
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
virtio_scsi_acquire(s);
|
2020-12-17 18:00:38 +03:00
|
|
|
if (!s->dataplane_fenced) {
|
|
|
|
assert(s->ctx && s->dataplane_started);
|
|
|
|
progress = virtio_scsi_handle_event_vq(s, vq);
|
|
|
|
}
|
virtio-scsi: Fix acquire/release in dataplane handlers
After the AioContext lock push down, there is a race between
virtio_scsi_dataplane_start and those "assert(s->ctx &&
s->dataplane_started)", because the latter doesn't isn't wrapped in
aio_context_acquire.
Reproducer is simply booting a Fedora guest with an empty
virtio-scsi-dataplane controller:
qemu-system-x86_64 \
-drive if=none,id=root,format=raw,file=Fedora-Cloud-Base-25-1.3.x86_64.raw \
-device virtio-scsi \
-device scsi-disk,drive=root,bootindex=1 \
-object iothread,id=io \
-device virtio-scsi-pci,iothread=io \
-net user,hostfwd=tcp::10022-:22 -net nic,model=virtio -m 2048 \
--enable-kvm
Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to
their callers - and wrap the broken assertions in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170317061447.16243-3-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-03-17 09:14:47 +03:00
|
|
|
virtio_scsi_release(s);
|
|
|
|
return progress;
|
2016-04-06 13:16:27 +03:00
|
|
|
}
|
|
|
|
|
2021-04-07 17:35:00 +03:00
|
|
|
static int virtio_scsi_set_host_notifier(VirtIOSCSI *s, VirtQueue *vq, int n)
|
2014-09-23 11:49:24 +04:00
|
|
|
{
|
|
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s)));
|
2014-10-15 17:15:24 +04:00
|
|
|
int rc;
|
2014-09-23 11:49:24 +04:00
|
|
|
|
|
|
|
/* Set up virtqueue notify */
|
2016-06-10 12:04:10 +03:00
|
|
|
rc = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), n, true);
|
2014-10-15 17:15:24 +04:00
|
|
|
if (rc != 0) {
|
|
|
|
fprintf(stderr, "virtio-scsi: Failed to set host notifier (%d)\n",
|
|
|
|
rc);
|
2014-10-15 17:15:26 +04:00
|
|
|
s->dataplane_fenced = true;
|
2016-02-14 20:17:10 +03:00
|
|
|
return rc;
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
2015-03-18 12:42:12 +03:00
|
|
|
|
2016-02-14 20:17:10 +03:00
|
|
|
return 0;
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
|
2018-03-07 17:42:04 +03:00
|
|
|
/* Context: BH in IOThread */
|
|
|
|
static void virtio_scsi_dataplane_stop_bh(void *opaque)
|
2014-10-15 17:15:25 +04:00
|
|
|
{
|
2018-03-07 17:42:04 +03:00
|
|
|
VirtIOSCSI *s = opaque;
|
2014-10-15 17:15:25 +04:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
|
|
|
int i;
|
|
|
|
|
2016-04-06 13:16:28 +03:00
|
|
|
virtio_queue_aio_set_host_notifier_handler(vs->ctrl_vq, s->ctx, NULL);
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vs->event_vq, s->ctx, NULL);
|
2016-02-14 20:17:10 +03:00
|
|
|
for (i = 0; i < vs->conf.num_queues; i++) {
|
2016-04-06 13:16:28 +03:00
|
|
|
virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx, NULL);
|
2014-10-15 17:15:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:49:24 +04:00
|
|
|
/* Context: QEMU global mutex held */
|
2016-10-21 23:48:10 +03:00
|
|
|
int virtio_scsi_dataplane_start(VirtIODevice *vdev)
|
2014-09-23 11:49:24 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
2020-12-17 18:00:39 +03:00
|
|
|
int vq_init_count = 0;
|
2016-10-21 23:48:10 +03:00
|
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
2014-09-23 11:49:24 +04:00
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2016-10-21 23:48:10 +03:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
2014-09-23 11:49:24 +04:00
|
|
|
|
|
|
|
if (s->dataplane_started ||
|
|
|
|
s->dataplane_starting ||
|
2016-10-21 23:48:10 +03:00
|
|
|
s->dataplane_fenced) {
|
|
|
|
return 0;
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s->dataplane_starting = true;
|
|
|
|
|
|
|
|
/* Set up guest notifier (irq) */
|
|
|
|
rc = k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, true);
|
|
|
|
if (rc != 0) {
|
2018-06-13 08:05:19 +03:00
|
|
|
error_report("virtio-scsi: Failed to set guest notifiers (%d), "
|
|
|
|
"ensure -accel kvm is set.", rc);
|
2014-10-15 17:15:25 +04:00
|
|
|
goto fail_guest_notifiers;
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
|
2021-05-17 16:26:37 +03:00
|
|
|
/*
|
|
|
|
* Batch all the host notifiers in a single transaction to avoid
|
|
|
|
* quadratic time complexity in address_space_update_ioeventfds().
|
|
|
|
*/
|
2021-04-07 17:35:01 +03:00
|
|
|
memory_region_transaction_begin();
|
|
|
|
|
2021-04-07 17:35:00 +03:00
|
|
|
rc = virtio_scsi_set_host_notifier(s, vs->ctrl_vq, 0);
|
|
|
|
if (rc != 0) {
|
|
|
|
goto fail_host_notifiers;
|
2014-10-15 17:15:25 +04:00
|
|
|
}
|
2020-12-17 18:00:39 +03:00
|
|
|
|
|
|
|
vq_init_count++;
|
2021-04-07 17:35:00 +03:00
|
|
|
rc = virtio_scsi_set_host_notifier(s, vs->event_vq, 1);
|
|
|
|
if (rc != 0) {
|
|
|
|
goto fail_host_notifiers;
|
2014-10-15 17:15:25 +04:00
|
|
|
}
|
2020-12-17 18:00:39 +03:00
|
|
|
|
|
|
|
vq_init_count++;
|
2021-04-07 17:35:00 +03:00
|
|
|
|
2014-09-23 11:49:24 +04:00
|
|
|
for (i = 0; i < vs->conf.num_queues; i++) {
|
2021-04-07 17:35:00 +03:00
|
|
|
rc = virtio_scsi_set_host_notifier(s, vs->cmd_vqs[i], i + 2);
|
2016-02-14 20:17:10 +03:00
|
|
|
if (rc) {
|
2021-04-07 17:35:00 +03:00
|
|
|
goto fail_host_notifiers;
|
2014-10-15 17:15:25 +04:00
|
|
|
}
|
2020-12-17 18:00:39 +03:00
|
|
|
vq_init_count++;
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
|
2021-04-07 17:35:01 +03:00
|
|
|
memory_region_transaction_commit();
|
|
|
|
|
2021-04-07 17:35:00 +03:00
|
|
|
aio_context_acquire(s->ctx);
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vs->ctrl_vq, s->ctx,
|
|
|
|
virtio_scsi_data_plane_handle_ctrl);
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vs->event_vq, s->ctx,
|
|
|
|
virtio_scsi_data_plane_handle_event);
|
|
|
|
|
|
|
|
for (i = 0; i < vs->conf.num_queues; i++) {
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx,
|
|
|
|
virtio_scsi_data_plane_handle_cmd);
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:49:24 +04:00
|
|
|
s->dataplane_starting = false;
|
|
|
|
s->dataplane_started = true;
|
2014-10-31 19:38:04 +03:00
|
|
|
aio_context_release(s->ctx);
|
2016-10-21 23:48:10 +03:00
|
|
|
return 0;
|
2014-10-15 17:15:25 +04:00
|
|
|
|
2021-04-07 17:35:00 +03:00
|
|
|
fail_host_notifiers:
|
2020-12-17 18:00:39 +03:00
|
|
|
for (i = 0; i < vq_init_count; i++) {
|
2016-06-10 12:04:14 +03:00
|
|
|
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
|
2021-04-07 17:35:01 +03:00
|
|
|
}
|
|
|
|
|
2021-05-17 16:26:37 +03:00
|
|
|
/*
|
|
|
|
* The transaction expects the ioeventfds to be open when it
|
|
|
|
* commits. Do it now, before the cleanup loop.
|
|
|
|
*/
|
2021-04-07 17:35:01 +03:00
|
|
|
memory_region_transaction_commit();
|
|
|
|
|
|
|
|
for (i = 0; i < vq_init_count; i++) {
|
2018-01-29 17:20:56 +03:00
|
|
|
virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
|
2014-10-15 17:15:25 +04:00
|
|
|
}
|
|
|
|
k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);
|
|
|
|
fail_guest_notifiers:
|
2016-02-14 20:17:10 +03:00
|
|
|
s->dataplane_fenced = true;
|
2014-10-15 17:15:25 +04:00
|
|
|
s->dataplane_starting = false;
|
2016-02-14 20:17:10 +03:00
|
|
|
s->dataplane_started = true;
|
2016-10-21 23:48:10 +03:00
|
|
|
return -ENOSYS;
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Context: QEMU global mutex held */
|
2016-10-21 23:48:10 +03:00
|
|
|
void virtio_scsi_dataplane_stop(VirtIODevice *vdev)
|
2014-09-23 11:49:24 +04:00
|
|
|
{
|
2016-10-21 23:48:10 +03:00
|
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
2014-09-23 11:49:24 +04:00
|
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
2016-10-21 23:48:10 +03:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
|
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
2016-06-10 12:04:14 +03:00
|
|
|
int i;
|
2014-09-23 11:49:24 +04:00
|
|
|
|
2016-02-14 20:17:10 +03:00
|
|
|
if (!s->dataplane_started || s->dataplane_stopping) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-15 17:15:26 +04:00
|
|
|
/* Better luck next time. */
|
|
|
|
if (s->dataplane_fenced) {
|
|
|
|
s->dataplane_fenced = false;
|
2016-02-14 20:17:10 +03:00
|
|
|
s->dataplane_started = false;
|
2014-09-23 11:49:24 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->dataplane_stopping = true;
|
|
|
|
|
|
|
|
aio_context_acquire(s->ctx);
|
2018-03-07 17:42:04 +03:00
|
|
|
aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s);
|
2016-10-27 13:49:05 +03:00
|
|
|
aio_context_release(s->ctx);
|
2014-09-23 11:49:24 +04:00
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_drain_all(); /* ensure there are no in-flight requests */
|
2014-09-23 11:49:24 +04:00
|
|
|
|
2021-05-17 16:26:37 +03:00
|
|
|
/*
|
|
|
|
* Batch all the host notifiers in a single transaction to avoid
|
|
|
|
* quadratic time complexity in address_space_update_ioeventfds().
|
|
|
|
*/
|
2021-04-07 17:35:01 +03:00
|
|
|
memory_region_transaction_begin();
|
|
|
|
|
2014-09-23 11:49:24 +04:00
|
|
|
for (i = 0; i < vs->conf.num_queues + 2; i++) {
|
2016-06-10 12:04:14 +03:00
|
|
|
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
|
2021-04-07 17:35:01 +03:00
|
|
|
}
|
|
|
|
|
2021-05-17 16:26:37 +03:00
|
|
|
/*
|
|
|
|
* The transaction expects the ioeventfds to be open when it
|
|
|
|
* commits. Do it now, before the cleanup loop.
|
|
|
|
*/
|
2021-04-07 17:35:01 +03:00
|
|
|
memory_region_transaction_commit();
|
|
|
|
|
|
|
|
for (i = 0; i < vs->conf.num_queues + 2; i++) {
|
2018-01-29 17:20:56 +03:00
|
|
|
virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
|
2014-09-23 11:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up guest notifier (irq) */
|
|
|
|
k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);
|
|
|
|
s->dataplane_stopping = false;
|
|
|
|
s->dataplane_started = false;
|
|
|
|
}
|