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

/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 215 lines | 128 code | 17 blank | 70 comment | 36 complexity | a09b81d991da5cbaafafc0f75efddb28 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 "@(#)zfs_destroy_001_pos.ksh 1.3 09/08/06 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. . $STF_SUITE/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib
  31. #################################################################################
  32. #
  33. # __stc_assertion_start
  34. #
  35. # ID: zfs_destroy_001_pos
  36. #
  37. # DESCRIPTION:
  38. # 'zfs destroy -r|-rf|-R|-Rf <fs|ctr|vol|snap>' should recursively destroy
  39. # all children and clones based on options.
  40. #
  41. # STRATEGY:
  42. # 1. Create test environment according to options. There are three test
  43. # models can be created. Only ctr, fs & vol; with snap; with clone.
  44. # 2. According to option, make the dataset busy or not.
  45. # 3. Run 'zfs destroy [-rRf] <dataset>'
  46. # 4. According to dataset and option, check if get the expected results.
  47. #
  48. # TESTABILITY: explicit
  49. #
  50. # TEST_AUTOMATION_LEVEL: automated
  51. #
  52. # CODING_STATUS: COMPLETED (2005-07-22)
  53. #
  54. # __stc_assertion_end
  55. #
  56. ################################################################################
  57. verify_runnable "both"
  58. #
  59. # According to parameters, 1st, create suitable testing environment. 2nd,
  60. # run 'zfs destroy $opt <dataset>'. 3rd, check the system status.
  61. #
  62. # $1 option of 'zfs destroy'
  63. # $2 dataset will be destroied.
  64. #
  65. function test_n_check
  66. {
  67. typeset opt=$1
  68. typeset dtst=$2
  69. if ! is_global_zone ; then
  70. if [[ $dtst == $VOL || $dtst == $VOLSNAP ]]; then
  71. log_note "UNSUPPORTED: Volume are unavailable in LZ."
  72. return
  73. fi
  74. fi
  75. # '-f' has no effect on non-filesystems
  76. if [[ $opt == -f ]]; then
  77. if [[ $dtst != $FS || $dtst != $CTR ]]; then
  78. log_note "UNSUPPORTED: '-f ' is only available for FS."
  79. return
  80. fi
  81. fi
  82. # Clean the test environment and make it clear.
  83. if datasetexists $CTR; then
  84. log_must $ZFS destroy -Rf $CTR
  85. fi
  86. # According to option create test compatible environment.
  87. case $opt in
  88. -r|-rf) setup_testenv snap ;;
  89. -R|-Rf) setup_testenv clone ;;
  90. -f) setup_testenv ;;
  91. *) log_fail "Incorrect option: '$opt'." ;;
  92. esac
  93. #
  94. # According to different dataset type, create busy condition when try to
  95. # destroy this dataset.
  96. #
  97. typeset mpt_dir
  98. case $dtst in
  99. $CTR|$FS)
  100. if [[ $opt == *f* ]]; then
  101. mpt_dir=$(get_prop mountpoint $FS)
  102. make_dir_busy $mpt_dir
  103. log_mustnot $ZFS destroy -rR $dtst
  104. make_dir_unbusy $mpt_dir
  105. fi
  106. ;;
  107. $VOL)
  108. if [[ $opt == *f* ]]; then
  109. make_dir_busy $TESTDIR1
  110. log_mustnot $ZFS destroy -rR $dtst
  111. make_dir_unbusy $TESTDIR1
  112. fi
  113. ;;
  114. $FSSNAP)
  115. if [[ $opt == *f* ]]; then
  116. mpt_dir=$(snapshot_mountpoint $dtst)
  117. init_dir=$PWD
  118. make_dir_busy $mpt_dir
  119. log_must $ZFS destroy -rR $dtst
  120. log_must $ZFS snapshot $dtst
  121. make_dir_unbusy $mpt_dir
  122. fi
  123. ;;
  124. $VOLSNAP)
  125. if [[ $opt == *f* ]]; then
  126. mpt_dir=$TESTDIR1
  127. init_dir=$PWD
  128. make_dir_busy $mpt_dir
  129. log_must $ZFS destroy -rR $dtst
  130. log_must $ZFS snapshot $dtst
  131. make_dir_unbusy $mpt_dir
  132. fi
  133. ;;
  134. *) log_fail "Unsupported dataset: '$dtst'."
  135. esac
  136. # Firstly, umount ufs filesystem which was created by zfs volume.
  137. if is_global_zone; then
  138. log_must $UMOUNT -f $TESTDIR1
  139. fi
  140. # Invoke 'zfs destroy [-rRf] <dataset>'
  141. log_must $ZFS destroy $opt $dtst
  142. case $dtst in
  143. $CTR) check_dataset datasetnonexists \
  144. $CTR $FS $VOL $FSSNAP $VOLSNAP
  145. if [[ $opt == *R* ]]; then
  146. check_dataset datasetnonexists \
  147. $FSCLONE $VOLCLONE
  148. fi
  149. ;;
  150. $FS) check_dataset datasetexists $CTR $VOL
  151. check_dataset datasetnonexists $FS
  152. if [[ $opt != -f ]]; then
  153. check_dataset datasetexists $VOLSNAP
  154. check_dataset datasetnonexists $FSSNAP
  155. fi
  156. if [[ $opt == *R* ]]; then
  157. check_dataset datasetexists $VOLCLONE
  158. check_dataset datasetnonexists $FSCLONE
  159. fi
  160. ;;
  161. $VOL) check_dataset datasetexists $CTR $FS $FSSNAP
  162. check_dataset datasetnonexists $VOL $VOLSNAP
  163. if [[ $opt == *R* ]]; then
  164. check_dataset datasetexists $FSCLONE
  165. check_dataset datasetnonexists $VOLCLONE
  166. fi
  167. ;;
  168. $FSSNAP)
  169. check_dataset datasetexists $CTR $FS $VOL $VOLSNAP
  170. check_dataset datasetnonexists $FSSNAP
  171. if [[ $opt == *R* ]]; then
  172. check_dataset datasetexists $VOLCLONE
  173. check_dataset datasetnonexists $FSCLONE
  174. fi
  175. ;;
  176. $VOLSNAP)
  177. check_dataset datasetexists $CTR $FS $VOL $FSSNAP
  178. check_dataset datasetnonexists $VOLSNAP
  179. if [[ $opt == *R* ]]; then
  180. check_dataset datasetexists $FSCLONE
  181. check_dataset datasetnonexists $VOLCLONE
  182. fi
  183. ;;
  184. esac
  185. log_note "'$ZFS destroy $opt $dtst' passed."
  186. }
  187. log_assert "'zfs destroy -r|-R|-f|-rf|-Rf <fs|ctr|vol|snap>' should " \
  188. "recursively destroy all children."
  189. log_onexit cleanup_testenv
  190. typeset dtst=""
  191. typeset opt=""
  192. for dtst in $CTR $FS $VOL $FSSNAP $VOLSNAP; do
  193. for opt in "-r" "-R" "-f" "-rf" "-Rf"; do
  194. log_note "Starting test: $ZFS destroy $opt $dtst"
  195. test_n_check $opt $dtst
  196. done
  197. done
  198. log_pass "'zfs destroy -r|-R|-f|-rf|-Rf <fs|ctr|vol|snap>' passed."