/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 163 lines · 85 code · 21 blank · 57 comment · 26 complexity · 42df5307546dff9965ecb9e03ae65b06 MD5 · raw file

  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/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
  30. #
  31. # DESCRIPTION:
  32. # The following options can be set on a temporary basis using the -o option
  33. # without affecting the on-disk property. The original on-disk value will be
  34. # restored when the file system is unmounted and mounted.
  35. #
  36. # PROPERTY MOUNT OPTION
  37. # atime atime/noatime
  38. # devices devices/nodevices
  39. # exec exec/noexec
  40. # readonly ro/rw
  41. # setuid setuid/nosetuid
  42. #
  43. # STRATEGY:
  44. # 1. Create filesystem and get original property value.
  45. # 2. Using 'zfs mount -o' to set filesystem property.
  46. # 3. Verify the property was set temporarily.
  47. # 4. Verify it will not affect the property that is stored on disk.
  48. #
  49. function cleanup
  50. {
  51. if ! ismounted $TESTPOOL/$TESTFS; then
  52. log_must zfs mount $TESTPOOL/$TESTFS
  53. fi
  54. }
  55. log_assert "Verify '-o' will set filesystem property temporarily, " \
  56. "without affecting the property that is stored on disk."
  57. log_onexit cleanup
  58. set -A properties "atime" "exec" "readonly" "setuid"
  59. if ! is_freebsd; then
  60. properties+=("devices")
  61. fi
  62. #
  63. # Get the specified filesystem property reverse mount option.
  64. #
  65. # $1 filesystem
  66. # $2 property
  67. #
  68. function get_reverse_option
  69. {
  70. typeset fs=$1
  71. typeset prop=$2
  72. # Define property value: "reverse if value=on" "reverse if value=off"
  73. if is_linux; then
  74. set -A values "noatime" "atime" \
  75. "noexec" "exec" \
  76. "rw" "ro" \
  77. "nosuid" "suid" \
  78. "nodev" "dev"
  79. elif is_freebsd; then
  80. set -A values "noatime" "atime" \
  81. "noexec" "exec" \
  82. "rw" "ro" \
  83. "nosetuid" "setuid"
  84. else
  85. set -A values "noatime" "atime" \
  86. "noexec" "exec" \
  87. "rw" "ro" \
  88. "nosetuid" "setuid" \
  89. "nodevices" "devices"
  90. fi
  91. typeset -i i=0
  92. while (( i < ${#properties[@]} )); do
  93. if [[ $prop == ${properties[$i]} ]]; then
  94. break
  95. fi
  96. (( i += 1 ))
  97. done
  98. if (( i >= ${#properties[@]} )); then
  99. log_fail "Incorrect option: $prop"
  100. fi
  101. typeset val
  102. typeset -i ind=0
  103. val=$(get_prop $prop $fs) || log_fail "get_prop $prop $fs"
  104. if [[ $val == "on" ]]; then
  105. (( ind = i * 2 ))
  106. else
  107. (( ind = i * 2 + 1 ))
  108. fi
  109. echo ${values[$ind]}
  110. }
  111. fs=$TESTPOOL/$TESTFS
  112. cleanup
  113. for property in ${properties[@]}; do
  114. orig_val=$(get_prop $property $fs)
  115. (($? != 0)) && log_fail "get_prop $property $fs"
  116. # Set filesystem property temporarily
  117. reverse_opt=$(get_reverse_option $fs $property)
  118. log_must zfs unmount $fs
  119. log_must zfs mount -o $reverse_opt $fs
  120. cur_val=$(get_prop $property $fs)
  121. (($? != 0)) && log_fail "get_prop $property $fs"
  122. # In LZ, a user with all zone privileges can never with "devices"
  123. if ! is_global_zone && [[ $property == devices ]] ; then
  124. if [[ $cur_val != off || $orig_val != off ]]; then
  125. log_fail "'devices' property shouldn't " \
  126. "be enabled in LZ"
  127. fi
  128. elif [[ $orig_val == $cur_val ]]; then
  129. log_fail "zfs mount -o $reverse_opt " \
  130. "doesn't change property."
  131. fi
  132. # unmount & mount will revert property to the original value
  133. log_must zfs unmount $fs
  134. log_must zfs mount $fs
  135. cur_val=$(get_prop $property $fs)
  136. (($? != 0)) && log_fail "get_prop $property $fs"
  137. if [[ $orig_val != $cur_val ]]; then
  138. log_fail "zfs mount -o $reverse_opt " \
  139. "change the property that is stored on disks"
  140. fi
  141. done
  142. log_pass "Verify '-o' set filesystem property temporarily passed."