PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 197 lines | 93 code | 43 blank | 61 comment | 22 complexity | 814f3ad5b0a5129584a5e6fb561012df MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  1. #!/bin/ksh -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 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
  31. . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
  32. #
  33. # DESCRIPTION:
  34. # Once a pool has been exported, and one or more devices are
  35. # move to other place, import should handle this kind of situation
  36. # as described:
  37. # - Regular, report error while any number of devices failing.
  38. # - Mirror could withstand (N-1) devices failing
  39. # before data integrity is compromised
  40. # - Raidz could withstand one devices failing
  41. # before data integrity is compromised
  42. # Verify that is true.
  43. #
  44. # STRATEGY:
  45. # 1. Create test pool upon device files 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. Move one or more device files to other directory
  52. # 5. Verify 'zpool import -d' with the new directory
  53. # will handle moved files successfully.
  54. # Using the various combinations.
  55. # - Regular import
  56. # - Alternate Root Specified
  57. #
  58. verify_runnable "global"
  59. set -A vdevs "" "mirror" "raidz"
  60. set -A options "" "-R $ALTER_ROOT"
  61. function cleanup
  62. {
  63. cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
  64. [[ -e $DEVICE_DIR/$DEVICE_ARCHIVE ]] && \
  65. log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
  66. poolexists $TESTPOOL1 || \
  67. log_must zpool import -d $DEVICE_DIR $TESTPOOL1
  68. cleanup_filesystem $TESTPOOL1 $TESTFS
  69. destroy_pool $TESTPOOL1
  70. }
  71. function cleanup_all
  72. {
  73. cleanup
  74. # recover dev files
  75. typeset i=0
  76. while (( i < $MAX_NUM )); do
  77. typeset dev_file=${DEVICE_DIR}/${DEVICE_FILE}$i
  78. if [[ ! -e ${dev_file} ]]; then
  79. log_must mkfile $FILE_SIZE ${dev_file}
  80. fi
  81. ((i += 1))
  82. done
  83. log_must rm -f $DEVICE_DIR/$DEVICE_ARCHIVE
  84. cd $CWD || log_fail "Unable change directory to $CWD"
  85. [[ -d $ALTER_ROOT ]] && \
  86. log_must rm -rf $ALTER_ROOT
  87. [[ -d $BACKUP_DEVICE_DIR ]] && \
  88. log_must rm -rf $BACKUP_DEVICE_DIR
  89. }
  90. log_onexit cleanup_all
  91. log_assert "Verify that import could handle moving device."
  92. CWD=$PWD
  93. [[ ! -d $BACKUP_DEVICE_DIR ]] &&
  94. log_must mkdir -p $BACKUP_DEVICE_DIR
  95. cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
  96. typeset -i i=0
  97. typeset -i j=0
  98. typeset -i count=0
  99. typeset basedir backup
  100. typeset action
  101. while (( i < ${#vdevs[*]} )); do
  102. (( i != 0 )) && \
  103. log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
  104. setup_filesystem "$DEVICE_FILES" \
  105. $TESTPOOL1 $TESTFS $TESTDIR1 \
  106. "" ${vdevs[i]}
  107. guid=$(get_config $TESTPOOL1 pool_guid)
  108. backup=""
  109. log_must cp $MYTESTFILE $TESTDIR1/$TESTFILE0
  110. log_must zfs umount $TESTDIR1
  111. j=0
  112. while (( j < ${#options[*]} )); do
  113. count=0
  114. #
  115. # Restore all device files.
  116. #
  117. [[ -n $backup ]] && \
  118. log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
  119. log_must rm -f $BACKUP_DEVICE_DIR/*
  120. for device in $DEVICE_FILES ; do
  121. poolexists $TESTPOOL1 && \
  122. log_must zpool export $TESTPOOL1
  123. #
  124. # Backup all device files while filesystem prepared.
  125. #
  126. if [[ -z $backup ]] ; then
  127. log_must tar cf $DEVICE_DIR/$DEVICE_ARCHIVE ${DEVICE_FILE}*
  128. backup="true"
  129. fi
  130. log_must mv $device $BACKUP_DEVICE_DIR
  131. (( count = count + 1 ))
  132. action=log_mustnot
  133. case "${vdevs[i]}" in
  134. 'mirror') (( count < $GROUP_NUM )) && \
  135. action=log_must
  136. ;;
  137. 'raidz') (( count == 1 )) && \
  138. action=log_must
  139. ;;
  140. esac
  141. typeset target=$TESTPOOL1
  142. if (( RANDOM % 2 == 0 )) ; then
  143. target=$guid
  144. log_note "Import by guid."
  145. fi
  146. $action zpool import \
  147. -d $DEVICE_DIR ${options[j]} $target
  148. done
  149. ((j = j + 1))
  150. done
  151. cleanup
  152. ((i = i + 1))
  153. done
  154. log_pass "Import could handle moving device."