PageRenderTime 50ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh

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