PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 239 lines | 127 code | 46 blank | 66 comment | 29 complexity | 4bdb947f6c8fa9c4725cebc86162f9d8 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_003_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. ################################################################################
  32. #
  33. # __stc_assertion_start
  34. #
  35. # ID: zpool_import_missing_003_pos
  36. #
  37. # DESCRIPTION:
  38. # Once a pool has been exported, but one or more devices are
  39. # overlapped with other exported pool, import should handle
  40. # this kind of situation properly.
  41. #
  42. # STRATEGY:
  43. # 1. Repeat 1-3, create two test pools upon device files separately.
  44. # These two pools should have one or more devices are overlapped.
  45. # using the various combinations.
  46. # - Regular pool
  47. # - Mirror
  48. # - Raidz
  49. # 2. Create necessary filesystem and test files.
  50. # 3. Export the test pool.
  51. # 4. Verify 'zpool import -d' with these two pools will have results
  52. # as described:
  53. # - Regular, report error while any number of devices failing.
  54. # - Mirror could withstand (N-1) devices failing
  55. # before data integrity is compromised
  56. # - Raidz could withstand one devices failing
  57. # before data integrity is compromised
  58. #
  59. # TESTABILITY: explicit
  60. #
  61. # TEST_AUTOMATION_LEVEL: automated
  62. #
  63. # CODING_STATUS: COMPLETED (2005-08-10)
  64. #
  65. # __stc_assertion_end
  66. #
  67. ################################################################################
  68. verify_runnable "global"
  69. set -A vdevs "" "mirror" "raidz"
  70. function verify
  71. {
  72. typeset pool=$1
  73. typeset fs=$2
  74. typeset mtpt=$3
  75. typeset health=$4
  76. typeset file=$5
  77. typeset checksum1=$6
  78. typeset myhealth
  79. typeset mymtpt
  80. typeset checksum2
  81. log_must poolexists $pool
  82. myhealth=$($ZPOOL list -H -o health $pool)
  83. [[ $myhealth == $health ]] || \
  84. log_fail "$pool: Incorrect health ($myhealth), " \
  85. "expected ($health)."
  86. log_must ismounted $pool/$fs
  87. mymtpt=$(get_prop mountpoint $pool/$fs)
  88. [[ $mymtpt == $mtpt ]] || \
  89. log_fail "$pool/$fs: Incorrect mountpoint ($mymtpt), " \
  90. "expected ($mtpt)."
  91. [[ ! -e $mtpt/$file ]] && \
  92. log_fail "$mtpt/$file missing after import."
  93. checksum2=$($SUM $mymtpt/$file | $AWK '{print $1}')
  94. [[ "$checksum1" != "$checksum2" ]] && \
  95. log_fail "Checksums differ ($checksum1 != $checksum2)"
  96. return 0
  97. }
  98. function cleanup
  99. {
  100. cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
  101. for pool in $TESTPOOL1 $TESTPOOL2; do
  102. if poolexists "$pool" ; then
  103. cleanup_filesystem $pool $TESTFS
  104. destroy_pool $pool
  105. fi
  106. done
  107. [[ -e $DEVICE_ARCHIVE ]] && log_must $TAR xf $DEVICE_ARCHIVE
  108. }
  109. function cleanup_all
  110. {
  111. cleanup
  112. # recover dev files
  113. typeset i=0
  114. while (( i < $MAX_NUM )); do
  115. log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i
  116. ((i += 1))
  117. done
  118. log_must $RM -f $DEVICE_ARCHIVE
  119. cd $CWD || log_fail "Unable change directory to $CWD"
  120. }
  121. log_onexit cleanup_all
  122. log_assert "Verify that import could handle device overlapped."
  123. CWD=$PWD
  124. cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
  125. log_must $TAR cf $DEVICE_ARCHIVE ${DEVICE_FILE}*
  126. checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
  127. typeset -i i=0
  128. typeset -i j=0
  129. typeset -i count=0
  130. typeset -i num=0
  131. typeset vdev1=""
  132. typeset vdev2=""
  133. typeset action
  134. while (( num < $GROUP_NUM )); do
  135. vdev1="$vdev1 ${DEVICE_DIR}/${DEVICE_FILE}$num"
  136. (( num = num + 1 ))
  137. done
  138. while (( i < ${#vdevs[*]} )); do
  139. j=0
  140. while (( j < ${#vdevs[*]} )); do
  141. (( j != 0 )) && \
  142. log_must $TAR xf $DEVICE_ARCHIVE
  143. typeset -i overlap=1
  144. typeset -i begin
  145. typeset -i end
  146. while (( overlap <= $GROUP_NUM )); do
  147. vdev2=""
  148. (( begin = $GROUP_NUM - overlap ))
  149. (( end = 2 * $GROUP_NUM - overlap - 1 ))
  150. (( num = begin ))
  151. while (( num <= end )); do
  152. vdev2="$vdev2 ${DEVICE_DIR}/${DEVICE_FILE}$num"
  153. (( num = num + 1 ))
  154. done
  155. setup_filesystem "$vdev1" $TESTPOOL1 $TESTFS $TESTDIR1 \
  156. "" ${vdevs[i]}
  157. log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0
  158. log_must $ZFS umount $TESTDIR1
  159. poolexists $TESTPOOL1 && \
  160. log_must $ZPOOL export $TESTPOOL1
  161. setup_filesystem "$vdev2" $TESTPOOL2 $TESTFS $TESTDIR2 \
  162. "" ${vdevs[j]}
  163. log_must $CP $MYTESTFILE $TESTDIR2/$TESTFILE0
  164. log_must $ZFS umount $TESTDIR2
  165. poolexists $TESTPOOL2 && \
  166. log_must $ZPOOL export $TESTPOOL2
  167. action=log_must
  168. case "${vdevs[i]}" in
  169. 'mirror') (( overlap == $GROUP_NUM )) && \
  170. action=log_mustnot
  171. ;;
  172. 'raidz') (( overlap > 1 )) && \
  173. action=log_mustnot
  174. ;;
  175. '') action=log_mustnot
  176. ;;
  177. esac
  178. $action $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
  179. log_must $ZPOOL import -d $DEVICE_DIR $TESTPOOL2
  180. if [[ $action == log_must ]]; then
  181. verify "$TESTPOOL1" "$TESTFS" "$TESTDIR1" \
  182. "DEGRADED" "$TESTFILE0" "$checksum1"
  183. fi
  184. verify "$TESTPOOL2" "$TESTFS" "$TESTDIR2" \
  185. "ONLINE" "$TESTFILE0" "$checksum1"
  186. cleanup
  187. (( overlap = overlap + 1 ))
  188. done
  189. ((j = j + 1))
  190. done
  191. ((i = i + 1))
  192. done
  193. log_pass "Import could handle device overlapped."