From patchwork Fri Sep 1 09:41:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 13372332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EE8ACA0FEA for ; Fri, 1 Sep 2023 09:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348883AbjIAJmH (ORCPT ); Fri, 1 Sep 2023 05:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348890AbjIAJmB (ORCPT ); Fri, 1 Sep 2023 05:42:01 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE6810F0; Fri, 1 Sep 2023 02:41:55 -0700 (PDT) Received: from kwepemm600012.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RcXyH0ncdzhZJG; Fri, 1 Sep 2023 17:37:59 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 1 Sep 2023 17:41:52 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: Hannes Reinecke , , , , Wenchao Hao Subject: [RFC PATCH v2 03/19] scsi: scsi_error: Check if to do reset in scsi_try_xxx_reset Date: Fri, 1 Sep 2023 17:41:11 +0800 Message-ID: <20230901094127.2010873-4-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230901094127.2010873-1-haowenchao2@huawei.com> References: <20230901094127.2010873-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600012.china.huawei.com (7.193.23.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This is preparation for a genernal LUN/target based error handle strategy, the strategy would reuse some error handler APIs, but some steps of these function should not be performed. For example, we should not perform target reset if we just stop IOs on one single LUN. This change add checks in scsi_try_xxx_reset to make sure the reset operations would not be performed only if the condition is not satisfied. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 879fdd7c165b..48ed035d44ce 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -923,7 +923,7 @@ void scsi_eh_done(struct scsi_cmnd *scmd) * scsi_try_host_reset - ask host adapter to reset itself * @scmd: SCSI cmd to send host reset. */ -static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd) +static enum scsi_disposition __scsi_try_host_reset(struct scsi_cmnd *scmd) { unsigned long flags; enum scsi_disposition rtn; @@ -949,11 +949,19 @@ static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd) return rtn; } +static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd) +{ + if (!scsi_host_in_recovery(scmd->device->host)) + return FAILED; + + return __scsi_try_host_reset(scmd); +} + /** * scsi_try_bus_reset - ask host to perform a bus reset * @scmd: SCSI cmd to send bus reset. */ -static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd) +static enum scsi_disposition __scsi_try_bus_reset(struct scsi_cmnd *scmd) { unsigned long flags; enum scsi_disposition rtn; @@ -979,6 +987,14 @@ static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd) return rtn; } +static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd) +{ + if (!scsi_host_in_recovery(scmd->device->host)) + return FAILED; + + return __scsi_try_bus_reset(scmd); +} + static void __scsi_report_device_reset(struct scsi_device *sdev, void *data) { sdev->was_reset = 1; @@ -995,7 +1011,7 @@ static void __scsi_report_device_reset(struct scsi_device *sdev, void *data) * timer on it, and set the host back to a consistent state prior to * returning. */ -static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd) +static enum scsi_disposition __scsi_try_target_reset(struct scsi_cmnd *scmd) { unsigned long flags; enum scsi_disposition rtn; @@ -1016,6 +1032,15 @@ static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd) return rtn; } +static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd) +{ + if (!(scsi_target_in_recovery(scsi_target(scmd->device)) || + scsi_host_in_recovery(scmd->device->host))) + return FAILED; + + return __scsi_try_target_reset(scmd); +} + /** * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev * @scmd: SCSI cmd used to send BDR @@ -2534,17 +2559,17 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg) break; fallthrough; case SG_SCSI_RESET_TARGET: - rtn = scsi_try_target_reset(scmd); + rtn = __scsi_try_target_reset(scmd); if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) break; fallthrough; case SG_SCSI_RESET_BUS: - rtn = scsi_try_bus_reset(scmd); + rtn = __scsi_try_bus_reset(scmd); if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) break; fallthrough; case SG_SCSI_RESET_HOST: - rtn = scsi_try_host_reset(scmd); + rtn = __scsi_try_host_reset(scmd); if (rtn == SUCCESS) break; fallthrough;