From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [RFC PATCH v2 10/10] virtio-scsi: Hook up with dataplane
Date: Fri, 19 Sep 2014 11:30:29 +0200 [thread overview]
Message-ID: <541BF7B5.6080509@redhat.com> (raw)
In-Reply-To: <1407303308-4615-11-git-send-email-famz@redhat.com>
Il 06/08/2014 07:35, Fam Zheng ha scritto:
> 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>
> ---
> hw/scsi/virtio-scsi.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 71 insertions(+), 3 deletions(-)
>
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index 9e78e21..1f2a9b6 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -62,6 +62,22 @@ void virtio_scsi_free_req(VirtIOSCSIReq *req)
> g_free(req);
> }
>
> +static void virtio_scsi_aio_acquire(VirtIOSCSICommon *vs)
> +{
> + if (vs->dataplane_started) {
> + assert(vs->ctx);
> + aio_context_acquire(vs->ctx);
> + }
> +}
> +
> +static void virtio_scsi_aio_release(VirtIOSCSICommon *vs)
> +{
> + if (vs->dataplane_started) {
> + assert(vs->ctx);
> + aio_context_release(vs->ctx);
> + }
> +}
These are not needed if you do the acquire/release in
virtio_scsi_push_event.
> static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
> {
> VirtIOSCSI *s = req->dev;
> @@ -69,13 +85,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)
> @@ -204,10 +226,16 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
> static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
> {
> SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf.lun);
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
> SCSIRequest *r, *next;
> BusChild *kid;
> int target;
>
> + if (vs->dataplane_started && bdrv_get_aio_context(d->conf.bs) != vs->ctx) {
> + aio_context_acquire(vs->ctx);
> + bdrv_set_aio_context(d->conf.bs, vs->ctx);
> + aio_context_release(vs->ctx);
> + }
> /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
> req->resp.tmf.response = VIRTIO_SCSI_S_OK;
>
> @@ -344,8 +372,13 @@ void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req)
> static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
> {
> VirtIOSCSI *s = (VirtIOSCSI *)vdev;
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vdev;
> VirtIOSCSIReq *req;
>
> + if (vs->ctx) {
> + virtio_scsi_dataplane_start(vs);
> + return;
> + }
> while ((req = virtio_scsi_pop_req(s, vq))) {
> virtio_scsi_handle_ctrl_req(s, req);
> }
> @@ -439,6 +472,11 @@ void virtio_scsi_handle_cmd_req(VirtIOSCSI *s, VirtIOSCSIReq *req)
> virtio_scsi_complete_cmd_req(req);
> return;
> }
> + if (vs->dataplane_started && bdrv_get_aio_context(d->conf.bs) != vs->ctx) {
> + aio_context_acquire(vs->ctx);
> + bdrv_set_aio_context(d->conf.bs, vs->ctx);
> + aio_context_release(vs->ctx);
> + }
> req->sreq = scsi_req_new(d, req->req.cmd.tag,
> virtio_scsi_get_lun(req->req.cmd.lun),
> req->req.cdb, req);
> @@ -461,8 +499,13 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
> {
> /* use non-QOM casts in the data path */
> VirtIOSCSI *s = (VirtIOSCSI *)vdev;
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vdev;
> VirtIOSCSIReq *req;
>
> + if (vs->ctx) {
> + virtio_scsi_dataplane_start(vs);
> + return;
> + }
A migration state change notifier (like in virtio-blk-dataplane) is missing.
> while ((req = virtio_scsi_pop_req(s, vq))) {
> virtio_scsi_handle_cmd_req(s, req);
> }
> @@ -513,6 +556,9 @@ static void virtio_scsi_reset(VirtIODevice *vdev)
> VirtIOSCSI *s = VIRTIO_SCSI(vdev);
> VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
>
> + if (vs->ctx) {
> + virtio_scsi_dataplane_stop(vs);
> + }
> s->resetting++;
> qbus_reset_all(&s->bus.qbus);
> s->resetting--;
> @@ -555,7 +601,11 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
> return;
> }
>
> - req = virtio_scsi_pop_req(s, vs->event_vq);
> + if (vs->dataplane_started) {
> + req = virtio_scsi_pop_req_vring(s, vs->event_vring);
> + } else {
> + req = virtio_scsi_pop_req(s, vs->event_vq);
> + }
> if (!req) {
> s->events_dropped = true;
> return;
> @@ -592,7 +642,12 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
> static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
> {
> VirtIOSCSI *s = VIRTIO_SCSI(vdev);
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vdev;
>
> + if (vs->ctx) {
> + virtio_scsi_dataplane_start(vs);
> + return;
> + }
> if (s->events_dropped) {
> virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
> }
> @@ -602,11 +657,14 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
> {
> VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
> VirtIODevice *vdev = VIRTIO_DEVICE(s);
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vdev;
>
> if (((vdev->guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) &&
> dev->type != TYPE_ROM) {
> + virtio_scsi_aio_acquire(vs);
> virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE,
> sense.asc | (sense.ascq << 8));
> + virtio_scsi_aio_release(vs);
> }
> }
>
> @@ -614,10 +672,13 @@ static void virtio_scsi_hotplug(SCSIBus *bus, SCSIDevice *dev)
> {
> VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
> VirtIODevice *vdev = VIRTIO_DEVICE(s);
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vdev;
>
> if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
> + virtio_scsi_aio_acquire(vs);
> virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_TRANSPORT_RESET,
> VIRTIO_SCSI_EVT_RESET_RESCAN);
> + virtio_scsi_aio_release(vs);
> }
> }
>
> @@ -625,10 +686,13 @@ static void virtio_scsi_hot_unplug(SCSIBus *bus, SCSIDevice *dev)
> {
> VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
> VirtIODevice *vdev = VIRTIO_DEVICE(s);
> + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vdev;
>
> if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
> + virtio_scsi_aio_acquire(vs);
> virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_TRANSPORT_RESET,
> VIRTIO_SCSI_EVT_RESET_REMOVED);
> + virtio_scsi_aio_release(vs);
> }
> }
>
> @@ -671,6 +735,10 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
> s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
> cmd);
> }
> +
> + if (s->conf.iothread) {
> + virtio_scsi_set_iothread(s, s->conf.iothread);
> + }
> }
>
> static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
>
next prev parent reply other threads:[~2014-09-19 9:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-06 5:34 [Qemu-devel] [RFC PATCH v2 00/10] virtio-scsi: Dataplane on single iothread Fam Zheng
2014-08-06 5:34 ` [Qemu-devel] [RFC PATCH v2 01/10] virtio: Compile vring code unconditionally Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 02/10] virtio-scsi: Split virtio_scsi_handle_cmd_req from virtio_scsi_handle_cmd Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 03/10] virtio-scsi: Split virtio_scsi_handle_ctrl_req from virtio_scsi_handle_ctrl Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 04/10] virtio-scsi: Add VirtIOSCSIVring in VirtIOSCSIReq Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 05/10] virtio-scsi: Make virtio_scsi_init_req public Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 06/10] virtio-scsi: Make virtio_scsi_free_req public Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 07/10] virtio-scsi: Make virtio_scsi_push_event public Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 08/10] virtio-scsi: Add 'iothread' property to virtio-scsi-pci Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 09/10] virtio-scsi-dataplane: Code to run virtio-scsi on iothread Fam Zheng
2014-08-06 8:45 ` Paolo Bonzini
2014-08-06 9:07 ` Fam Zheng
2014-09-19 9:29 ` Paolo Bonzini
2014-09-22 5:56 ` Fam Zheng
2014-09-22 8:09 ` Paolo Bonzini
2014-09-22 8:33 ` Fam Zheng
2014-09-22 6:14 ` Fam Zheng
2014-08-06 5:35 ` [Qemu-devel] [RFC PATCH v2 10/10] virtio-scsi: Hook up with dataplane Fam Zheng
2014-09-19 9:30 ` Paolo Bonzini [this message]
2014-09-19 9:28 ` [Qemu-devel] [RFC PATCH v2 00/10] virtio-scsi: Dataplane on single iothread Paolo Bonzini
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=541BF7B5.6080509@redhat.com \
--to=pbonzini@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@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).