summaryrefslogtreecommitdiff
path: root/hw/scsi
diff options
context:
space:
mode:
authorMaxim Levitsky <mlevitsk@redhat.com>2020-10-06 14:38:57 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2020-10-12 11:50:50 -0400
commit7a8202c521a5d1ac9e289d5c2b5125a9310af178 (patch)
tree36443d62096d656ff0f7af19a47760bc074bda43 /hw/scsi
parentbb755ba47f3747251c0eadf681ee68b9033309b8 (diff)
downloadqemu-7a8202c521a5d1ac9e289d5c2b5125a9310af178.zip
scsi/scsi_bus: switch search direction in scsi_device_find
This change will allow us to convert the bus children list to RCU, while not changing the logic of this function Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20200913160259.32145-2-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/scsi')
-rw-r--r--hw/scsi/scsi-bus.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index 3284a5d1fb..6b1ed7ae9a 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -1572,7 +1572,7 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
BusChild *kid;
SCSIDevice *target_dev = NULL;
- QTAILQ_FOREACH_REVERSE(kid, &bus->qbus.children, sibling) {
+ QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
DeviceState *qdev = kid->child;
SCSIDevice *dev = SCSI_DEVICE(qdev);
@@ -1580,7 +1580,15 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
if (dev->lun == lun) {
return dev;
}
- target_dev = dev;
+
+ /*
+ * If we don't find exact match (channel/bus/lun),
+ * we will return the first device which matches channel/bus
+ */
+
+ if (!target_dev) {
+ target_dev = dev;
+ }
}
}
return target_dev;