diff mbox series

scsi: scsi_debug: fix create target debugfs failure

Message ID 20240619013803.3008857-1-ming.lei@redhat.com
State New
Headers show
Series scsi: scsi_debug: fix create target debugfs failure | expand

Commit Message

Ming Lei June 19, 2024, 1:38 a.m. UTC
Target debugfs entry is removed via async_schedule() which isn't drained
when adding same name target, so failure of "Directory 'target11:0:0' with
parent 'scsi_debug' already present!" can be triggered easily.

Fix it by switching to domain async schedule, and draining it before
adding new target debugfs entry.

Cc: Wenchao Hao <haowenchao2@huawei.com>
Fixes: f084fe52c640 ("scsi: scsi_debug: Add debugfs interface to fail target reset")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/scsi/scsi_debug.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Wenchao Hao June 20, 2024, 8:07 a.m. UTC | #1
On 2024/6/19 9:38, Ming Lei wrote:
> Target debugfs entry is removed via async_schedule() which isn't drained
> when adding same name target, so failure of "Directory 'target11:0:0' with
> parent 'scsi_debug' already present!" can be triggered easily.
> 
> Fix it by switching to domain async schedule, and draining it before
> adding new target debugfs entry.
> 

Thank you for the fix, the change is looks good to me.

> Cc: Wenchao Hao <haowenchao2@huawei.com>
> Fixes: f084fe52c640 ("scsi: scsi_debug: Add debugfs interface to fail target reset")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>   drivers/scsi/scsi_debug.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index acf0592d63da..91f022fb8d0c 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -926,6 +926,7 @@ static const int device_qfull_result =
>   static const int condition_met_result = SAM_STAT_CONDITION_MET;
>   
>   static struct dentry *sdebug_debugfs_root;
> +static ASYNC_DOMAIN_EXCLUSIVE(sdebug_async_domain);
>   
>   static void sdebug_err_free(struct rcu_head *head)
>   {
> @@ -1148,6 +1149,8 @@ static int sdebug_target_alloc(struct scsi_target *starget)
>   	if (!targetip)
>   		return -ENOMEM;
>   
> +	async_synchronize_full_domain(&sdebug_async_domain);
> +
>   	targetip->debugfs_entry = debugfs_create_dir(dev_name(&starget->dev),
>   				sdebug_debugfs_root);
>   
> @@ -1174,7 +1177,8 @@ static void sdebug_target_destroy(struct scsi_target *starget)
>   	targetip = (struct sdebug_target_info *)starget->hostdata;
>   	if (targetip) {
>   		starget->hostdata = NULL;
> -		async_schedule(sdebug_tartget_cleanup_async, targetip);
> +		async_schedule_domain(sdebug_tartget_cleanup_async, targetip,
> +				&sdebug_async_domain);
>   	}
>   }
>
Martin K. Petersen June 27, 2024, 3:36 a.m. UTC | #2
On Wed, 19 Jun 2024 09:38:03 +0800, Ming Lei wrote:

> Target debugfs entry is removed via async_schedule() which isn't drained
> when adding same name target, so failure of "Directory 'target11:0:0' with
> parent 'scsi_debug' already present!" can be triggered easily.
> 
> Fix it by switching to domain async schedule, and draining it before
> adding new target debugfs entry.
> 
> [...]

Applied to 6.10/scsi-fixes, thanks!

[1/1] scsi: scsi_debug: fix create target debugfs failure
      https://git.kernel.org/mkp/scsi/c/b402a0dce64a
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index acf0592d63da..91f022fb8d0c 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -926,6 +926,7 @@  static const int device_qfull_result =
 static const int condition_met_result = SAM_STAT_CONDITION_MET;
 
 static struct dentry *sdebug_debugfs_root;
+static ASYNC_DOMAIN_EXCLUSIVE(sdebug_async_domain);
 
 static void sdebug_err_free(struct rcu_head *head)
 {
@@ -1148,6 +1149,8 @@  static int sdebug_target_alloc(struct scsi_target *starget)
 	if (!targetip)
 		return -ENOMEM;
 
+	async_synchronize_full_domain(&sdebug_async_domain);
+
 	targetip->debugfs_entry = debugfs_create_dir(dev_name(&starget->dev),
 				sdebug_debugfs_root);
 
@@ -1174,7 +1177,8 @@  static void sdebug_target_destroy(struct scsi_target *starget)
 	targetip = (struct sdebug_target_info *)starget->hostdata;
 	if (targetip) {
 		starget->hostdata = NULL;
-		async_schedule(sdebug_tartget_cleanup_async, targetip);
+		async_schedule_domain(sdebug_tartget_cleanup_async, targetip,
+				&sdebug_async_domain);
 	}
 }