PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/zfsonlinux/zfs
Korn Shell | 150 lines | 90 code | 20 blank | 40 comment | 12 complexity | e546f06934aab94aec0fc2a5f2abbf6a 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) 2012, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
  31. #
  32. # DESCRIPTION:
  33. # Setting valid canmount to filesystem, it is successful.
  34. # Whatever is set to volume or snapshot, it is failed.
  35. # 'zfs set canmount=noauto <fs>'
  36. #
  37. # STRATEGY:
  38. # 1. Setup a pool and create fs, volume, snapshot clone within it.
  39. # 2. Set canmount=noauto for each dataset and check the return value
  40. # and check if it still can be mounted by mount -a.
  41. # 3. mount each dataset(except volume) to see if it can be mounted.
  42. #
  43. verify_runnable "both"
  44. set -A dataset_pos \
  45. "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
  46. if is_global_zone ; then
  47. set -A dataset_neg \
  48. "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
  49. "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1"
  50. else
  51. set -A dataset_neg \
  52. "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
  53. fi
  54. function cleanup
  55. {
  56. i=0
  57. while (( i < ${#dataset_pos[*]} )); do
  58. ds=${dataset_pos[i]}
  59. if datasetexists $ds; then
  60. log_must zfs set mountpoint=${old_mnt[i]} $ds
  61. log_must zfs set canmount=${old_canmount[i]} $ds
  62. fi
  63. (( i = i + 1 ))
  64. done
  65. ds=$TESTPOOL/$TESTCLONE
  66. if datasetexists $ds; then
  67. mntp=$(get_prop mountpoint $ds)
  68. log_must zfs destroy $ds
  69. if [[ -d $mntp ]]; then
  70. rm -fr $mntp
  71. fi
  72. fi
  73. if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
  74. log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
  75. fi
  76. if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
  77. log_must zfs destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
  78. fi
  79. zfs unmount -a > /dev/null 2>&1
  80. log_must zfs mount -a
  81. if [[ -d $tmpmnt ]]; then
  82. rm -fr $tmpmnt
  83. fi
  84. }
  85. log_assert "Setting canmount=noauto to file system, it must be successful."
  86. log_onexit cleanup
  87. set -A old_mnt
  88. set -A old_canmount
  89. typeset tmpmnt=/tmpmount$$
  90. typeset ds
  91. log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
  92. log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
  93. log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
  94. log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
  95. typeset -i i=0
  96. while (( i < ${#dataset_pos[*]} )); do
  97. ds=${dataset_pos[i]}
  98. old_mnt[i]=$(get_prop mountpoint $ds)
  99. old_canmount[i]=$(get_prop canmount $ds)
  100. (( i = i + 1 ))
  101. done
  102. i=0
  103. while (( i < ${#dataset_pos[*]} )) ; do
  104. dataset=${dataset_pos[i]}
  105. set_n_check_prop "noauto" "canmount" "$dataset"
  106. log_must zfs set mountpoint=$tmpmnt $dataset
  107. if ismounted $dataset; then
  108. zfs unmount -a > /dev/null 2>&1
  109. log_must mounted $dataset
  110. log_must zfs unmount $dataset
  111. log_must unmounted $dataset
  112. log_must zfs mount -a
  113. log_must unmounted $dataset
  114. else
  115. log_must zfs mount -a
  116. log_must unmounted $dataset
  117. zfs unmount -a > /dev/null 2>&1
  118. log_must unmounted $dataset
  119. fi
  120. log_must zfs mount $dataset
  121. log_must mounted $dataset
  122. log_must zfs set canmount="${old_canmount[i]}" $dataset
  123. log_must zfs set mountpoint="${old_mnt[i]}" $dataset
  124. (( i = i + 1 ))
  125. done
  126. for dataset in "${dataset_neg[@]}" ; do
  127. set_n_check_prop "noauto" "canmount" "$dataset" "false"
  128. log_mustnot ismounted $dataset
  129. done
  130. log_pass "Setting canmount=noauto to filesystem pass."