1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh 5 6TID="generic_15" 7ERR_CODE=0 8 9_test_partition_scan_no_hang() 10{ 11 local recovery_flag=$1 12 local expected_state=$2 13 local dev_id 14 local state 15 local daemon_pid 16 local start_time 17 local elapsed 18 19 # Create ublk device with fault_inject target and very large delay 20 # to simulate hang during partition table read 21 # --delay_us 60000000 = 60 seconds delay 22 # Use _add_ublk_dev_no_settle to avoid udevadm settle hang waiting 23 # for partition scan events to complete 24 if [ "$recovery_flag" = "yes" ]; then 25 echo "Testing partition scan with recovery support..." 26 dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000 -r 1) 27 else 28 echo "Testing partition scan without recovery..." 29 dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000) 30 fi 31 32 _check_add_dev "$TID" $? 33 34 # The add command should return quickly because partition scan is async. 35 # Now sleep briefly to let the async partition scan work start and hit 36 # the delay in the fault_inject handler. 37 sleep 1 38 39 # Kill the ublk daemon while partition scan is potentially blocked 40 # And check state transitions properly 41 start_time=${SECONDS} 42 daemon_pid=$(_get_ublk_daemon_pid "${dev_id}") 43 state=$(__ublk_kill_daemon "${dev_id}" "${expected_state}") 44 elapsed=$((SECONDS - start_time)) 45 46 # Verify the device transitioned to expected state 47 if [ "$state" != "${expected_state}" ]; then 48 echo "FAIL: Device state is $state, expected ${expected_state}" 49 ERR_CODE=255 50 ${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1 51 return 52 fi 53 echo "PASS: Device transitioned to ${expected_state} in ${elapsed}s without hanging" 54 55 # Clean up the device 56 ${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1 57} 58 59_prep_test "partition_scan" "verify async partition scan prevents IO hang" 60 61# Test 1: Without recovery support - should transition to DEAD 62_test_partition_scan_no_hang "no" "DEAD" 63 64# Test 2: With recovery support - should transition to QUIESCED 65_test_partition_scan_no_hang "yes" "QUIESCED" 66 67_cleanup_test "partition_scan" 68_show_result $TID $ERR_CODE 69