PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zfsonlinux/zfs
Korn Shell | 211 lines | 136 code | 27 blank | 48 comment | 29 complexity | 6f82ca2713eeb5bb51e3d71e361fa5c1 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 2009 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, it should be recreated after a
  35. # successful import, all the sub-filesystems within it should all be restored,
  36. # include mount & share status. Verify that is true.
  37. #
  38. # STRATEGY:
  39. # 1. Create the test pool and hierarchical filesystems.
  40. # 2. Export the test pool, or destroy the test pool,
  41. # depend on testing import [-Df].
  42. # 3. Import it using the various combinations.
  43. # - Regular import
  44. # - Alternate Root Specified
  45. # 4. Verify the mount & share status is restored.
  46. #
  47. verify_runnable "global"
  48. set -A pools "$TESTPOOL" "$TESTPOOL1"
  49. set -A devs "" "-d $DEVICE_DIR"
  50. set -A options "" "-R $ALTER_ROOT"
  51. set -A mtpts "$TESTDIR" "$TESTDIR1"
  52. function cleanup
  53. {
  54. typeset -i i=0
  55. while ((i < ${#pools[*]})); do
  56. if poolexists ${pools[i]}; then
  57. log_must zpool export ${pools[i]}
  58. log_note "Try to import ${devs[i]} ${pools[i]}"
  59. zpool import ${devs[i]} ${pools[i]}
  60. else
  61. log_note "Try to import $option ${devs[i]} ${pools[i]}"
  62. zpool import $option ${devs[i]} ${pools[i]}
  63. fi
  64. if poolexists ${pools[i]}; then
  65. is_shared ${pools[i]} && \
  66. log_must zfs set sharenfs=off ${pools[i]}
  67. ismounted "${pools[i]}/$TESTFS" || \
  68. log_must zfs mount ${pools[i]}/$TESTFS
  69. fi
  70. ((i = i + 1))
  71. done
  72. destroy_pool $TESTPOOL1
  73. if datasetexists $TESTPOOL/$TESTFS; then
  74. log_must zfs destroy -Rf $TESTPOOL/$TESTFS
  75. fi
  76. log_must zfs create $TESTPOOL/$TESTFS
  77. log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  78. [[ -d $ALTER_ROOT ]] && \
  79. log_must rm -rf $ALTER_ROOT
  80. }
  81. log_onexit cleanup
  82. log_assert "Verify all mount & share status of sub-filesystems within a pool \
  83. can be restored after import [-Df]."
  84. setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
  85. # create a hierarchy of filesystem
  86. for pool in ${pools[@]} ; do
  87. log_must zfs create $pool/$TESTFS/$TESTCTR
  88. log_must zfs create $pool/$TESTFS/$TESTCTR/$TESTCTR1
  89. log_must zfs set canmount=off $pool/$TESTFS/$TESTCTR
  90. log_must zfs set canmount=off $pool/$TESTFS/$TESTCTR/$TESTCTR1
  91. log_must zfs create $pool/$TESTFS/$TESTCTR/$TESTFS1
  92. log_must zfs create $pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1
  93. log_must zfs create $pool/$TESTFS/$TESTFS1
  94. log_must zfs snapshot $pool/$TESTFS/$TESTFS1@snap
  95. log_must zfs clone $pool/$TESTFS/$TESTFS1@snap $pool/$TESTCLONE1
  96. done
  97. typeset mount_fs="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \
  98. $TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1"
  99. typeset nomount_fs="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1"
  100. typeset -i i=0
  101. typeset -i j=0
  102. typeset -i nfs_share_bit=0
  103. typeset -i guid_bit=0
  104. typeset basedir
  105. for option in "" "-Df"; do
  106. i=0
  107. while ((i < ${#pools[*]})); do
  108. pool=${pools[i]}
  109. guid=$(get_pool_prop guid $pool)
  110. j=0
  111. while ((j < ${#options[*]})); do
  112. # set sharenfs property off/on
  113. nfs_share_bit=0
  114. while ((nfs_share_bit <= 1)); do
  115. typeset f_share=""
  116. typeset nfs_flag="sharenfs=off"
  117. if ((nfs_share_bit == 1)); then
  118. log_note "Set sharenfs=on $pool"
  119. log_must zfs set sharenfs=on $pool
  120. ! is_freebsd && log_must is_shared $pool
  121. f_share="true"
  122. nfs_flag="sharenfs=on"
  123. fi
  124. # for every off/on nfs bit import guid/pool_name
  125. guid_bit=0
  126. while ((guid_bit <= 1)); do
  127. typeset guid_flag="pool name"
  128. if [[ -z $option ]]; then
  129. log_must zpool export $pool
  130. else
  131. log_must zpool destroy $pool
  132. fi
  133. typeset target=$pool
  134. if ((guid_bit == 1)); then
  135. log_note "Import by guid."
  136. if [[ -z $guid ]]; then
  137. log_fail "guid should "\
  138. "not be empty!"
  139. else
  140. target=$guid
  141. guid_flag="$guid"
  142. fi
  143. fi
  144. log_note "Import with $nfs_flag and " \
  145. "$guid_flag"
  146. zpool import $option ${devs[i]} \
  147. ${options[j]} $target
  148. #import by GUID if import by pool name fails
  149. if [[ $? != 0 ]]; then
  150. log_note "Possible pool name" \
  151. "duplicates. Try GUID import"
  152. target=$guid
  153. log_must zpool import $option \
  154. ${devs[i]} ${options[j]} \
  155. $target
  156. fi
  157. log_must poolexists $pool
  158. for fs in $mount_fs; do
  159. log_must ismounted $pool/$fs
  160. [[ -n $f_share ]] && \
  161. ! is_freebsd && \
  162. log_must is_shared $pool/$fs
  163. done
  164. for fs in $nomount_fs; do
  165. log_mustnot ismounted $pool/$fs
  166. ! is_freebsd && \
  167. log_mustnot is_shared $pool/$fs
  168. done
  169. ((guid_bit = guid_bit + 1))
  170. done
  171. # reset nfsshare=off
  172. if [[ -n $f_share ]]; then
  173. log_must zfs set sharenfs=off $pool
  174. ! is_freebsd && log_mustnot is_shared $pool
  175. fi
  176. ((nfs_share_bit = nfs_share_bit + 1))
  177. done
  178. ((j = j + 1))
  179. done
  180. ((i = i + 1))
  181. done
  182. done
  183. log_pass "All mount & share status of sub-filesystems within a pool \
  184. can be restored after import [-Df]."