PageRenderTime 29ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 117 lines | 54 code | 21 blank | 42 comment | 12 complexity | e359f9e586d32593fc64d07773ac44f5 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/zpool_destroy/zpool_destroy.cfg
  31. #
  32. # DESCRIPTION:
  33. # 'zpool destroy -f <pool>' can forcely destroy the specified pool.
  34. #
  35. # STRATEGY:
  36. # 1. Create a storage pool
  37. # 2. Create some datasets within the pool
  38. # 3. Change directory to any mountpoint of these datasets,
  39. # Verify 'zpool destroy' without '-f' will fail.
  40. # 4. 'zpool destroy -f' the pool
  41. # 5. Verify the pool is destroyed successfully
  42. #
  43. verify_runnable "global"
  44. function cleanup
  45. {
  46. [[ -n $cwd ]] && log_must cd $cwd
  47. if [[ -d $TESTDIR ]]; then
  48. ismounted $TESTDIR && log_must umount $TESTDIR
  49. log_must rm -rf $TESTDIR
  50. fi
  51. typeset -i i=0
  52. while (( $i < ${#datasets[*]} )); do
  53. datasetexists ${datasets[i]} && \
  54. log_must zfs destroy ${datasets[i]}
  55. (( i = i + 1 ))
  56. done
  57. poolexists $TESTPOOL && destroy_pool $TESTPOOL
  58. }
  59. set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \
  60. "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \
  61. log_assert "'zpool destroy -f <pool>' can forcely destroy the specified pool"
  62. log_onexit cleanup
  63. create_pool $TESTPOOL $DISK0
  64. log_must zfs create $TESTPOOL/$TESTFS
  65. log_must mkdir -p $TESTDIR
  66. log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  67. log_must zfs create $TESTPOOL/$TESTCTR
  68. log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1
  69. log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL
  70. typeset -i i=0
  71. while (( $i < ${#datasets[*]} )); do
  72. datasetexists "${datasets[i]}" || \
  73. log_fail "Create datasets fail."
  74. ((i = i + 1))
  75. done
  76. log_note "'zpool destroy' without '-f' will fail " \
  77. "while pool is busy."
  78. for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do
  79. log_must cd $dir
  80. log_mustnot zpool destroy $TESTPOOL
  81. # Need mount here, otherwise some dataset may be unmounted.
  82. log_must zfs mount -a
  83. i=0
  84. while (( i < ${#datasets[*]} )); do
  85. datasetexists "${datasets[i]}" || \
  86. log_fail "Dataset ${datasets[i]} removed unexpected."
  87. ((i = i + 1))
  88. done
  89. done
  90. # 4. 'zpool destroy -f' the pool (unsupported behavior in Linux)
  91. if is_linux; then
  92. log_must cd $cwd
  93. fi
  94. destroy_pool $TESTPOOL
  95. log_mustnot poolexists "$TESTPOOL"
  96. log_pass "'zpool destroy -f <pool>' success."