All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: target-devel <target-devel@vger.kernel.org>
Cc: lf-virt <virtualization@lists.linux-foundation.org>,
	kvm-devel <kvm@vger.kernel.org>,
	qemu-devel <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Zhi Yong Wu <wuzhy@cn.ibm.com>,
	Anthony Liguori <aliguori@linux.vnet.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Subject: [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi
Date: Mon, 13 Aug 2012 08:35:15 +0000	[thread overview]
Message-ID: <1344846917-7411-5-git-send-email-nab@linux-iscsi.org> (raw)
In-Reply-To: <1344846917-7411-1-git-send-email-nab@linux-iscsi.org>

From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

This patch starts and stops vhost as the virtio device transitions
through its status phases.  Vhost can only be started once the guest
reports its driver has successfully initialized, which means the
virtqueues have been set up by the guest.

v2: - Squash virtio-scsi: use the vhost-scsi host device from stefan (nab)
    - Fix up virtio_scsi_properties[] conflict w/ upstream qemu (nab)
    - Drop usage of to_virtio_scsi() in virtio_scsi_set_status()
      (reported by paolo)
    - Use modern VirtIOSCSIConf define in virtio-scsi.h (reported by paolo)
    - Use s->conf->vhost_scsi instead of proxyconf->vhost_scsi in
      virtio_scsi_init() (reported by paolo)
    - Only register QEMU SCSI bus is vhost-scsi is not active (reported
      by paolo)

Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 hw/virtio-pci.c  |    1 +
 hw/virtio-scsi.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-scsi.h |    1 +
 3 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 125eded..b29fc3b 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1036,6 +1036,7 @@ static void virtio_scsi_exit_pci(PCIDevice *pci_dev)
 }
 
 static Property virtio_scsi_properties[] = {
+    DEFINE_PROP_VHOST_SCSI("vhost-scsi", VirtIOPCIProxy, scsi.vhost_scsi),
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
     DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 5f737ac..8130956 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -13,9 +13,13 @@
  *
  */
 
+#include "qemu-common.h"
+#include "qemu-error.h"
+#include "vhost-scsi.h"
 #include "virtio-scsi.h"
 #include <hw/scsi.h>
 #include <hw/scsi-defs.h>
+#include "vhost.h"
 
 #define VIRTIO_SCSI_VQ_SIZE     128
 #define VIRTIO_SCSI_CDB_SIZE    32
@@ -147,6 +151,9 @@ typedef struct {
     VirtQueue *ctrl_vq;
     VirtQueue *event_vq;
     VirtQueue *cmd_vqs[0];
+
+    bool vhost_started;
+    VHostSCSI *vhost_scsi;
 } VirtIOSCSI;
 
 typedef struct VirtIOSCSIReq {
@@ -699,6 +706,38 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = {
     .load_request = virtio_scsi_load_request,
 };
 
+static bool virtio_scsi_started(VirtIOSCSI *s, uint8_t val)
+{
+    return (val & VIRTIO_CONFIG_S_DRIVER_OK) && s->vdev.vm_running;
+}
+
+static void virtio_scsi_set_status(VirtIODevice *vdev, uint8_t val)
+{
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
+    bool start = virtio_scsi_started(s, val);
+
+    if (s->vhost_started == start) {
+        return;
+    }
+
+    if (start) {
+        int ret;
+
+        ret = vhost_scsi_start(s->vhost_scsi, vdev);
+        if (ret < 0) {
+            error_report("virtio-scsi: unable to start vhost: %s\n",
+                         strerror(-ret));
+
+            /* There is no userspace virtio-scsi fallback so exit */
+            exit(1);
+        }
+    } else {
+        vhost_scsi_stop(s->vhost_scsi, vdev);
+    }
+
+    s->vhost_started = start;
+}
+
 VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
 {
     VirtIOSCSI *s;
@@ -712,12 +751,17 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
 
     s->qdev = dev;
     s->conf = proxyconf;
+    s->vhost_started = false;
+    s->vhost_scsi = s->conf->vhost_scsi;
 
     /* TODO set up vdev function pointers */
     s->vdev.get_config = virtio_scsi_get_config;
     s->vdev.set_config = virtio_scsi_set_config;
     s->vdev.get_features = virtio_scsi_get_features;
     s->vdev.reset = virtio_scsi_reset;
+    if (s->vhost_scsi) {
+        s->vdev.set_status = virtio_scsi_set_status;
+    }
 
     s->ctrl_vq = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
                                    virtio_scsi_handle_ctrl);
@@ -743,5 +787,9 @@ void virtio_scsi_exit(VirtIODevice *vdev)
 {
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
     unregister_savevm(s->qdev, "virtio-scsi", s);
+
+    /* This will stop vhost backend if appropriate. */
+    virtio_scsi_set_status(vdev, 0);
+
     virtio_cleanup(vdev);
 }
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 4bc889d..74e9422 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -22,6 +22,7 @@
 #define VIRTIO_ID_SCSI  8
 
 struct VirtIOSCSIConf {
+    VHostSCSI *vhost_scsi;
     uint32_t num_queues;
     uint32_t max_sectors;
     uint32_t cmd_per_lun;
-- 
1.7.2.5

WARNING: multiple messages have this Message-ID (diff)
From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: target-devel <target-devel@vger.kernel.org>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm-devel <kvm@vger.kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Zhi Yong Wu <wuzhy@cn.ibm.com>,
	Anthony Liguori <aliguori@linux.vnet.ibm.com>,
	Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
	Hannes Reinecke <hare@suse.de>,
	Paolo Bonzini <pbonzini@redhat.com>,
	lf-virt <virtualization@lists.linux-foundation.org>,
	Christoph Hellwig <hch@lst.de>
Subject: [Qemu-devel] [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi
Date: Mon, 13 Aug 2012 08:35:15 +0000	[thread overview]
Message-ID: <1344846917-7411-5-git-send-email-nab@linux-iscsi.org> (raw)
In-Reply-To: <1344846917-7411-1-git-send-email-nab@linux-iscsi.org>

From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

This patch starts and stops vhost as the virtio device transitions
through its status phases.  Vhost can only be started once the guest
reports its driver has successfully initialized, which means the
virtqueues have been set up by the guest.

v2: - Squash virtio-scsi: use the vhost-scsi host device from stefan (nab)
    - Fix up virtio_scsi_properties[] conflict w/ upstream qemu (nab)
    - Drop usage of to_virtio_scsi() in virtio_scsi_set_status()
      (reported by paolo)
    - Use modern VirtIOSCSIConf define in virtio-scsi.h (reported by paolo)
    - Use s->conf->vhost_scsi instead of proxyconf->vhost_scsi in
      virtio_scsi_init() (reported by paolo)
    - Only register QEMU SCSI bus is vhost-scsi is not active (reported
      by paolo)

Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 hw/virtio-pci.c  |    1 +
 hw/virtio-scsi.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-scsi.h |    1 +
 3 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 125eded..b29fc3b 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1036,6 +1036,7 @@ static void virtio_scsi_exit_pci(PCIDevice *pci_dev)
 }
 
 static Property virtio_scsi_properties[] = {
+    DEFINE_PROP_VHOST_SCSI("vhost-scsi", VirtIOPCIProxy, scsi.vhost_scsi),
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
     DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 5f737ac..8130956 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -13,9 +13,13 @@
  *
  */
 
+#include "qemu-common.h"
+#include "qemu-error.h"
+#include "vhost-scsi.h"
 #include "virtio-scsi.h"
 #include <hw/scsi.h>
 #include <hw/scsi-defs.h>
+#include "vhost.h"
 
 #define VIRTIO_SCSI_VQ_SIZE     128
 #define VIRTIO_SCSI_CDB_SIZE    32
@@ -147,6 +151,9 @@ typedef struct {
     VirtQueue *ctrl_vq;
     VirtQueue *event_vq;
     VirtQueue *cmd_vqs[0];
+
+    bool vhost_started;
+    VHostSCSI *vhost_scsi;
 } VirtIOSCSI;
 
 typedef struct VirtIOSCSIReq {
@@ -699,6 +706,38 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = {
     .load_request = virtio_scsi_load_request,
 };
 
+static bool virtio_scsi_started(VirtIOSCSI *s, uint8_t val)
+{
+    return (val & VIRTIO_CONFIG_S_DRIVER_OK) && s->vdev.vm_running;
+}
+
+static void virtio_scsi_set_status(VirtIODevice *vdev, uint8_t val)
+{
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
+    bool start = virtio_scsi_started(s, val);
+
+    if (s->vhost_started == start) {
+        return;
+    }
+
+    if (start) {
+        int ret;
+
+        ret = vhost_scsi_start(s->vhost_scsi, vdev);
+        if (ret < 0) {
+            error_report("virtio-scsi: unable to start vhost: %s\n",
+                         strerror(-ret));
+
+            /* There is no userspace virtio-scsi fallback so exit */
+            exit(1);
+        }
+    } else {
+        vhost_scsi_stop(s->vhost_scsi, vdev);
+    }
+
+    s->vhost_started = start;
+}
+
 VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
 {
     VirtIOSCSI *s;
@@ -712,12 +751,17 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
 
     s->qdev = dev;
     s->conf = proxyconf;
+    s->vhost_started = false;
+    s->vhost_scsi = s->conf->vhost_scsi;
 
     /* TODO set up vdev function pointers */
     s->vdev.get_config = virtio_scsi_get_config;
     s->vdev.set_config = virtio_scsi_set_config;
     s->vdev.get_features = virtio_scsi_get_features;
     s->vdev.reset = virtio_scsi_reset;
+    if (s->vhost_scsi) {
+        s->vdev.set_status = virtio_scsi_set_status;
+    }
 
     s->ctrl_vq = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
                                    virtio_scsi_handle_ctrl);
@@ -743,5 +787,9 @@ void virtio_scsi_exit(VirtIODevice *vdev)
 {
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
     unregister_savevm(s->qdev, "virtio-scsi", s);
+
+    /* This will stop vhost backend if appropriate. */
+    virtio_scsi_set_status(vdev, 0);
+
     virtio_cleanup(vdev);
 }
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 4bc889d..74e9422 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -22,6 +22,7 @@
 #define VIRTIO_ID_SCSI  8
 
 struct VirtIOSCSIConf {
+    VHostSCSI *vhost_scsi;
     uint32_t num_queues;
     uint32_t max_sectors;
     uint32_t cmd_per_lun;
-- 
1.7.2.5

  parent reply	other threads:[~2012-08-13  8:35 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-13  8:35 [RFC-v2 0/6] vhost-scsi: Add support for host virtualized target Nicholas A. Bellinger
2012-08-13  8:35 ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  8:35 ` [RFC-v2 1/6] msix: Work-around for vhost-scsi with KVM in-kernel MSI injection Nicholas A. Bellinger
2012-08-13  8:35   ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  8:51   ` Michael S. Tsirkin
2012-08-13  8:51     ` [Qemu-devel] " Michael S. Tsirkin
2012-08-13 12:06   ` Jan Kiszka
2012-08-13 12:06   ` Jan Kiszka
2012-08-13 12:06     ` [Qemu-devel] " Jan Kiszka
2012-08-13 18:03     ` Michael S. Tsirkin
2012-08-13 18:03       ` [Qemu-devel] " Michael S. Tsirkin
2012-08-13 18:06       ` Jan Kiszka
2012-08-13 18:06         ` [Qemu-devel] " Jan Kiszka
2012-08-13 18:17         ` Michael S. Tsirkin
2012-08-13 18:17         ` Michael S. Tsirkin
2012-08-13 18:17           ` [Qemu-devel] " Michael S. Tsirkin
2012-08-14 20:10           ` Nicholas A. Bellinger
2012-08-14 20:10             ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13 19:39   ` Blue Swirl
2012-08-13 19:39     ` Blue Swirl
2012-08-13 19:39   ` Blue Swirl
2012-08-13  8:35 ` [RFC-v2 2/6] vhost: Pass device path to vhost_dev_init() Nicholas A. Bellinger
2012-08-13  8:35   ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  8:35 ` Nicholas A. Bellinger
2012-08-13  8:35 ` [RFC-v2 3/6] vhost-scsi: add -vhost-scsi host device for use with tcm-vhost Nicholas A. Bellinger
2012-08-13  8:35 ` Nicholas A. Bellinger
2012-08-13  8:35   ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  8:53   ` Michael S. Tsirkin
2012-08-13  8:53     ` [Qemu-devel] " Michael S. Tsirkin
2012-08-14 20:31     ` Nicholas A. Bellinger
2012-08-14 20:31       ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-18 19:12       ` Michael S. Tsirkin
2012-08-18 19:12         ` [Qemu-devel] " Michael S. Tsirkin
2012-08-19  0:36         ` Nicholas A. Bellinger
2012-08-19  0:36           ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-19  8:44           ` Michael S. Tsirkin
2012-08-19  8:44             ` [Qemu-devel] " Michael S. Tsirkin
2012-08-20 22:24             ` Nicholas A. Bellinger
2012-08-20 22:24               ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  8:59   ` Michael S. Tsirkin
2012-08-13  8:59     ` [Qemu-devel] " Michael S. Tsirkin
2012-08-14 21:12     ` Nicholas A. Bellinger
2012-08-14 21:12     ` Nicholas A. Bellinger
2012-08-14 21:12       ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-18 19:10       ` Michael S. Tsirkin
2012-08-18 19:10         ` [Qemu-devel] " Michael S. Tsirkin
2012-08-18 23:38         ` Nicholas A. Bellinger
2012-08-18 23:38         ` Nicholas A. Bellinger
2012-08-18 23:38           ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13 19:47   ` Blue Swirl
2012-08-13 19:47   ` Blue Swirl
2012-08-13 19:47     ` Blue Swirl
2012-08-14 21:17     ` Nicholas A. Bellinger
2012-08-14 21:17     ` Nicholas A. Bellinger
2012-08-14 21:17       ` Nicholas A. Bellinger
2012-08-20  9:02   ` Paolo Bonzini
2012-08-20  9:02     ` [Qemu-devel] " Paolo Bonzini
2012-08-13  8:35 ` [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi Nicholas A. Bellinger
2012-08-13  8:35 ` Nicholas A. Bellinger [this message]
2012-08-13  8:35   ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-20  9:04   ` Paolo Bonzini
2012-08-20  9:04     ` [Qemu-devel] " Paolo Bonzini
2012-08-20 11:31     ` Stefan Hajnoczi
2012-08-20 11:31       ` [Qemu-devel] " Stefan Hajnoczi
2012-08-20 11:57       ` Michael S. Tsirkin
2012-08-20 11:57         ` [Qemu-devel] " Michael S. Tsirkin
2012-08-20 12:00         ` Paolo Bonzini
2012-08-20 12:00           ` [Qemu-devel] " Paolo Bonzini
2012-08-20 11:31     ` Stefan Hajnoczi
2012-08-13  8:35 ` [RFC-v2 5/6] virtio-scsi: Set max_target=0 during vhost-scsi operation Nicholas A. Bellinger
2012-08-13  8:35 ` Nicholas A. Bellinger
2012-08-13  8:35   ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  8:35 ` [RFC-v2 6/6] virtio-scsi: Fix incorrect VirtIOSCSI->cmd_vqs[0] definition Nicholas A. Bellinger
2012-08-13  8:35 ` Nicholas A. Bellinger
2012-08-13  8:35   ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  9:02   ` Michael S. Tsirkin
2012-08-13  9:02     ` [Qemu-devel] " Michael S. Tsirkin
2012-08-14 20:20     ` Nicholas A. Bellinger
2012-08-14 20:20     ` Nicholas A. Bellinger
2012-08-14 20:20       ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-18 18:52       ` Paolo Bonzini
2012-08-18 18:52         ` [Qemu-devel] " Paolo Bonzini
2012-08-18 21:47         ` Nicholas A. Bellinger
2012-08-18 21:47         ` Nicholas A. Bellinger
2012-08-18 21:47           ` [Qemu-devel] " Nicholas A. Bellinger
2012-08-13  9:04 ` [RFC-v2 0/6] vhost-scsi: Add support for host virtualized target Michael S. Tsirkin
2012-08-13  9:04   ` [Qemu-devel] " Michael S. Tsirkin

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=1344846917-7411-5-git-send-email-nab@linux-iscsi.org \
    --to=nab@linux-iscsi.org \
    --cc=aliguori@linux.vnet.ibm.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=target-devel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wuzhy@cn.ibm.com \
    --cc=wuzhy@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.