scsi/scsi_bus: Add scsi_device_get
authorMaxim Levitsky <mlevitsk@redhat.com>
Tue, 6 Oct 2020 12:39:02 +0000 (15:39 +0300)
committerwanchao-xu <wanchao.xu@samsung.com>
Tue, 9 Jan 2024 11:50:28 +0000 (19:50 +0800)
Git-commit: 8ff34495601067d02edb54b4346cace84ec4e1df
References: bsc#1184574

Add scsi_device_get which finds the scsi device
and takes a reference to it.

Suggested-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20200913160259.32145-8-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20201006123904.610658-12-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Lin Ma <lma@suse.com>
hw/scsi/scsi-bus.c
include/hw/scsi/scsi.h

index 643d87966c88f0575404f09278565787e3ab2f9f..856148399c720c58cfda01ff69208f3e3c0a9a8b 100644 (file)
@@ -73,6 +73,17 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
     return do_scsi_device_find(bus, channel, id, lun, false);
 }
 
+SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int id, int lun)
+{
+    SCSIDevice *d;
+    RCU_READ_LOCK_GUARD();
+    d = do_scsi_device_find(bus, channel, id, lun, false);
+    if (d) {
+        object_ref(d);
+    }
+    return d;
+}
+
 static void scsi_device_realize(SCSIDevice *s, Error **errp)
 {
     SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
index ead723690114f847d0d3638c3c2efd03123cb84c..b695e5e6ec6bd9ac60ec99a529ed6042811d2010 100644 (file)
@@ -195,6 +195,7 @@ int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
 int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size,
                         uint8_t *buf, uint8_t buf_size, uint32_t timeout);
 SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
+SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int target, int lun);
 
 /* scsi-generic.c. */
 extern const SCSIReqOps scsi_generic_req_ops;