Skip to contentSkip to conversation

block/001: wait until device is added

PATCH Applied Ming Lei 2 participants 2 messages Aug 24, 2021 – Aug 25, 2021

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block/001: wait until device is added

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.

---
 tests/block/001 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tests/block/001 +7 -2
index 51ec9d8..01356d0 100755
@@ -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
Signature · 1 line
2.31.1
#1 lore raw
Quoted 28 lines · Ming Lei

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.

---
 tests/block/001 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tests/block/001 +1 -1
index 51ec9d8..01356d0 100755
@@ -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#*:}"

tests/block/001 stress_scsi_debug() { · line 37

Quoted 10 lines
tests/block/001 +6 -1
 		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.