PageRenderTime 121ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/zfsd/zfsd_fault_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 163 lines | 75 code | 20 blank | 68 comment | 16 complexity | 16e0fcb8253e5256fdc5fb00466bd02f MD5 | raw file
  1. #!/usr/local/bin/ksh93 -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # The contents of this file are subject to the terms of the
  6. # Common Development and Distribution License (the "License").
  7. # You may not use this file except in compliance with the License.
  8. #
  9. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. # or http://www.opensolaris.org/os/licensing.
  11. # See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. #
  14. # When distributing Covered Code, include this CDDL HEADER in each
  15. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. # If applicable, add the following below this CDDL HEADER, with the
  17. # fields enclosed by brackets "[]" replaced with your own identifying
  18. # information: Portions Copyright [yyyy] [name of copyright owner]
  19. #
  20. # CDDL HEADER END
  21. #
  22. #
  23. # Copyright (c) 2012,2013 Spectra Logic Corporation. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. # $FreeBSD$
  27. . $STF_SUITE/include/libtest.kshlib
  28. ################################################################################
  29. #
  30. # __stc_assertion_start
  31. #
  32. # ID: zfsd_fault_001_pos
  33. #
  34. # DESCRIPTION:
  35. # If a vdev experiences IO errors, it will become faulted.
  36. #
  37. #
  38. # STRATEGY:
  39. # 1. Create a storage pool. Only use the da driver (FreeBSD's SCSI disk
  40. # driver) because it has a special interface for simulating IO errors.
  41. # 2. Inject IO errors while doing IO to the pool.
  42. # 3. Verify that the vdev becomes FAULTED.
  43. # 4. ONLINE it and verify that it resilvers and joins the pool.
  44. #
  45. # TESTABILITY: explicit
  46. #
  47. # TEST_AUTOMATION_LEVEL: automated
  48. #
  49. # CODING STATUS: COMPLETED (2012-08-09)
  50. #
  51. # __stc_assertion_end
  52. #
  53. ###############################################################################
  54. verify_runnable "global"
  55. function cleanup
  56. {
  57. # Disable error injection, if still active
  58. sysctl kern.cam.da.$TMPDISKNUM.error_inject=0 > /dev/null
  59. if poolexists $TESTPOOL; then
  60. # We should not get here if the test passed. Print the output
  61. # of zpool status to assist in debugging.
  62. $ZPOOL status
  63. # Clear out artificially generated errors and destroy the pool
  64. $ZPOOL clear $TESTPOOL
  65. destroy_pool $TESTPOOL
  66. fi
  67. }
  68. log_assert "ZFS will fault a vdev that produces IO errors"
  69. log_onexit cleanup
  70. ensure_zfsd_running
  71. # Make sure that at least one of the disks is using the da driver, and use
  72. # that disk for inject errors
  73. typeset TMPDISK=""
  74. for d in $DISKS
  75. do
  76. b=`basename $d`
  77. if test ${b%%[0-9]*} == da
  78. then
  79. TMPDISK=$b
  80. TMPDISKNUM=${b##da}
  81. break
  82. fi
  83. done
  84. if test -z $TMPDISK
  85. then
  86. log_unsupported "This test requires at least one disk to use the da driver"
  87. fi
  88. for type in "raidz" "mirror"; do
  89. log_note "Testing raid type $type"
  90. # Create a pool on the supplied disks
  91. create_pool $TESTPOOL $type $DISKS
  92. log_must $ZFS create $TESTPOOL/$TESTFS
  93. # Cause some IO errors writing to the pool
  94. while true; do
  95. # Running zpool status after every dd operation is too slow.
  96. # So we will run several dd's in a row before checking zpool
  97. # status. sync between dd operations to ensure that the disk
  98. # gets IO
  99. for ((i=0; $i<64; i=$i+1)); do
  100. sysctl kern.cam.da.$TMPDISKNUM.error_inject=1 > \
  101. /dev/null
  102. $DD if=/dev/zero bs=128k count=1 >> \
  103. /$TESTPOOL/$TESTFS/$TESTFILE 2> /dev/null
  104. $FSYNC /$TESTPOOL/$TESTFS/$TESTFILE
  105. done
  106. # Check to see if the pool is faulted yet
  107. $ZPOOL status $TESTPOOL | grep -q 'state: DEGRADED'
  108. if [ $? == 0 ]
  109. then
  110. log_note "$TESTPOOL got degraded"
  111. break
  112. fi
  113. done
  114. log_must check_state $TESTPOOL $TMPDISK "FAULTED"
  115. #find the failed disk guid
  116. typeset FAILED_VDEV=`$ZPOOL status $TESTPOOL |
  117. awk "/^[[:space:]]*$TMPDISK[[:space:]]*FAULTED/ {print \\$1}"`
  118. # Reattach the failed disk
  119. $ZPOOL online $TESTPOOL $FAILED_VDEV > /dev/null
  120. if [ $? != 0 ]; then
  121. log_fail "Could not reattach $FAILED_VDEV"
  122. fi
  123. # Verify that the pool resilvers and goes to the ONLINE state
  124. for (( retries=60; $retries>0; retries=$retries+1 ))
  125. do
  126. $ZPOOL status $TESTPOOL | egrep -q "scan:.*resilvered"
  127. RESILVERED=$?
  128. $ZPOOL status $TESTPOOL | egrep -q "state:.*ONLINE"
  129. ONLINE=$?
  130. if test $RESILVERED -a $ONLINE
  131. then
  132. break
  133. fi
  134. $SLEEP 2
  135. done
  136. if [ $retries == 0 ]
  137. then
  138. log_fail "$TESTPOOL never resilvered in the allowed time"
  139. fi
  140. destroy_pool $TESTPOOL
  141. log_must $RM -rf /$TESTPOOL
  142. done
  143. log_pass