Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3707607rwb; Tue, 20 Sep 2022 03:39:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tGf6lgLhF9sO4WO1OfbI60AIbRezZNA3Txnrt7zemdvsJeK2ZXkofMBlE3BdigYK4vfU3 X-Received: by 2002:a17:907:724e:b0:780:45d1:969b with SMTP id ds14-20020a170907724e00b0078045d1969bmr16799674ejc.26.1663670370894; Tue, 20 Sep 2022 03:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663670370; cv=none; d=google.com; s=arc-20160816; b=pijiF++yzyJsg8URyyFjkAgnK0fAIZaSsLF9ndZV2N8uw/QHhI/1nHeQV1jZNvk0jV NOibq4s//zd8BwFtRZ6t2gaylvpa4Dui1PczyDcuYfcJpKsOHqq9Aj4jUfrhiSExqlLi /QkWP8Hl2kwIC2U4kcRTyrscM+h6k4Hf35MuWT04+xSxU1oqbMC0h5dNxZEf484I3HKU dp0ttoVWSnHtrKTUtp2Z6k7r98XftVuz8A1jFL51kHMgqbaYicHW27KyM6Rc+nqoyLEg 3cx/3OXDJN7XbaF1RXjVch0brv8owXfBOQhv1BrDEYOa4+nXL4aUhB1UCj4Pem0OFUGq cJbw== 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=4zThGrHvo2n/Df+Uju74TTfAgqJz7coeLytUZAsTycY=; b=kqbalzt9jVFV6GNMSGjPJ4oRKkOkDg5QhYaKtHJG26YwZOu3pOwjjY3xl15aH7RDj3 PKj6oxscZ79LlM0MSOBVZIfJeeiJPCOkO2ex8XeJX1UoyR20TVZVtOpZOONf1y8e57YS 8J0sD4suw01Dtj6wraqnEFg/NsQmuN321PxXK8vvVB+r+zoiKaA/gtqREhLa9VkOVDOh raqlIwA2nJlsxtSk9racl84j3eaKx+wTwabTALUs//HMw1lLKXUzQftdYA5OkTMwig3t Vl3jRltcsdEx/Qi539LOPK/ICPvkG62dk1V39iY776U+RWSe3DVfBlD/0witYoxoSeD/ 41PA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb18-20020a1709077e9200b007414081b2ebsi1036612ejc.148.2022.09.20.03.39.05; Tue, 20 Sep 2022 03:39:30 -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 S231371AbiITKgj (ORCPT + 99 others); Tue, 20 Sep 2022 06:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbiITKf5 (ORCPT ); Tue, 20 Sep 2022 06:35:57 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DAEA74CF5; Tue, 20 Sep 2022 03:34:03 -0700 (PDT) Received: from fraeml737-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MWyYN2gMQz6H73Y; Tue, 20 Sep 2022 18:32:56 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml737-chm.china.huawei.com (10.206.15.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 12:33:58 +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, 20 Sep 2022 11:33:55 +0100 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH RFC 3/6] scsi: core: Add scsi_get_dev() Date: Tue, 20 Sep 2022 18:27:07 +0800 Message-ID: <1663669630-21333-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1663669630-21333-1-git-send-email-john.garry@huawei.com> References: <1663669630-21333-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 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 --- 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