PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/freebsd/freebsd
Korn Shell | 194 lines | 108 code | 29 blank | 57 comment | 21 complexity | 5ec77e71388b1d7d2ecf6719a90a3695 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 "@(#)zpool_import_012_pos.ksh 1.4 09/05/19 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_012_pos
  36. #
  37. # DESCRIPTION:
  38. # Once a pool has been exported, it should be recreated after a
  39. # successful import, all the sub-filesystems within it should all be restored,
  40. # include mount & share status. Verify that is true.
  41. #
  42. # STRATEGY:
  43. # 1. Create the test pool and hierarchical filesystems.
  44. # 2. Export the test pool, or destroy the test pool,
  45. # depend on testing import [-Df].
  46. # 3. Import it using the various combinations.
  47. # - Regular import
  48. # - Alternate Root Specified
  49. # 4. Verify the mount & share status is restored.
  50. #
  51. # TESTABILITY: explicit
  52. #
  53. # TEST_AUTOMATION_LEVEL: automated
  54. #
  55. # CODING_STATUS: COMPLETED (2006-11-01)
  56. #
  57. # __stc_assertion_end
  58. #
  59. ################################################################################
  60. verify_runnable "global"
  61. set -A pools "$TESTPOOL" "$TESTPOOL1"
  62. set -A devs "" "-d $DEVICE_DIR"
  63. set -A options "" "-R $ALTER_ROOT"
  64. set -A mtpts "$TESTDIR" "$TESTDIR1"
  65. function cleanup
  66. {
  67. typeset -i i=0
  68. while (( i < ${#pools[*]} )); do
  69. if poolexists ${pools[i]} ; then
  70. log_must $ZPOOL export ${pools[i]}
  71. log_note "Try to import ${devs[i]} ${pools[i]}"
  72. $ZPOOL import ${devs[i]} ${pools[i]}
  73. else
  74. log_note "Try to import $option ${devs[i]} ${pools[i]}"
  75. $ZPOOL import $option ${devs[i]} ${pools[i]}
  76. fi
  77. if poolexists ${pools[i]} ; then
  78. is_shared ${pools[i]} && \
  79. log_must $ZFS set sharenfs=off ${pools[i]}
  80. ismounted "${pools[i]}/$TESTFS" || \
  81. log_must $ZFS mount ${pools[i]}/$TESTFS
  82. fi
  83. ((i = i + 1))
  84. done
  85. destroy_pool $TESTPOOL1
  86. if datasetexists $TESTPOOL/$TESTFS ; then
  87. log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
  88. fi
  89. log_must $ZFS create $TESTPOOL/$TESTFS
  90. log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  91. [[ -d $ALTER_ROOT ]] && \
  92. log_must $RM -rf $ALTER_ROOT
  93. }
  94. log_onexit cleanup
  95. log_assert "Verify all mount & share status of sub-filesystems within a pool \
  96. can be restored after import [-Df]."
  97. setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
  98. for pool in ${pools[@]} ; do
  99. log_must $ZFS create $pool/$TESTFS/$TESTCTR
  100. log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1
  101. log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR
  102. log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR/$TESTCTR1
  103. log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTFS1
  104. log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1
  105. log_must $ZFS create $pool/$TESTFS/$TESTFS1
  106. log_must $ZFS snapshot $pool/$TESTFS/$TESTFS1@snap
  107. log_must $ZFS clone $pool/$TESTFS/$TESTFS1@snap $pool/$TESTCLONE1
  108. done
  109. typeset mount_fs="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \
  110. $TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1"
  111. typeset nomount_fs="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1"
  112. typeset -i i=0
  113. typeset -i j=0
  114. typeset basedir
  115. for option in "" "-Df" ; do
  116. i=0
  117. while (( i < ${#pools[*]} )); do
  118. pool=${pools[i]}
  119. guid=$(get_config $pool pool_guid)
  120. j=0
  121. while (( j < ${#options[*]} )); do
  122. typeset f_share=""
  123. if ((RANDOM % 2 == 0)); then
  124. log_note "Set sharenfs=on $pool"
  125. log_must $ZFS set sharenfs=on $pool
  126. log_must is_shared $pool
  127. f_share="true"
  128. fi
  129. if [[ -z $option ]]; then
  130. log_must $ZPOOL export $pool
  131. else
  132. log_must $ZPOOL destroy $pool
  133. fi
  134. typeset target=$pool
  135. if (( RANDOM % 2 == 0 )) ; then
  136. log_note "Import by guid."
  137. if [[ -z $guid ]]; then
  138. log_fail "guid should not be empty!"
  139. else
  140. target=$guid
  141. fi
  142. fi
  143. log_must $ZPOOL import $option \
  144. ${devs[i]} ${options[j]} $target
  145. log_must poolexists $pool
  146. for fs in $mount_fs ; do
  147. log_must ismounted $pool/$fs
  148. [[ -n $f_share ]] && \
  149. log_must is_shared $pool/$fs
  150. done
  151. for fs in $nomount_fs ; do
  152. log_mustnot ismounted $pool/$fs
  153. log_mustnot is_shared $pool/$fs
  154. done
  155. if [[ -n $f_share ]] ; then
  156. log_must $ZFS set sharenfs=off $pool
  157. log_mustnot is_shared $pool
  158. fi
  159. ((j = j + 1))
  160. done
  161. ((i = i + 1))
  162. done
  163. done
  164. log_pass "All mount & share status of sub-filesystems within a pool \
  165. can be restored after import [-Df]."