PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 160 lines | 90 code | 32 blank | 38 comment | 14 complexity | c9f94af85b3d4fdc03792447435c4c46 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) 2014, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
  30. #
  31. # DESCRIPTION:
  32. # Setting readonly on a dataset, it should keep the dataset as readonly.
  33. #
  34. # STRATEGY:
  35. # 1. Create pool, then create filesystem and volume within it.
  36. # 2. Setting readonly to each dataset.
  37. # 3. Check the return value and make sure it is 0.
  38. # 4. Verify the stuff under mountpoint is readonly.
  39. #
  40. verify_runnable "both"
  41. function cleanup
  42. {
  43. for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
  44. snapexists ${dataset}@$TESTSNAP && \
  45. log_must zfs destroy -R ${dataset}@$TESTSNAP
  46. done
  47. }
  48. function initial_dataset # $1 dataset
  49. {
  50. typeset dataset=$1
  51. typeset fstype=$(get_prop type $dataset)
  52. if [[ $fstype == "filesystem" ]] ; then
  53. typeset mtpt=$(get_prop mountpoint $dataset)
  54. log_must touch $mtpt/$TESTFILE0
  55. log_must mkdir -p $mtpt/$TESTDIR0
  56. fi
  57. }
  58. function cleanup_dataset # $1 dataset
  59. {
  60. typeset dataset=$1
  61. typeset fstype=$(get_prop type $dataset)
  62. if [[ $fstype == "filesystem" ]] ; then
  63. typeset mtpt=$(get_prop mountpoint $dataset)
  64. log_must rm -f $mtpt/$TESTFILE0
  65. log_must rm -rf $mtpt/$TESTDIR0
  66. fi
  67. }
  68. function verify_readonly # $1 dataset, $2 on|off
  69. {
  70. typeset dataset=$1
  71. typeset value=$2
  72. if datasetnonexists $dataset ; then
  73. log_note "$dataset does not exist!"
  74. return 1
  75. fi
  76. typeset fstype=$(get_prop type $dataset)
  77. expect="log_must"
  78. if [[ $2 == "on" ]] ; then
  79. expect="log_mustnot"
  80. fi
  81. case $fstype in
  82. filesystem)
  83. typeset mtpt=$(get_prop mountpoint $dataset)
  84. $expect touch $mtpt/$TESTFILE1
  85. $expect mkdir -p $mtpt/$TESTDIR1
  86. $expect eval "echo 'y' | rm $mtpt/$TESTFILE0"
  87. $expect rmdir $mtpt/$TESTDIR0
  88. if [[ $expect == "log_must" ]] ; then
  89. log_must eval "echo 'y' | rm $mtpt/$TESTFILE1"
  90. log_must rmdir $mtpt/$TESTDIR1
  91. log_must touch $mtpt/$TESTFILE0
  92. log_must mkdir -p $mtpt/$TESTDIR0
  93. fi
  94. ;;
  95. volume)
  96. $expect eval "new_fs \
  97. ${ZVOL_DEVDIR}/$dataset > /dev/null 2>&1"
  98. ;;
  99. *)
  100. ;;
  101. esac
  102. return 0
  103. }
  104. log_onexit cleanup
  105. log_assert "Setting a valid readonly property on a dataset succeeds."
  106. typeset all_datasets
  107. log_must zfs mount -a
  108. log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
  109. log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
  110. if is_global_zone ; then
  111. log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
  112. log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
  113. all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL "
  114. all_datasets+="$TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1"
  115. else
  116. all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE"
  117. fi
  118. for dataset in $all_datasets; do
  119. for value in on off; do
  120. set_n_check_prop "off" "readonly" "$dataset"
  121. initial_dataset $dataset
  122. set_n_check_prop "$value" "readonly" "$dataset"
  123. verify_readonly $dataset $value
  124. set_n_check_prop "off" "readonly" "$dataset"
  125. cleanup_dataset $dataset
  126. done
  127. done
  128. log_pass "Setting a valid readonly property on a dataset succeeds."