From: Maxim Levitsky <mlevitsk@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Maxim Levitsky" <mlevitsk@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH v2 6/7] scsi: Add scsi_device_get
Date: Mon, 11 May 2020 19:09:50 +0300 [thread overview]
Message-ID: <20200511160951.8733-7-mlevitsk@redhat.com> (raw)
In-Reply-To: <20200511160951.8733-1-mlevitsk@redhat.com>
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>
---
hw/scsi/scsi-bus.c | 31 ++++++++++++++++++++++++-------
include/hw/scsi/scsi.h | 2 ++
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index 2bf6d005f3..4e15de0bd7 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -1584,8 +1584,13 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev)
return g_strdup_printf("channel@%x/%s@%x,%x", d->channel,
qdev_fw_name(dev), d->id, d->lun);
}
-
-SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
+/*
+ * Finds a matching channel/id/lun device on scsi bus, and
+ * takes a reference to it and returns it.
+ * If we don't find exact match (channel/bus/lun),
+ * we will return the first device which matches channel/bus
+ * */
+SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int id, int lun)
{
BusChild *kid;
SCSIDevice *target_dev = NULL;
@@ -1598,25 +1603,37 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
if (dev->channel == channel && dev->id == id) {
if (dev->lun == lun) {
+ object_ref(OBJECT(dev));
rcu_read_unlock();
return 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;
}
}
}
+ object_ref(OBJECT(target_dev));
rcu_read_unlock();
return target_dev;
}
+/*
+ * This function works like scsi_device_get but doesn't take a refernce
+ * to the returned object. Intended for legacy code
+ */
+SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
+{
+ SCSIDevice *dev = scsi_device_get(bus, channel, id, lun);
+
+ if (!dev)
+ return NULL;
+
+ object_unref(OBJECT(dev));
+ return dev;
+}
+
/* SCSI request list. For simplicity, pv points to the whole device */
static int put_scsi_requests(QEMUFile *f, void *pv, size_t size,
diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
index 332ef602f4..5e1d31ab6d 100644
--- a/include/hw/scsi/scsi.h
+++ b/include/hw/scsi/scsi.h
@@ -193,7 +193,9 @@ void scsi_generic_read_device_inquiry(SCSIDevice *dev);
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);
+
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;
--
2.17.2
next prev parent reply other threads:[~2020-05-11 16:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 16:09 [PATCH v2 0/7] RFC/WIP: Fix scsi devices plug/unplug races w.r.t virtio-scsi iothread Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 1/7] scsi/scsi_bus: switch search direction in scsi_device_find Maxim Levitsky
2020-05-27 12:53 ` Stefan Hajnoczi
2020-05-11 16:09 ` [PATCH v2 2/7] Implement drain_call_rcu and use it in hmp_device_del Maxim Levitsky
2020-05-27 13:11 ` Stefan Hajnoczi
2020-07-09 9:34 ` Maxim Levitsky
2020-07-09 11:42 ` Markus Armbruster
2020-07-09 11:56 ` Maxim Levitsky
2020-07-09 12:02 ` Paolo Bonzini
2020-05-11 16:09 ` [PATCH v2 3/7] device-core: use RCU for list of childs of a bus Maxim Levitsky
2020-05-27 14:45 ` Stefan Hajnoczi
2020-07-09 9:40 ` Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 4/7] device-core: use atomic_set on .realized property Maxim Levitsky
2020-05-27 15:00 ` Stefan Hajnoczi
2020-07-09 10:24 ` Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 5/7] virtio-scsi: don't touch scsi devices that are not yet realized or about to be un-realized Maxim Levitsky
2020-05-27 15:08 ` Stefan Hajnoczi
2020-05-11 16:09 ` Maxim Levitsky [this message]
2020-05-27 15:27 ` [PATCH v2 6/7] scsi: Add scsi_device_get Stefan Hajnoczi
2020-07-09 10:35 ` Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 7/7] virtio-scsi: use scsi_device_get Maxim Levitsky
2020-05-27 15:50 ` Stefan Hajnoczi
2020-07-09 10:43 ` Maxim Levitsky
2020-05-27 15:50 ` Stefan Hajnoczi
2020-05-11 18:03 ` [PATCH v2 0/7] RFC/WIP: Fix scsi devices plug/unplug races w.r.t virtio-scsi iothread no-reply
2020-05-11 18:03 ` no-reply
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=20200511160951.8733-7-mlevitsk@redhat.com \
--to=mlevitsk@redhat.com \
--cc=berrange@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.