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