[PATCH 1/4] s390x: follow qdev tree to detect SCSI device on a CCW bus

Paolo Bonzini posted 4 patches 3 years, 10 months ago
Maintainers: Christian Borntraeger <borntraeger@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
[PATCH 1/4] s390x: follow qdev tree to detect SCSI device on a CCW bus
Posted by Paolo Bonzini 3 years, 10 months ago
Do not make assumptions on the parent type of the SCSIDevice, instead
use object_dynamic_cast all the way up to the CcwDevice.  This is cleaner
because there is no guarantee that the bus is on a virtio-scsi device;
that is only the case for the default configuration of QEMU's s390x
target.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/s390x/ipl.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index 84971e537b..e21776822a 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -375,14 +375,18 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)
                 object_dynamic_cast(OBJECT(dev_st),
                                     TYPE_SCSI_DEVICE);
             if (sd) {
-                SCSIBus *bus = scsi_bus_from_device(sd);
-                VirtIOSCSI *vdev = container_of(bus, VirtIOSCSI, bus);
-                VirtIOSCSICcw *scsi_ccw = container_of(vdev, VirtIOSCSICcw,
-                                                       vdev);
-
-                ccw_dev = (CcwDevice *)object_dynamic_cast(OBJECT(scsi_ccw),
-                                                           TYPE_CCW_DEVICE);
-                tmp_dt = CCW_DEVTYPE_SCSI;
+                SCSIBus *sbus = scsi_bus_from_device(sd);
+                VirtIODevice *vdev = (VirtIODevice *)
+                    object_dynamic_cast(OBJECT(sbus->qbus.parent),
+                                        TYPE_VIRTIO_DEVICE);
+		if (vdev) {
+                    ccw_dev = (CcwDevice *)
+                        object_dynamic_cast(OBJECT(qdev_get_parent_bus(DEVICE(vdev))->parent),
+                                            TYPE_CCW_DEVICE);
+                    if (ccw_dev) {
+                        tmp_dt = CCW_DEVTYPE_SCSI;
+                    }
+		}
             }
         }
     }
-- 
2.35.1
Re: [PATCH 1/4] s390x: follow qdev tree to detect SCSI device on a CCW bus
Posted by Thomas Huth 3 years, 10 months ago
On 28/03/2022 16.30, Paolo Bonzini wrote:
> Do not make assumptions on the parent type of the SCSIDevice, instead
> use object_dynamic_cast all the way up to the CcwDevice.  This is cleaner
> because there is no guarantee that the bus is on a virtio-scsi device;
> that is only the case for the default configuration of QEMU's s390x
> target.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   hw/s390x/ipl.c | 20 ++++++++++++--------
>   1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index 84971e537b..e21776822a 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -375,14 +375,18 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)
>                   object_dynamic_cast(OBJECT(dev_st),
>                                       TYPE_SCSI_DEVICE);
>               if (sd) {
> -                SCSIBus *bus = scsi_bus_from_device(sd);
> -                VirtIOSCSI *vdev = container_of(bus, VirtIOSCSI, bus);
> -                VirtIOSCSICcw *scsi_ccw = container_of(vdev, VirtIOSCSICcw,
> -                                                       vdev);
> -
> -                ccw_dev = (CcwDevice *)object_dynamic_cast(OBJECT(scsi_ccw),
> -                                                           TYPE_CCW_DEVICE);
> -                tmp_dt = CCW_DEVTYPE_SCSI;
> +                SCSIBus *sbus = scsi_bus_from_device(sd);
> +                VirtIODevice *vdev = (VirtIODevice *)
> +                    object_dynamic_cast(OBJECT(sbus->qbus.parent),
> +                                        TYPE_VIRTIO_DEVICE);
> +		if (vdev) {

Seems like you accidentally used TABs for indentation here?

With TABs replaced by spaces:

  Reviewed-by: Thomas Huth <thuth@redhat.com>


> +                    ccw_dev = (CcwDevice *)
> +                        object_dynamic_cast(OBJECT(qdev_get_parent_bus(DEVICE(vdev))->parent),
> +                                            TYPE_CCW_DEVICE);
> +                    if (ccw_dev) {
> +                        tmp_dt = CCW_DEVTYPE_SCSI;
> +                    }
> +		}
>               }
>           }
>       }
Re: [PATCH 1/4] s390x: follow qdev tree to detect SCSI device on a CCW bus
Posted by Halil Pasic 3 years, 10 months ago
On Mon, 28 Mar 2022 16:30:16 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Do not make assumptions on the parent type of the SCSIDevice, instead
> use object_dynamic_cast all the way up to the CcwDevice.  This is cleaner
> because there is no guarantee that the bus is on a virtio-scsi device;
> that is only the case for the default configuration of QEMU's s390x
> target.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Halil Pasic <pasic@linux.ibm.com>