/tests/zfs-tests/tests/functional/fault/auto_spare_002_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 96 lines · 36 code · 19 blank · 41 comment · 3 complexity · cdb799298b342ec91508eaaad1763c92 MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # This file and its contents are supplied under the terms of the
  6. # Common Development and Distribution License ("CDDL"), version 1.0.
  7. # You may only use this file in accordance with the terms of version
  8. # 1.0 of the CDDL.
  9. #
  10. # A full copy of the text of the CDDL should have accompanied this
  11. # source. A copy of the CDDL is also available via the Internet at
  12. # http://www.illumos.org/license/CDDL.
  13. #
  14. # CDDL HEADER END
  15. #
  16. #
  17. # Copyright (c) 2017 by Intel Corporation. All rights reserved.
  18. #
  19. . $STF_SUITE/include/libtest.shlib
  20. . $STF_SUITE/tests/functional/fault/fault.cfg
  21. #
  22. # DESCRIPTION:
  23. # Testing Fault Management Agent ZED Logic - Automated Auto-Spare Test when
  24. # drive is faulted due to CHECKSUM ERRORS.
  25. #
  26. # STRATEGY:
  27. # 1. Create a pool with hot spares
  28. # 2. Create a filesystem with the primary cache disable to force reads
  29. # 3. Write a file to the pool to be read back
  30. # 4. Inject CHECKSUM ERRORS on read with a zinject error handler
  31. # 5. Verify the ZED kicks in a hot spare and expected pool/device status
  32. # 6. Clear the fault
  33. # 7. Verify the hot spare is available and expected pool/device status
  34. #
  35. verify_runnable "both"
  36. function cleanup
  37. {
  38. log_must zinject -c all
  39. destroy_pool $TESTPOOL
  40. rm -f $VDEV_FILES $SPARE_FILE
  41. }
  42. log_assert "Testing automated auto-spare FMA test"
  43. log_onexit cleanup
  44. # Events not supported on FreeBSD
  45. if ! is_freebsd; then
  46. # Clear events from previous runs
  47. zed_events_drain
  48. fi
  49. TESTFILE="/$TESTPOOL/$TESTFS/testfile"
  50. for type in "mirror" "raidz" "raidz2"; do
  51. # 1. Create a pool with hot spares
  52. truncate -s $SPA_MINDEVSIZE $VDEV_FILES $SPARE_FILE
  53. log_must zpool create -f $TESTPOOL $type $VDEV_FILES spare $SPARE_FILE
  54. # 2. Create a filesystem with the primary cache disable to force reads
  55. log_must zfs create -o primarycache=none $TESTPOOL/$TESTFS
  56. log_must zfs set recordsize=16k $TESTPOOL/$TESTFS
  57. # 3. Write a file to the pool to be read back
  58. log_must dd if=/dev/urandom of=$TESTFILE bs=1M count=16
  59. # 4. Inject CHECKSUM ERRORS on read with a zinject error handler
  60. log_must zinject -d $FAULT_FILE -e corrupt -f 50 -T read $TESTPOOL
  61. log_must cp $TESTFILE /dev/null
  62. # 5. Verify the ZED kicks in a hot spare and expected pool/device status
  63. log_note "Wait for ZED to auto-spare"
  64. log_must wait_vdev_state $TESTPOOL $FAULT_FILE "DEGRADED" 60
  65. log_must wait_vdev_state $TESTPOOL $SPARE_FILE "ONLINE" 60
  66. log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "INUSE"
  67. log_must check_state $TESTPOOL "" "DEGRADED"
  68. # 6. Clear the fault
  69. log_must zinject -c all
  70. log_must zpool clear $TESTPOOL $FAULT_FILE
  71. # 7. Verify the hot spare is available and expected pool/device status
  72. log_must wait_vdev_state $TESTPOOL $FAULT_FILE "ONLINE" 60
  73. log_must wait_hotspare_state $TESTPOOL $SPARE_FILE "AVAIL"
  74. log_must check_state $TESTPOOL "" "ONLINE"
  75. cleanup
  76. done
  77. log_pass "Auto-spare test successful"