Skip to contentSkip to conversation

virtio-scsi: abort in-flight I/O when the device is reset

PATCH Applied Paolo Bonzini 4 participants 7 messages Jan 10, 2013 – Jan 11, 2013

lore
Share & tools
lore
#0 lore raw

cover virtio-scsi: abort in-flight I/O when the device is reset

This fixes the virtio-scsi problem by forcing a reset of the SCSI bus from virtio_reset. The reset will happen twice on machine initialization (and this is why I preferred the other approach, using qdev_reset_all in virtio code), but that's harmless.

Paolo Bonzini (2):
qdev: add qbus_reset_all
virtio-scsi: abort in-flight I/O when the device is reset

 hw/qdev-core.h   | 12 ++++++++++++
 hw/qdev.c        |  7 ++++++-
 hw/virtio-scsi.c |  4 ++++
 3 files changed, 22 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1
#1 lore raw

PATCH 1/2 qdev: add qbus_reset_all

---
 hw/qdev-core.h | 12 ++++++++++++
 hw/qdev.c      |  7 ++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
hw/qdev-core.h +12 -0
index fdf14ec..853bd08 100644
@@ -182,6 +182,18 @@ int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
                        qbus_walkerfn *busfn, void *opaque);
 void qdev_reset_all(DeviceState *dev);
+
+/**
+ * @qbus_reset_all:
+ * @bus: Bus to be reset.
+ *
+ * Reset @bus and perform a bus-level ("hard") reset of all devices connected
+ * to it, including recursive processing of all buses below @bus itself.  A
+ * hard reset means that qbus_reset_all will reset all state of the device.
+ * For PCI devices, for example, this will include the base address registers
+ * or configuration space.
+ */
+void qbus_reset_all(BusState *bus);
 void qbus_reset_all_fn(void *opaque);
 
 void qbus_free(BusState *bus);
hw/qdev.c +6 -1
index f2c2484..e2f957e 100644
@@ -228,10 +228,15 @@ void qdev_reset_all(DeviceState *dev)
     qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL);
 }
 
+void qbus_reset_all(BusState *bus)
+{
+    qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL);
+}
+
 void qbus_reset_all_fn(void *opaque)
 {
     BusState *bus = opaque;
-    qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL);
+    qbus_reset_all(bus);
 }
 
 /* can be used as ->unplug() callback for the simple cases */
Signature · 1 line
1.8.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev: add qbus_reset_all

Am 10.01.2013 15:49, schrieb Paolo Bonzini:

Quoted 11 lines
---
 hw/qdev-core.h | 12 ++++++++++++
 hw/qdev.c      |  7 ++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
hw/qdev-core.h +0 -0
index fdf14ec..853bd08 100644

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 187

Quoted 6 lines
hw/qdev-core.h +3 -0
@@ -182,6 +182,18 @@ int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
                        qbus_walkerfn *busfn, void *opaque);
 void qdev_reset_all(DeviceState *dev);
+
+/**
+ * @qbus_reset_all:

Just " * qbus_reset_all:" please.

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 192

Quoted 5 lines
hw/qdev-core.h +5 -0
+ * @bus: Bus to be reset.
+ *
+ * Reset @bus and perform a bus-level ("hard") reset of all devices connected
+ * to it, including recursive processing of all buses below @bus itself.  A
+ * hard reset means that qbus_reset_all will reset all state of the device.

qbus_reset_all()?

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 193

Quoted 1 line
hw/qdev-core.h +1 -0
+ * For PCI devices, for example, this will include the base address registers

#PCIDevice?

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 196

Quoted 3 lines
hw/qdev-core.h +3 -0
+ * or configuration space.
+ */
+void qbus_reset_all(BusState *bus);

Otherwise looks trivial and okay.

Andreas

Quoted 24 lines
hw/qdev-core.h +0 -0
 void qbus_reset_all_fn(void *opaque);
 
 void qbus_free(BusState *bus);
hw/qdev.c +6 -1
index f2c2484..e2f957e 100644
@@ -228,10 +228,15 @@ void qdev_reset_all(DeviceState *dev)
     qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL);
 }
 
+void qbus_reset_all(BusState *bus)
+{
+    qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL);
+}
+
 void qbus_reset_all_fn(void *opaque)
 {
     BusState *bus = opaque;
-    qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL);
+    qbus_reset_all(bus);
 }
 
 /* can be used as ->unplug() callback for the simple cases */
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev: add qbus_reset_all

Am 10.01.2013 19:34, schrieb Andreas Färber:

Quoted 7 lines

Am 10.01.2013 15:49, schrieb Paolo Bonzini:

Quoted 6 lines
---
 hw/qdev-core.h | 12 ++++++++++++
 hw/qdev.c      |  7 ++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
Quoted 13 lines

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 187

Quoted 11 lines
hw/qdev-core.h +3 -0
index fdf14ec..853bd08 100644
@@ -182,6 +182,18 @@ int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
                        qbus_walkerfn *busfn, void *opaque);
 void qdev_reset_all(DeviceState *dev);
+
+/**
+ * @qbus_reset_all:

Just " * qbus_reset_all:" please.

Patch was applied nontheless, please fix in a follow-up.

Andreas

Quoted 23 lines

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 192

Quoted 5 lines
hw/qdev-core.h +5 -0
+ * @bus: Bus to be reset.
+ *
+ * Reset @bus and perform a bus-level ("hard") reset of all devices connected
+ * to it, including recursive processing of all buses below @bus itself.  A
+ * hard reset means that qbus_reset_all will reset all state of the device.

qbus_reset_all()?

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 193

Quoted 1 line
hw/qdev-core.h +1 -0
+ * For PCI devices, for example, this will include the base address registers

#PCIDevice?

hw/qdev-core.h int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, · line 196

Quoted 3 lines
hw/qdev-core.h +3 -0
+ * or configuration space.
+ */
+void qbus_reset_all(BusState *bus);

Otherwise looks trivial and okay.

Andreas

Quoted 3 lines
hw/qdev-core.h +0 -0
 void qbus_reset_all_fn(void *opaque);
 
 void qbus_free(BusState *bus);

[snip]

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw

PATCH 2/2 virtio-scsi: abort in-flight I/O when the device is reset

In reply to Paolo Bonzini

When the device is reset, the SCSI bus should also be reset so that in-flight I/O is cancelled.

---
 hw/virtio-scsi.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/virtio-scsi.c +4 -0
index bfe1860..0715865 100644
@@ -565,6 +565,10 @@ static void virtio_scsi_reset(VirtIODevice *vdev)
 {
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
+    s->resetting++;
+    qbus_reset_all(&s->bus.qbus);
+    s->resetting--;
+
     s->sense_size = VIRTIO_SCSI_SENSE_SIZE;
     s->cdb_size = VIRTIO_SCSI_CDB_SIZE;
     s->events_dropped = false;
Signature · 1 line
1.8.1
#5 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

This fixes the virtio-scsi problem by forcing a reset of the SCSI bus from virtio_reset. The reset will happen twice on machine initialization (and this is why I preferred the other approach, using qdev_reset_all in virtio code), but that's harmless.

Now I finally see what you worry about. It's the double reset. Yes a bit ugly but harmless.

Quoted 11 lines

Paolo Bonzini (2):
qdev: add qbus_reset_all
virtio-scsi: abort in-flight I/O when the device is reset

 hw/qdev-core.h   | 12 ++++++++++++
 hw/qdev.c        |  7 ++++++-
 hw/virtio-scsi.c |  4 ++++
 3 files changed, 22 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1