From patchwork Wed Dec 14 07:08:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 33083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp58723wrn; Tue, 13 Dec 2022 23:20:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Ow9E3QtLcH+KHtrO2jbhxNKcI4NAv3lG2497UDLDISw9LoBx0J5CDjq60hy5s5kbPi0gI X-Received: by 2002:a17:906:cc55:b0:7c1:6981:d062 with SMTP id mm21-20020a170906cc5500b007c16981d062mr11163487ejb.72.1671002453490; Tue, 13 Dec 2022 23:20:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671002453; cv=none; d=google.com; s=arc-20160816; b=bf0EnevlHUE50bXN3XBUoXj9kXqzTM9ir47uSNlH4NUir0w5httxMCM0pPUbRynq5+ cul8vJNWLDcpnABNW0XkUzEzw+QwC/ZIGoi1dd31ls1xvkzVHoTZyxcIEHX7bAY5D80R B4sqSAib2tao6Y9zXXzwd2hpXz6KbRGmCZE3eEpLUJK9rUko/RwSvVpSD3cfnsAoexIR 2YFIwIOUrQWtBj282ZHW2qz/22MZvy2nK+xAhwN2yB6BlbJSxflX01DEissowQXTCh9H d+2Lz0OWbvhxQqPA+pr093N6J+a+xg+6oaNQaf9f3u+GViEzV68xTgIwmhIcpubPatik NepQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hirhkT9wN2ZvkmwzO81bHsfX0CCKQNgVHL0ZxDXJZ5U=; b=0ydEPI/HJ+H4Th75uLX8uzgsQ+cnz6DBpy23oW8ELbewDotGuoNzhDrAS4vh59dG3F xwgHsDJWplmxRJ2P9MbuHXrjGBVIY7pDv9ZzXT7q81oLT+nKiL6JaYCxDxt3DswIx8ai zsUjLMSz4WCkR8QAxdNHcFOynNiJhJqjmZA6PdE0bY3vY0qSQou3OhcP5db0vO/wZB1S NA3h048dsJeDnIk33oGA/mt4AaD1lnuJihAPcY6cxsXSzUgn+cnuFOXCbMq+zIKxMDzr /dwKqMCyQmVp0z6jI7Ch0qyeNtpDrrAFdklpTRWDeOLFh7Tz8F0cm7rSMoukNYHOwhMm R1Nw== 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 rq5-20020a17090788c500b007807e1f3d9dsi9104448ejc.842.2022.12.13.23.20.29; Tue, 13 Dec 2022 23:20:53 -0800 (PST) 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 S237524AbiLNHJ2 (ORCPT + 99 others); Wed, 14 Dec 2022 02:09:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237510AbiLNHJP (ORCPT ); Wed, 14 Dec 2022 02:09:15 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 322E363F8; Tue, 13 Dec 2022 23:09:14 -0800 (PST) Received: from dggpemm500017.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NX5zv6LrkzRpxP; Wed, 14 Dec 2022 15:08:11 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 14 Dec 2022 15:09:12 +0800 From: Wenchao Hao To: "Martin K . Petersen" , Mike Christie , "James E . J . Bottomley" , Lee Duncan , Chris Leech , , CC: , , , Wenchao Hao Subject: [PATCH 1/2] scsi:core:Add sysfs interface to control if skip lun with PQ=1 Date: Wed, 14 Dec 2022 15:08:45 +0800 Message-ID: <20221214070846.1808300-2-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221214070846.1808300-1-haowenchao@huawei.com> References: <20221214070846.1808300-1-haowenchao@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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?1752173068594069024?= X-GMAIL-MSGID: =?utf-8?q?1752173068594069024?= commit 948e922fc4461 ("scsi: core: map PQ=1, PDT=other values to SCSI_SCAN_TARGET_PRESENT") returns SCSI_SCAN_TARGET_PRESENT if inquiry returns PQ=1. According to the SPC, PQ=1 means the addressed logical unit having the indicated device type is not accessible, it does not mean the addressed logical unit is invalid. We still can map this lun to an sg device. In some conditions, we do not want to skip these devices, for example with iSCSI: When iSCSI initiator logged in target, the target attached none valid lun but lun0. lun0 is not an valid disk, while it would response inquiry command with PQ=1 and other general scsi commands like probe lun. The others luns of target is added/removed dynamicly. We want the lun0 to be mapped to an sg device in initiator, so we can probe luns of target based on lun0. I add an sysfs interface named no_skip_pq1 in each Scsi_Host to control if to skip lun which return PQ=1 for inquiry. The default behavior is not changed, which means we would still skip add lun if inquiry returns PQ=1. We can set host's no_skip_pq1 in specific drivers or via sysfs. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_scan.c | 9 ++++++--- drivers/scsi/scsi_sysfs.c | 29 +++++++++++++++++++++++++++++ include/scsi/scsi_host.h | 3 +++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 920b145f80b7..bd4faaabee8c 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1233,10 +1233,13 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, * that no LUN is present, so don't add sdev in these cases. * Two specific examples are: * 1) NetApp targets: return PQ=1, PDT=0x1f - * 2) IBM/2145 targets: return PQ=1, PDT=0 - * 3) USB UFI: returns PDT=0x1f, with the PQ bits being "reserved" + * 2) USB UFI: returns PDT=0x1f, with the PQ bits being "reserved" * in the UFI 1.0 spec (we cannot rely on reserved bits). * + * Targets set PQ=1 would be skipped if shost->no_skip_pq1 is not set + * For example: + * 1) IBM/2145 targets: return PQ=1, PDT=0 + * * References: * 1) SCSI SPC-3, pp. 145-146 * PQ=1: "A peripheral device having the specified peripheral @@ -1248,7 +1251,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, * PDT=00h Direct-access device (floppy) * PDT=1Fh none (no FDD connected to the requested logical unit) */ - if (((result[0] >> 5) == 1 || + if ((((result[0] >> 5) == 1 && !shost->no_skip_pq1) || (starget->pdt_1f_for_no_lun && (result[0] & 0x1f) == 0x1f)) && !scsi_is_wlun(lun)) { SCSI_LOG_SCAN_BUS(3, sdev_printk(KERN_INFO, sdev, diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index f2a345cc0f8a..a72466c7e3c4 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -369,6 +369,34 @@ store_shost_eh_deadline(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR(eh_deadline, S_IRUGO | S_IWUSR, show_shost_eh_deadline, store_shost_eh_deadline); +static ssize_t +show_no_skip_pq1(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct Scsi_Host *shost = class_to_shost(dev); + + return sysfs_emit(buf, "%s\n", shost->no_skip_pq1 ? "Y" : "N"); +} + +static ssize_t +store_no_skip_pq1(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct Scsi_Host *shost = class_to_shost(dev); + int ret = -EINVAL; + bool store_val; + + ret = kstrtobool(buf, &store_val); + if (ret) + return ret; + + shost->no_skip_pq1 = store_val; + + return count; +} + +static DEVICE_ATTR(no_skip_pq1, S_IRUGO | S_IWUSR, show_no_skip_pq1, store_no_skip_pq1); + shost_rd_attr(unique_id, "%u\n"); shost_rd_attr(cmd_per_lun, "%hd\n"); shost_rd_attr(can_queue, "%d\n"); @@ -421,6 +449,7 @@ static struct attribute *scsi_sysfs_shost_attrs[] = { &dev_attr_host_reset.attr, &dev_attr_eh_deadline.attr, &dev_attr_nr_hw_queues.attr, + &dev_attr_no_skip_pq1.attr, NULL }; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 587cc767bb67..56bb11d9a886 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -659,6 +659,9 @@ struct Scsi_Host { /* The transport requires the LUN bits NOT to be stored in CDB[1] */ unsigned no_scsi2_lun_in_cdb:1; + /* Do not skip adding lun if inquiry command returns PQ == 1 */ + unsigned no_skip_pq1:1; + /* * Optional work queue to be utilized by the transport */ From patchwork Wed Dec 14 07:08:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 33084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp58754wrn; Tue, 13 Dec 2022 23:20:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JLp+VCk+P6M/aBn0VZ04BN7gOCQzpZAcCdnzDLIjyM19mggQMrqlrIMtEbv4AB/Dh0FvD X-Received: by 2002:a05:6a20:4f02:b0:a9:111a:236f with SMTP id gi2-20020a056a204f0200b000a9111a236fmr27354016pzb.33.1671002458388; Tue, 13 Dec 2022 23:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671002458; cv=none; d=google.com; s=arc-20160816; b=VB8UFeK3hpeDh9Sduh2iKI1i4oFyRRpczcUmESSNq4VYj6oizIBBvia9n+SG2OjWOS DsAJXJmHMlfv9Ire5qsUCDkvs+XcT1UKUf0wgscAq5/F/Fw31qQMkeviSiqLPAOBZyCb ucDxrz/GzgvvlcBJtHjxdLLkbhEQ1mI35fqbuOVrnuNpjxcP/agk85X1XDCy9MhvtGy3 Iy9p7XG1jtIi7PTVgeLacaSSRRkJiCT66uYp5+Zwf8HHPt4YV0r0zaspvx/0ZvrnnPv1 ff6vQA4yR5MU9hncfP0VIAkGcYTwib0yphdolcdm4ExOCWBqsVEQC3U0Spf1zhtYh81Q wRjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6cnVG4aUD9h9ZXhr5zwZjLZmyQSP5RkgqBFjFuknPBE=; b=BoYF2Jxv4Ri+i59U3U8uIwoxwbcREwuJJqbxFRGyyuZjUbEAajhnIIAu19+XSuzk1V XBAQ4IUkR3rGXul6BHSXHo3MftHt6VRC4qB3p5T7d6Q25WY3swd0jZcjpJ1xrn3CH9z1 rHWINfJmOIESop8I6gjta5Kp1SSjrx3hq1Sj7oGoxsQFrkI7bydJRHdZWDL3z12ICXWn 0OPru2u71RWZhcBJrsMwXV1SS7r/hkAVqC6efJGkEbwPMMgaZmhOrcQZN/j0lhQbFRdE MZSdbHOIPSlLV9m0VFp62FNl+unV5MHgdpXjx6chA4dFr+hjrZlhclGPa3ZtSryuuuBP eSNQ== 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 6-20020a631346000000b0047888d9f3aesi14586541pgt.547.2022.12.13.23.20.44; Tue, 13 Dec 2022 23:20:58 -0800 (PST) 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 S237510AbiLNHJc (ORCPT + 99 others); Wed, 14 Dec 2022 02:09:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237517AbiLNHJP (ORCPT ); Wed, 14 Dec 2022 02:09:15 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0E42654E; Tue, 13 Dec 2022 23:09:14 -0800 (PST) Received: from dggpemm500017.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NX5zw36R2zRq3H; Wed, 14 Dec 2022 15:08:12 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 14 Dec 2022 15:09:12 +0800 From: Wenchao Hao To: "Martin K . Petersen" , Mike Christie , "James E . J . Bottomley" , Lee Duncan , Chris Leech , , CC: , , , Wenchao Hao Subject: [PATCH 2/2] scsi:iscsi_tcp:Do not skip lun inquiry returns PQ=1 Date: Wed, 14 Dec 2022 15:08:46 +0800 Message-ID: <20221214070846.1808300-3-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221214070846.1808300-1-haowenchao@huawei.com> References: <20221214070846.1808300-1-haowenchao@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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?1752173073611128153?= X-GMAIL-MSGID: =?utf-8?q?1752173073611128153?= When luns inquiry return PQ=1, do not skip this lun and try to map these luns to an sg device. Signed-off-by: Wenchao Hao --- drivers/scsi/iscsi_tcp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 5fb1f364e815..316e2e17c72d 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -941,6 +941,7 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, shost->max_id = 0; shost->max_channel = 0; shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE; + shost->no_skip_pq1 = 1; rc = iscsi_host_get_max_scsi_cmds(shost, cmds_max); if (rc < 0)