All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, cohuck@redhat.com, farman@linux.ibm.com,
	pasic@linux.ibm.com, qemu-s390x@nongnu.org,
	borntraeger@linux.ibm.com
Subject: [PATCH 1/4] s390x: follow qdev tree to detect SCSI device on a CCW bus
Date: Mon, 28 Mar 2022 16:30:16 +0200	[thread overview]
Message-ID: <20220328143019.682245-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20220328143019.682245-1-pbonzini@redhat.com>

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




  reply	other threads:[~2022-03-28 14:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28 14:30 [PATCH 0/4] virtio-ccw: remove device declarations from virtio-ccw.h Paolo Bonzini
2022-03-28 14:30 ` Paolo Bonzini [this message]
2022-03-29 12:45   ` [PATCH 1/4] s390x: follow qdev tree to detect SCSI device on a CCW bus Thomas Huth
2022-03-31  0:21   ` Halil Pasic
2022-03-28 14:30 ` [PATCH 2/4] virtio-ccw: move vhost_ccw_scsi to a separate file Paolo Bonzini
2022-03-29 13:34   ` Thomas Huth
2022-03-29 20:09   ` Eric Farman
2022-03-31 11:46   ` Halil Pasic
2022-04-04 14:43   ` Cornelia Huck
2022-03-28 14:30 ` [PATCH 3/4] virtio-ccw: move device type declarations to .c files Paolo Bonzini
2022-03-30  7:11   ` Thomas Huth
2022-03-31 12:14   ` Halil Pasic
2022-03-28 14:30 ` [PATCH 4/4] virtio-ccw: do not include headers for all virtio devices Paolo Bonzini
2022-03-30  7:12   ` Thomas Huth
2022-03-31 13:50   ` Halil Pasic

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=20220328143019.682245-2-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=thuth@redhat.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.