Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp488195pxf; Thu, 18 Mar 2021 05:37:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQRvbvJYSe9pUah21VYfTQkyk3YzJrGfIkpZOLOULESO7wEVv+KUKssAR8VjRYJun7DKCv X-Received: by 2002:aa7:c903:: with SMTP id b3mr3386963edt.156.1616071069719; Thu, 18 Mar 2021 05:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616071069; cv=none; d=google.com; s=arc-20160816; b=dKNeNKdoSb7NB+w1rUHXssD7/pNbILlCa0qFT4X1YSqDvht1f7jIsCuB/cK5djW5R3 X+GkiZ08m9+Mnvn9b0CvsYsJlzeV3AKjiMjWd+opte3qK3vCt3XUNI85rdHjFWu2Htfp z5T4KSUDZlV1LYMEr6fnAp4UsTK3NaMm2k7yYiuGbMewMDoGKaJbXiUOX5S1qVBrFkNp gKqgMlMEjEzaiCMmF0xAz++Te7T69LD2MpArYfM9FeWEG5HVyD2cyQ8Mgpt1piJg9PYG w3QAYX7LPwg+biCIWuCSLuJ3sHO55I8t6DdjL0c2duyRgAXAl0VqraBOd4FjXDu5di+J RaJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=orKoMAZkJ9GaBrEmbg2MeO7ZyZTeEm7mlKSrLgsvSTs=; b=c5sDaR5mSz1u10d0Mdiqz4eg2jiX/3KwSNv6CPby902S6ffYEkHp6ZPMnfefifSdvO ucKIal6by+ZMFNFtPPLVOSF54sTNJ3SseAuy9ia0maWexamF6OaEp4uJwnq+5c3G/Yoc 4NLmoxE9CT8jihGgt4M1L6AYOd8CHzwIQKdz6SpIrukfHdphaBUrtW+NES+vM6xymyyi p8K3IKqPiAYMNPoxaNy/ZyKUpaVW0b/gdZtqWfrEULMzU1Ncd4aI3e5VpsdkAqf4+Rvi Mmfr7IzVk+jaV40T/FUGXAg6Kw7dzJAbqJc90xTAeBnHk4Uy0VmSELF4S1Zo/SctVspu D3gA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si1464885ejz.383.2021.03.18.05.37.27; Thu, 18 Mar 2021 05:37:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbhCRMgJ (ORCPT + 99 others); Thu, 18 Mar 2021 08:36:09 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14090 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbhCRMgG (ORCPT ); Thu, 18 Mar 2021 08:36:06 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F1RKW4Z1cz19GFr; Thu, 18 Mar 2021 20:34:07 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Thu, 18 Mar 2021 20:35:55 +0800 From: Wu Bo To: , , CC: , , Subject: [RFC PATCH] ata: add lun validity check on ata_sas_queuecmd Date: Thu, 18 Mar 2021 20:53:53 +0800 Message-ID: <1616072033-287811-1-git-send-email-wubo40@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, After executing rescan-scsi-bus.sh -r -m, the system adds 255 more disks. The reason is as follows: 1. Execute the rescan-scsi-bus.sh script to scan all targets. 2. The REPORT_LUNS failed due to some errors on the device of sdb(LUN0). 3. Do a sequential scan on the target which sdb belongs to. 4. Have already scanned LUN 0, so start at LUN 1. and keep scanning until reach the max. 5. For SATA device, the driver of ata does not check the validity of LUN ID before dispatch commands to ATA device. Result in LUN 1~MAX successfully added to the system. trace: __scsi_scan_target() -> scsi_report_lun_scan() -> scsi_sequential_lun_scan() Steps to reproduce as follow: step1: lsscsi [1:0:0:0] disk ATA /dev/sda [1:0:1:0] disk ATA /dev/sdb [1:0:2:0] disk ATA /dev/sdc [1:0:3:0] disk ATA /dev/sdd [1:0:4:0] disk ATA /dev/sde step2: echo "offline" > /sys/block/sdb/device/state step3: rescan-scsi-bus.sh -r -m step4: lsscsi [1:0:0:0] disk ATA /dev/sda [1:0:1:1] disk ATA /dev/sdr [1:0:1:2] disk ATA /dev/sds [1:0:1:3] disk ATA /dev/sdt [1:0:1:4] disk ATA /dev/sdu ...... [1:0:1:251] disk ATA /dev/sdjh [1:0:1:252] disk ATA /dev/sdji [1:0:1:253] disk ATA /dev/sdjj [1:0:1:254] disk ATA /dev/sdjk [1:0:1:255] disk ATA /dev/sdjl [1:0:2:0] disk ATA /dev/sdc [1:0:3:0] disk ATA /dev/sdd [1:0:4:0] disk ATA /dev/sde Signed-off-by: Wu Bo --- drivers/ata/libata-sata.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index c16423e..e30a412 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1242,7 +1242,8 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap) ata_scsi_dump_cdb(ap, cmd); - if (likely(ata_dev_enabled(ap->link.device))) + if (likely(ata_dev_enabled(ap->link.device)) && + (cmd->device->lun == 0)) rc = __ata_scsi_queuecmd(cmd, ap->link.device); else { cmd->result = (DID_BAD_TARGET << 16); -- 1.8.3.1