From patchwork Tue Oct 25 10:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 10671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp908176wru; Tue, 25 Oct 2022 02:53:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Xn3Fyro97jMagIxWIdOPtKQEl9tZmS/l0fLZB4qOZ5ctz5TicZjfFhfXtTiLtSI3Bg6QJ X-Received: by 2002:aa7:c78e:0:b0:456:c524:90ec with SMTP id n14-20020aa7c78e000000b00456c52490ecmr35016643eds.192.1666691602082; Tue, 25 Oct 2022 02:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666691602; cv=none; d=google.com; s=arc-20160816; b=HQuHrWA84+9LmLyUu6eiD3JP9Z+3z+HzGUKjBGaS7ut07mmDehdwjF4/kvlQu5Dag4 HdP+rfZW3gnp+eKcuTfxnfntl3KGA6KzOs08mTw2DKZjCyjwiZBY1AqQtG+yvr15l/Cz 2DDSUBIGBQrIGW/FM4IjdyOcGV3tkPXZxcLRqeJ3vklQyWMZ3xSwBeIQB7Y8pYvqwC23 Hny7XSj35eg6GEkHC1uuPRlMi1TqxFrnnB2MhiwuDGgYHrgnhEkoVSC/sb4xT+WP+xB+ PmhGLD0pJrIXPtlb9OXxeZo9WPzkqcqkartJ5aZt1ngk8u4pUKugO2dVWM1EbvjnUvOM GZPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=89p/4Sxgc4CQxkP/odqAY1iHQPJkyP+KtH39Ey8Dy0Y=; b=YHipkAz+XSzNzmdOBzzUOoQo/1rHN52YEyHaLmtDQeFYlylBa84Nw2Y2Ijp9o8j4f5 OSHzBYEK1myEiZv6pZFSvOIqFZ9mMbK6HxPU+AOnx4DPZDPYGez+uUK/9AgMX/D6Tksm 2JDyRRqr9HoEW9/vGR6UkmmmnwBivIO3cF2qMyPG79KpELDa3i2suX0WP0WnYS/8OLRn l1BsNxja8+xmMouiCOj7IYgOBNzw6+LBoEQX1ETTm2Y+c0XOdup7sjMq9v+EtDwXEbWq L8TiyyTAtZtcZ/3SNYeadAF51rwYf4tFdpec6fY5JamDihuOuQpvEzgrM9uFqI2OlX10 pxhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020a170906368500b007a6843971c0si2270752ejc.190.2022.10.25.02.52.57; Tue, 25 Oct 2022 02:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231878AbiJYJs0 (ORCPT + 99 others); Tue, 25 Oct 2022 05:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbiJYJsG (ORCPT ); Tue, 25 Oct 2022 05:48:06 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F3D1110B0E; Tue, 25 Oct 2022 02:48:04 -0700 (PDT) Received: from fraeml705-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MxRqL71Xnz6893Q; Tue, 25 Oct 2022 17:44:30 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml705-chm.china.huawei.com (10.206.15.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.31; Tue, 25 Oct 2022 11:48:00 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 10:47:57 +0100 From: John Garry To: , , , , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v3 02/22] scsi: core: Add scsi_get_dev() Date: Tue, 25 Oct 2022 18:17:56 +0800 Message-ID: <1666693096-180008-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1666693096-180008-1-git-send-email-john.garry@huawei.com> References: <1666693096-180008-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747652813433808309?= X-GMAIL-MSGID: =?utf-8?q?1747652813433808309?= 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 --- 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.