PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zfsonlinux/zfs
Korn Shell | 146 lines | 76 code | 20 blank | 50 comment | 17 complexity | 0cae678adde02e15c6df0885efba5c43 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 2007 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 should fail with bad parameters or scenarios:
  33. # 1. bad option;
  34. # 2. too many arguments;
  35. # 3. null arguments;
  36. # 4. invalid datasets;
  37. # 5. invalid mountpoint;
  38. # 6. already unmounted zfs filesystem;
  39. # 7. legacy mounted zfs filesystem
  40. #
  41. # STRATEGY:
  42. # 1. Make an array of bad parameters
  43. # 2. Use zfs unmount to unmount the filesystem
  44. # 3. Verify that zfs unmount returns error
  45. #
  46. verify_runnable "both"
  47. function cleanup
  48. {
  49. for ds in $vol $fs1; do
  50. if datasetexists $ds; then
  51. log_must zfs destroy -f $ds
  52. fi
  53. done
  54. if snapexists $snap; then
  55. log_must zfs destroy $snap
  56. fi
  57. if [[ -e /tmp/$file ]]; then
  58. rm -f /tmp/$file
  59. fi
  60. if [[ -d /tmp/$dir ]]; then
  61. rm -rf /tmp/$dir
  62. fi
  63. }
  64. log_assert "zfs unmount fails with bad parameters or scenarios"
  65. log_onexit cleanup
  66. fs=$TESTPOOL/$TESTFS
  67. vol=$TESTPOOL/vol.$$
  68. snap=$TESTPOOL/$TESTFS@snap.$$
  69. set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?"
  70. if ! ismounted $fs; then
  71. log_must zfs mount $fs
  72. fi
  73. log_must zfs snapshot $snap
  74. if is_global_zone; then
  75. log_must zfs create -V 10m $vol
  76. else
  77. vol=""
  78. fi
  79. # Testing bad options
  80. for arg in ${badargs[@]}; do
  81. log_mustnot eval "zfs unmount $arg $fs >/dev/null 2>&1"
  82. done
  83. # Testing invalid datasets
  84. for ds in $snap $vol "blah"; do
  85. for opt in "" "-f"; do
  86. log_mustnot eval "zfs unmount $opt $ds >/dev/null 2>&1"
  87. done
  88. done
  89. # Testing invalid mountpoint
  90. dir=foodir.$$
  91. file=foo.$$
  92. fs1=$TESTPOOL/fs.$$
  93. mkdir /tmp/$dir
  94. touch /tmp/$file
  95. log_must zfs create -o mountpoint=/tmp/$dir $fs1
  96. curpath=`dirname $0`
  97. cd /tmp
  98. for mpt in "./$dir" "./$file" "/tmp"; do
  99. for opt in "" "-f"; do
  100. log_mustnot eval "zfs unmount $opt $mpt >/dev/null 2>&1"
  101. done
  102. done
  103. cd $curpath
  104. # Testing null argument and too many arguments
  105. for opt in "" "-f"; do
  106. log_mustnot eval "zfs unmount $opt >/dev/null 2>&1"
  107. log_mustnot eval "zfs unmount $opt $fs $fs1 >/dev/null 2>&1"
  108. done
  109. # Testing already unmounted filesystem
  110. log_must zfs unmount $fs1
  111. for opt in "" "-f"; do
  112. log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1"
  113. log_mustnot eval "zfs unmount /tmp/$dir >/dev/null 2>&1"
  114. done
  115. # Testing legacy mounted filesystem
  116. log_must zfs set mountpoint=legacy $fs1
  117. if is_linux || is_freebsd; then
  118. log_must mount -t zfs $fs1 /tmp/$dir
  119. else
  120. log_must mount -F zfs $fs1 /tmp/$dir
  121. fi
  122. for opt in "" "-f"; do
  123. log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1"
  124. done
  125. umount /tmp/$dir
  126. log_pass "zfs unmount fails with bad parameters or scenarios as expected."