mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00

nvdimm hotplug support
virtio migration and ioeventfd rework
virtio crypto device
ipmi fixes
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJYGM+cAAoJECgfDbjSjVRpw1UH/3lZ4gVM3NO6l++XnautmiQ0
BkzZWpwUDOISn+6i0uZ5sc8pYXCZ/BpAR7ySRCmDSZLN2SzL0Bhp5JWbP/QZ/dNI
PBqR5cQrytkj3kWNNfFnAKCOjCxazGnsbmQLUBd0nzxlDqmpZ1+bKp/4aTZKqOnR
FbFl8F1W+0JwZszXG4mC84Yhe45KNBc3G9UeWfl7uuZ+OEfZrubBpBVbZFvClIyo
RTLJmZad+0PrC/ECsnEeAGOOrOoz6WSx5/Ydl1aCCj/CZkpyw+06ET2/aJ7y0UMO
WJRJiYJQir/kUegoV/YBU2yHHmVY8YQZss6Q5EpVbZ0PoAXvG9oBlULA9YkiLMo=
=2bfB
-----END PGP SIGNATURE-----
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
virtio, pc: fixes and features
nvdimm hotplug support
virtio migration and ioeventfd rework
virtio crypto device
ipmi fixes
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
# gpg: Signature made Tue 01 Nov 2016 05:23:40 PM GMT
# gpg: using RSA key 0x281F0DB8D28D5469
# gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>"
# gpg: aka "Michael S. Tsirkin <mst@redhat.com>"
# Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67
# Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469
* remotes/mst/tags/for_upstream: (47 commits)
acpi: fix assert failure caused by commit 35c5a52d
acpi/ipmi: Initialize the fwinfo before fetching it
ipmi: Add graceful shutdown handling to the external BMC
ipmi: fix build config variable name for ipmi_bmc_extern.o
ipmi: Implement shutdown via ACPI overtemp
ipmi: chassis poweroff should use qemu_system_shutdown_request()
ipmi_bmc_sim: Remove an unnecessary mutex
ipmi: Remove hotplug from IPMI BMCs
pc: memhp: enable nvdimm device hotplug
nvdimm acpi: introduce _FIT
nvdimm acpi: introduce fit buffer
nvdimm acpi: prebuild nvdimm devices for available slots
nvdimm acpi: use common macros instead of magic names
acpi nvdimm: rename result_size to dsm_out_buf_siz
nvdimm acpi: compile nvdimm acpi code arch-independently
acpi nvdimm: fix Arg6 usage
acpi nvdimm: fix ARG3 conflict
acpi nvdimm: fix device physical address base
acpi nvdimm: fix OperationRegion definition
acpi nvdimm: fix wrong buffer size returned by DSM method
...
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
217 lines
6.3 KiB
C
217 lines
6.3 KiB
C
/*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qapi/error.h"
|
|
#include "hw/virtio/virtio-scsi.h"
|
|
#include "qemu/error-report.h"
|
|
#include "sysemu/block-backend.h"
|
|
#include "hw/scsi/scsi.h"
|
|
#include "block/scsi.h"
|
|
#include "hw/virtio/virtio-bus.h"
|
|
#include "hw/virtio/virtio-access.h"
|
|
|
|
/* Context: QEMU global mutex held */
|
|
void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)
|
|
{
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
|
VirtIODevice *vdev = VIRTIO_DEVICE(s);
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
static void virtio_scsi_data_plane_handle_cmd(VirtIODevice *vdev,
|
|
VirtQueue *vq)
|
|
{
|
|
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
|
|
|
|
assert(s->ctx && s->dataplane_started);
|
|
virtio_scsi_handle_cmd_vq(s, vq);
|
|
}
|
|
|
|
static void virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev,
|
|
VirtQueue *vq)
|
|
{
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
assert(s->ctx && s->dataplane_started);
|
|
virtio_scsi_handle_ctrl_vq(s, vq);
|
|
}
|
|
|
|
static void virtio_scsi_data_plane_handle_event(VirtIODevice *vdev,
|
|
VirtQueue *vq)
|
|
{
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
assert(s->ctx && s->dataplane_started);
|
|
virtio_scsi_handle_event_vq(s, vq);
|
|
}
|
|
|
|
static int virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, int n,
|
|
void (*fn)(VirtIODevice *vdev, VirtQueue *vq))
|
|
{
|
|
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s)));
|
|
int rc;
|
|
|
|
/* Set up virtqueue notify */
|
|
rc = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), n, true);
|
|
if (rc != 0) {
|
|
fprintf(stderr, "virtio-scsi: Failed to set host notifier (%d)\n",
|
|
rc);
|
|
s->dataplane_fenced = true;
|
|
return rc;
|
|
}
|
|
|
|
virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, fn);
|
|
return 0;
|
|
}
|
|
|
|
void virtio_scsi_dataplane_notify(VirtIODevice *vdev, VirtIOSCSIReq *req)
|
|
{
|
|
if (virtio_should_notify(vdev, req->vq)) {
|
|
event_notifier_set(virtio_queue_get_guest_notifier(req->vq));
|
|
}
|
|
}
|
|
|
|
/* assumes s->ctx held */
|
|
static void virtio_scsi_clear_aio(VirtIOSCSI *s)
|
|
{
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
|
|
int i;
|
|
|
|
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);
|
|
for (i = 0; i < vs->conf.num_queues; i++) {
|
|
virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx, NULL);
|
|
}
|
|
}
|
|
|
|
/* Context: QEMU global mutex held */
|
|
int virtio_scsi_dataplane_start(VirtIODevice *vdev)
|
|
{
|
|
int i;
|
|
int rc;
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
|
if (s->dataplane_started ||
|
|
s->dataplane_starting ||
|
|
s->dataplane_fenced) {
|
|
return 0;
|
|
}
|
|
|
|
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) {
|
|
fprintf(stderr, "virtio-scsi: Failed to set guest notifiers (%d), "
|
|
"ensure -enable-kvm is set\n", rc);
|
|
goto fail_guest_notifiers;
|
|
}
|
|
|
|
aio_context_acquire(s->ctx);
|
|
rc = virtio_scsi_vring_init(s, vs->ctrl_vq, 0,
|
|
virtio_scsi_data_plane_handle_ctrl);
|
|
if (rc) {
|
|
goto fail_vrings;
|
|
}
|
|
rc = virtio_scsi_vring_init(s, vs->event_vq, 1,
|
|
virtio_scsi_data_plane_handle_event);
|
|
if (rc) {
|
|
goto fail_vrings;
|
|
}
|
|
for (i = 0; i < vs->conf.num_queues; i++) {
|
|
rc = virtio_scsi_vring_init(s, vs->cmd_vqs[i], i + 2,
|
|
virtio_scsi_data_plane_handle_cmd);
|
|
if (rc) {
|
|
goto fail_vrings;
|
|
}
|
|
}
|
|
|
|
s->dataplane_starting = false;
|
|
s->dataplane_started = true;
|
|
aio_context_release(s->ctx);
|
|
return 0;
|
|
|
|
fail_vrings:
|
|
virtio_scsi_clear_aio(s);
|
|
aio_context_release(s->ctx);
|
|
for (i = 0; i < vs->conf.num_queues + 2; i++) {
|
|
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
|
|
}
|
|
k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);
|
|
fail_guest_notifiers:
|
|
s->dataplane_fenced = true;
|
|
s->dataplane_starting = false;
|
|
s->dataplane_started = true;
|
|
return -ENOSYS;
|
|
}
|
|
|
|
/* Context: QEMU global mutex held */
|
|
void virtio_scsi_dataplane_stop(VirtIODevice *vdev)
|
|
{
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
|
|
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
int i;
|
|
|
|
if (!s->dataplane_started || s->dataplane_stopping) {
|
|
return;
|
|
}
|
|
|
|
/* Better luck next time. */
|
|
if (s->dataplane_fenced) {
|
|
s->dataplane_fenced = false;
|
|
s->dataplane_started = false;
|
|
return;
|
|
}
|
|
s->dataplane_stopping = true;
|
|
|
|
aio_context_acquire(s->ctx);
|
|
virtio_scsi_clear_aio(s);
|
|
aio_context_release(s->ctx);
|
|
|
|
blk_drain_all(); /* ensure there are no in-flight requests */
|
|
|
|
for (i = 0; i < vs->conf.num_queues + 2; i++) {
|
|
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
|
|
}
|
|
|
|
/* 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;
|
|
}
|