From patchwork Fri Mar 14 01:29:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016120 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 742FF1A29A; Fri, 14 Mar 2025 01:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914618; cv=none; b=ms39lTlHctwr7nIqV8iN/T9adcyn4+meoYASks8ikNCSz7hKLORyHBc304kvM0QmiXdstr1VUIoV0GXxoweGhmMi5wj03+Q7FbdxgOH0gSQlVgC4qqkAtP68AKhA13kHWx81fHBUtLt46J0WdGJplL3Lr9AfU5HihQWntMFtdlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914618; c=relaxed/simple; bh=3FHW5eEqXzBmOUVv02+YImEYpFZuDeUJ3fjJpUMrVZg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IInym485Blgx4YRB6M235N9zWHYfycjn/qjrlQarwVETvXrImJcY6HcQdMCGDZNClGay//FtmUI5cEVZhVvT1lcS2KmCa01YPLZQjtjWowfPjVOPQTw39wy0D+JPMcEsJd2XxaBEVaENW7AEVZH5qmj/KGOG1wOmp8M5faME4TM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4ZDR8C5b2GztQbZ; Fri, 14 Mar 2025 09:08:43 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id BBEDE1800E4; Fri, 14 Mar 2025 09:10:12 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:11 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 01/19] scsi: scsi_error: Define framework for LUN/target based error handle Date: Fri, 14 Mar 2025 09:29:09 +0800 Message-ID: <20250314012927.150860-2-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao The old scsi error handle logic is based on host, once a scsi command in one LUN of this host is classfied as failed, SCSI mid-level would set the whole host to recovery state, and no IO can be submitted to all LUNs of this host any more before recovery finished, while the recovery process might take a long time to finish. It's unreasonable when there are a lot of LUNs in one host. This change introduce a way for driver to implement its own error handle logic which can be based on scsi LUN or scsi target as minimum unit. scsi_device_eh is defined for error handle based on scsi LUN, and pointer struct scsi_device_eh "eh" is added in scsi_device, which is NULL by default. LLDs can initialize the sdev->eh in hostt->slave_alloc to implement an scsi LUN based error handle. If this member is not NULL, SCSI mid-level would branch to drivers' error handler rather than the old one which block whole host's IO. scsi_target_eh is defined for error handle based on scsi target, and pointer struct scsi_target_eh "eh" is added in scsi_target, which is NULL by default. LLDs can initialize the starget->eh in hostt->target_alloc to implement an scsi target based error handle. If this member is not NULL, SCSI mid-level would branch to drivers' error handler rather than the old one which block whole host's IO. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 57 +++++++++++++++++++++++++++++++- drivers/scsi/scsi_lib.c | 12 +++++++ drivers/scsi/scsi_priv.h | 18 ++++++++++ include/scsi/scsi_device.h | 67 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 815e7d63f3e2..f89de23a6807 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -291,11 +291,48 @@ static void scsi_eh_inc_host_failed(struct rcu_head *head) spin_unlock_irqrestore(shost->host_lock, flags); } +#define SCSI_EH_NO_HANDLER 1 + +static int __scsi_eh_scmd_add_sdev(struct scsi_cmnd *scmd) +{ + struct scsi_device *sdev = scmd->device; + struct scsi_device_eh *eh = sdev->eh; + + if (!eh || !eh->add_cmnd) + return SCSI_EH_NO_HANDLER; + + scsi_eh_reset(scmd); + eh->add_cmnd(scmd); + + if (eh->wakeup) + eh->wakeup(sdev); + + return 0; +} + +static int __scsi_eh_scmd_add_starget(struct scsi_cmnd *scmd) +{ + struct scsi_device *sdev = scmd->device; + struct scsi_target *starget = scsi_target(sdev); + struct scsi_target_eh *eh = starget->eh; + + if (!eh || !eh->add_cmnd) + return SCSI_EH_NO_HANDLER; + + scsi_eh_reset(scmd); + eh->add_cmnd(scmd); + + if (eh->wakeup) + eh->wakeup(starget); + + return 0; +} + /** * scsi_eh_scmd_add - add scsi cmd to error handling. * @scmd: scmd to run eh on. */ -void scsi_eh_scmd_add(struct scsi_cmnd *scmd) +static void __scsi_eh_scmd_add(struct scsi_cmnd *scmd) { struct Scsi_Host *shost = scmd->device->host; unsigned long flags; @@ -322,6 +359,24 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scmd) call_rcu_hurry(&scmd->rcu, scsi_eh_inc_host_failed); } +void scsi_eh_scmd_add(struct scsi_cmnd *scmd) +{ + struct scsi_device *sdev = scmd->device; + struct scsi_target *starget = scsi_target(sdev); + struct Scsi_Host *shost = sdev->host; + + if (unlikely(scsi_host_in_recovery(shost))) + __scsi_eh_scmd_add(scmd); + + if (unlikely(scsi_target_in_recovery(starget))) + if (__scsi_eh_scmd_add_starget(scmd)) + __scsi_eh_scmd_add(scmd); + + if (__scsi_eh_scmd_add_sdev(scmd)) + if (__scsi_eh_scmd_add_starget(scmd)) + __scsi_eh_scmd_add(scmd); +} + /** * scsi_timeout - Timeout function for normal scsi commands. * @req: request that is timing out. diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index f1cfe0bb89b2..8cdab7ac5980 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -399,6 +399,12 @@ void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd) sbitmap_put(&sdev->budget_map, cmd->budget_token); cmd->budget_token = -1; + + if (sdev->eh && sdev->eh->wakeup) + sdev->eh->wakeup(sdev); + + if (starget->eh && starget->eh->wakeup) + starget->eh->wakeup(starget); } /* @@ -1357,6 +1363,9 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, { int token; + if (scsi_device_in_recovery(sdev)) + return -1; + token = sbitmap_get(&sdev->budget_map); if (token < 0) return -1; @@ -1390,6 +1399,9 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost, struct scsi_target *starget = scsi_target(sdev); unsigned int busy; + if (scsi_target_in_recovery(starget)) + return 0; + if (starget->single_lun) { spin_lock_irq(shost->host_lock); if (starget->starget_sdev_user && diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 9fc397a9ce7a..90e1e6d80265 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -193,6 +193,24 @@ static inline void scsi_dh_add_device(struct scsi_device *sdev) { } static inline void scsi_dh_release_device(struct scsi_device *sdev) { } #endif +static inline int scsi_device_in_recovery(struct scsi_device *sdev) +{ + struct scsi_device_eh *eh = sdev->eh; + + if (eh && eh->is_busy) + return eh->is_busy(sdev); + return 0; +} + +static inline int scsi_target_in_recovery(struct scsi_target *starget) +{ + struct scsi_target_eh *eh = starget->eh; + + if (eh && eh->is_busy) + return eh->is_busy(starget); + return 0; +} + struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev); extern int scsi_device_max_queue_depth(struct scsi_device *sdev); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 7acd0ec82bb0..5911c82ca435 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -100,6 +100,71 @@ struct scsi_vpd { unsigned char data[]; }; +struct scsi_device; +struct scsi_target; + +struct scsi_device_eh { + /* + * add scsi command to error handler so it would be handuled by + * driver's error handle strategy + */ + void (*add_cmnd)(struct scsi_cmnd *scmd); + + /* + * to judge if the device is busy handling errors, called before + * dispatch scsi cmnd + * + * return 0 if it's ready to accepy scsi cmnd + * return 0 if it's in error handle, command's would not be dispatched + */ + int (*is_busy)(struct scsi_device *sdev); + + /* + * wakeup device's error handle + * + * usually the error handler strategy would not run at once when + * error command is added. This function would be called when any + * scsi cmnd is finished or when scsi cmnd is added. + */ + int (*wakeup)(struct scsi_device *sdev); + + /* + * data entity for device specific error handler + */ + unsigned long driver_data[]; +}; + +struct scsi_target_eh { + /* + * add scsi command to error handler so it would be handuled by + * driver's error handle strategy + */ + void (*add_cmnd)(struct scsi_cmnd *scmd); + + /* + * to judge if the device is busy handling errors, called before + * dispatch scsi cmnd + * + * return 0 if it's ready to accepy scsi cmnd + * return 0 if it's in error handle, command's would not be dispatched + */ + int (*is_busy)(struct scsi_target *starget); + + /* + * wakeup device's error handle + * + * usually the error handler strategy would not run at once when + * error command is added. This function would be called when any + * scsi cmnd is finished or when scsi cmnd is added. + */ + int (*wakeup)(struct scsi_target *starget); + + /* + * data entity for device specific error handler + */ + unsigned long driver_data[]; +}; + struct scsi_device { struct Scsi_Host *host; struct request_queue *request_queue; @@ -281,6 +346,7 @@ struct scsi_device { struct mutex state_mutex; enum scsi_device_state sdev_state; struct task_struct *quiesced_by; + struct scsi_device_eh *eh; unsigned long sdev_data[]; } __attribute__((aligned(sizeof(unsigned long)))); @@ -367,6 +433,7 @@ struct scsi_target { char scsi_level; enum scsi_target_state state; void *hostdata; /* available to low-level driver */ + struct scsi_target_eh *eh; unsigned long starget_data[]; /* for the transport */ /* starget_data must be the last element!!!! */ } __attribute__((aligned(sizeof(unsigned long)))); From patchwork Fri Mar 14 01:29:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016121 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CBAE1BC3C; Fri, 14 Mar 2025 01:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914618; cv=none; b=IOhX7uePlPJkThzYGlN/VjPz7HB7BupmvuX+lG99owSk4sW76Esty56+y8AKB1/snIY4EATDGBVtTyrXKKn3m/0sqmVcNkeYUJxBeDe/ce0VuwvtMoq2+8GSdmDoNw6yBnifjjP0REmz5W0pibbjO/wvYO+T5pxM9Kx9r7WlhU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914618; c=relaxed/simple; bh=FA/bM8YrOrG7YN0tT8yx9kjvDbFL54SCRb8IgSF5WC4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qzWOt5+bNZkVa5txm7q0c31TxeqVA5ANvXgXCJwIxjR6GaCO0JRATkija0LUV/BBJvpPu4BB9BicONNnsOaxNKwgfo+x6tlbiIgm0cqZLjce8d1hTgahaE19/a3h0wx0Fx1HAnnuj5lDgzpYSSYUtilQCjwO2l+GWujLnWftE60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZDR4s5dNfz1ltZt; Fri, 14 Mar 2025 09:05:49 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 3D99A180069; Fri, 14 Mar 2025 09:10:13 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:12 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 02/19] scsi: scsi_error: Move complete variable eh_action from shost to sdevice Date: Fri, 14 Mar 2025 09:29:10 +0800 Message-ID: <20250314012927.150860-3-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao eh_action is used to wait for error handle command's completion if scsi command is send in error handle. Now the error handler might based on scsi_device, so move it to scsi_device. This is preparation for a genernal LUN/target based error handle strategy. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 6 +++--- include/scsi/scsi_device.h | 2 ++ include/scsi/scsi_host.h | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index f89de23a6807..4f37af9e20b6 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -916,7 +916,7 @@ void scsi_eh_done(struct scsi_cmnd *scmd) SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, "%s result: %x\n", __func__, scmd->result)); - eh_action = scmd->device->host->eh_action; + eh_action = scmd->device->eh_action; if (eh_action) complete(eh_action); } @@ -1205,7 +1205,7 @@ static enum scsi_disposition scsi_send_eh_cmnd(struct scsi_cmnd *scmd, retry: scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes); - shost->eh_action = &done; + sdev->eh_action = &done; scsi_log_send(scmd); scmd->submitter = SUBMITTED_BY_SCSI_ERROR_HANDLER; @@ -1249,7 +1249,7 @@ static enum scsi_disposition scsi_send_eh_cmnd(struct scsi_cmnd *scmd, rtn = SUCCESS; } - shost->eh_action = NULL; + sdev->eh_action = NULL; scsi_log_completion(scmd, rtn); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 5911c82ca435..6388abb6c0d4 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -347,6 +347,8 @@ struct scsi_device { enum scsi_device_state sdev_state; struct task_struct *quiesced_by; struct scsi_device_eh *eh; + struct completion *eh_action; /* Wait for specific actions */ + /* on the device. */ unsigned long sdev_data[]; } __attribute__((aligned(sizeof(unsigned long)))); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 26bc23419cfd..de014c60746c 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -558,8 +558,6 @@ struct Scsi_Host { struct list_head eh_abort_list; struct list_head eh_cmd_q; struct task_struct * ehandler; /* Error recovery thread. */ - struct completion * eh_action; /* Wait for specific actions on the - host. */ wait_queue_head_t host_wait; const struct scsi_host_template *hostt; struct scsi_transport_template *transportt; From patchwork Fri Mar 14 01:29:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016129 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C28DF12E5D; Fri, 14 Mar 2025 01:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914624; cv=none; b=RouuFew+a7ivx3tmQDo4ZHraxe098sBhd+gsJBR8CA94GCvWsZsGo1vTAW1MQ0BUHPPs8u9FhfQa7wO4uhF0H8ZCXO3mNilJhJFduN5kJnLq6S10695cX4iQ4RSqverNjikZwzI+TWcxa9ofnf0p2x9wyODVhS6aa5vDBt7EYfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914624; c=relaxed/simple; bh=Q/dwwbC1eHY4Zi6jqCUK1bren11pNwo6AThHBStMBu0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hb5anrg/LTqatU3OKaOgcAW5AhhOuyZFp1ET9FfxI8LHMvhSZbQwK89YU4j5/DiiYAeALP2Ft1fkbzfWpoMSiHC/aGR639nHr62OL4mYoFtZt1dlAM/IaVYTrEOlluRBrqcRuaVTbAK67nIQp0xPhhn3peWgGiVxBotSF0WUNVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZDR5V2wtFzvWqS; Fri, 14 Mar 2025 09:06:22 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id B559A18006C; Fri, 14 Mar 2025 09:10:13 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:13 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 03/19] scsi: scsi_error: Check if to do reset in scsi_try_xxx_reset Date: Fri, 14 Mar 2025 09:29:11 +0800 Message-ID: <20250314012927.150860-4-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao 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 4f37af9e20b6..cc3a5adb9daa 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -925,7 +925,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; @@ -951,11 +951,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; @@ -981,6 +989,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; @@ -997,7 +1013,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; @@ -1018,6 +1034,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 @@ -2541,17 +2566,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; From patchwork Fri Mar 14 01:29:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016128 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2926146D57; Fri, 14 Mar 2025 01:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914623; cv=none; b=Q74ww2pupi4P8BLyACZkdC0RaG67fd14IPhHw/h1hLWPt8aETdWphtH29FR8Pt05Hj5cagKxhZrXDSQ3IjHIorCCII8Kv0b5vONKxh+WyyZOMeEOKrqB7JpYipJuDVCeUnApCcp7c9K4eDSULzqlK9lirx1SYu+9d6ycv/9bVWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914623; c=relaxed/simple; bh=NrbH2jA5dfQRKEuR+ftka6mcnaeS1IrqYubeKYKyXHE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L0hu8UZO+4xy93w4iW+2XTyuWs7/3gUcUNJbxQyKg0s04vYRgh+vSmMlLCvNAQDcWECol8VCwI/FgesLuK7q2Ad0yb3IGhGpmcooMdaa7C2tJA+NfhX1XuzT8OgdV9vEg0QR58U0Nl4Z8BDhVMDpND0W7rHIzJAdHKt3qIvKPJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZDR9q3gQnzyS0S; Fri, 14 Mar 2025 09:10:07 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 3AFF4140414; Fri, 14 Mar 2025 09:10:14 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:13 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 04/19] scsi: scsi_error: Add helper scsi_eh_sdev_stu to do START_UNIT Date: Fri, 14 Mar 2025 09:29:12 +0800 Message-ID: <20250314012927.150860-5-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add helper function scsi_eh_sdev_stu() to perform START_UNIT 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 | 50 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index cc3a5adb9daa..3b55642fb585 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1567,6 +1567,31 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd) return 1; } +static int scsi_eh_sdev_stu(struct scsi_cmnd *scmd, + struct list_head *work_q, + struct list_head *done_q) +{ + struct scsi_device *sdev = scmd->device; + struct scsi_cmnd *next; + + SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, + "%s: Sending START_UNIT\n", current->comm)); + + if (scsi_eh_try_stu(scmd)) { + SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, + "%s: START_UNIT failed\n", current->comm)); + return 0; + } + + if (!scsi_device_online(sdev) || !scsi_eh_tur(scmd)) + list_for_each_entry_safe(scmd, next, work_q, eh_entry) + if (scmd->device == sdev && + scsi_eh_action(scmd, SUCCESS) == SUCCESS) + scsi_eh_finish_cmd(scmd, done_q); + + return list_empty(work_q); +} + /** * scsi_eh_stu - send START_UNIT if needed * @shost: &scsi host being recovered. @@ -1581,7 +1606,7 @@ static int scsi_eh_stu(struct Scsi_Host *shost, struct list_head *work_q, struct list_head *done_q) { - struct scsi_cmnd *scmd, *stu_scmd, *next; + struct scsi_cmnd *scmd, *stu_scmd; struct scsi_device *sdev; shost_for_each_device(sdev, shost) { @@ -1604,26 +1629,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost, if (!stu_scmd) continue; - SCSI_LOG_ERROR_RECOVERY(3, - sdev_printk(KERN_INFO, sdev, - "%s: Sending START_UNIT\n", - current->comm)); - - if (!scsi_eh_try_stu(stu_scmd)) { - if (!scsi_device_online(sdev) || - !scsi_eh_tur(stu_scmd)) { - list_for_each_entry_safe(scmd, next, - work_q, eh_entry) { - if (scmd->device == sdev && - scsi_eh_action(scmd, SUCCESS) == SUCCESS) - scsi_eh_finish_cmd(scmd, done_q); - } - } - } else { - SCSI_LOG_ERROR_RECOVERY(3, - sdev_printk(KERN_INFO, sdev, - "%s: START_UNIT failed\n", - current->comm)); + if (scsi_eh_sdev_stu(stu_scmd, work_q, done_q)) { + scsi_device_put(sdev); + break; } } From patchwork Fri Mar 14 01:29:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016122 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 257ED2E3374; Fri, 14 Mar 2025 01:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914619; cv=none; b=jYA1o8yT6KpOUFM4uEG0kNo5AshCbTOqyk3Hv4VcHwOFKiWaCcKe4s6TbRLsod+TLRn5g7SejhpfQvlKZLxlFomoBmd3RNNWvH2SYinkR5sMyxm0hKXBKdbibjWYjnqToHIbtb7P/ggwfmOaCOi8u6ZF3g6onER7ByKJac8brwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914619; c=relaxed/simple; bh=FiroMEstMQXRMTvsiFyhVjQwh2yTBGDEo2CByl4FbFQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m9997mkAhchuENyEUKoeUZIajem9eeR6FpEw+H3kWZ82LUMuEUjW5Fd8JZFmO9WiNsUuncHEc9lwhQ1w2pDaKq523nSRu3O4iKBjMZc7tUlquElAQ10byApM2jkhOL7w1EG3scMLny3q9UgAWE6cEvapepRudJedGr3kINIy/YA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZDR8069nFz1R6bW; Fri, 14 Mar 2025 09:08:32 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id B7BF31A0171; Fri, 14 Mar 2025 09:10:14 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:14 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 05/19] scsi: scsi_error: Add helper scsi_eh_sdev_reset to do lun reset Date: Fri, 14 Mar 2025 09:29:13 +0800 Message-ID: <20250314012927.150860-6-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao 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 3b55642fb585..80e5787055d3 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1638,6 +1638,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 @@ -1655,9 +1683,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)) { @@ -1678,26 +1705,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; } } From patchwork Fri Mar 14 01:29:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016124 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 599E62E3382; Fri, 14 Mar 2025 01:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914619; cv=none; b=DX1IJjJUfHqaT0o3+VPPzidP6u/BEYjv0VhoQYzBB5+P7QIVQhF2eaaOT4wFjrAzOl11N9N77w5Qy9W4Hjr/BVYF5pSVmDEBTiTdyafkhe16C9zPiBxs5BPPL2Mej/Zc+V62mSvwfEPd+FtsS6A+tFSUWEY3V8kmTCdE4uyt1Ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914619; c=relaxed/simple; bh=XTXliUfYEwLhbUuqtXXlqZhKqQNWomihSNae6xtoezk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j5iJC/6HuqiqExS7hDyiFwjYw9OlyYWrbMOTtb8GsN4rFyosNLaE4z/gqSrfU/uOoFfjOFALLsnPGoxBYnuzHSzetn8brpuz66yoiQaqCfUejlayc3cDDRWo56lFaFv6Nosx1oewSaB+/UH0CPI9omrKU23Feb1j6po5cXfCpv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZDR812Rglz1R6jr; Fri, 14 Mar 2025 09:08:33 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 37FEE1A0188; Fri, 14 Mar 2025 09:10:15 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:14 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 06/19] scsi: scsi_error: Add flags to mark error handle steps has done Date: Fri, 14 Mar 2025 09:29:14 +0800 Message-ID: <20250314012927.150860-7-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao LUN based error handle would mainly do three steps to recover commands which are check sense, start unit, and reset lun. It might fallback to target/host based error handle which would do these steps too. Target based error handle would reset target, it would also fallback to host based error handle. Add some flags to mark these steps are done to avoid repeating these steps. The flags should be cleared when LUN/target based error handler is waked up or when target/host based error handle finished, and set when fallback to target/host based error handle. scsi_eh_get_sense, scsi_eh_stu, scsi_eh_bus_device_reset and scsi_eh_target_reset would check these flags before actually action. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 55 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_device.h | 28 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 80e5787055d3..628ecbfcfff2 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -57,10 +57,50 @@ #define BUS_RESET_SETTLE_TIME (10) #define HOST_RESET_SETTLE_TIME (10) +#define sdev_flags_done(flag) \ +static inline int sdev_##flag(struct scsi_device *sdev) \ +{ \ + struct scsi_device_eh *eh = sdev->eh; \ + if (!eh) \ + return 0; \ + return eh->flag; \ +} + static int scsi_eh_try_stu(struct scsi_cmnd *scmd); static enum scsi_disposition scsi_try_to_abort_cmd(const struct scsi_host_template *, struct scsi_cmnd *); +sdev_flags_done(get_sense_done); +sdev_flags_done(stu_done); +sdev_flags_done(reset_done); + +static inline int starget_reset_done(struct scsi_target *starget) +{ + struct scsi_target_eh *eh = starget->eh; + + if (!eh) + return 0; + return eh->reset_done; +} + +static inline void shost_clear_eh_done(struct Scsi_Host *shost) +{ + struct scsi_device *sdev; + struct scsi_target *starget; + + list_for_each_entry(starget, &shost->__targets, siblings) + if (starget->eh) + starget->eh->reset_done = 0; + + shost_for_each_device(sdev, shost) { + if (!sdev->eh) + continue; + sdev->eh->get_sense_done = 0; + sdev->eh->stu_done = 0; + sdev->eh->reset_done = 0; + } +} + void scsi_eh_wakeup(struct Scsi_Host *shost, unsigned int busy) { lockdep_assert_held(shost->host_lock); @@ -1405,6 +1445,9 @@ int scsi_eh_get_sense(struct list_head *work_q, current->comm)); break; } + if (sdev_get_sense_done(scmd->device) || + starget_reset_done(scsi_target(scmd->device))) + continue; if (!scsi_status_is_check_condition(scmd->result)) /* * don't request sense if there's no check condition @@ -1618,6 +1661,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost, scsi_device_put(sdev); break; } + if (sdev_stu_done(sdev) || + starget_reset_done(scsi_target(sdev))) + continue; stu_scmd = NULL; list_for_each_entry(scmd, work_q, eh_entry) if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && @@ -1701,6 +1747,9 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, bdr_scmd = scmd; break; } + if (sdev_reset_done(sdev) || + starget_reset_done(scsi_target(sdev))) + continue; if (!bdr_scmd) continue; @@ -1749,6 +1798,11 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost, } scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry); + if (starget_reset_done(scsi_target(scmd->device))) { + /* push back on work queue for further processing */ + list_move(&scmd->eh_entry, work_q); + continue; + } id = scmd_id(scmd); SCSI_LOG_ERROR_RECOVERY(3, @@ -2365,6 +2419,7 @@ static void scsi_unjam_host(struct Scsi_Host *shost) if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q)) scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q); + shost_clear_eh_done(shost); spin_lock_irqsave(shost->host_lock, flags); if (shost->eh_deadline != -1) shost->last_reset = 0; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 6388abb6c0d4..5cc18ca69fc7 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -104,6 +104,24 @@ struct scsi_device; struct scsi_target; struct scsi_device_eh { + /* + * LUN rebased error handle would mainly do three + * steps to recovery commands which are + * check sense + * start unit + * reset lun + * While we would fallback to target or host based error handle + * which would do these steps too. Add flags to mark thes steps + * are done to avoid repeating these steps. + * + * The flags should be cleared when LUN based error handler is + * wakedup or when target/host based error handle finished, + * set when fallback to target or host based error handle. + */ + unsigned get_sense_done:1; + unsigned stu_done:1; + unsigned reset_done:1; + /* * add scsi command to error handler so it would be handuled by * driver's error handle strategy @@ -135,6 +153,16 @@ struct scsi_device_eh { }; struct scsi_target_eh { + /* + * flag to mark target reset is done to avoid repeating + * these steps when fallback to host based error handle + * + * The flag should be cleared when target based error handler + * is * wakedup or when host based error handle finished, + * set when fallback to host based error handle. + */ + unsigned reset_done:1; + /* * add scsi command to error handler so it would be handuled by * driver's error handle strategy From patchwork Fri Mar 14 01:29:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016125 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF9C52D05E; Fri, 14 Mar 2025 01:10:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914620; cv=none; b=lJWgylQaxkOarZ2Lp1DZvf7kvZAr9IpRG6+prw5CbuIGvhpGsHHXe7w6l9GWBn6ReBjw7TijVphEm3wcIlbN1wLpKOOr4fdAUPQtDHA805hI2iBT4fNv524UEXaOZEx7VsFGH5lWbTG9zI9Kdfq42qO1cZiohUdT+Ig8fnASW10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914620; c=relaxed/simple; bh=EfssYDyJB1OHmxnmuyKOLIsm2nAgdczTKJiBdiYP48k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aKc3uq+2Ji9vUlOKOfb2UN19L+RnSC7+uLKMOZ3njEnwseXCBu3LbKK9oaH4zmmBWpgSbgVS5RGzGDfRzEVXjkoukS9l/PnYl+9eBfNEQKzVuJUdA6Rp1DB8/gyIyWlD2mxkGZB7j74fshIe6qCTYdZ799JJMOCx4Ksv1wPUl08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4ZDR9s1Nxqz1cyZ2; Fri, 14 Mar 2025 09:10:09 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id BEDA018006C; Fri, 14 Mar 2025 09:10:15 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:15 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 07/19] scsi: scsi_error: Add helper to handle scsi device's error command list Date: Fri, 14 Mar 2025 09:29:15 +0800 Message-ID: <20250314012927.150860-8-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add helper scsi_sdev_eh() to handle scsi device's error command list, it would perform some steps which can be done with LUN's IO blocked, including check sense, start unit and reset lun. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 37 +++++++++++++++++++++++++++++++++++++ include/scsi/scsi_eh.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 628ecbfcfff2..21f72c075531 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2516,6 +2516,43 @@ int scsi_error_handler(void *data) return 0; } +/* + * Single LUN error handle + * + * @work_q: list of scsi commands need to recovery + * @done_q: list of scsi commands handled + * + * return: return 1 if all commands in work_q is recoveryed, else 0 is returned + */ +int scsi_sdev_eh(struct scsi_device *sdev, + struct list_head *work_q, + struct list_head *done_q) +{ + int ret = 0; + struct scsi_cmnd *scmd; + + SCSI_LOG_ERROR_RECOVERY(2, sdev_printk(KERN_INFO, sdev, + "%s:luneh: checking sense\n", current->comm)); + ret = scsi_eh_get_sense(work_q, done_q); + if (ret) + return ret; + + SCSI_LOG_ERROR_RECOVERY(2, sdev_printk(KERN_INFO, sdev, + "%s:luneh: start unit\n", current->comm)); + scmd = list_first_entry(work_q, struct scsi_cmnd, eh_entry); + ret = scsi_eh_sdev_stu(scmd, work_q, done_q); + if (ret) + return ret; + + SCSI_LOG_ERROR_RECOVERY(2, sdev_printk(KERN_INFO, sdev, + "%s:luneh reset LUN\n", current->comm)); + scmd = list_first_entry(work_q, struct scsi_cmnd, eh_entry); + ret = scsi_eh_sdev_reset(scmd, work_q, done_q); + + return ret; +} +EXPORT_SYMBOL_GPL(scsi_sdev_eh); + /** * scsi_report_bus_reset() - report bus reset observed * diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index 1ae08e81339f..5ce791063baf 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -18,6 +18,8 @@ extern int scsi_block_when_processing_errors(struct scsi_device *); extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd, struct scsi_sense_hdr *sshdr); extern enum scsi_disposition scsi_check_sense(struct scsi_cmnd *); +extern int scsi_sdev_eh(struct scsi_device *sdev, struct list_head *workq, + struct list_head *doneq); static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr) { From patchwork Fri Mar 14 01:29:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016133 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9CC715573F; Fri, 14 Mar 2025 01:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914626; cv=none; b=tuuI2i8ZjwAwd6wc0XCdy/Zi/tGsyygPzb+rGXr/skWNu4kVWafn7AsSPxP1b4MZ8vlED8ld2V7CZ/1c9z8Lwy9c7y+BStqH4/DgAklGcORwwUA+G1FYkp+u1W/m440JWpveMpjU4wBJR3KWvQ4I4ad0anxi2qGBQ8J5mk3XU1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914626; c=relaxed/simple; bh=d9ajH5E4b3zFqyrtsSlhkb6bpRYiRJD79v2eaonvz/w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S1SmTlow6D5epJbwh8bb5IZcaseiQjoCXSPtra82h6csZvU9Ly0rPW2KWZU3dLX50OWGrmEpi+Rbh6XXLfO2UeBgxXDRU0vtG8m2rcG+LAFyUtsHVTKGbgc3Wsh0LbUr/QNxuTc/ohnoCO1oHCu5FxtIRwtODYcDM0uKmEL0XyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZDR5X6JHYzvWpq; Fri, 14 Mar 2025 09:06:24 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 363B7180102; Fri, 14 Mar 2025 09:10:16 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:15 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 08/19] scsi: scsi_error: Add a general LUN based error handler Date: Fri, 14 Mar 2025 09:29:16 +0800 Message-ID: <20250314012927.150860-9-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add a general LUN based error handler which can be used by drivers directly. This error handler implements an scsi_device_eh, when handling error commands, it would call helper function scsi_sdev_eh() added before to try recover error commands. The behavior if scsi_sdev_eh() can not recover all error commands depends on fallback flag, which is initialized when scsi_device is allocated. If fallback is set, it would fallback to further error recover strategy like old host based error handle; else it would mark this scsi device offline and flush all error commands. To using this error handler, drivers should call scsi_device_setup_eh() in its slave_alloc() to setup it's LUN based error handler; call scsi_device_clear_eh() in its slave_destroy() to clear LUN based error handler. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 170 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_eh.h | 2 + 2 files changed, 172 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 21f72c075531..7302536ba62a 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2766,3 +2766,173 @@ bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, } } EXPORT_SYMBOL(scsi_get_sense_info_fld); + +struct scsi_lun_eh { + spinlock_t eh_lock; + unsigned int eh_num; + struct list_head eh_cmd_q; + struct scsi_device *sdev; + struct work_struct eh_handle_work; + unsigned int fallback:1; /* If fallback to further */ + /* recovery on failure */ +}; + +/* + * error handle strategy based on LUN, following steps + * is applied to recovery error commands in list: + * check sense data + * send start unit + * reset lun + * if there are still error commands, it would fallback to + * target based or host based error handle for further recovery. + */ +static void sdev_eh_work(struct work_struct *work) +{ + unsigned long flags; + struct scsi_lun_eh *luneh = + container_of(work, struct scsi_lun_eh, eh_handle_work); + struct scsi_device *sdev = luneh->sdev; + struct scsi_device_eh *eh = sdev->eh; + struct Scsi_Host *shost = sdev->host; + struct scsi_cmnd *scmd, *next; + LIST_HEAD(eh_work_q); + LIST_HEAD(eh_done_q); + + spin_lock_irqsave(&luneh->eh_lock, flags); + list_splice_init(&luneh->eh_cmd_q, &eh_work_q); + spin_unlock_irqrestore(&luneh->eh_lock, flags); + + if (scsi_sdev_eh(sdev, &eh_work_q, &eh_done_q)) + goto out_flush_done; + + if (!luneh->fallback) { + list_for_each_entry_safe(scmd, next, &eh_work_q, eh_entry) + scsi_eh_finish_cmd(scmd, &eh_done_q); + + sdev_printk(KERN_INFO, sdev, "%s:luneh: Device offlined - " + "not ready after error recovery\n", current->comm); + + mutex_lock(&sdev->state_mutex); + scsi_device_set_state(sdev, SDEV_OFFLINE); + mutex_unlock(&sdev->state_mutex); + + goto out_flush_done; + } + + /* + * fallback to target or host based error handle + */ + SCSI_LOG_ERROR_RECOVERY(2, sdev_printk(KERN_INFO, sdev, + "%s:luneh fallback to further recovery\n", current->comm)); + list_for_each_entry_safe(scmd, next, &eh_work_q, eh_entry) { + list_del_init(&scmd->eh_entry); + + if (scsi_host_in_recovery(shost) || + __scsi_eh_scmd_add_starget(scmd)) + __scsi_eh_scmd_add(scmd); + } + + eh->get_sense_done = 1; + eh->stu_done = 1; + eh->reset_done = 1; + +out_flush_done: + scsi_eh_flush_done_q(&eh_done_q); + spin_lock_irqsave(&luneh->eh_lock, flags); + luneh->eh_num = 0; + spin_unlock_irqrestore(&luneh->eh_lock, flags); +} +static void sdev_eh_add_cmnd(struct scsi_cmnd *scmd) +{ + unsigned long flags; + struct scsi_lun_eh *luneh; + struct scsi_device *sdev = scmd->device; + + luneh = (struct scsi_lun_eh *)sdev->eh->driver_data; + + spin_lock_irqsave(&luneh->eh_lock, flags); + list_add_tail(&scmd->eh_entry, &luneh->eh_cmd_q); + luneh->eh_num++; + spin_unlock_irqrestore(&luneh->eh_lock, flags); +} +static int sdev_eh_is_busy(struct scsi_device *sdev) +{ + int ret = 0; + unsigned long flags; + struct scsi_lun_eh *luneh; + + if (!sdev->eh) + return 0; + + luneh = (struct scsi_lun_eh *)sdev->eh->driver_data; + + spin_lock_irqsave(&luneh->eh_lock, flags); + ret = luneh->eh_num; + spin_unlock_irqrestore(&luneh->eh_lock, flags); + + return ret; +} +static int sdev_eh_wakeup(struct scsi_device *sdev) +{ + unsigned long flags; + unsigned int nr_error; + unsigned int nr_busy; + struct scsi_lun_eh *luneh; + + luneh = (struct scsi_lun_eh *)sdev->eh->driver_data; + + spin_lock_irqsave(&luneh->eh_lock, flags); + nr_error = luneh->eh_num; + spin_unlock_irqrestore(&luneh->eh_lock, flags); + + nr_busy = scsi_device_busy(sdev); + + if (!nr_error || nr_busy != nr_error) { + SCSI_LOG_ERROR_RECOVERY(5, sdev_printk(KERN_INFO, sdev, + "%s:luneh: do not wake up, busy/error: %d/%d\n", + current->comm, nr_busy, nr_error)); + return 0; + } + + SCSI_LOG_ERROR_RECOVERY(2, sdev_printk(KERN_INFO, sdev, + "%s:luneh: waking up, busy/error: %d/%d\n", + current->comm, nr_busy, nr_error)); + + return schedule_work(&luneh->eh_handle_work); +} + +int scsi_device_setup_eh(struct scsi_device *sdev, int fallback) +{ + struct scsi_device_eh *eh; + struct scsi_lun_eh *luneh; + + eh = kzalloc(sizeof(struct scsi_device_eh) + sizeof(struct scsi_lun_eh), + GFP_KERNEL); + if (!eh) { + sdev_printk(KERN_ERR, sdev, "failed to setup error handle\n"); + return -ENOMEM; + } + luneh = (struct scsi_lun_eh *)eh->driver_data; + + eh->add_cmnd = sdev_eh_add_cmnd; + eh->is_busy = sdev_eh_is_busy; + eh->wakeup = sdev_eh_wakeup; + + luneh->fallback = fallback; + luneh->sdev = sdev; + spin_lock_init(&luneh->eh_lock); + INIT_LIST_HEAD(&luneh->eh_cmd_q); + INIT_WORK(&luneh->eh_handle_work, sdev_eh_work); + + sdev->eh = eh; + + return 0; +} +EXPORT_SYMBOL_GPL(scsi_device_setup_eh); + +void scsi_device_clear_eh(struct scsi_device *sdev) +{ + kfree(sdev->eh); + sdev->eh = NULL; +} +EXPORT_SYMBOL_GPL(scsi_device_clear_eh); diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index 5ce791063baf..89b471aa484f 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -20,6 +20,8 @@ extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd, extern enum scsi_disposition scsi_check_sense(struct scsi_cmnd *); extern int scsi_sdev_eh(struct scsi_device *sdev, struct list_head *workq, struct list_head *doneq); +extern int scsi_device_setup_eh(struct scsi_device *sdev, int fallback); +extern void scsi_device_clear_eh(struct scsi_device *sdev); static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr) { From patchwork Fri Mar 14 01:29:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016134 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8355715D5C4; Fri, 14 Mar 2025 01:10:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914626; cv=none; b=Fw96Y4bP/PhnohVb+QcvvEjuXVW1Zc8KGj/ByCmWAM8b/fVbz5TRsi902x+rw+x9w6uUYEwMX5witx+KNczueGumptAcavszTnZ7KSHd11fjJFkwnZcF+3vHTPFeXKC0j9EYRKTGSLrh71joDBpSoHJbze9xWUiaFZ9NQjUl1Fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914626; c=relaxed/simple; bh=WlDROKFimy2M3ERNPkejUxJFEzrcYWTkIFsDT4inJcA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eBb8FBbW+HxQLSIKebmWiF78eUcDBfRH10H3HVrMcJTMLbZ8u3kwhxcMdVv7tCmt6dCYvPJdPozQF+Il3DmpI2hpA0shX8621myODuONONoLGXt6aX0Dp/lDapVt1dGGdX/T7dlhhhgcw2Et85kgPm/gFUADaPo4hTbwM5+MYXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZDR5Y2tFJzvWqN; Fri, 14 Mar 2025 09:06:25 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id B4828180102; Fri, 14 Mar 2025 09:10:16 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:16 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 09/19] scsi: core: increase/decrease target_busy without check can_queue Date: Fri, 14 Mar 2025 09:29:17 +0800 Message-ID: <20250314012927.150860-10-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao This is preparation for a genernal target based error handle strategy to check if to wake up actual error handler. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_lib.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8cdab7ac5980..e477c5d3c393 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -394,8 +394,7 @@ void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd) scsi_dec_host_busy(shost, cmd); - if (starget->can_queue > 0) - atomic_dec(&starget->target_busy); + atomic_dec(&starget->target_busy); sbitmap_put(&sdev->budget_map, cmd->budget_token); cmd->budget_token = -1; @@ -1413,10 +1412,10 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost, spin_unlock_irq(shost->host_lock); } + busy = atomic_inc_return(&starget->target_busy) - 1; if (starget->can_queue <= 0) return 1; - busy = atomic_inc_return(&starget->target_busy) - 1; if (atomic_read(&starget->target_blocked) > 0) { if (busy) goto starved; @@ -1441,8 +1440,7 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost, list_move_tail(&sdev->starved_entry, &shost->starved_list); spin_unlock_irq(shost->host_lock); out_dec: - if (starget->can_queue > 0) - atomic_dec(&starget->target_busy); + atomic_dec(&starget->target_busy); return 0; } @@ -1886,8 +1884,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, out_dec_host_busy: scsi_dec_host_busy(shost, cmd); out_dec_target_busy: - if (scsi_target(sdev)->can_queue > 0) - atomic_dec(&scsi_target(sdev)->target_busy); + atomic_dec(&scsi_target(sdev)->target_busy); out_put_budget: scsi_mq_put_budget(q, cmd->budget_token); cmd->budget_token = -1; From patchwork Fri Mar 14 01:29:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016135 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24EB816F0FE; Fri, 14 Mar 2025 01:10:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914627; cv=none; b=qTDZK5lOQFrdTnGXi5Xv8/b53+DKuV254C+C+LbqkKA3iV+GY9WT0qK4hwrmCLwyXpZ3m8SoxBPf5oqRvV3coFRnk6T5X028+53NxNF5KNNtRvp25wXSRWb+Dm2kk80fPwjG6mhNSNKBDJ/ONwY18rkDM2Mv77iDZ2CEYpNY9XE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914627; c=relaxed/simple; bh=GyJuYWKI/YW8xAyJzIpy80EXHqTTzIovG+xm9SLaNbQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bdg+EaSMJ9QRUFIYTUiNid1gccA2wxIZdbH3Wv7J0LUi3sd4ZKuV7bEO7l8mBe1QgPkwJYd4nsz4w6W/RsSZvYI1Ark1nKyJsPL8HQcVW0w7dG5qUL+K+5pjGGfmaURACZBjVV+k3TWSL4i3TdalCF3Uc/fsyF871kgu2ZEMXa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4ZDR6K4jklzph0L; Fri, 14 Mar 2025 09:07:05 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 324DA1A016C; Fri, 14 Mar 2025 09:10:17 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:16 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 10/19] scsi: scsi_error: Add helper to handle scsi target's error command list Date: Fri, 14 Mar 2025 09:29:18 +0800 Message-ID: <20250314012927.150860-11-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add helper scsi_starget_eh() to handle scsi target's error command list, it would perform some steps which can be done with target's IO blocked, including check sense, start unit, reset lun and reset target. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 129 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_eh.h | 2 + 2 files changed, 131 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 7302536ba62a..46415db951ed 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2553,6 +2553,135 @@ int scsi_sdev_eh(struct scsi_device *sdev, } EXPORT_SYMBOL_GPL(scsi_sdev_eh); +static int starget_eh_stu(struct scsi_target *starget, + struct list_head *work_q, + struct list_head *done_q) +{ + struct scsi_device *sdev; + struct scsi_cmnd *scmd, *stu_scmd; + + list_for_each_entry(sdev, &starget->devices, same_target_siblings) { + if (sdev_stu_done(sdev)) + continue; + + stu_scmd = NULL; + list_for_each_entry(scmd, work_q, eh_entry) + if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && + scsi_check_sense(scmd) == FAILED) { + stu_scmd = scmd; + break; + } + if (!stu_scmd) + continue; + + if (scsi_eh_sdev_stu(stu_scmd, work_q, done_q)) + return 1; + } + + return 0; +} + +static int starget_eh_reset_lun(struct scsi_target *starget, + struct list_head *work_q, + struct list_head *done_q) +{ + struct scsi_device *sdev; + struct scsi_cmnd *scmd, *bdr_scmd; + + list_for_each_entry(sdev, &starget->devices, same_target_siblings) { + if (sdev_reset_done(sdev)) + continue; + + bdr_scmd = NULL; + list_for_each_entry(scmd, work_q, eh_entry) + if (scmd->device) { + bdr_scmd = scmd; + break; + } + if (!bdr_scmd) + continue; + + if (scsi_eh_sdev_reset(bdr_scmd, work_q, done_q)) + return 1; + } + + return 0; +} + +static int starget_eh_reset_target(struct scsi_target *starget, + struct list_head *work_q, + struct list_head *done_q) +{ + enum scsi_disposition rtn; + struct scsi_cmnd *scmd, *next; + LIST_HEAD(check_list); + + scmd = list_first_entry(work_q, struct scsi_cmnd, eh_entry); + + SCSI_LOG_ERROR_RECOVERY(3, starget_printk(KERN_INFO, starget, + "%s: Sending target reset\n", current->comm)); + + rtn = scsi_try_target_reset(scmd); + if (rtn != SUCCESS && rtn != FAST_IO_FAIL) { + SCSI_LOG_ERROR_RECOVERY(3, starget_printk(KERN_INFO, starget, + "%s: Target reset failed\n", + current->comm)); + return 0; + } + + SCSI_LOG_ERROR_RECOVERY(3, starget_printk(KERN_INFO, starget, + "%s: Target reset success\n", current->comm)); + + list_for_each_entry_safe(scmd, next, work_q, eh_entry) { + if (rtn == SUCCESS) + list_move_tail(&scmd->eh_entry, &check_list); + else if (rtn == FAST_IO_FAIL) + scsi_eh_finish_cmd(scmd, done_q); + } + + return scsi_eh_test_devices(&check_list, work_q, done_q, 0); +} + +/* + * Target based error handle + * + * @work_q: list of scsi commands need to recovery + * @done_q: list of scsi commands handled + * + * return: return 1 if all commands in work_q is recoveryed, else 0 is returned + */ +int scsi_starget_eh(struct scsi_target *starget, + struct list_head *work_q, + struct list_head *done_q) +{ + int ret = 0; + + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh: checking sense\n", current->comm)); + ret = scsi_eh_get_sense(work_q, done_q); + if (ret) + return ret; + + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh: start unit\n", current->comm)); + ret = starget_eh_stu(starget, work_q, done_q); + if (ret) + return ret; + + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh reset LUN\n", current->comm)); + ret = starget_eh_reset_lun(starget, work_q, done_q); + if (ret) + return ret; + + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh reset target\n", current->comm)); + ret = starget_eh_reset_target(starget, work_q, done_q); + + return ret; +} +EXPORT_SYMBOL_GPL(scsi_starget_eh); + /** * scsi_report_bus_reset() - report bus reset observed * diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index 89b471aa484f..80e2f130e884 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -20,6 +20,8 @@ extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd, extern enum scsi_disposition scsi_check_sense(struct scsi_cmnd *); extern int scsi_sdev_eh(struct scsi_device *sdev, struct list_head *workq, struct list_head *doneq); +extern int scsi_starget_eh(struct scsi_target *starget, + struct list_head *workq, struct list_head *doneq); extern int scsi_device_setup_eh(struct scsi_device *sdev, int fallback); extern void scsi_device_clear_eh(struct scsi_device *sdev); From patchwork Fri Mar 14 01:29:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016136 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED98D18DB06; Fri, 14 Mar 2025 01:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914628; cv=none; b=VgPR1ZM9vzemPFaEiah5NsBjFTel75Mc/hnrMgNVA8Wd0IpxbZAQu07AT7hpTyBsEmNIoCXO1JW5S2sKUQnDm/D74eFnZ4X0slc8rq5eROAQyghWHUlCp9KcbST92byD+cRab9hy4/+v06VSPg9hZEnaTW1vxlju7W0uv3ivvKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914628; c=relaxed/simple; bh=oiS9otWeEytgNDxKRliLOmICulriE0Hi/MP2nTBkWq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n0Ol1bCMspez/yV3Z1Z/J+43KZHmzpdJm/OGM1oCjSETzbhG8+qLfdZYsGQOajuqRFgABHPSxB42PQMXhxhu8CgFIIu1oS89NxTZvHGZkOFsnPTACZ7z02p1UNQufLIFanJ+WHCM6KZknugvHyvOTlO6yz0EZgcM19iYG4ah1/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4ZDR6L18Vyzph0q; Fri, 14 Mar 2025 09:07:06 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id AB90614011D; Fri, 14 Mar 2025 09:10:17 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:17 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 11/19] scsi: scsi_error: Add a general target based error handler Date: Fri, 14 Mar 2025 09:29:19 +0800 Message-ID: <20250314012927.150860-12-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add a general target based error handler which can be used by drivers directly. This error handler implements an scsi_target_eh, when handling error commands, it would call helper function scsi_starget_eh() added before to try recover error commands. The behavior if scsi_starget_eh() can not recover all error commands depends on fallback flag, which is initialized when scsi_target is allocated. If fallback is set, it would fallback to further error recover strategy like old host based error handle; else it would mark this scsi devices of this target offline and flush all error commands. To using this error handler, drivers should call scsi_target_setup_eh() in its target_alloc() to setup it's target based error handler; call scsi_device_clear_eh() in its target_destroy() to clear this target based error handler. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 161 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_eh.h | 2 + 2 files changed, 163 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 46415db951ed..d9415d3d32c9 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -101,6 +101,19 @@ static inline void shost_clear_eh_done(struct Scsi_Host *shost) } } +static inline void starget_clear_eh_done(struct scsi_target *starget) +{ + struct scsi_device *sdev; + + list_for_each_entry(sdev, &starget->devices, same_target_siblings) { + if (!sdev->eh) + continue; + sdev->eh->get_sense_done = 0; + sdev->eh->stu_done = 0; + sdev->eh->reset_done = 0; + } +} + void scsi_eh_wakeup(struct Scsi_Host *shost, unsigned int busy) { lockdep_assert_held(shost->host_lock); @@ -3065,3 +3078,151 @@ void scsi_device_clear_eh(struct scsi_device *sdev) sdev->eh = NULL; } EXPORT_SYMBOL_GPL(scsi_device_clear_eh); + +struct starget_eh { + spinlock_t eh_lock; + unsigned int eh_num; + struct list_head eh_cmd_q; + struct scsi_target *starget; + struct work_struct eh_handle_work; + unsigned int fallback:1; +}; + +static void starget_eh_work(struct work_struct *work) +{ + struct scsi_cmnd *scmd, *next; + unsigned long flags; + LIST_HEAD(eh_work_q); + LIST_HEAD(eh_done_q); + struct starget_eh *stargeteh = + container_of(work, struct starget_eh, eh_handle_work); + struct scsi_target *starget = stargeteh->starget; + struct scsi_target_eh *eh = starget->eh; + + spin_lock_irqsave(&stargeteh->eh_lock, flags); + list_splice_init(&stargeteh->eh_cmd_q, &eh_work_q); + spin_unlock_irqrestore(&stargeteh->eh_lock, flags); + + if (scsi_starget_eh(starget, &eh_work_q, &eh_done_q)) + goto out_clear_flag; + + if (!stargeteh->fallback) { + scsi_eh_offline_sdevs(&eh_work_q, &eh_done_q); + goto out_clear_flag; + } + + /* + * fallback to host based error handle + */ + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh fallback to further recovery\n", current->comm)); + eh->reset_done = 1; + list_for_each_entry_safe(scmd, next, &eh_work_q, eh_entry) { + list_del_init(&scmd->eh_entry); + __scsi_eh_scmd_add(scmd); + } + goto out_flush_done; + +out_clear_flag: + starget_clear_eh_done(starget); + +out_flush_done: + scsi_eh_flush_done_q(&eh_done_q); + spin_lock_irqsave(&stargeteh->eh_lock, flags); + stargeteh->eh_num = 0; + spin_unlock_irqrestore(&stargeteh->eh_lock, flags); +} + +static void starget_eh_add_cmnd(struct scsi_cmnd *scmd) +{ + unsigned long flags; + struct scsi_target *starget = scmd->device->sdev_target; + struct starget_eh *eh; + + eh = (struct starget_eh *)starget->eh->driver_data; + + spin_lock_irqsave(&eh->eh_lock, flags); + list_add_tail(&scmd->eh_entry, &eh->eh_cmd_q); + eh->eh_num++; + spin_unlock_irqrestore(&eh->eh_lock, flags); +} + +static int starget_eh_is_busy(struct scsi_target *starget) +{ + int ret = 0; + unsigned long flags; + struct starget_eh *eh; + + eh = (struct starget_eh *)starget->eh->driver_data; + + spin_lock_irqsave(&eh->eh_lock, flags); + ret = eh->eh_num; + spin_unlock_irqrestore(&eh->eh_lock, flags); + + return ret; +} + +static int starget_eh_wakeup(struct scsi_target *starget) +{ + unsigned long flags; + unsigned int nr_error; + unsigned int nr_busy; + struct starget_eh *eh; + + eh = (struct starget_eh *)starget->eh->driver_data; + + spin_lock_irqsave(&eh->eh_lock, flags); + nr_error = eh->eh_num; + spin_unlock_irqrestore(&eh->eh_lock, flags); + + nr_busy = atomic_read(&starget->target_busy); + + if (!nr_error || nr_busy != nr_error) { + SCSI_LOG_ERROR_RECOVERY(5, starget_printk(KERN_INFO, starget, + "%s:targeteh: do not wake up, busy/error is %d/%d\n", + current->comm, nr_busy, nr_error)); + return 0; + } + + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh: waking up, busy/error is %d/%d\n", + current->comm, nr_busy, nr_error)); + + return schedule_work(&eh->eh_handle_work); +} + +int scsi_target_setup_eh(struct scsi_target *starget, int fallback) +{ + struct scsi_target_eh *eh; + struct starget_eh *stargeteh; + + eh = kzalloc(sizeof(struct scsi_device_eh) + sizeof(struct starget_eh), + GFP_KERNEL); + if (!eh) { + starget_printk(KERN_ERR, starget, "failed to setup eh\n"); + return -ENOMEM; + } + stargeteh = (struct starget_eh *)eh->driver_data; + + eh->add_cmnd = starget_eh_add_cmnd; + eh->is_busy = starget_eh_is_busy; + eh->wakeup = starget_eh_wakeup; + stargeteh->starget = starget; + stargeteh->fallback = fallback; + + spin_lock_init(&stargeteh->eh_lock); + INIT_LIST_HEAD(&stargeteh->eh_cmd_q); + INIT_WORK(&stargeteh->eh_handle_work, starget_eh_work); + + starget->eh = eh; + + return 0; +} +EXPORT_SYMBOL_GPL(scsi_target_setup_eh); + +void scsi_target_clear_eh(struct scsi_target *starget) +{ + kfree(starget->eh); + starget->eh = NULL; +} +EXPORT_SYMBOL_GPL(scsi_target_clear_eh); diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index 80e2f130e884..011f63030589 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -24,6 +24,8 @@ extern int scsi_starget_eh(struct scsi_target *starget, struct list_head *workq, struct list_head *doneq); extern int scsi_device_setup_eh(struct scsi_device *sdev, int fallback); extern void scsi_device_clear_eh(struct scsi_device *sdev); +extern int scsi_target_setup_eh(struct scsi_target *starget, int fallback); +extern void scsi_target_clear_eh(struct scsi_target *starget); static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr) { From patchwork Fri Mar 14 01:29:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016126 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6829D143736; Fri, 14 Mar 2025 01:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914623; cv=none; b=slJt8GXe7Yba1UWe8Unp5LWKRsOXcnp+bxvBFKCjV7VSqVyZ0HfOyYc6z3RwQNbF/LxbStv9Wx65Scdq3n7T4N33+ku0g+qKcsUVUQj0GMZY9AivdXABcahJNIY5HoKP7N5tfVcA6Qdb0XX4CN2tpAN2DnngBoEXuW3CQyLjEWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914623; c=relaxed/simple; bh=UVuBdIHacnnNzdvXQxtCQVcu9luVYIGcFcL3UkcSp2M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o6B4haIJawZUqlpAxTY3AGJorhDy970oHa3Hr7Q2l/dDHcXr4eE5aCHseMGuXSb9jIxzPWtGDQzguOmadL8O/P9chaCZssu1di4cia/YKOh5u8EwE7xSBfTZB2tCiA3ZyeuLAuoJn427+dNmVj0UiKz4Rt7D5ww36AHFsBbBcxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZDR842b8tz1R5tK; Fri, 14 Mar 2025 09:08:36 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 3B13E14011D; Fri, 14 Mar 2025 09:10:18 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:17 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 12/19] scsi: scsi_debug: Add param to control LUN bassed error handler Date: Fri, 14 Mar 2025 09:29:20 +0800 Message-ID: <20250314012927.150860-13-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new module param lun_eh to control if enable LUN based error handle, and param lun_eh_fallback to control if fallback to further recover when LUN recovery can not recover all error commands. This is used to test the LUN based error handle. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 5ceaa4665e5d..162728cca99d 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -884,6 +884,8 @@ static bool write_since_sync; static bool sdebug_statistics = DEF_STATISTICS; static bool sdebug_wp; static bool sdebug_allow_restart; +static bool sdebug_lun_eh; +static bool sdebug_lun_eh_fallback; static enum { BLK_ZONED_NONE = 0, BLK_ZONED_HA = 1, @@ -5885,6 +5887,9 @@ static int scsi_debug_sdev_init(struct scsi_device *sdp) pr_info("sdev_init <%u %u %u %llu>\n", sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); + if (sdebug_lun_eh) + return scsi_device_setup_eh(sdp, sdebug_lun_eh_fallback); + return 0; } @@ -5953,6 +5958,9 @@ static void scsi_debug_sdev_destroy(struct scsi_device *sdp) /* make this slot available for re-use */ devip->used = false; sdp->hostdata = NULL; + + if (sdebug_lun_eh) + scsi_device_clear_eh(sdp); } /* Returns true if we require the queued memory to be freed by the caller. */ @@ -6644,6 +6652,8 @@ module_param_named(zone_max_open, sdeb_zbc_max_open, int, S_IRUGO); module_param_named(zone_nr_conv, sdeb_zbc_nr_conv, int, S_IRUGO); module_param_named(zone_size_mb, sdeb_zbc_zone_size_mb, int, S_IRUGO); module_param_named(allow_restart, sdebug_allow_restart, bool, S_IRUGO | S_IWUSR); +module_param_named(lun_eh, sdebug_lun_eh, bool, S_IRUGO); +module_param_named(lun_eh_fallback, sdebug_lun_eh_fallback, bool, S_IRUGO); MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); MODULE_DESCRIPTION("SCSI debug adapter driver"); @@ -6723,6 +6733,8 @@ MODULE_PARM_DESC(zone_max_open, "Maximum number of open zones; [0] for no limit MODULE_PARM_DESC(zone_nr_conv, "Number of conventional zones (def=1)"); MODULE_PARM_DESC(zone_size_mb, "Zone size in MiB (def=auto)"); MODULE_PARM_DESC(allow_restart, "Set scsi_device's allow_restart flag(def=0)"); +MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); +MODULE_PARM_DESC(lun_eh_fallback, "Fallback to further recovery if LUN recovery failed (def=0)"); #define SDEBUG_INFO_LEN 256 static char sdebug_info[SDEBUG_INFO_LEN]; From patchwork Fri Mar 14 01:29:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016138 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1D1F19307F; Fri, 14 Mar 2025 01:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914629; cv=none; b=ETFo9VnZURXxVhP0u0NIAR+MLBSmyjAFA6j4kkaqARd+VivP/2i3xIZfKYrU92pzn+fReLfB+bUg0Ea/52AS5K2PWCbsJ/DGyBn/bpfXRSRiZZQ5uVxd3AE0LfwFPCVW3+g4yhUMaGyA799O+9vnpq1qWubtTV/7lWOLw3kQ6s0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914629; c=relaxed/simple; bh=PYuQvxkgQXGECHwGA2MVuDhfRPY04++PpqHyo5ilvPc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sTfpROldjqy9CDJJAGIv3V7R/QRr5HlHVZHXuBCWnicfIOhaeJyaj3MmwgJcLwuSGJlSmewAqg1pO1zC3WiF94b2CDP+yyw32fTSnxEVTg4Lu5gPG9N3AAVK42XcBZNZceCNGDUAgN/cfyFhAhE+o8nB0NsMYbh7xR/qbTFNd5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZDR5b2gLyzvWpl; Fri, 14 Mar 2025 09:06:27 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id AAA82140393; Fri, 14 Mar 2025 09:10:18 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:18 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 13/19] scsi: scsi_debug: Add param to control target based error handle Date: Fri, 14 Mar 2025 09:29:21 +0800 Message-ID: <20250314012927.150860-14-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new module param target_eh to control if enable target based error handler, and param target_eh_fallback to control if fallback to further recover when target recovery can not recover all error commands. This is used to test the target based error handle. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 162728cca99d..5c0c2529b865 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -886,6 +886,8 @@ static bool sdebug_wp; static bool sdebug_allow_restart; static bool sdebug_lun_eh; static bool sdebug_lun_eh_fallback; +static bool sdebug_target_eh; +static bool sdebug_target_eh_fallback; static enum { BLK_ZONED_NONE = 0, BLK_ZONED_HA = 1, @@ -1195,6 +1197,9 @@ static int sdebug_target_alloc(struct scsi_target *starget) starget->hostdata = targetip; + if (sdebug_target_eh) + return scsi_target_setup_eh(starget, sdebug_target_eh_fallback); + return 0; } @@ -1210,6 +1215,9 @@ static void sdebug_target_destroy(struct scsi_target *starget) { struct sdebug_target_info *targetip; + if (sdebug_target_eh) + scsi_target_clear_eh(starget); + targetip = (struct sdebug_target_info *)starget->hostdata; if (targetip) { starget->hostdata = NULL; @@ -6654,6 +6662,8 @@ module_param_named(zone_size_mb, sdeb_zbc_zone_size_mb, int, S_IRUGO); module_param_named(allow_restart, sdebug_allow_restart, bool, S_IRUGO | S_IWUSR); module_param_named(lun_eh, sdebug_lun_eh, bool, S_IRUGO); module_param_named(lun_eh_fallback, sdebug_lun_eh_fallback, bool, S_IRUGO); +module_param_named(target_eh, sdebug_target_eh, bool, S_IRUGO); +module_param_named(target_eh_fallback, sdebug_target_eh_fallback, bool, S_IRUGO); MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); MODULE_DESCRIPTION("SCSI debug adapter driver"); @@ -6735,6 +6745,8 @@ MODULE_PARM_DESC(zone_size_mb, "Zone size in MiB (def=auto)"); MODULE_PARM_DESC(allow_restart, "Set scsi_device's allow_restart flag(def=0)"); MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); MODULE_PARM_DESC(lun_eh_fallback, "Fallback to further recovery if LUN recovery failed (def=0)"); +MODULE_PARM_DESC(target_eh, "target based error handle (def=0)"); +MODULE_PARM_DESC(target_eh_fallback, "Fallback to further recovery if target recovery failed (def=0)"); #define SDEBUG_INFO_LEN 256 static char sdebug_info[SDEBUG_INFO_LEN]; From patchwork Fri Mar 14 01:29:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016137 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E67861946AA; Fri, 14 Mar 2025 01:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914629; cv=none; b=px4VF6U0iWII1+PNdh905jmKTc11DiKay0J2jPVmxM5C3k6tf+AhLRjkfpQLaueN7yWA/lSKrB/qhyruk3JAqpi75VLdU9jpTTveUGTfvSN7GVeIM5eh+zHZf13W+1fOpL0G3hv6bJwTAB/1W85Nxd5/n1ds0UnKxeIrF2dJHMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914629; c=relaxed/simple; bh=avghMgFjPeUTvjk6WUJz3BpzKN2b/Dc6sK35L2Ty46s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cao59PtKNaPfW0CXu6lxn1+wjT98JhMn5EZm8w+o3NYQzsw9HG+GRkZNna9HY3cn/rAoVEIFc6XFHTQfPq+GYzqh1L6zs3OYrCMyymVp8rkPS0Nc4y5xvkHJGQIcBSa73cWU76Qk9R9r7xJnODTLfDAvTPzENU+Fb8E3dADWEhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4ZDRBk3LTrz27gXH; Fri, 14 Mar 2025 09:10:54 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 2E35414011D; Fri, 14 Mar 2025 09:10:19 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:18 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 14/19] scsi: mpt3sas: Add param to control LUN based error handle Date: Fri, 14 Mar 2025 09:29:22 +0800 Message-ID: <20250314012927.150860-15-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new module param lun_eh to control if enable LUN based error handler, since mpt3sas defined callback eh_host_reset and eh_target_reset, so make it fallback to further recover when LUN based recovery can not recover all error commands. Signed-off-by: Wenchao Hao --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index a456e5ec74d8..b3ceba3c1ea8 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -173,6 +173,10 @@ module_param(host_tagset_enable, int, 0444); MODULE_PARM_DESC(host_tagset_enable, "Shared host tagset enable/disable Default: enable(1)"); +static bool lun_eh; +module_param(lun_eh, bool, 0444); +MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); + /* raid transport support */ static struct raid_template *mpt3sas_raid_template; static struct raid_template *mpt2sas_raid_template; @@ -2043,6 +2047,13 @@ scsih_sdev_init(struct scsi_device *sdev) struct _sas_device *sas_device; struct _pcie_device *pcie_device; unsigned long flags; + int ret = 0; + + if (lun_eh) { + ret = scsi_device_setup_eh(sdev, 1); + if (ret) + return ret; + } sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), GFP_KERNEL); @@ -2121,6 +2132,9 @@ scsih_sdev_destroy(struct scsi_device *sdev) struct _pcie_device *pcie_device; unsigned long flags; + if (lun_eh) + scsi_device_clear_eh(sdev); + if (!sdev->hostdata) return; From patchwork Fri Mar 14 01:29:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016127 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C51146585; Fri, 14 Mar 2025 01:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914623; cv=none; b=nF63nfzhKyNAnZXoa10ugdVukq5Ylj/PD8bmZL38ZY60dmkfFWVgNnuIMpYtTp3fL5TpAtw3cmCAIcZrxllDmVz4RxbKMD6yedTczfwwsZ5PO7vtdMYlZ9qgs6f9c0ZXXQElc1gOqxKMTSeuTq3N7U+ZcNT4J+8VW64U+jCQt9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914623; c=relaxed/simple; bh=0Gje1SR8UgouUOWXw4TnLAlKrs8hTvO6GR3fvSwAeAc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VZu5vqSqaA0uKyozHMtjryfy4SkwaT2hw+aGBcce6GGtOSWJpBMoRgeyDPwtK4+YM31lBXG4S7g8Avhvzpf8IYOr3tTl7JWyoK/HKSIW58guDmYPhYrRYcDm07XaLg7aF3RuSY9bXBxHiX8AmkqqOZi2uJnhJZyA31xOBzAS85Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZDR5c2RmNzvWrn; Fri, 14 Mar 2025 09:06:28 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id A5A19180102; Fri, 14 Mar 2025 09:10:19 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:19 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 15/19] scsi: mpt3sas: Add param to control target based error handle Date: Fri, 14 Mar 2025 09:29:23 +0800 Message-ID: <20250314012927.150860-16-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new module param target_eh to control if enable target based error handle, since mpt3sas defined callback eh_host_reset, so make it fallback to further recover when target based recovery can not recover all error commands. Signed-off-by: Wenchao Hao --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index b3ceba3c1ea8..6f3eced511bf 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -177,6 +177,10 @@ static bool lun_eh; module_param(lun_eh, bool, 0444); MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); +static bool target_eh; +module_param(target_eh, bool, 0444); +MODULE_PARM_DESC(target_eh, "target based error handle (def=0)"); + /* raid transport support */ static struct raid_template *mpt3sas_raid_template; static struct raid_template *mpt2sas_raid_template; @@ -1878,6 +1882,13 @@ scsih_target_alloc(struct scsi_target *starget) struct _pcie_device *pcie_device; unsigned long flags; struct sas_rphy *rphy; + int ret = 0; + + if (target_eh) { + ret = scsi_target_setup_eh(starget, 1); + if (ret) + return ret; + } sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), GFP_KERNEL); @@ -1968,6 +1979,9 @@ scsih_target_destroy(struct scsi_target *starget) struct _pcie_device *pcie_device; unsigned long flags; + if (target_eh) + scsi_target_clear_eh(starget); + sas_target_priv_data = starget->hostdata; if (!sas_target_priv_data) return; From patchwork Fri Mar 14 01:29:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016130 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97BBB6EB7C; Fri, 14 Mar 2025 01:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914624; cv=none; b=id2WWsoznPf1Kqhfp6fO6pT1sMOrSAV1uaNAl7oU8jL7fY6mxsz4QPgnLGx3J7NzWRwuhVDehb60qXWNrvMIQxWpyQdvw/G74spa5oIWQ72XKUVV5AVGIpuQV8VHipPKKRH/eH9Mf2KU2v3gODWWqQlsBsorBUA8BH4iM1/uick= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914624; c=relaxed/simple; bh=WD1gJUModLnJXFrVTVWHo4vwDdbbVHXiJ3PH+9VD73g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b5gwSfApqrEj3hqSnWoib1ZjTQMI3H/jNz4h8n5+02TXY5L7VS3RwKyDQWnH9uArb41bF1ucZHNR7sJBswK4gj5iJiybs/wGNKoTRSScnZISflHZqmdjlRz9fAKbLQ930veGjJl5yt5J7Q1KpAnOPIgTyjBLQfFj1qogVTBOrJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4ZDR4z6sP3z1f0bZ; Fri, 14 Mar 2025 09:05:55 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 2CFCD1A0188; Fri, 14 Mar 2025 09:10:20 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:19 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 16/19] scsi: smartpqi: Add param to control LUN based error handle Date: Fri, 14 Mar 2025 09:29:24 +0800 Message-ID: <20250314012927.150860-17-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new param lun_eh to control if enable LUN based error handler, since smartpqi did not define other further reset callbacks, it is not necessary to fallback to further recover any more, so set the LUN error handler with fallback set to 0. Signed-off-by: Wenchao Hao --- drivers/scsi/smartpqi/smartpqi_init.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c index 0da7be40c925..eb6e9be2efc2 100644 --- a/drivers/scsi/smartpqi/smartpqi_init.c +++ b/drivers/scsi/smartpqi/smartpqi_init.c @@ -189,6 +189,10 @@ module_param_named(ctrl_ready_timeout, MODULE_PARM_DESC(ctrl_ready_timeout, "Timeout in seconds for driver to wait for controller ready."); +static bool pqi_lun_eh; +module_param_named(lun_eh, pqi_lun_eh, bool, 0444); +MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); + static char *raid_levels[] = { "RAID-0", "RAID-4", @@ -6496,6 +6500,13 @@ static int pqi_sdev_init(struct scsi_device *sdev) struct pqi_ctrl_info *ctrl_info; struct scsi_target *starget; struct sas_rphy *rphy; + int ret = 0; + + if (pqi_lun_eh) { + ret = scsi_device_setup_eh(sdev, 0); + if (ret) + return ret; + } ctrl_info = shost_to_hba(sdev->host); @@ -6583,6 +6594,9 @@ static void pqi_sdev_destroy(struct scsi_device *sdev) ctrl_info = shost_to_hba(sdev->host); + if (pqi_lun_eh) + scsi_device_clear_eh(sdev); + mutex_acquired = mutex_trylock(&ctrl_info->scan_mutex); if (!mutex_acquired) return; From patchwork Fri Mar 14 01:29:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016139 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1780A1A2390; Fri, 14 Mar 2025 01:10:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914633; cv=none; b=NkO5FTjbiGT+MgY53W9GEsKpDUUQaWkOPPJ7tlDWYAbUOx8lH5MBhdcjwk7l9zk101wu6fC9+O+k9vsHDsmzA29A17v4LntOND4v3bHB6Jdsa9CFJecop5ebhRoRcxdRsU/rVFHG96aYHxSZN0YxpH6k3aHhiLaKfS3ES2zY6F0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914633; c=relaxed/simple; bh=J0hYHKj4MYP/FclISPNyiqtAvRygCCjd6NqZuvwhwgw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HuCZi7dOfbvKicDtZIi2qBL+HtqnQH2rbV1/EyHMh5vOmAE0xFjOYDkUVTAw8lO1PGQn+65Iqq7da7tKFNTC3MCYl25TYdAztsBMkv3Ru/RYJCRxTBnR9dagPOC6QrurLl4vFopZpVzH7jYMtglqNMmx9YLfgmft0h6LdKH5Prc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4ZDRBl6pBLz27gDV; Fri, 14 Mar 2025 09:10:55 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id A55CA14011D; Fri, 14 Mar 2025 09:10:20 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:20 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 17/19] scsi: megaraid_sas: Add param to control target based error handle Date: Fri, 14 Mar 2025 09:29:25 +0800 Message-ID: <20250314012927.150860-18-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new param target_eh to control if enable target based error handler, since megaraid_sas did not define callback eh_device_reset, so only target based error handler is enabled; and megaraid_sas defined eh_host_reset, so make it fallback to further recover when target based recovery can not recover all error commands. Signed-off-by: Wenchao Hao --- drivers/scsi/megaraid/megaraid_sas_base.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index d85f990aec88..4ea4b754b090 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "megaraid_sas_fusion.h" #include "megaraid_sas.h" @@ -126,6 +127,10 @@ int host_tagset_enable = 1; module_param(host_tagset_enable, int, 0444); MODULE_PARM_DESC(host_tagset_enable, "Shared host tagset enable/disable Default: enable(1)"); +static bool target_eh; +module_param(target_eh, bool, 0444); +MODULE_PARM_DESC(target_eh, "target based error handle (def=0)"); + MODULE_LICENSE("GPL"); MODULE_VERSION(MEGASAS_VERSION); MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com"); @@ -2176,6 +2181,19 @@ static void megasas_sdev_destroy(struct scsi_device *sdev) sdev->hostdata = NULL; } +static int megasas_target_alloc(struct scsi_target *starget) +{ + if (target_eh) + return scsi_target_setup_eh(starget, 1); + return 0; +} + +static void megasas_target_destroy(struct scsi_target *starget) +{ + if (target_eh) + scsi_target_clear_eh(starget); +} + /* * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a * kill adapter @@ -3524,6 +3542,8 @@ static const struct scsi_host_template megasas_template = { .change_queue_depth = scsi_change_queue_depth, .max_segment_size = 0xffffffff, .cmd_size = sizeof(struct megasas_cmd_priv), + .target_alloc = megasas_target_alloc, + .target_destroy = megasas_target_destroy, }; /** From patchwork Fri Mar 14 01:29:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016131 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CF791519B5; Fri, 14 Mar 2025 01:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914625; cv=none; b=gJ/7yI6AoYwGFmMW6Mo8Lnsppw7f/ZRCR7dSdS1KRXB+f4vZoJ1JeK5DJD7MfVUc0P0V8GFFR9klsoluqi2EIqQbBxdixh3Pd75cP+44jynAMX6w0S1AGuF+o7vU1N5tSmA8SduahggnRD7Zrk0Elmzv4AM2Y0frXo80PM9Au8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914625; c=relaxed/simple; bh=iTWeO/0L3NSvusXc+Ug/fjUBrTnenMPdKn+kG1amEKU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R1UbUw1b/Wz6E2R8tJBUkh+/YHtwgp8PTlM0XEKIRWLhjFuSGVp/XdMNAAgvvBfcn8N/p8G0S+dVWrZa3q2INzF0Gm7cyiDjgkKkajODItNKXUJh4ZQ+xqKFe+arbTrzKtPZ7A7MwmZIX5KHRkIKLB+Tm82iYXKp/ETLbza54h0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZDR8720Vsz1R6bW; Fri, 14 Mar 2025 09:08:39 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id 2ABE71402CA; Fri, 14 Mar 2025 09:10:21 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:20 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 18/19] scsi: virtio_scsi: Add param to control LUN based error handle Date: Fri, 14 Mar 2025 09:29:26 +0800 Message-ID: <20250314012927.150860-19-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new param lun_eh to control if enable LUN based error handler, since virtio_scsi did not define other further reset callbacks, it is not necessary to fallback to further recover any more, so set the LUN error handler with fallback set to 0. Signed-off-by: Wenchao Hao --- drivers/scsi/virtio_scsi.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 21ce3e940192..99276ad0e441 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "sd.h" @@ -41,6 +42,10 @@ module_param(virtscsi_poll_queues, uint, 0644); MODULE_PARM_DESC(virtscsi_poll_queues, "The number of dedicated virtqueues for polling I/O"); +static bool lun_eh; +module_param(lun_eh, bool, 0444); +MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); + /* Command queue element */ struct virtio_scsi_cmd { struct scsi_cmnd *sc; @@ -682,9 +687,18 @@ static int virtscsi_device_alloc(struct scsi_device *sdevice) */ sdevice->sdev_bflags = BLIST_TRY_VPD_PAGES; + if (lun_eh) + return scsi_device_setup_eh(sdevice, 0); + return 0; } +static void virtscsi_device_destroy(struct scsi_device *sdevice) +{ + if (lun_eh) + return scsi_device_clear_eh(sdevice); +} + /** * virtscsi_change_queue_depth() - Change a virtscsi target's queue depth @@ -801,7 +815,7 @@ static const struct scsi_host_template virtscsi_host_template = { .eh_device_reset_handler = virtscsi_device_reset, .eh_timed_out = virtscsi_eh_timed_out, .sdev_init = virtscsi_device_alloc, - + .sdev_destroy = virtscsi_device_destroy, .dma_boundary = UINT_MAX, .map_queues = virtscsi_map_queues, .track_queue_depth = 1, From patchwork Fri Mar 14 01:29:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JiangJianJun X-Patchwork-Id: 14016132 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2835154C04; Fri, 14 Mar 2025 01:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914625; cv=none; b=dgyhcC3LJK6H13Z47dOsG4IWVK7U/iRdEpoCKqgGvdKGZfZjbNcDBRhKmlziGY9Y8fQ+uE3q3cpVJ0K5Bp2WUuF07uWtwbUdmjTBef5p0Yp8gOujT6BLR3zeb9Tgqci/sE0wC86CS7l4pw7Iodz9CDdpR8st/mZmFm0fQRbyjFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741914625; c=relaxed/simple; bh=31cApgEEPr/vjgh4U3S1W4MvPj8aH5QcHE7QBy2M1Ak=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UnVAo2mswrh4vrXKYkR2L0IhCD8r+ZlX1Iv2U6GOQYbcuOEQgESxzteWqlMcTd1KS30CBU5vhBYbJHij+b+HaKoVAw9GnHTpUTCEEzAGInG4yvr0Jn6i02qyXGk/WR0xabnUYXXdIKZPbjLo2Aw8fSvt+IRP02Ywcv8fydian00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4ZDR521Tfjz1ltZq; Fri, 14 Mar 2025 09:05:58 +0800 (CST) Received: from dggpemf500016.china.huawei.com (unknown [7.185.36.197]) by mail.maildlp.com (Postfix) with ESMTPS id A351B180069; Fri, 14 Mar 2025 09:10:21 +0800 (CST) Received: from localhost.localdomain (10.175.101.6) by dggpemf500016.china.huawei.com (7.185.36.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 14 Mar 2025 09:10:21 +0800 From: JiangJianJun To: , , CC: , , , , , Subject: [RFC PATCH v3 19/19] scsi: iscsi_tcp: Add param to control LUN based error handle Date: Fri, 14 Mar 2025 09:29:27 +0800 Message-ID: <20250314012927.150860-20-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250314012927.150860-1-jiangjianjun3@huawei.com> References: <20250314012927.150860-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf500016.china.huawei.com (7.185.36.197) From: Wenchao Hao Add new param lun_eh to control if enable LUN based error handler, since iscsi_tcp defined callback eh_target_reset, so make it fallback to further recover when LUN based recovery can not recover all error commands. Signed-off-by: Wenchao Hao --- drivers/scsi/iscsi_tcp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index e81f60985193..6212d88a4259 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,10 @@ module_param_named(debug_iscsi_tcp, iscsi_sw_tcp_dbg, int, MODULE_PARM_DESC(debug_iscsi_tcp, "Turn on debugging for iscsi_tcp module " "Set to 1 to turn on, and zero to turn off. Default is off."); +static bool iscsi_sw_tcp_lun_eh; +module_param_named(lun_eh, iscsi_sw_tcp_lun_eh, bool, 0444); +MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=0)"); + #define ISCSI_SW_TCP_DBG(_conn, dbg_fmt, arg...) \ do { \ if (iscsi_sw_tcp_dbg) \ @@ -1069,6 +1074,19 @@ static int iscsi_sw_tcp_sdev_configure(struct scsi_device *sdev, return 0; } +static int iscsi_sw_tcp_sdev_alloc(struct scsi_device *sdev) +{ + if (iscsi_sw_tcp_lun_eh) + return scsi_device_setup_eh(sdev, 1); + return 0; +} + +static void iscsi_sw_tcp_sdev_destroy(struct scsi_device *sdev) +{ + if (iscsi_sw_tcp_lun_eh) + return scsi_device_clear_eh(sdev); +} + static const struct scsi_host_template iscsi_sw_tcp_sht = { .module = THIS_MODULE, .name = "iSCSI Initiator over TCP/IP", @@ -1084,6 +1102,8 @@ static const struct scsi_host_template iscsi_sw_tcp_sht = { .eh_target_reset_handler = iscsi_eh_recover_target, .dma_boundary = PAGE_SIZE - 1, .sdev_configure = iscsi_sw_tcp_sdev_configure, + .sdev_init = iscsi_sw_tcp_sdev_alloc, + .sdev_destroy = iscsi_sw_tcp_sdev_destroy, .proc_name = "iscsi_tcp", .this_id = -1, .track_queue_depth = 1,