PageRenderTime 110ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh

https://github.com/freebsd/freebsd
Korn Shell | 141 lines | 63 code | 21 blank | 57 comment | 11 complexity | 444b832252abf85043e93adc81937f2f 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_unmount_009_pos.ksh 1.2 09/05/19 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. ###############################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: zfs_unmount_009_pos
  35. #
  36. # DESCRIPTION:
  37. # Verify that zfs unmount and destroy in a snapshot directory will not cause error.
  38. #
  39. # STRATEGY:
  40. # 1. Create a file in a zfs filesystem, snapshot it and change directory to snapshot directory
  41. # 2. Verify that 'zfs unmount -a' will fail and 'zfs unmount -fa' will succeed
  42. # 3. Verify 'ls' and 'cd /' will succeed
  43. # 4. 'zfs mount -a' and change directory to snapshot directory again
  44. # 5. Verify that zfs destroy snapshot will succeed
  45. # 6. Verify 'ls' and 'cd /' will succeed
  46. # 7. Create zfs filesystem, create a file, snapshot it and change to snapshot directory
  47. # 8. Verify that zpool destroy the pool will succeed
  48. # 9. Verify 'ls' 'cd /' 'zpool list' and etc will succeed
  49. #
  50. # TESTABILITY: explicit
  51. #
  52. # TEST_AUTOMATION_LEVEL: automated
  53. #
  54. # CODING_STATUS: COMPLETED (2008-07-29)
  55. #
  56. # __stc_assertion_end
  57. #
  58. ################################################################################
  59. verify_runnable "both"
  60. function cleanup
  61. {
  62. DISK=${DISKS%% *}
  63. for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
  64. typeset snap=$fs@$TESTSNAP
  65. if snapexists $snap; then
  66. log_must $ZFS destroy $snap
  67. fi
  68. done
  69. if ! poolexists $TESTPOOL && is_global_zone; then
  70. log_must $ZPOOL create $TESTPOOL $DISK
  71. fi
  72. if ! datasetexists $TESTPOOL/$TESTFS; then
  73. log_must $ZFS create $TESTPOOL/$TESTFS
  74. log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  75. fi
  76. }
  77. function restore_dataset
  78. {
  79. if ! datasetexists $TESTPOOL/$TESTFS ; then
  80. log_must $ZFS create $TESTPOOL/$TESTFS
  81. log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  82. log_must cd $TESTDIR
  83. $ECHO hello > world
  84. log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
  85. log_must cd $(get_snapdir_name)/$TESTSNAP
  86. fi
  87. }
  88. log_assert "zfs fource unmount and destroy in snapshot directory will not cause error."
  89. log_onexit cleanup
  90. for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
  91. typeset snap=$fs@$TESTSNAP
  92. typeset mtpt=$(get_prop mountpoint $fs)
  93. log_must cd $mtpt
  94. $ECHO hello > world
  95. log_must $ZFS snapshot $snap
  96. log_must cd $(get_snapdir_name)/$TESTSNAP
  97. log_mustnot $ZFS unmount -a
  98. log_must $ZFS unmount -fa
  99. log_mustnot $LS
  100. log_must cd /
  101. log_must $ZFS mount -a
  102. log_must cd $mtpt
  103. log_must cd $(get_snapdir_name)/$TESTSNAP
  104. if is_global_zone || [[ $fs != $TESTPOOL ]] ; then
  105. log_must $ZFS destroy -rf $fs
  106. log_mustnot $LS
  107. log_must cd /
  108. fi
  109. restore_dataset
  110. done
  111. if is_global_zone ; then
  112. log_must $ZPOOL destroy -f $TESTPOOL
  113. log_mustnot $LS
  114. log_must cd /
  115. fi
  116. log_must eval $ZFS list > /dev/null 2>&1
  117. log_must eval $ZPOOL list > /dev/null 2>&1
  118. log_must eval $ZPOOL status > /dev/null 2>&1
  119. $ZPOOL iostat > /dev/null 2>&1
  120. log_pass "zfs fource unmount and destroy in snapshot directory will not cause error."