All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: <damien.lemoal@opensource.wdc.com>, <jejb@linux.ibm.com>,
	<martin.petersen@oracle.com>, <hare@suse.de>, <hch@lst.de>
Cc: <linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-scsi@vger.kernel.org>, <brking@us.ibm.com>,
	John Garry <john.garry@huawei.com>
Subject: [PATCH RFC 3/6] scsi: core: Add scsi_get_dev()
Date: Tue, 20 Sep 2022 18:27:07 +0800	[thread overview]
Message-ID: <1663669630-21333-4-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com>

Add a function which allows use to alloc a sdev with configurable
device parent, and channel:id:lun.

This is useful for separating adding a scsi device into separate alloc
and scan steps.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/scsi_scan.c | 25 +++++++++++++++++++++++++
 include/scsi/scsi_host.h |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 3759b1a77504..fd15ddac01b6 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1988,3 +1988,28 @@ void scsi_forget_host(struct Scsi_Host *shost)
 	spin_unlock_irqrestore(shost->host_lock, flags);
 }
 
+struct scsi_device *scsi_get_dev(struct device *parent, int channel, uint id, u64 lun)
+{
+	struct Scsi_Host *shost = dev_to_shost(parent);
+	struct scsi_device *sdev = NULL;
+	struct scsi_target *starget;
+
+	mutex_lock(&shost->scan_mutex);
+	if (!scsi_host_scan_allowed(shost))
+		goto out;
+
+	starget = scsi_alloc_target(parent, 0, id);
+	if (!starget)
+		goto out;
+
+	sdev = scsi_alloc_sdev(starget, 0, NULL);
+	if (sdev)
+		sdev->borken = 0;
+	else
+		scsi_target_reap(starget);
+	put_device(&starget->dev);
+ out:
+	mutex_unlock(&shost->scan_mutex);
+	return sdev;
+}
+EXPORT_SYMBOL(scsi_get_dev);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index aa7b7496c93a..5142c7df7647 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -794,7 +794,10 @@ void scsi_host_busy_iter(struct Scsi_Host *,
 
 struct class_container;
 
+extern struct scsi_device *scsi_get_dev(struct device *parent, int channel, uint id, u64 lun);
+
 /*
+
  * DIF defines the exchange of protection information between
  * initiator and SBC block device.
  *
-- 
2.35.3


  parent reply	other threads:[~2022-09-20 10:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 10:27 [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata port probe John Garry
2022-09-20 10:27 ` [PATCH 1/6] scsi: core: Use SCSI_SCAN_RESCAN in __scsi_add_device() John Garry
2022-09-20 22:03   ` Damien Le Moal
2022-09-20 10:27 ` [PATCH RFC 2/6] scsi: scsi_transport_sas: Allocate end device target id in the rphy alloc John Garry
2022-09-20 22:02   ` Damien Le Moal
2022-09-21  9:21     ` John Garry
2022-09-20 10:27 ` John Garry [this message]
2022-09-20 21:58   ` [PATCH RFC 3/6] scsi: core: Add scsi_get_dev() Damien Le Moal
2022-09-21  9:17     ` John Garry
2022-09-20 10:27 ` [PATCH RFC 4/6] ata: libata-scsi: Add ata_scsi_setup_sdev() John Garry
2022-09-20 10:27 ` [PATCH RFC 5/6] scsi: libsas: Add sas_ata_setup_device() John Garry
2022-09-20 10:27 ` [PATCH RFC 6/6] ata: libata-scsi: Allocate sdev early in port probe John Garry
2022-09-24  4:21   ` kernel test robot
2022-09-21  4:04 ` [PATCH RFC 0/6] libata/scsi/libsas: Allocate SCSI device earlier for ata " Damien Le Moal
2022-09-21  8:24   ` John Garry
2022-09-21  8:31     ` Damien Le Moal

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=1663669630-21333-4-git-send-email-john.garry@huawei.com \
    --to=john.garry@huawei.com \
    --cc=brking@us.ibm.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jejb@linux.ibm.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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.