Blame 0002-virtio-scsi-fix-ctrl-and-event-handler-functions-in-.patch

a575c5
From: Stefan Hajnoczi <stefanha@redhat.com>
a575c5
Date: Wed, 27 Apr 2022 15:35:36 +0100
a575c5
Subject: [PATCH] virtio-scsi: fix ctrl and event handler functions in
a575c5
 dataplane mode
a575c5
Content-type: text/plain
a575c5
a575c5
Commit f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare
a575c5
virtio_scsi_handle_cmd for dataplane") prepared the virtio-scsi cmd
a575c5
virtqueue handler function to be used in both the dataplane and
a575c5
non-datpalane code paths.
a575c5
a575c5
It failed to convert the ctrl and event virtqueue handler functions,
a575c5
which are not designed to be called from the dataplane code path but
a575c5
will be since the ioeventfd is set up for those virtqueues when
a575c5
dataplane starts.
a575c5
a575c5
Convert the ctrl and event virtqueue handler functions now so they
a575c5
operate correctly when called from the dataplane code path. Avoid code
a575c5
duplication by extracting this code into a helper function.
a575c5
a575c5
Fixes: f34e8d8b8d48d73f36a67b6d5e492ef9784b5012 ("virtio-scsi: prepare virtio_scsi_handle_cmd for dataplane")
a575c5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
a575c5
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
a575c5
Message-id: 20220427143541.119567-2-stefanha@redhat.com
a575c5
[Fixed s/by used/be used/ typo pointed out by Michael Tokarev
a575c5
<mjt@tls.msk.ru>.
a575c5
--Stefan]
a575c5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
a575c5
(cherry picked from commit 2f743ef6366c2df4ef51ef3ae318138cdc0125ab)
a575c5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
a575c5
---
a575c5
 hw/scsi/virtio-scsi.c | 42 +++++++++++++++++++++++++++---------------
a575c5
 1 file changed, 27 insertions(+), 15 deletions(-)
a575c5
a575c5
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
a575c5
index 34a968ecfb..417fbc71d6 100644
a575c5
--- a/hw/scsi/virtio-scsi.c
a575c5
+++ b/hw/scsi/virtio-scsi.c
a575c5
@@ -472,16 +472,32 @@ bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq)
a575c5
     return progress;
a575c5
 }
a575c5
 
a575c5
+/*
a575c5
+ * If dataplane is configured but not yet started, do so now and return true on
a575c5
+ * success.
a575c5
+ *
a575c5
+ * Dataplane is started by the core virtio code but virtqueue handler functions
a575c5
+ * can also be invoked when a guest kicks before DRIVER_OK, so this helper
a575c5
+ * function helps us deal with manually starting ioeventfd in that case.
a575c5
+ */
a575c5
+static bool virtio_scsi_defer_to_dataplane(VirtIOSCSI *s)
a575c5
+{
a575c5
+    if (!s->ctx || s->dataplane_started) {
a575c5
+        return false;
a575c5
+    }
a575c5
+
a575c5
+    virtio_device_start_ioeventfd(&s->parent_obj.parent_obj);
a575c5
+    return !s->dataplane_fenced;
a575c5
+}
a575c5
+
a575c5
 static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
a575c5
 {
a575c5
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
a575c5
 
a575c5
-    if (s->ctx) {
a575c5
-        virtio_device_start_ioeventfd(vdev);
a575c5
-        if (!s->dataplane_fenced) {
a575c5
-            return;
a575c5
-        }
a575c5
+    if (virtio_scsi_defer_to_dataplane(s)) {
a575c5
+        return;
a575c5
     }
a575c5
+
a575c5
     virtio_scsi_acquire(s);
a575c5
     virtio_scsi_handle_ctrl_vq(s, vq);
a575c5
     virtio_scsi_release(s);
a575c5
@@ -720,12 +736,10 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq)
a575c5
     /* use non-QOM casts in the data path */
a575c5
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
a575c5
 
a575c5
-    if (s->ctx && !s->dataplane_started) {
a575c5
-        virtio_device_start_ioeventfd(vdev);
a575c5
-        if (!s->dataplane_fenced) {
a575c5
-            return;
a575c5
-        }
a575c5
+    if (virtio_scsi_defer_to_dataplane(s)) {
a575c5
+        return;
a575c5
     }
a575c5
+
a575c5
     virtio_scsi_acquire(s);
a575c5
     virtio_scsi_handle_cmd_vq(s, vq);
a575c5
     virtio_scsi_release(s);
a575c5
@@ -855,12 +869,10 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
a575c5
 {
a575c5
     VirtIOSCSI *s = VIRTIO_SCSI(vdev);
a575c5
 
a575c5
-    if (s->ctx) {
a575c5
-        virtio_device_start_ioeventfd(vdev);
a575c5
-        if (!s->dataplane_fenced) {
a575c5
-            return;
a575c5
-        }
a575c5
+    if (virtio_scsi_defer_to_dataplane(s)) {
a575c5
+        return;
a575c5
     }
a575c5
+
a575c5
     virtio_scsi_acquire(s);
a575c5
     virtio_scsi_handle_event_vq(s, vq);
a575c5
     virtio_scsi_release(s);