From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v4 09/14] virtio-scsi: Hook up with dataplane
Date: Wed, 24 Sep 2014 15:21:47 +0800 [thread overview]
Message-ID: <1411543312-6511-10-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1411543312-6511-1-git-send-email-famz@redhat.com>
This enables the virtio-scsi-dataplane code by setting the iothread
in virtio-scsi device, and makes any function that is called by
back from dataplane to cooperate with the caller: they need to be
vring/iothread aware when handling the requests and using scsi devices
on the bus.
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/virtio-scsi.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 48 insertions(+), 4 deletions(-)
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 91ead26..dc705f0 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -69,13 +69,19 @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
VirtIODevice *vdev = VIRTIO_DEVICE(s);
qemu_iovec_from_buf(&req->resp_iov, 0, &req->resp, req->resp_size);
- virtqueue_push(vq, &req->elem, req->qsgl.size + req->resp_iov.size);
+ if (req->vring) {
+ assert(req->vq == NULL);
+ virtio_scsi_vring_push_notify(req);
+ } else {
+ virtqueue_push(vq, &req->elem, req->qsgl.size + req->resp_iov.size);
+ virtio_notify(vdev, vq);
+ }
+
if (req->sreq) {
req->sreq->hba_private = NULL;
scsi_req_unref(req->sreq);
}
virtio_scsi_free_req(req);
- virtio_notify(vdev, vq);
}
static void virtio_scsi_bad_req(void)
@@ -208,6 +214,11 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
BusChild *kid;
int target;
+ if (s->dataplane_started && bdrv_get_aio_context(d->conf.bs) != s->ctx) {
+ aio_context_acquire(s->ctx);
+ bdrv_set_aio_context(d->conf.bs, s->ctx);
+ aio_context_release(s->ctx);
+ }
/* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
req->resp.tmf.response = VIRTIO_SCSI_S_OK;
@@ -346,6 +357,10 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
VirtIOSCSIReq *req;
+ if (s->ctx) {
+ virtio_scsi_dataplane_start(s);
+ return;
+ }
while ((req = virtio_scsi_pop_req(s, vq))) {
virtio_scsi_handle_ctrl_req(s, req);
}
@@ -457,6 +472,11 @@ void virtio_scsi_handle_cmd_req(VirtIOSCSI *s, VirtIOSCSIReq *req)
virtio_scsi_complete_cmd_req(req);
return;
}
+ if (s->dataplane_started && bdrv_get_aio_context(d->conf.bs) != s->ctx) {
+ aio_context_acquire(s->ctx);
+ bdrv_set_aio_context(d->conf.bs, s->ctx);
+ aio_context_release(s->ctx);
+ }
req->sreq = scsi_req_new(d, req->req.cmd.tag,
virtio_scsi_get_lun(req->req.cmd.lun),
req->req.cdb, req);
@@ -481,6 +501,10 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
VirtIOSCSI *s = (VirtIOSCSI *)vdev;
VirtIOSCSIReq *req;
+ if (s->ctx) {
+ virtio_scsi_dataplane_start(s);
+ return;
+ }
while ((req = virtio_scsi_pop_req(s, vq))) {
virtio_scsi_handle_cmd_req(s, req);
}
@@ -531,6 +555,9 @@ static void virtio_scsi_reset(VirtIODevice *vdev)
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
+ if (s->ctx) {
+ virtio_scsi_dataplane_stop(s);
+ }
s->resetting++;
qbus_reset_all(&s->bus.qbus);
s->resetting--;
@@ -573,10 +600,19 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
return;
}
- req = virtio_scsi_pop_req(s, vs->event_vq);
+ if (s->dataplane_started) {
+ assert(s->ctx);
+ aio_context_acquire(s->ctx);
+ }
+
+ if (s->dataplane_started) {
+ req = virtio_scsi_pop_req_vring(s, s->event_vring);
+ } else {
+ req = virtio_scsi_pop_req(s, vs->event_vq);
+ }
if (!req) {
s->events_dropped = true;
- return;
+ goto out;
}
if (s->events_dropped) {
@@ -605,12 +641,20 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
evt->lun[3] = dev->lun & 0xFF;
}
virtio_scsi_complete_req(req);
+out:
+ if (s->dataplane_started) {
+ aio_context_release(s->ctx);
+ }
}
static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+ if (s->ctx) {
+ virtio_scsi_dataplane_start(s);
+ return;
+ }
if (s->events_dropped) {
virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
}
--
1.9.3
next prev parent reply other threads:[~2014-09-24 7:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-24 7:21 [Qemu-devel] [PATCH v4 00/14] virtio-scsi: Dataplane on single iothread Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 01/14] virtio-scsi: Split virtio_scsi_handle_cmd_req from virtio_scsi_handle_cmd Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 02/14] virtio-scsi: Split virtio_scsi_handle_ctrl_req from virtio_scsi_handle_ctrl Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 03/14] virtio-scsi: Add VirtIOSCSIVring in VirtIOSCSIReq Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 04/14] virtio-scsi: Make virtio_scsi_init_req public Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 05/14] virtio-scsi: Make virtio_scsi_free_req public Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 06/14] virtio-scsi: Make virtio_scsi_push_event public Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 07/14] virtio-scsi: Add 'iothread' property to virtio-scsi-pci Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 08/14] virtio-scsi-dataplane: Code to run virtio-scsi on iothread Fam Zheng
2014-09-24 7:21 ` Fam Zheng [this message]
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 10/14] virtio-scsi: Add migration state notifier for dataplane code Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 11/14] virtio-scsi: Two stages processing of cmd request Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 12/14] virtio-scsi: Batched prepare for cmd reqs Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 13/14] virtio-scsi: Call bdrv_io_plug/bdrv_io_unplug in cmd request handling Fam Zheng
2014-09-24 7:21 ` [Qemu-devel] [PATCH v4 14/14] virtio-scsi: Process ".iothread" property Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411543312-6511-10-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).