/tests/sys/cddl/zfs/tests/cli_root/zfs_set/readonly_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base · Korn Shell · 172 lines · 88 code · 32 blank · 52 comment · 14 complexity · 8c56776758fb6e94988850636819f68f 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 "@(#)readonly_001_pos.ksh 1.1 09/05/19 SMI"
  28. #
  29. . $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
  30. ###############################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: readonly_001_pos
  35. #
  36. # DESCRIPTION:
  37. # Setting readonly on a dataset, it should keep the dataset as readonly.
  38. #
  39. # STRATEGY:
  40. # 1. Create pool, then create filesystem and volume within it.
  41. # 2. Setting readonly to each dataset.
  42. # 3. Check the return value and make sure it is 0.
  43. # 4. Verify the stuff under mountpoint is readonly.
  44. #
  45. # TESTABILITY: explicit
  46. #
  47. # TEST_AUTOMATION_LEVEL: automated
  48. #
  49. # CODING_STATUS: COMPLETED (2009-04-21)
  50. #
  51. # __stc_assertion_end
  52. #
  53. ################################################################################
  54. verify_runnable "both"
  55. function cleanup
  56. {
  57. for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
  58. snapexists ${dataset}@$TESTSNAP && \
  59. log_must $ZFS destroy -R ${dataset}@$TESTSNAP
  60. done
  61. }
  62. function initial_dataset # $1 dataset
  63. {
  64. typeset dataset=$1
  65. typeset fstype=$(get_prop type $dataset)
  66. if [[ $fstype == "filesystem" ]] ; then
  67. typeset mtpt=$(get_prop mountpoint $dataset)
  68. log_must $TOUCH $mtpt/$TESTFILE0
  69. log_must $MKDIR -p $mtpt/$TESTDIR0
  70. fi
  71. }
  72. function cleanup_dataset # $1 dataset
  73. {
  74. typeset dataset=$1
  75. typeset fstype=$(get_prop type $dataset)
  76. if [[ $fstype == "filesystem" ]] ; then
  77. typeset mtpt=$(get_prop mountpoint $dataset)
  78. log_must $RM -f $mtpt/$TESTFILE0
  79. log_must $RM -rf $mtpt/$TESTDIR0
  80. fi
  81. }
  82. function verify_readonly # $1 dataset, $2 on|off
  83. {
  84. typeset dataset=$1
  85. typeset value=$2
  86. if datasetnonexists $dataset ; then
  87. log_note "$dataset not exist!"
  88. return 1
  89. fi
  90. typeset fstype=$(get_prop type $dataset)
  91. expect="log_must"
  92. if [[ $2 == "on" ]] ; then
  93. expect="log_mustnot"
  94. fi
  95. case $fstype in
  96. filesystem)
  97. typeset mtpt=$(get_prop mountpoint $dataset)
  98. $expect $TOUCH $mtpt/$TESTFILE1
  99. $expect $MKDIR -p $mtpt/$TESTDIR1
  100. $expect $ECHO 'y' | $RM $mtpt/$TESTFILE0
  101. $expect $RMDIR $mtpt/$TESTDIR0
  102. if [[ $expect == "log_must" ]] ; then
  103. log_must $ECHO 'y' | $RM $mtpt/$TESTFILE1
  104. log_must $RMDIR $mtpt/$TESTDIR1
  105. log_must $TOUCH $mtpt/$TESTFILE0
  106. log_must $MKDIR -p $mtpt/$TESTDIR0
  107. fi
  108. ;;
  109. volume)
  110. $expect eval "$ECHO 'y' | $NEWFS /dev/zvol/$dataset > /dev/null 2>&1"
  111. ;;
  112. *)
  113. ;;
  114. esac
  115. return 0
  116. }
  117. log_onexit cleanup
  118. log_assert "Setting a valid readonly property on a dataset succeeds."
  119. typeset all_datasets
  120. log_must $ZFS mount -a
  121. log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
  122. log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
  123. if is_global_zone ; then
  124. log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
  125. log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
  126. all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1"
  127. else
  128. all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE"
  129. fi
  130. for dataset in $all_datasets; do
  131. for value in on off; do
  132. set_n_check_prop "off" "readonly" "$dataset"
  133. initial_dataset $dataset
  134. set_n_check_prop "$value" "readonly" "$dataset"
  135. verify_readonly $dataset $value
  136. set_n_check_prop "off" "readonly" "$dataset"
  137. cleanup_dataset $dataset
  138. done
  139. done
  140. log_pass "Setting a valid readonly property on a dataset succeeds."