[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1666693096-180008-3-git-send-email-john.garry@huawei.com>
Date: Tue, 25 Oct 2022 18:17:56 +0800
From: John Garry <john.garry@...wei.com>
To: <axboe@...nel.dk>, <damien.lemoal@...nsource.wdc.com>,
<jejb@...ux.ibm.com>, <martin.petersen@...cle.com>,
<jinpu.wang@...ud.ionos.com>, <hare@...e.de>, <bvanassche@....org>,
<hch@....de>, <ming.lei@...hat.com>, <niklas.cassel@....com>
CC: <linux-block@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-ide@...r.kernel.org>, <linux-scsi@...r.kernel.org>,
<linuxarm@...wei.com>, John Garry <john.garry@...wei.com>
Subject: [PATCH RFC v3 02/22] scsi: core: Add scsi_get_dev()
Add a function which allows us 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@...wei.com>
---
drivers/scsi/scsi_scan.c | 25 +++++++++++++++++++++++++
include/scsi/scsi_host.h | 4 ++++
2 files changed, 29 insertions(+)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 5d27f5196de6..ad0a5902d1a0 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1979,3 +1979,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, channel, id);
+ if (!starget)
+ goto out;
+
+ sdev = scsi_alloc_sdev(starget, lun, 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 e71436183c0d..750ccf126377 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -787,6 +787,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
Powered by blists - more mailing lists