linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block/001: wait until device is added
@ 2021-08-24  3:17 Ming Lei
  2021-08-25  0:56 ` Omar Sandoval
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2021-08-24  3:17 UTC (permalink / raw)
  To: Omar Sandoval; +Cc: linux-block, Ming Lei, Martin K. Petersen, linux-scsi

Writing to the scan attribute of scsi host is usually one sync scan, but
devices in this sync scan may be delay added if there is concurrent
asnyc scan.

So wait until the device is added in block/001 for avoiding to fail
the test.

Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 tests/block/001 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/block/001 b/tests/block/001
index 51ec9d8..01356d0 100755
--- a/tests/block/001
+++ b/tests/block/001
@@ -21,15 +21,20 @@ stress_scsi_debug() {
 		return
 	fi
 
-	local host target
+	local host target target_path
 	for target in "${SCSI_DEBUG_TARGETS[@]}"; do
 		(
 		host="${target%%:*}"
 		scan="${target#*:}"
 		scan="${scan//:/ }"
+		target_path="/sys/class/scsi_device/${target}"
 		while [[ ! -e "$TMPDIR/stop" ]]; do
 			echo "${scan}" > "/sys/class/scsi_host/host${host}/scan"
-			echo 1 > "/sys/class/scsi_device/${target}/device/delete"
+			while [ ! -d ${target_path} ]; do
+				sleep 0.01;
+				[[ -e "$TMPDIR/stop" ]] && break
+			done
+			[ -d ${target_path} ] && echo 1 > ${target_path}/device/delete
 		done
 		) &
 	done
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block/001: wait until device is added
  2021-08-24  3:17 [PATCH] block/001: wait until device is added Ming Lei
@ 2021-08-25  0:56 ` Omar Sandoval
  0 siblings, 0 replies; 2+ messages in thread
From: Omar Sandoval @ 2021-08-25  0:56 UTC (permalink / raw)
  To: Ming Lei; +Cc: Omar Sandoval, linux-block, Martin K. Petersen, linux-scsi

On Tue, Aug 24, 2021 at 11:17:53AM +0800, Ming Lei wrote:
> Writing to the scan attribute of scsi host is usually one sync scan, but
> devices in this sync scan may be delay added if there is concurrent
> asnyc scan.
> 
> So wait until the device is added in block/001 for avoiding to fail
> the test.
> 
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  tests/block/001 | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/block/001 b/tests/block/001
> index 51ec9d8..01356d0 100755
> --- a/tests/block/001
> +++ b/tests/block/001
> @@ -21,15 +21,20 @@ stress_scsi_debug() {
>  		return
>  	fi
>  
> -	local host target
> +	local host target target_path
>  	for target in "${SCSI_DEBUG_TARGETS[@]}"; do
>  		(
>  		host="${target%%:*}"
>  		scan="${target#*:}"
>  		scan="${scan//:/ }"
> +		target_path="/sys/class/scsi_device/${target}"
>  		while [[ ! -e "$TMPDIR/stop" ]]; do
>  			echo "${scan}" > "/sys/class/scsi_host/host${host}/scan"
> -			echo 1 > "/sys/class/scsi_device/${target}/device/delete"
> +			while [ ! -d ${target_path} ]; do
> +				sleep 0.01;
> +				[[ -e "$TMPDIR/stop" ]] && break
> +			done
> +			[ -d ${target_path} ] && echo 1 > ${target_path}/device/delete

Applied, with the shellcheck errors fixed and simplified logic. Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-25  0:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24  3:17 [PATCH] block/001: wait until device is added Ming Lei
2021-08-25  0:56 ` Omar Sandoval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).