Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1030770rdb; Mon, 4 Sep 2023 00:04:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbTi0/zLAtqoL6WRec1/vfGxwHBs5ZkYsIjDB+p52LObkE5B3PBn8P7TzQelzgHwqRIZLz X-Received: by 2002:a05:6a20:9191:b0:14d:7b6:cf34 with SMTP id v17-20020a056a20919100b0014d07b6cf34mr12426377pzd.1.1693811083662; Mon, 04 Sep 2023 00:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693811083; cv=none; d=google.com; s=arc-20160816; b=R6D0CocW2rqn7q66M49LYoa08HOweLpYdmms5n0Iai5/6GPXjB5P2vhO+7fwvF+Byl IutYPFT+uAuePfYD3lK+G4mVy9sBtFLu7Opn4JZ668eNFQS3UCSUmgFLj01/Jauo52Kz 7h9kAo26Kw6ZXnZ1ygiSTjNzcfyiujA5ybou6Pfeyy5/LZZ8GpJCMgjZZf75mCyxLO5o aXcaD15Nu2Vnv4HZJeNuTCRXaGotkQuJe8jN7bK7JNCzLjywxqjNuV7SPbApznZqemCi ohvcFWrlROjkat1K0ZhyZfY7Z6WQ3YuAC9tIUpGR7h1bYzhYlKNN/kkGsKWwlivVi78V 3j3Q== 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=N0dlrCS4PTtXf0wDsxdvo+NcSjbMcVsKbEVnHm6QS18=; fh=U8QwZ5xHaU2/8ln497S/E2sKzHGkM9mdrpYdmq3DJOs=; b=I87lJpGQqEYnz5CJ0xUl8AMzqSy2/n+x+oThOgsGfuPLd5an2AGGxfSNrz0zqGq+ig MrqiZeET8aanuYEQ+U3pjwiuFFmRMI+c+2s20gzL6IVtsIxNvtr5I1G9v1NzbmdgffDR 32JIeH48Rhm1n7EHU28R2sTew3YfT9GIQUQp6/HvxRw47U0PcGrz6zoVc8u2ZL21Ivwf /bQz/tcM6lZ3od1G3oA9FRJbAUiSXTe6XkAvmsnWfz10wJlXBHJcdAkUscazCH9TD7qE LcQwIBXAa1JZMwlwq8ph1rfgfE7xBm4iwMxf8es5nEvF7W8qfZ+9xPUm7Cm36SxP8+jC 1a8g== 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 a4-20020a656404000000b00564bdf6958fsi7515209pgv.649.2023.09.04.00.04.30; Mon, 04 Sep 2023 00:04:43 -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 S236230AbjIAJmN (ORCPT + 99 others); Fri, 1 Sep 2023 05:42:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348881AbjIAJmF (ORCPT ); Fri, 1 Sep 2023 05:42:05 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A975610D7; Fri, 1 Sep 2023 02:41:56 -0700 (PDT) Received: from kwepemm600012.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RcXz35PtczQjKk; Fri, 1 Sep 2023 17:38:39 +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:53 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: Hannes Reinecke , , , , Wenchao Hao Subject: [RFC PATCH v2 05/19] scsi: scsi_error: Add helper scsi_eh_sdev_reset to do lun reset Date: Fri, 1 Sep 2023 17:41:13 +0800 Message-ID: <20230901094127.2010873-6-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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 helper function scsi_eh_sdev_reset() to perform lun reset and check if to finish some error commands. This is preparation for a genernal LUN/target based error handle strategy and did not change original logic. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 54 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 64eb616261ec..16888540b663 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1635,6 +1635,34 @@ static int scsi_eh_stu(struct Scsi_Host *shost, return list_empty(work_q); } +static int scsi_eh_sdev_reset(struct scsi_cmnd *scmd, + struct list_head *work_q, + struct list_head *done_q) +{ + struct scsi_cmnd *next; + struct scsi_device *sdev = scmd->device; + enum scsi_disposition rtn; + + SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, + "%s: Sending BDR\n", current->comm)); + + rtn = scsi_try_bus_device_reset(scmd); + if (rtn != SUCCESS && rtn != FAST_IO_FAIL) { + SCSI_LOG_ERROR_RECOVERY(3, + sdev_printk(KERN_INFO, sdev, + "%s: BDR failed\n", current->comm)); + return 0; + } + + if (!scsi_device_online(sdev) || rtn == FAST_IO_FAIL || + !scsi_eh_tur(scmd)) + list_for_each_entry_safe(scmd, next, work_q, eh_entry) + if (scmd->device == sdev && + scsi_eh_action(scmd, rtn) != FAILED) + scsi_eh_finish_cmd(scmd, done_q); + + return list_empty(work_q); +} /** * scsi_eh_bus_device_reset - send bdr if needed @@ -1652,9 +1680,8 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, struct list_head *work_q, struct list_head *done_q) { - struct scsi_cmnd *scmd, *bdr_scmd, *next; + struct scsi_cmnd *scmd, *bdr_scmd; struct scsi_device *sdev; - enum scsi_disposition rtn; shost_for_each_device(sdev, shost) { if (scsi_host_eh_past_deadline(shost)) { @@ -1675,26 +1702,9 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, if (!bdr_scmd) continue; - SCSI_LOG_ERROR_RECOVERY(3, - sdev_printk(KERN_INFO, sdev, - "%s: Sending BDR\n", current->comm)); - rtn = scsi_try_bus_device_reset(bdr_scmd); - if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { - if (!scsi_device_online(sdev) || - rtn == FAST_IO_FAIL || - !scsi_eh_tur(bdr_scmd)) { - list_for_each_entry_safe(scmd, next, - work_q, eh_entry) { - if (scmd->device == sdev && - scsi_eh_action(scmd, rtn) != FAILED) - scsi_eh_finish_cmd(scmd, - done_q); - } - } - } else { - SCSI_LOG_ERROR_RECOVERY(3, - sdev_printk(KERN_INFO, sdev, - "%s: BDR failed\n", current->comm)); + if (scsi_eh_sdev_reset(bdr_scmd, work_q, done_q)) { + scsi_device_put(sdev); + break; } } -- 2.35.3