test_part_02.sh 2.1 KB

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