PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/hotspare/hotspare_import_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 167 lines | 67 code | 27 blank | 73 comment | 12 complexity | b4a98e3e0fc27f7625cece12949d78fd 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 2009 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)hotspare_import_001_pos.ksh 1.4 09/06/22 SMI"
  28. #
  29. . $STF_SUITE/tests/hotspare/hotspare.kshlib
  30. ################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: hotspare_import_001_pos
  35. #
  36. # DESCRIPTION:
  37. # If a storage pool has hot spare,
  38. # regardless it has been activated or NOT,
  39. # invoke "zpool export" then import with this storage pool
  40. # should runs successfully, and the data should keep integrity
  41. # after import.
  42. #
  43. # STRATEGY:
  44. # 1. Create a storage pool with hot spares
  45. # 2. Do 'zpool export' then 'zpool import' with following scernarios
  46. # - the hotspare is only in available list
  47. # - the hotspare is activated
  48. # - the hotspare is activated but offline
  49. # - the hotspare is activated but the basic vdev is offline
  50. # 3. Verify the export/import runs successfully,
  51. # and the data keep integrity after import
  52. #
  53. # TESTABILITY: explicit
  54. #
  55. # TEST_AUTOMATION_LEVEL: automated
  56. #
  57. # CODING STATUS: COMPLETED (2006-06-14)
  58. #
  59. # __stc_assertion_end
  60. #
  61. ###############################################################################
  62. verify_runnable "global"
  63. function cleanup
  64. {
  65. poolexists $TESTPOOL && \
  66. destroy_pool $TESTPOOL
  67. partition_cleanup
  68. }
  69. function verify_export_import #pool #file #chksum
  70. {
  71. typeset pool=$1
  72. typeset file=$2
  73. typeset checksum1=$3
  74. typeset -i n=0
  75. if ! $ZPOOL export $pool; then
  76. # Rarely, this can fail with EBUSY if the pool's configuration
  77. # has already changed within the same transaction group. In
  78. # that case, it is appropriate to retry.
  79. while ((n < 3)); do
  80. $SYNC
  81. log_note "$ZPOOL busy, retrying export (${n})..."
  82. if ((n == 2)); then
  83. log_must $ZPOOL export $pool
  84. else
  85. $ZPOOL export $pool && break
  86. fi
  87. $SLEEP 1
  88. n=$((n + 1))
  89. done
  90. fi
  91. log_must $ZPOOL import -d $HOTSPARE_TMPDIR $pool
  92. [[ ! -e $file ]] && \
  93. log_fail "$file missing after detach hotspare."
  94. checksum2=$($SUM $file | $AWK '{print $1}')
  95. [[ "$checksum1" != "$checksum2" ]] && \
  96. log_fail "Checksums differ ($checksum1 != $checksum2)"
  97. return 0
  98. }
  99. function verify_assertion # dev
  100. {
  101. typeset dev=$1
  102. typeset odev=${pooldevs[0]}
  103. #
  104. # - the hotspare is activated
  105. #
  106. log_must $ZPOOL replace $TESTPOOL $odev $dev
  107. while ! is_pool_resilvered $TESTPOOL ; do
  108. $SLEEP 2
  109. done
  110. verify_export_import $TESTPOOL \
  111. $mtpt/$TESTFILE0 $checksum1
  112. #
  113. # - the hotspare is activated
  114. # but the basic vdev is offline
  115. #
  116. log_must $ZPOOL offline $TESTPOOL $odev
  117. verify_export_import $TESTPOOL \
  118. $mtpt/$TESTFILE0 $checksum1
  119. log_must $ZPOOL online $TESTPOOL $odev
  120. log_must $ZPOOL detach $TESTPOOL $dev
  121. }
  122. log_assert "'zpool export/import <pool>' should runs successfully regardless the hotspare is only in list, activated, or offline."
  123. log_onexit cleanup
  124. typeset mtpt=""
  125. set_devs
  126. checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
  127. for keyword in "${keywords[@]}" ; do
  128. setup_hotspares "$keyword"
  129. mtpt=$(get_prop mountpoint $TESTPOOL)
  130. log_must $CP $MYTESTFILE $mtpt/$TESTFILE0
  131. #
  132. # - the hotspare is only in available list
  133. #
  134. verify_export_import $TESTPOOL \
  135. $mtpt/$TESTFILE0 $checksum1
  136. iterate_over_hotspares verify_assertion "${vdev%% *}"
  137. log_must $RM -f $mtpt/$TESTFILE0
  138. destroy_pool "$TESTPOOL"
  139. done
  140. log_pass "'zpool export/import <pool>' should runs successfully regardless the hotspare is only in list, activated, or offline."