PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 171 lines | 71 code | 26 blank | 74 comment | 19 complexity | d26252755d5547ef157bdf48e4729fa3 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. # $FreeBSD$
  23. #
  24. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)zpool_import_missing_001_pos.ksh 1.4 07/10/09 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. . $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
  31. . $STF_SUITE/tests/cli_root/zpool_import/zpool_import.kshlib
  32. ################################################################################
  33. #
  34. # __stc_assertion_start
  35. #
  36. # ID: zpool_import_missing_001_pos
  37. #
  38. # DESCRIPTION:
  39. # Once a pool has been exported, and one or more devices are
  40. # damaged or missing (d/m), import should handle this kind of situation
  41. # as described:
  42. # - Regular, report error while any number of devices failing.
  43. # - Mirror could withstand (N-1) devices failing
  44. # before data integrity is compromised
  45. # - Raidz could withstand one devices failing
  46. # before data integrity is compromised
  47. # Verify those are true.
  48. #
  49. # STRATEGY:
  50. # 1. Create test pool upon device files using the various combinations.
  51. # - Regular pool
  52. # - Mirror
  53. # - Raidz
  54. # 2. Create necessary filesystem and test files.
  55. # 3. Export the test pool.
  56. # 4. Remove one or more devices
  57. # 5. Verify 'zpool import' will handle d/m device successfully.
  58. # Using the various combinations.
  59. # - Regular import
  60. # - Alternate Root Specified
  61. # It should be succeed with single d/m device upon 'raidz' & 'mirror',
  62. # but failed against 'regular' or more d/m devices.
  63. # 6. If import succeed, verify following is true:
  64. # - The pool shows up under 'zpool list'.
  65. # - The pool's health should be DEGRADED.
  66. # - It contains the correct test file
  67. #
  68. # TESTABILITY: explicit
  69. #
  70. # TEST_AUTOMATION_LEVEL: automated
  71. #
  72. # CODING_STATUS: COMPLETED (2005-08-01)
  73. #
  74. # __stc_assertion_end
  75. #
  76. ################################################################################
  77. verify_runnable "global"
  78. set -A vdevs "" "mirror" "raidz"
  79. set -A options "" "-R $ALTER_ROOT"
  80. function perform_inner_test
  81. {
  82. typeset action=$1
  83. typeset import_opts=$2
  84. typeset target=$3
  85. typeset basedir
  86. $action $ZPOOL import -d $DEVICE_DIR ${import_opts} $target
  87. [[ $action == "log_mustnot" ]] && return
  88. log_must poolexists $TESTPOOL1
  89. health=$($ZPOOL list -H -o health $TESTPOOL1)
  90. [[ "$health" == "DEGRADED" ]] || \
  91. log_fail "ERROR: $TESTPOOL1: Incorrect health '$health'"
  92. log_must ismounted $TESTPOOL1/$TESTFS
  93. basedir=$TESTDIR1
  94. [[ -n "${import_opts}" ]] && basedir=$ALTER_ROOT/$TESTDIR1
  95. [[ ! -e "$basedir/$TESTFILE0" ]] && \
  96. log_fail "ERROR: $basedir/$TESTFILE0 missing after import."
  97. checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
  98. [[ "$checksum1" != "$checksum2" ]] && \
  99. log_fail "ERROR: Checksums differ ($checksum1 != $checksum2)"
  100. log_must $ZPOOL export $TESTPOOL1
  101. }
  102. log_onexit cleanup_missing
  103. log_assert "Verify that import could handle damaged or missing device."
  104. CWD=$PWD
  105. cd $DEVICE_DIR || log_fail "ERROR: Unable change directory to $DEVICE_DIR"
  106. checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
  107. typeset -i i=0
  108. while :; do
  109. typeset vdtype="${vdevs[i]}"
  110. typeset -i j=0
  111. while (( j < ${#options[*]} )); do
  112. typeset opts="${options[j]}"
  113. [ -n "$vdtype" ] && typestr="$vdtype" || typestr="stripe"
  114. # Prepare the pool.
  115. setup_missing_test_pool $vdtype
  116. guid=$(get_config $TESTPOOL1 pool_guid $DEVICE_DIR)
  117. log_note "*** Testing $typestr tvd guid $guid opts '${opts}'"
  118. typeset -i count=0
  119. for device in $DEVICE_FILES ; do
  120. log_mustnot poolexists $TESTPOOL1
  121. log_must $RM -f $device
  122. (( count = count + 1 ))
  123. action=log_must
  124. case "$vdtype" in
  125. 'mirror') (( count == $GROUP_NUM )) && \
  126. action=log_mustnot
  127. ;;
  128. 'raidz') (( count > 1 )) && \
  129. action=log_mustnot
  130. ;;
  131. '') action=log_mustnot
  132. ;;
  133. esac
  134. log_note "Testing import by name; ${count} removed."
  135. perform_inner_test $action "${opts}" $TESTPOOL1
  136. log_note "Testing import by GUID; ${count} removed."
  137. perform_inner_test $action "${opts}" $guid
  138. done
  139. recreate_missing_files
  140. (( j = j + 1 ))
  141. done
  142. (( i = i + 1 ))
  143. (( i == ${#vdevs[*]} )) && break
  144. done
  145. log_pass "Import could handle damaged or missing device."