diff mbox

[RFC,7/9] virtio-scsi: Start/stop vhost

Message ID 1343169246-17636-8-git-send-email-nab@linux-iscsi.org
State New
Headers show

Commit Message

Nicholas A. Bellinger July 24, 2012, 10:34 p.m. UTC
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)

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: 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  |    2 ++
 hw/virtio-scsi.c |   41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletions(-)

Comments

Paolo Bonzini July 25, 2012, 7:01 a.m. UTC | #1
Il 25/07/2012 00:34, Nicholas A. Bellinger ha scritto:
> 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)
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> Signed-off-by: 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>

Hmm, this is not what the patch does... :)

Paolo
Paolo Bonzini July 25, 2012, 7:03 a.m. UTC | #2
Il 25/07/2012 09:01, Paolo Bonzini ha scritto:
>> > 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)
>> > 
>> > Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>> > Signed-off-by: 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>
> Hmm, this is not what the patch does... :)

Oops, the above comment was meant for patch 5.  Which is a one-liner
that can be squashed here.

Anyway there is some problem with the ordering of the patches, because
this patch includes vhost-scsi.h (introduced in patch 9) and patch 5
uses VHostSCSI (defined by vhost-scsi.h).

Paolo
diff mbox

Patch

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 0f0f766..64f2f0d 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1060,6 +1060,8 @@  static int virtio_scsi_exit_pci(PCIDevice *pci_dev)
 }
 
 static Property virtio_scsi_properties[] = {
+    DEFINE_PROP_VHOST_SCSI("vhost-scsi", VirtIOPCIProxy,
+                            scsi.vhost_scsi),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
     DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
     DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index dea3269..b0adfde 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -15,6 +15,7 @@ 
 
 #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>
@@ -601,6 +602,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 = to_virtio_scsi(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;
@@ -622,6 +655,9 @@  VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
     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);
@@ -647,6 +683,9 @@  void virtio_scsi_exit(VirtIODevice *vdev)
 {
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
     unregister_savevm(s->qdev, "virtio-scsi", s);
-    vhost_dev_cleanup(&s->vhost_scsi);
+
+    /* This will stop vhost backend if appropriate. */
+    virtio_scsi_set_status(vdev, 0);
+
     virtio_cleanup(vdev);
 }