From nobody Sat Oct 4 12:46:56 2025 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 849CF16CD33; Sat, 16 Aug 2025 10:53:09 +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=1755341592; cv=none; b=GPxKyKISFQlUhMLh86lNVV/U53rkP3y+FMx4TfHXr1tzJXT6QEpYOXMcr61Q5zYfUTCiqvi61KVtgzR0L2TrsGDG9AMC7fm3yF4m2Snh+YOhGXmm1u6hEcIDYThwl2lgyGbqtsJhXao/68pRs8uYukykDAzWYfXOTGntZQQtKeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341592; c=relaxed/simple; bh=PtLMa25NjnVa7ZipYbGIOp1IB++53uW25vaQwit5LT4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JqOGOZ1ZIW0oBSznKN4JxHMtf/6jM873LdwKhZsaJKjSKLajVi41Kik88bBNFC/xTANZuH9EsM61hnA8Gg4wZ+y9RS1KR/R7lt6PFarHurATGi2dWayO/y1z0hN6zBukly9bN1t0jv9CVFTh8iMUwyzNz+P6jtwDzfFfxXP372k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c3whz1P0Sz13N1j; Sat, 16 Aug 2025 18:49:39 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 566B31401E9; Sat, 16 Aug 2025 18:53:07 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:06 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 01/14] scsi: scsi_error: Define framework for LUN/target based error handle Date: Sat, 16 Aug 2025 19:24:04 +0800 Message-ID: <20250816112417.3581253-2-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- drivers/scsi/scsi_error.c | 81 ++++++++++++++++++++++++++++++++++++-- drivers/scsi/scsi_lib.c | 8 ++++ drivers/scsi/scsi_priv.h | 15 +++++++ include/scsi/scsi_device.h | 57 +++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 746ff6a1f309..135b63d89d72 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -271,8 +271,9 @@ scsi_abort_command(struct scsi_cmnd *scmd) */ static void scsi_eh_reset(struct scsi_cmnd *scmd) { + struct scsi_driver *sdrv =3D scsi_cmd_to_driver(scmd); + if (!blk_rq_is_passthrough(scsi_cmd_to_rq(scmd))) { - struct scsi_driver *sdrv =3D scsi_cmd_to_driver(scmd); if (sdrv->eh_reset) sdrv->eh_reset(scmd); } @@ -291,11 +292,46 @@ static void scsi_eh_inc_host_failed(struct rcu_head *= head) spin_unlock_irqrestore(shost->host_lock, flags); } =20 +static bool scsi_eh_scmd_add_sdev(struct scsi_cmnd *scmd) +{ + struct scsi_device *sdev =3D scmd->device; + struct scsi_device_eh *eh =3D sdev->eh; + + if (!eh || !eh->add_cmnd) + return true; + + scsi_eh_reset(scmd); + eh->add_cmnd(scmd); + + if (eh->wakeup) + eh->wakeup(sdev); + + return false; +} + +static bool scsi_eh_scmd_add_starget(struct scsi_cmnd *scmd) +{ + struct scsi_device *sdev =3D scmd->device; + struct scsi_target *starget =3D scsi_target(sdev); + struct scsi_target_eh *eh =3D starget->eh; + + if (!eh || !eh->add_cmnd) + return true; + + scsi_eh_reset(scmd); + eh->add_cmnd(scmd); + + if (eh->wakeup) + eh->wakeup(starget); + + return false; +} + /** - * scsi_eh_scmd_add - add scsi cmd to error handling. - * @scmd: scmd to run eh on. + * Add scsi cmd to error handling of Scsi_Host. + * This is default action of error handle. */ -void scsi_eh_scmd_add(struct scsi_cmnd *scmd) +static void scsi_eh_scmd_add_shost(struct scsi_cmnd *scmd) { struct Scsi_Host *shost =3D scmd->device->host; unsigned long flags; @@ -322,6 +358,43 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scmd) call_rcu_hurry(&scmd->rcu, scsi_eh_inc_host_failed); } =20 +/** + * 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) +{ + struct scsi_device *sdev =3D scmd->device; + struct scsi_target *starget =3D scsi_target(sdev); + struct Scsi_Host *shost =3D sdev->host; + + if (unlikely(scsi_host_in_recovery(shost))) { + scsi_eh_scmd_add_shost(scmd); + return; + } + + if (unlikely(scsi_target_in_recovery(starget))) { + if (scsi_eh_scmd_add_starget(scmd)) + scsi_eh_scmd_add_shost(scmd); + return; + } + + if (scsi_eh_scmd_add_sdev(scmd)) + if (scsi_eh_scmd_add_starget(scmd)) + scsi_eh_scmd_add_shost(scmd); +} + +void scsi_eh_try_wakeup(struct scsi_device *sdev) +{ + struct scsi_target *starget =3D scsi_target(sdev); + + if (sdev->eh && sdev->eh->wakeup) + sdev->eh->wakeup(sdev); + + if (starget->eh && starget->eh->wakeup) + starget->eh->wakeup(starget); +} + /** * 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 0c65ecfedfbd..63bd33af336b 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -398,6 +398,8 @@ void scsi_device_unbusy(struct scsi_device *sdev, struc= t scsi_cmnd *cmd) =20 sbitmap_put(&sdev->budget_map, cmd->budget_token); cmd->budget_token =3D -1; + + scsi_eh_try_wakeup(sdev); } =20 /* @@ -1360,6 +1362,9 @@ static inline int scsi_dev_queue_ready(struct request= _queue *q, { int token; =20 + if (scsi_device_in_recovery(sdev)) + return -1; + token =3D sbitmap_get(&sdev->budget_map); if (token < 0) return -1; @@ -1393,6 +1398,9 @@ static inline int scsi_target_queue_ready(struct Scsi= _Host *shost, struct scsi_target *starget =3D scsi_target(sdev); unsigned int busy; =20 + 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 5b2b19f5e8ec..cd98f71830f4 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -92,6 +92,7 @@ extern int scsi_error_handler(void *host); extern enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *cmd= ); extern void scsi_eh_wakeup(struct Scsi_Host *shost, unsigned int busy); extern void scsi_eh_scmd_add(struct scsi_cmnd *); +extern void scsi_eh_try_wakeup(struct scsi_device *sdev); void scsi_eh_ready_devs(struct Scsi_Host *shost, struct list_head *work_q, struct list_head *done_q); @@ -191,6 +192,20 @@ static inline void scsi_dh_add_device(struct scsi_devi= ce *sdev) { } static inline void scsi_dh_release_device(struct scsi_device *sdev) { } #endif =20 +static inline bool scsi_device_in_recovery(struct scsi_device *sdev) +{ + struct scsi_device_eh *eh =3D sdev->eh; + + return eh && eh->is_busy && eh->is_busy(sdev); +} + +static inline bool scsi_target_in_recovery(struct scsi_target *starget) +{ + struct scsi_target_eh *eh =3D starget->eh; + + return eh && eh->is_busy && eh->is_busy(starget); +} + struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev); =20 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 6d6500148c4b..6a58b297e74c 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -100,6 +100,61 @@ struct scsi_vpd { unsigned char data[]; }; =20 +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 1 if it's in error handle, command's would not be dispatched + */ + bool (*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. + */ + void (*wakeup)(struct scsi_device *sdev); +}; + +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 1 if it's in error handle, command's would not be dispatched + */ + bool (*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. + */ + void (*wakeup)(struct scsi_target *starget); +}; + struct scsi_device { struct Scsi_Host *host; struct request_queue *request_queue; @@ -289,6 +344,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)))); =20 @@ -375,6 +431,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)))); --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 051D5270540; Sat, 16 Aug 2025 10:53:10 +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=1755341593; cv=none; b=qUZpdmP2nLe37NEB5nu89A59Olwfjutzne0Rp7fVYzvwwgo8DV2NR9yH16gUVp2Y48xz4FZbTwmnFmIn1prkZqzfXsXe6qFyDgudcieBMQa5Y43LZmD4gmxB6thsjbj3ireMHuZafyQyFpzbz8rlc/jiEW9cj/YE50cjjBwSW6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341593; c=relaxed/simple; bh=34tW2e3C5M3cp3ogF+1sE3TiPvSLtG2Dj12a0Ql5z0o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lgoxLUWx1/exVpyoKd7EBghTADPO2ymfBA33UuwJeu58rIP+bSiNQzrziZDPQ+WTqYSGe9lrTIQ4x5jxQ6aO40MpSPgKQhO+4kzGvvC8fyv2NysJ/N1uUMzFW/9yBJ9vs5aR4QbIJCkYnpYwNdvyUM4HGoNte9V0vVI4Ukyl0XY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c3wjh68VDz2gKxD; Sat, 16 Aug 2025 18:50:16 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 2C08A1A016C; Sat, 16 Aug 2025 18:53:08 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:07 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 02/14] scsi: scsi_error: Move complete variable eh_action from shost to sdevice Date: Sat, 16 Aug 2025 19:24:05 +0800 Message-ID: <20250816112417.3581253-3-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- 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 135b63d89d72..6020f20c7f07 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -954,7 +954,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)); =20 - eh_action =3D scmd->device->host->eh_action; + eh_action =3D scmd->device->eh_action; if (eh_action) complete(eh_action); } @@ -1243,7 +1243,7 @@ static enum scsi_disposition scsi_send_eh_cmnd(struct= scsi_cmnd *scmd, =20 retry: scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes); - shost->eh_action =3D &done; + sdev->eh_action =3D &done; =20 scsi_log_send(scmd); scmd->submitter =3D SUBMITTED_BY_SCSI_ERROR_HANDLER; @@ -1287,7 +1287,7 @@ static enum scsi_disposition scsi_send_eh_cmnd(struct= scsi_cmnd *scmd, rtn =3D SUCCESS; } =20 - shost->eh_action =3D NULL; + sdev->eh_action =3D NULL; =20 scsi_log_completion(scmd, rtn); =20 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 6a58b297e74c..6f47a7a74cd1 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -345,6 +345,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)))); =20 diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index c53812b9026f..46f57fe78505 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; --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 0516826FA6F; Sat, 16 Aug 2025 10:53:10 +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=1755341593; cv=none; b=k7J9rez5ncK5Iq70Fxp/4GbiXPwPE6rc7oxvDr3/tw/b2gnh2JL64Y82uGZkjxp2S2qFfJx1DKZ4+9GmdPgQfuQiLjbEeFjhDmKLxLFWUWQa28JdiUXdQm4wE5/1rFRqPmhGcba/tye4rClaDTaGkBvA/E6K7jPQS5qXZZDp4dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341593; c=relaxed/simple; bh=K/yI1lNvc7N80cU+T2iwSo88G6c8Owxd1eCKcjxLr6o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ACCpGW/uCvNKBv/O07q8DWaSd01kxss6sEQk09ipBLh0TnIBZBj+CJNmxjkvh9HLRN/Y9QReznNPGJYxs2ZRdCxegi2CK+v+JxEwFZlrR/utLV1gWQHnFMsQX4dU29KBTtkcLj3pBqicVlsFDbuDmr0KAXtigXusfCLmlLoPslg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c3wjj4ly6z2gKxN; Sat, 16 Aug 2025 18:50:17 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id F12F6140295; Sat, 16 Aug 2025 18:53:08 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:07 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 03/14] scsi: scsi_error: Check if to do reset in scsi_try_xxx_reset Date: Sat, 16 Aug 2025 19:24:06 +0800 Message-ID: <20250816112417.3581253-4-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- 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 6020f20c7f07..2da876a928c7 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -963,7 +963,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; @@ -989,11 +989,19 @@ static enum scsi_disposition scsi_try_host_reset(stru= ct scsi_cmnd *scmd) return rtn; } =20 +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; @@ -1019,6 +1027,14 @@ static enum scsi_disposition scsi_try_bus_reset(stru= ct scsi_cmnd *scmd) return rtn; } =20 +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 *dat= a) { sdev->was_reset =3D 1; @@ -1035,7 +1051,7 @@ static void __scsi_report_device_reset(struct scsi_de= vice *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 *scm= d) { unsigned long flags; enum scsi_disposition rtn; @@ -1056,6 +1072,15 @@ static enum scsi_disposition scsi_try_target_reset(s= truct scsi_cmnd *scmd) return rtn; } =20 +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 @@ -2579,17 +2604,17 @@ scsi_ioctl_reset(struct scsi_device *dev, int __use= r *arg) break; fallthrough; case SG_SCSI_RESET_TARGET: - rtn =3D scsi_try_target_reset(scmd); + rtn =3D __scsi_try_target_reset(scmd); if (rtn =3D=3D SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) break; fallthrough; case SG_SCSI_RESET_BUS: - rtn =3D scsi_try_bus_reset(scmd); + rtn =3D __scsi_try_bus_reset(scmd); if (rtn =3D=3D SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) break; fallthrough; case SG_SCSI_RESET_HOST: - rtn =3D scsi_try_host_reset(scmd); + rtn =3D __scsi_try_host_reset(scmd); if (rtn =3D=3D SUCCESS) break; fallthrough; --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 17F6226CE2F; Sat, 16 Aug 2025 10:53:11 +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=1755341594; cv=none; b=K9NCXmXUsREEDyKkD6AmXdAnMdWQG/SjMWvQumjjjgh7o8EMB4UH9dYWdVWQ2kGv7OABjs0BsCbi8fyliVHHpSnsvjklsywkQAM+NBbyI1t/Xo4EEfU1yuMXaSH/C02Gw+s7fS9eDTxmjNv6HWdBZlABpXtnmyRogyi54cAkFMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341594; c=relaxed/simple; bh=2CvrmPGixM7+DZb2SWRSYs9qJScsP9WPi5xYCGgEu2Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=npe+uRiNq4ScLs/0v2R33VQ9FFJmzKEhfuLl8TxI7GUcr9mX0/mciVZHgUkvI3e43Rtn6+8Hb2JPZ/bDhu0cYEWXIWjYfJ8o4njLcftNU/WWKfR/zhN7+QSElPY1gfcrFG5ltzIPbIuc8CbDWlE7FE6NsPTIkEtpM2Ry74/Cd7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c3wh05l9qz2Cg4H; Sat, 16 Aug 2025 18:48:48 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id C1779140259; Sat, 16 Aug 2025 18:53:09 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:08 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 04/14] scsi: scsi_error: Add helper scsi_eh_sdev_stu to do START_UNIT Date: Sat, 16 Aug 2025 19:24:07 +0800 Message-ID: <20250816112417.3581253-5-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- 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 2da876a928c7..24c695a36a76 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1605,6 +1605,31 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd) return 1; } =20 +static int scsi_eh_sdev_stu(struct scsi_cmnd *scmd, + struct list_head *work_q, + struct list_head *done_q) +{ + struct scsi_device *sdev =3D 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 =3D=3D sdev && + scsi_eh_action(scmd, SUCCESS) =3D=3D 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. @@ -1619,7 +1644,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; =20 shost_for_each_device(sdev, shost) { @@ -1642,26 +1667,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost, if (!stu_scmd) continue; =20 - 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 =3D=3D sdev && - scsi_eh_action(scmd, SUCCESS) =3D=3D 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; } } =20 --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 2799929A9E1; Sat, 16 Aug 2025 10:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341595; cv=none; b=pqrEQBxG4fx5EeH3obPi6l3VAa5aOMNCQ7hL9+/AyVMe15JyyIROMVTBsIFoPPcUUReSEzX+kOqoLtE1Dpo+A/Q1SvRNgD0Sinn75mnSmzosiWTt9qPBla+A35C9suXpaSOpc9mo3jq9+vhDpcaG+RWAO4CQNVZTY9cqRTcjDvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341595; c=relaxed/simple; bh=TKofgrDP115WrtIqX39g/FOcMKIypFZ8qKFs/HvZR2Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U0YTJlZH6+8YYIavKq9Yb341p8shA/OCikr0s8kLlCCqarZ/TChk3Vtr8uyRWBBvGpEE6qhUYLXegojfaHtNmHM71fRbDDnqf8g6Qb3EdrQSKkbkF/iHut8MXmRv4Dqm48MZFJbNAQ8LPNm/I6GGOXKsUXmvrzjcbu6MhhOtMG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4c3wh12Vx6zPtHS; Sat, 16 Aug 2025 18:48:49 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 8A1A3180087; Sat, 16 Aug 2025 18:53:10 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:09 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 05/14] scsi: scsi_error: Add helper scsi_eh_sdev_reset to do lun reset Date: Sat, 16 Aug 2025 19:24:08 +0800 Message-ID: <20250816112417.3581253-6-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- 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 24c695a36a76..02f6ef6393ed 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1676,6 +1676,34 @@ static int scsi_eh_stu(struct Scsi_Host *shost, return list_empty(work_q); } =20 +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 =3D scmd->device; + enum scsi_disposition rtn; + + SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, + "%s: Sending BDR\n", current->comm)); + + rtn =3D scsi_try_bus_device_reset(scmd); + if (rtn !=3D SUCCESS && rtn !=3D 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 =3D=3D FAST_IO_FAIL || + !scsi_eh_tur(scmd)) + list_for_each_entry_safe(scmd, next, work_q, eh_entry) + if (scmd->device =3D=3D sdev && + scsi_eh_action(scmd, rtn) !=3D FAILED) + scsi_eh_finish_cmd(scmd, done_q); + + return list_empty(work_q); +} =20 /** * scsi_eh_bus_device_reset - send bdr if needed @@ -1693,9 +1721,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; =20 shost_for_each_device(sdev, shost) { if (scsi_host_eh_past_deadline(shost)) { @@ -1716,26 +1743,9 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host= *shost, if (!bdr_scmd) continue; =20 - SCSI_LOG_ERROR_RECOVERY(3, - sdev_printk(KERN_INFO, sdev, - "%s: Sending BDR\n", current->comm)); - rtn =3D scsi_try_bus_device_reset(bdr_scmd); - if (rtn =3D=3D SUCCESS || rtn =3D=3D FAST_IO_FAIL) { - if (!scsi_device_online(sdev) || - rtn =3D=3D FAST_IO_FAIL || - !scsi_eh_tur(bdr_scmd)) { - list_for_each_entry_safe(scmd, next, - work_q, eh_entry) { - if (scmd->device =3D=3D sdev && - scsi_eh_action(scmd, rtn) !=3D 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; } } =20 --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 8484E29ACC4; Sat, 16 Aug 2025 10:53:13 +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=1755341596; cv=none; b=FNCaQPb8e2njzUKJjfk/qPPQJ4Emk65q+vrlh16wzi34ydbyy86OcT5l5LGpMJ30CqkG2bOVrxEqGLQWz8xK+6ub91+6HGYqFmRTmwWpIEfTW9yfBrFdYNSdq+Mewijd84L958qhfKgtfBzGDZRvHJLtla2bQWb2dmtwlOmhrtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341596; c=relaxed/simple; bh=p5dtF2b6pow8BO4cUDGVAQrm8n2xA2vU4BDB9giF1JE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A5Vdcs5mi25T0MH1sF0hnLnYc99uHkSYL9u6y4EVRGTiv7gH1pAxruodL2uxFU5mtsn6h9WujSTgti2xHDipbWxFAtbC2dhm1Yn2dMxrkt3eC/dg7l5ReaX53CpRq33IiQ2YKFmmBmFwFS4Frt0Chv1SlHjdWPrN04vSP8OAhXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c3wh22wtXz2Cg4c; Sat, 16 Aug 2025 18:48:50 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 5DB5D1A0188; Sat, 16 Aug 2025 18:53:11 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:10 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 06/14] scsi: scsi_error: Add flags to mark error handle steps has done Date: Sat, 16 Aug 2025 19:24:09 +0800 Message-ID: <20250816112417.3581253-7-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- 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 02f6ef6393ed..cd53e2744a4f 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) =20 +#define sdev_flags_done(flag) \ +static inline int sdev_##flag(struct scsi_device *sdev) \ +{ \ + struct scsi_device_eh *eh =3D 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 *); =20 +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 =3D 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 =3D 0; + + shost_for_each_device(sdev, shost) { + if (!sdev->eh) + continue; + sdev->eh->get_sense_done =3D 0; + sdev->eh->stu_done =3D 0; + sdev->eh->reset_done =3D 0; + } +} + void scsi_eh_wakeup(struct Scsi_Host *shost, unsigned int busy) { lockdep_assert_held(shost->host_lock); @@ -1443,6 +1483,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 @@ -1656,6 +1699,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 =3D NULL; list_for_each_entry(scmd, work_q, eh_entry) if (scmd->device =3D=3D sdev && SCSI_SENSE_VALID(scmd) && @@ -1739,6 +1785,9 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host = *shost, bdr_scmd =3D scmd; break; } + if (sdev_reset_done(sdev) || + starget_reset_done(scsi_target(sdev))) + continue; =20 if (!bdr_scmd) continue; @@ -1787,6 +1836,11 @@ static int scsi_eh_target_reset(struct Scsi_Host *sh= ost, } =20 scmd =3D 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 =3D scmd_id(scmd); =20 SCSI_LOG_ERROR_RECOVERY(3, @@ -2403,6 +2457,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); =20 + shost_clear_eh_done(shost); spin_lock_irqsave(shost->host_lock, flags); if (shost->eh_deadline !=3D -1) shost->last_reset =3D 0; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 6f47a7a74cd1..0f88b176cdf9 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -104,6 +104,24 @@ struct scsi_device; struct scsi_target; =20 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 @@ -130,6 +148,16 @@ struct scsi_device_eh { }; =20 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 --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 32E1A29B226; Sat, 16 Aug 2025 10:53:14 +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=1755341596; cv=none; b=aEHuIXuHbtmLbzFtYbO1r5UdfN2rz4ueXuTv8rEuqfhk7BFO3CI4/znkgY6WhnCEYQiGkmtYbh9pDcX26UKXNXB2S/AQQwlUnoEfXu8q7UVVF1iT/TMvm66g0PCERn3FeoK5wN5AcHIilbXsDgalewpb4M6YYDKKc3UxZyzNKuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341596; c=relaxed/simple; bh=RMPQPSn+mUHzHLpI8ljyTbmSs7mJn2hwNRgFCjB/Gyk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fyiHLl4XElnkAgr8WbIC0z/6jNBnJKmQLMWhoQSNtCPxzrryZPQXl+BB1BFRAdyE1ofy9gOyzdiAAblTcSzviql9zTliD8dShhAIB2zXejH7aEqw6Go1+HkhZ+Si1uxKR4/R80F9ON7LhL4IbtkdUYJ+SVzRnScQDT0zu3RWMNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c3wn214dwzvX78; Sat, 16 Aug 2025 18:53:10 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 28CA21402DF; Sat, 16 Aug 2025 18:53:12 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:11 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 07/14] scsi: scsi_error: Add helper to handle scsi device's error command list Date: Sat, 16 Aug 2025 19:24:10 +0800 Message-ID: <20250816112417.3581253-8-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- 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 cd53e2744a4f..b09f721d4d93 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2554,6 +2554,43 @@ int scsi_error_handler(void *data) return 0; } =20 +/* + * 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 ret= urned + */ +int scsi_sdev_eh(struct scsi_device *sdev, + struct list_head *work_q, + struct list_head *done_q) +{ + int ret =3D 0; + struct scsi_cmnd *scmd; + + SCSI_LOG_ERROR_RECOVERY(2, sdev_printk(KERN_INFO, sdev, + "%s:luneh: checking sense\n", current->comm)); + ret =3D 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 =3D list_first_entry(work_q, struct scsi_cmnd, eh_entry); + ret =3D 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 =3D list_first_entry(work_q, struct scsi_cmnd, eh_entry); + ret =3D 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); =20 static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *ssh= dr) { --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 73CE229CB49; Sat, 16 Aug 2025 10:53:15 +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=1755341597; cv=none; b=QYjHzpSc/KvA+lTscaKN2ecZm3IrtESXHVGPvJLVuQ6+BEQ2Ljaq5ccNfyiMsoJkOyPOMMsCF6CrNa+QzDbxO1yhi/03Z6DOnafQtWADtdBH+zAhdpyFrFkUS0henX1LOqdAGT2ZOtjbG0RkJMuFvQ6AuuGjPQ4O+7isNtyQ/18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341597; c=relaxed/simple; bh=LTav2CwatPk4LMjhb4iLXtCnvRNyyA4z38N2bpsscdM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZABhHQFcBZ2ZgaTkh+TWlz8adJmunTheCjmam5tMp1Mrgt/HRxBCgpzHwjIrhOwYnhrzC6BHxgbxKli3waCec+1guwNXuLspSH7ROxaToNkmJg51ngCEzSZ8vcW9I4fygxl3ykJNxdGO9oIApFcunuDBqC9kEveauFKvkuLmxWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c3wj45nKfz13NFP; Sat, 16 Aug 2025 18:49:44 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id EB8001402C8; Sat, 16 Aug 2025 18:53:12 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:11 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 08/14] scsi: scsi_error: Add a general LUN based error handler Date: Sat, 16 Aug 2025 19:24:11 +0800 Message-ID: <20250816112417.3581253-9-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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. Add a flag for controlling rollback in scsi_host_template. Add interface sdev_setup_eh/sdev_clear_eh in scsi_host_template, used for setup/clear LUN based error handler. Drivers can implements them custom, or use inner implements: scsi_device_setup_eh/scsi_device_clear_eh. Signed-off-by: Wenchao Hao Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- drivers/scsi/scsi_error.c | 179 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_scan.c | 7 ++ drivers/scsi/scsi_sysfs.c | 2 + include/scsi/scsi_eh.h | 2 + include/scsi/scsi_host.h | 16 ++++ 5 files changed, 206 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index b09f721d4d93..49344f30bab9 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2804,3 +2804,182 @@ bool scsi_get_sense_info_fld(const u8 *sense_buffer= , int sb_len, } } EXPORT_SYMBOL(scsi_get_sense_info_fld); + +static inline void *scsi_eh_device_priv(struct scsi_device_eh *eh) +{ + return eh + 1; +} + +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; +}; + +/* + * 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 =3D + container_of(work, struct scsi_lun_eh, eh_handle_work); + struct scsi_device *sdev =3D luneh->sdev; + struct scsi_device_eh *eh =3D sdev->eh; + struct Scsi_Host *shost =3D 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_shost(scmd); + } + + eh->get_sense_done =3D 1; + eh->stu_done =3D 1; + eh->reset_done =3D 1; + +out_flush_done: + scsi_eh_flush_done_q(&eh_done_q); + spin_lock_irqsave(&luneh->eh_lock, flags); + luneh->eh_num =3D 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 =3D scmd->device; + + luneh =3D scsi_eh_device_priv(sdev->eh); + + 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 bool sdev_eh_is_busy(struct scsi_device *sdev) +{ + int ret =3D 0; + unsigned long flags; + struct scsi_lun_eh *luneh; + + if (!sdev->eh) + return false; + + luneh =3D scsi_eh_device_priv(sdev->eh); + + spin_lock_irqsave(&luneh->eh_lock, flags); + ret =3D luneh->eh_num; + spin_unlock_irqrestore(&luneh->eh_lock, flags); + + return ret !=3D 0; +} +static void sdev_eh_wakeup(struct scsi_device *sdev) +{ + unsigned long flags; + unsigned int nr_error; + unsigned int nr_busy; + struct scsi_lun_eh *luneh; + + luneh =3D scsi_eh_device_priv(sdev->eh); + + spin_lock_irqsave(&luneh->eh_lock, flags); + nr_error =3D luneh->eh_num; + spin_unlock_irqrestore(&luneh->eh_lock, flags); + + nr_busy =3D scsi_device_busy(sdev); + + if (!nr_error || nr_busy !=3D 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; + } + + 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)); + + schedule_work(&luneh->eh_handle_work); +} + +/* + * This is default implement of Scsi_Host.sdev_setup_eh. + */ +int scsi_device_setup_eh(struct scsi_device *sdev) +{ + struct scsi_device_eh *eh; + struct scsi_lun_eh *luneh; + + eh =3D kzalloc(sizeof(struct scsi_device_eh) + sizeof(struct scsi_lun_eh), + GFP_KERNEL); + if (!eh) + return -ENOMEM; + luneh =3D scsi_eh_device_priv(eh); + + eh->add_cmnd =3D sdev_eh_add_cmnd; + eh->is_busy =3D sdev_eh_is_busy; + eh->wakeup =3D sdev_eh_wakeup; + + luneh->fallback =3D sdev->host->hostt->sdev_eh_fallback; + luneh->sdev =3D 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 =3D eh; + + return 0; +} +EXPORT_SYMBOL_GPL(scsi_device_setup_eh); + +/* + * This is default implement of Scsi_Host.sdev_clear_eh. + */ +void scsi_device_clear_eh(struct scsi_device *sdev) +{ + kfree(sdev->eh); + sdev->eh =3D NULL; +} +EXPORT_SYMBOL_GPL(scsi_device_clear_eh); diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 3c6e089e80c3..1c5cb77dfb22 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -377,9 +377,16 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi= _target *starget, goto out_device_destroy; } } + if (shost->hostt->sdev_setup_eh) { + ret =3D shost->hostt->sdev_setup_eh(sdev); + if (ret) + goto out_device_eh; + } =20 return sdev; =20 +out_device_eh: + shost->hostt->sdev_destroy(sdev); out_device_destroy: __scsi_remove_device(sdev); out: diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 169af7d47ce7..d859371c01bb 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1513,6 +1513,8 @@ void __scsi_remove_device(struct scsi_device *sdev) kref_put(&sdev->host->tagset_refcnt, scsi_mq_free_tags); cancel_work_sync(&sdev->requeue_work); =20 + if (sdev->host->hostt->sdev_clear_eh) + sdev->host->hostt->sdev_clear_eh(sdev); if (sdev->host->hostt->sdev_destroy) sdev->host->hostt->sdev_destroy(sdev); transport_destroy_device(dev); diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index 5ce791063baf..d8e4475ff004 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 scs= i_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); +extern void scsi_device_clear_eh(struct scsi_device *sdev); =20 static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *ssh= dr) { diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 46f57fe78505..9cc34bfff3f7 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -225,6 +225,19 @@ struct scsi_host_template { */ void (* sdev_destroy)(struct scsi_device *); =20 + /* + * Setup or clear error handler field scsi_device.eh. + * This error handler is working on designated device, it will only + * operate the designated device, do not affect other devices. + * If not set, error handle will fallback. + * LLDD can use custom error handler, or use inner defined: + * scsi_device_setup_eh/scsi_device_clear_eh + * + * Status: OPTIONAL + */ + int (*sdev_setup_eh)(struct scsi_device *sdev); + void (*sdev_clear_eh)(struct scsi_device *sdev); + /* * Before the mid layer attempts to scan for a new device attached * to a target where no target currently exists, it will call this @@ -468,6 +481,9 @@ struct scsi_host_template { /* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */ unsigned queuecommand_may_block:1; =20 + /* The error handle of scsi_device will fallback when failed. */ + unsigned sdev_eh_fallback:1; + /* * Countdown for host blocking with no commands outstanding. */ --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 EB9BC29D261; Sat, 16 Aug 2025 10:53:15 +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=1755341598; cv=none; b=CxQI8chs4B6Lp7P9V8rBPCRAjQb0GMzYWJYhqjq7Nly+HRAVPSAwmSuy1Tfo8vfRwAVZOvhwYvM54/aNMYt066HFsejkqq1a0LQtrTPWuNk1br74KpcAHePSlCzEP/F/LlklEA8oNBZiCqYydIuveua7tPpLpjxLNhsTkB1B+Eo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341598; c=relaxed/simple; bh=A8UN6nhnqb4wUk5VVG86mpla/61dO0D3CqACMOhUiaQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q2b7kRuP121NPR1SNUtbiVxqFRZ7b/UyIroSfMXxuFRrezwu4PxgrciBOklR6aCUJqIBow/XN3xV1tbMVC+tA0FRnd6d4aoLbVV5fyD3JGqTRvk4Q1wgfc9OIIUrEionBOgDSb2EzWXN9LZYBJuJwYGsNnvqII/43V5oa4TtG4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c3wjx4tcVz2VRG4; Sat, 16 Aug 2025 18:50:29 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id BA6B0140259; Sat, 16 Aug 2025 18:53:13 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:12 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 09/14] scsi: core: increase/decrease target_busy if set error handler Date: Sat, 16 Aug 2025 19:24:12 +0800 Message-ID: <20250816112417.3581253-10-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" From: JiangJianJun This is preparation for a genernal target based error handle strategy to check if to wake up actual error handler, we should enable counter field scsi_target.target_busy in this case. Signed-off-by: JiangJianJun --- drivers/scsi/scsi_lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 63bd33af336b..5115ab5d0942 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -393,7 +393,7 @@ void scsi_device_unbusy(struct scsi_device *sdev, struc= t scsi_cmnd *cmd) =20 scsi_dec_host_busy(shost, cmd); =20 - if (starget->can_queue > 0) + if (starget->can_queue > 0 || starget->eh) atomic_dec(&starget->target_busy); =20 sbitmap_put(&sdev->budget_map, cmd->budget_token); @@ -1412,8 +1412,11 @@ static inline int scsi_target_queue_ready(struct Scs= i_Host *shost, spin_unlock_irq(shost->host_lock); } =20 - if (starget->can_queue <=3D 0) + if (starget->can_queue <=3D 0) { + if (starget->eh) + atomic_inc(&starget->target_busy); return 1; + } =20 busy =3D atomic_inc_return(&starget->target_busy) - 1; if (atomic_read(&starget->target_blocked) > 0) { @@ -1885,7 +1888,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ct= x *hctx, out_dec_host_busy: scsi_dec_host_busy(shost, cmd); out_dec_target_busy: - if (scsi_target(sdev)->can_queue > 0) + if (scsi_target(sdev)->can_queue > 0 || scsi_target(sdev)->eh) atomic_dec(&scsi_target(sdev)->target_busy); out_put_budget: scsi_mq_put_budget(q, cmd->budget_token); --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 A4EDF29DB8F; Sat, 16 Aug 2025 10:53:16 +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=1755341598; cv=none; b=LpAm7CYDZaSdi2cCvzuPpgvjQemOrxP3gjOrAQU4e776M1fP8QMUTrkIg1PhwNNP8OtLLCqKUB4V0ooYdRiIlym8YlNwLeTcBs9wSLjfKYAHsl3d1yfa1CdaRAx+EFF9mruweI56GwLYEp9bIrMhUZiuZmUz9ODXzoUKUKP/6XE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341598; c=relaxed/simple; bh=c6OVxMkMAT3D7jiKcLOjGsSnANNz9tzrykBbHcLWIlE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GwYec5qOc94A/AiRQJYwbdivsZEhUj7gqT5DpQVXZ5UV288XYy43Dq5rHTh1gCjZ3sveBBO8zksuC3egWIVe0ZGtrT/EiZf2RzxekMyN0Y/BPDkEkz+JGf9VOxm7ehpRY39lGTzG0mWXQpQG3zVYJXO8eVj4v+d8aHIn893cxrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c3wh549Jdz2Cg8F; Sat, 16 Aug 2025 18:48:53 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 89229140295; Sat, 16 Aug 2025 18:53:14 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:13 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 10/14] scsi: scsi_error: Add helper to handle scsi target's error command list Date: Sat, 16 Aug 2025 19:24:13 +0800 Message-ID: <20250816112417.3581253-11-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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 Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- drivers/scsi/scsi_error.c | 130 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_eh.h | 2 + 2 files changed, 132 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 49344f30bab9..bc9ca7f38580 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2591,6 +2591,136 @@ int scsi_sdev_eh(struct scsi_device *sdev, } EXPORT_SYMBOL_GPL(scsi_sdev_eh); =20 +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 =3D NULL; + list_for_each_entry(scmd, work_q, eh_entry) + if (scmd->device =3D=3D sdev && SCSI_SENSE_VALID(scmd) && + scsi_check_sense(scmd) =3D=3D FAILED) { + stu_scmd =3D 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 =3D NULL; + list_for_each_entry(scmd, work_q, eh_entry) + if (scmd->device) { + bdr_scmd =3D 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 =3D 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 =3D scsi_try_target_reset(scmd); + if (rtn !=3D SUCCESS && rtn !=3D 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 %s\n", current->comm, + scsi_mlreturn_string(rtn))); + + list_for_each_entry_safe(scmd, next, work_q, eh_entry) { + if (rtn =3D=3D SUCCESS) + list_move_tail(&scmd->eh_entry, &check_list); + else if (rtn =3D=3D 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 ret= urned + */ +int scsi_starget_eh(struct scsi_target *starget, + struct list_head *work_q, + struct list_head *done_q) +{ + int ret =3D 0; + + SCSI_LOG_ERROR_RECOVERY(2, starget_printk(KERN_INFO, starget, + "%s:targeteh: checking sense\n", current->comm)); + ret =3D 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 =3D 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 =3D 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 =3D 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 d8e4475ff004..cda0b962fc47 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 scs= i_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); extern void scsi_device_clear_eh(struct scsi_device *sdev); =20 --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 B586D2BCF45; Sat, 16 Aug 2025 10:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341600; cv=none; b=WxqNMpNDvW+jXIu8vvJ+5tTvmHHe7FqDCJdiqSWtvbMm+bKR2HZcMOjEtopPyTR9NAGqNL3GqdeEXTCFiqQErarpSKAydpfztVdbr9WvFVsDAkrFidKFs2aC74EOfEU16WT4u0qy+fXV4MmNvqiEyP4sJ9Ii86lha8yO0bXGfAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341600; c=relaxed/simple; bh=P8/cPqr04hLQ7CWOtn4WK3IZ4WkYBFpOdvn6A0a3zdQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FNnAjVf7hksghp+gOE84n7IE4iIG+S8sOhSh72PTbkOV0lfZspILRMGRKg8TGlo3en/POqw3aotualAWH5xGzqZLPc/1mgXDL0OlbXFMRKU1R/j1/UTfX/HhNpRKMg65ho/r/JmKY8tAphOWw9ShTWY0Ql9O7eKUvk5jrisxvNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4c3wh60mPmzPtHD; Sat, 16 Aug 2025 18:48:54 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 51392180087; Sat, 16 Aug 2025 18:53:15 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:14 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 11/14] scsi: scsi_error: Add a general target based error handler Date: Sat, 16 Aug 2025 19:24:14 +0800 Message-ID: <20250816112417.3581253-12-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" 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. Add a flag for controlling rollback in scsi_host_template. Add interface target_setup_eh/target_clear_eh in scsi_host_template, used for setup/clear target based error handler. Drivers can implements them custom, or use inner implements: scsi_target_setup_eh/scsi_target_clear_eh. Signed-off-by: Wenchao Hao Co-developed-by: JiangJianJun Signed-off-by: JiangJianJun --- drivers/scsi/scsi_error.c | 171 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_scan.c | 12 +++ include/scsi/scsi_eh.h | 2 + include/scsi/scsi_host.h | 15 ++++ 4 files changed, 200 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index bc9ca7f38580..e2adf0349f81 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -3113,3 +3113,174 @@ void scsi_device_clear_eh(struct scsi_device *sdev) sdev->eh =3D NULL; } EXPORT_SYMBOL_GPL(scsi_device_clear_eh); + +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 =3D 0; + sdev->eh->stu_done =3D 0; + sdev->eh->reset_done =3D 0; + } +} + +static inline void *scsi_eh_starget_priv(struct scsi_target_eh *eh) +{ + return eh + 1; +} + +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 =3D + container_of(work, struct starget_eh, eh_handle_work); + struct scsi_target *starget =3D stargeteh->starget; + struct scsi_target_eh *eh =3D 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 =3D 1; + list_for_each_entry_safe(scmd, next, &eh_work_q, eh_entry) { + list_del_init(&scmd->eh_entry); + scsi_eh_scmd_add_shost(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 =3D 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 =3D scmd->device->sdev_target; + struct starget_eh *eh; + + eh =3D scsi_eh_starget_priv(starget->eh); + + 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 bool starget_eh_is_busy(struct scsi_target *starget) +{ + int ret =3D 0; + unsigned long flags; + struct starget_eh *eh; + + eh =3D scsi_eh_starget_priv(starget->eh); + + spin_lock_irqsave(&eh->eh_lock, flags); + ret =3D eh->eh_num; + spin_unlock_irqrestore(&eh->eh_lock, flags); + + return ret !=3D 0; +} + +static void starget_eh_wakeup(struct scsi_target *starget) +{ + unsigned long flags; + unsigned int nr_error; + unsigned int nr_busy; + struct starget_eh *eh; + + eh =3D scsi_eh_starget_priv(starget->eh); + + spin_lock_irqsave(&eh->eh_lock, flags); + nr_error =3D eh->eh_num; + spin_unlock_irqrestore(&eh->eh_lock, flags); + + nr_busy =3D atomic_read(&starget->target_busy); + + if (!nr_error || nr_busy !=3D 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; + } + + 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)); + + schedule_work(&eh->eh_handle_work); +} + +/* + * This is default implement of Scsi_Host.target_setup_eh. + */ +int scsi_target_setup_eh(struct scsi_target *starget) +{ + struct Scsi_Host *shost =3D dev_to_shost(starget->dev.parent); + struct scsi_target_eh *eh; + struct starget_eh *stargeteh; + + eh =3D kzalloc(sizeof(struct scsi_target_eh) + sizeof(struct starget_eh), + GFP_KERNEL); + if (!eh) + return -ENOMEM; + stargeteh =3D scsi_eh_starget_priv(eh); + + eh->add_cmnd =3D starget_eh_add_cmnd; + eh->is_busy =3D starget_eh_is_busy; + eh->wakeup =3D starget_eh_wakeup; + stargeteh->starget =3D starget; + stargeteh->fallback =3D shost->hostt->target_eh_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 =3D eh; + + return 0; +} +EXPORT_SYMBOL_GPL(scsi_target_setup_eh); + +/* + * This is default implement of Scsi_Host.target_clear_eh. + */ +void scsi_target_clear_eh(struct scsi_target *starget) +{ + kfree(starget->eh); + starget->eh =3D NULL; +} +EXPORT_SYMBOL_GPL(scsi_target_clear_eh); diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 1c5cb77dfb22..15848beb2b93 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -405,6 +405,8 @@ static void scsi_target_destroy(struct scsi_target *sta= rget) starget->state =3D STARGET_DEL; transport_destroy_device(dev); spin_lock_irqsave(shost->host_lock, flags); + if (shost->hostt->target_clear_eh) + shost->hostt->target_clear_eh(starget); if (shost->hostt->target_destroy) shost->hostt->target_destroy(starget); list_del_init(&starget->siblings); @@ -553,6 +555,16 @@ static struct scsi_target *scsi_alloc_target(struct de= vice *parent, return NULL; } } + if (shost->hostt->target_setup_eh) { + error =3D shost->hostt->target_setup_eh(starget); + if (error) { + dev_err(dev, "target setup error handler failed, error %d\n", + error); + scsi_target_destroy(starget); + return NULL; + } + } + get_device(dev); =20 return starget; diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index cda0b962fc47..4d302be8d6d8 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); extern void scsi_device_clear_eh(struct scsi_device *sdev); +extern int scsi_target_setup_eh(struct scsi_target *starget); +extern void scsi_target_clear_eh(struct scsi_target *starget); =20 static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *ssh= dr) { diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 9cc34bfff3f7..cac661cd9b5b 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -265,6 +265,19 @@ struct scsi_host_template { */ void (* target_destroy)(struct scsi_target *); =20 + /* + * Setup or clear error handler field scsi_target.eh. + * This error handler is working on designated target, it will only + * operate the designated target, do not affect other targets. + * If not set, error handle will fallback. + * LLDD can use custom error handler, or use inner defined: + * scsi_target_setup_eh/scsi_target_clear_eh + * + * Status: OPTIONAL + */ + int (*target_setup_eh)(struct scsi_target *starget); + void (*target_clear_eh)(struct scsi_target *starget); + /* * If a host has the ability to discover targets on its own instead * of scanning the entire bus, it can fill in this function and @@ -483,6 +496,8 @@ struct scsi_host_template { =20 /* The error handle of scsi_device will fallback when failed. */ unsigned sdev_eh_fallback:1; + /* The error handle of scsi_target will fallback when failed. */ + unsigned target_eh_fallback:1; =20 /* * Countdown for host blocking with no commands outstanding. --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 DF5582BD59E; Sat, 16 Aug 2025 10:53:18 +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=1755341601; cv=none; b=PbkASGjT4bmGCcqBBex2hno3sHKPREWXf4Kw67VrlYp6NR7Zku+n4dRIsyOhcbGWJA11gIIi2OB0EDrIb7OoLQm5ND30VX1+4uBPnutEUTBSx2Ryt8kIYqgfjWISUbqKzyTnCBdaSvGHCi+RxG3WlTdOg31w8t81vdmPdPlLaBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341601; c=relaxed/simple; bh=O0hdZPocvQU+gp7j/QXbA4boVviLicrP/JZ2u4a2kYM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pd0Qr9iQf/Fh2wusTyVVPh0Vf4Txa6hFtGyS56EWkUjkp5xLTKAFhFqw4By2pG0oAnNd0JVSD44qiY49c1l/5RGWntBSSblxpMcVyW4k65DN8E4x2gNGNZNRN0X9Z9N0B70sA8v/7HsEVP1wegI03JglYs0DuvUhsZzd4Ez/otU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4c3wm03YqdztSxr; Sat, 16 Aug 2025 18:52:16 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id 21EF71402CD; Sat, 16 Aug 2025 18:53:16 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:15 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 12/14] scsi: scsi_debug: Add params for configuring the error handler Date: Sat, 16 Aug 2025 19:24:15 +0800 Message-ID: <20250816112417.3581253-13-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" From: JiangJianJun Add a new module parameter to configure error handlers based on LUN/targets and toggle the enable/disable fallback functionality. Signed-off-by: JiangJianJun --- drivers/scsi/scsi_debug.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 0847767d4d43..64d5b85d961b 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -961,6 +961,10 @@ static bool write_since_sync; static bool sdebug_statistics =3D DEF_STATISTICS; 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 =3D 0, BLK_ZONED_HA =3D 1, @@ -7362,6 +7366,10 @@ 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, 0444); +module_param_named(lun_eh_fallback, sdebug_lun_eh_fallback, bool, 0444); +module_param_named(target_eh, sdebug_target_eh, bool, 0444); +module_param_named(target_eh_fallback, sdebug_target_eh_fallback, bool, 04= 44); =20 MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); MODULE_DESCRIPTION("SCSI debug adapter driver"); @@ -7441,6 +7449,10 @@ MODULE_PARM_DESC(zone_max_open, "Maximum number of o= pen zones; [0] for no limit MODULE_PARM_DESC(zone_nr_conv, "Number of conventional zones (def=3D1)"); MODULE_PARM_DESC(zone_size_mb, "Zone size in MiB (def=3Dauto)"); MODULE_PARM_DESC(allow_restart, "Set scsi_device's allow_restart flag(def= =3D0)"); +MODULE_PARM_DESC(lun_eh, "LUN based error handle (def=3D0)"); +MODULE_PARM_DESC(lun_eh_fallback, "Fallback to further recovery if LUN rec= overy failed (def=3D0)"); +MODULE_PARM_DESC(target_eh, "target based error handle (def=3D0)"); +MODULE_PARM_DESC(target_eh_fallback, "Fallback to further recovery if targ= et recovery failed (def=3D0)"); =20 #define SDEBUG_INFO_LEN 256 static char sdebug_info[SDEBUG_INFO_LEN]; @@ -8427,6 +8439,7 @@ static struct attribute *sdebug_drv_attrs[] =3D { ATTRIBUTE_GROUPS(sdebug_drv); =20 static struct device *pseudo_primary; +static struct scsi_host_template sdebug_driver_template; =20 static int __init scsi_debug_init(void) { @@ -8435,6 +8448,17 @@ static int __init scsi_debug_init(void) int k, ret, hosts_to_add; int idx =3D -1; =20 + if (sdebug_lun_eh) { + sdebug_driver_template.sdev_setup_eh =3D scsi_device_setup_eh; + sdebug_driver_template.sdev_clear_eh =3D scsi_device_clear_eh; + sdebug_driver_template.sdev_eh_fallback =3D sdebug_lun_eh_fallback; + } + if (sdebug_target_eh) { + sdebug_driver_template.target_setup_eh =3D scsi_target_setup_eh; + sdebug_driver_template.target_clear_eh =3D scsi_target_clear_eh; + sdebug_driver_template.target_eh_fallback =3D sdebug_target_eh_fallback; + } + if (sdebug_ndelay >=3D 1000 * 1000 * 1000) { pr_warn("ndelay must be less than 1 second, ignored\n"); sdebug_ndelay =3D 0; @@ -9412,7 +9436,7 @@ static int sdebug_init_cmd_priv(struct Scsi_Host *sho= st, struct scsi_cmnd *cmd) return 0; } =20 -static const struct scsi_host_template sdebug_driver_template =3D { +static struct scsi_host_template sdebug_driver_template =3D { .show_info =3D scsi_debug_show_info, .write_info =3D scsi_debug_write_info, .proc_name =3D sdebug_proc_name, --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 810CF2BE7A2; Sat, 16 Aug 2025 10:53:19 +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=1755341601; cv=none; b=VscfhV71ggt0xLA6sRj2SjoSbMXi3bvgESMaO0R2AgY8ceER2JiMlws7/cJGankqeDxIw8YYq7iRvlOht/2wHbNPFYezbwmx9cer7Ai7GcVbxE2sw0Od8kEgzvgaxPNAuGkajdsdf9WtZihAt6qtb004oCpT8sOb1cJayj4bDhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341601; c=relaxed/simple; bh=lrOAE3gu6nriXl31eGKX6Pght1ci2EPDlzWVNOFvFIY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZqClXbewXqRXV2VNdda+gge3BERSJDO6YCsuj0LVh2MUcjYMJM0oxuRCmHIqK6DEUuK65333V3TNPeqwfGtd003bHJTTkL85LQW1oAyfYmMRF+41jrk+0l61vkfwLP8eQ9lNDckE1/g7/EV5xQf87KmAPiXWRq9jAtgVD1GIXYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c3wj85x3zz13NFN; Sat, 16 Aug 2025 18:49:48 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id EE85B18048D; Sat, 16 Aug 2025 18:53:16 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:15 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 13/14] scsi: virtio_scsi: enable LUN based error handlers Date: Sat, 16 Aug 2025 19:24:16 +0800 Message-ID: <20250816112417.3581253-14-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" From: JiangJianJun Enable the virtio_scsi driver to support LUN-based error handlers. Since virtio_scsi does not define any further reset callbacks, there is no need to fallback for further recover, so we have disabled the fallback functionality. Signed-off-by: JiangJianJun --- drivers/scsi/virtio_scsi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 96a69edddbe5..3c525521351c 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -28,6 +28,7 @@ #include #include #include +#include #include =20 #include "sd.h" @@ -801,6 +802,8 @@ static const struct scsi_host_template virtscsi_host_te= mplate =3D { .eh_device_reset_handler =3D virtscsi_device_reset, .eh_timed_out =3D virtscsi_eh_timed_out, .sdev_init =3D virtscsi_device_alloc, + .sdev_setup_eh =3D scsi_device_setup_eh, + .sdev_clear_eh =3D scsi_device_clear_eh, =20 .dma_boundary =3D UINT_MAX, .map_queues =3D virtscsi_map_queues, --=20 2.33.0 From nobody Sat Oct 4 12:46:56 2025 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 DC56E2BEC39; Sat, 16 Aug 2025 10:53:19 +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=1755341602; cv=none; b=uXf28osGiSYUEjZoZKCT48n1DBbU8Ve9hTvuVkMHvDYvRco4AP4k4rOAUz1oSdraeetrOSeDPs6uNx4R+Qxx4JhtgttjO9mp+LHKccPFOm3DxfcSPs83CNm3RQIMhbQHFC5RJC1kMlsrtQ96qWN/TH9KlZVzJssNDLHVCGx9030= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755341602; c=relaxed/simple; bh=6FAPIP5FkbuIRoAUBawSKb4AJYRef3OuI3wUeKdsop4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RRosJ2A0HGvTWiuGX1t3ru/ixp8G6rAiOZd1zDBcaBCYrMoAyLX11dnr9C9mSjkoHQWyVHFNBjENbOAXnbK4HSwTJQN7DJhPXSclVZ4ZwHYZn23cKvxPxNuIl4XllmvLGLXycGPTMzEqejmyaVkvRX3ER6zTVALzuByJcashITg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c3wn75S70zvX7s; Sat, 16 Aug 2025 18:53:15 +0800 (CST) Received: from kwepemk500001.china.huawei.com (unknown [7.202.194.86]) by mail.maildlp.com (Postfix) with ESMTPS id BDF9C180B5A; Sat, 16 Aug 2025 18:53:17 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by kwepemk500001.china.huawei.com (7.202.194.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 16 Aug 2025 18:53:16 +0800 From: JiangJianJun To: , , CC: , , , , , , , , , , , Subject: [PATCH 14/14] scsi: iscsi_tcp: enable LUN-based and target-based error handlers Date: Sat, 16 Aug 2025 19:24:17 +0800 Message-ID: <20250816112417.3581253-15-jiangjianjun3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250816112417.3581253-1-jiangjianjun3@huawei.com> References: <20250816112417.3581253-1-jiangjianjun3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500001.china.huawei.com (7.202.194.86) Content-Type: text/plain; charset="utf-8" From: JiangJianJun The iSCSI TCP driver now supports resetting LUNs or targets, allowing us to enable LUN-based error handlers and enable them to fall back to target-based error handlers. Signed-off-by: JiangJianJun --- drivers/scsi/iscsi_tcp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 7b4fe0e6afb2..328e76219b1c 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1040,6 +1041,9 @@ static const struct scsi_host_template iscsi_sw_tcp_s= ht =3D { .eh_target_reset_handler =3D iscsi_eh_recover_target, .dma_boundary =3D PAGE_SIZE - 1, .sdev_configure =3D iscsi_sw_tcp_sdev_configure, + .sdev_setup_eh =3D scsi_device_setup_eh, + .sdev_clear_eh =3D scsi_device_clear_eh, + .sdev_eh_fallback =3D 1, .proc_name =3D "iscsi_tcp", .this_id =3D -1, .track_queue_depth =3D 1, --=20 2.33.0