PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 185 lines | 141 code | 6 blank | 38 comment | 1 complexity | c1d0b3d3baa06228c1f1ac4c0085ba20 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 unshare [-a] <filesystem|mountpoint>' is aware of legacy share.
  33. #
  34. # STRATEGY:
  35. # 1. Set 'zfs set sharenfs=off'
  36. # 2. Use 'share' to share given filesystem
  37. # 3. Verify that 'zfs unshare <filesystem|mountpoint>' is aware of legacy share
  38. # 4. Verify that 'zfs unshare -a' is aware of legacy share.
  39. #
  40. verify_runnable "global"
  41. if is_linux; then
  42. log_unsupported "zfs set sharenfs=off won't unshare if already off"
  43. fi
  44. function cleanup
  45. {
  46. typeset -i i=0
  47. while (( i < ${#mntp_fs[*]} )); do
  48. is_shared ${mntp_fs[i]} && \
  49. log_must eval "unshare_nfs ${mntp_fs[i]}"
  50. ((i = i + 2))
  51. done
  52. if mounted $TESTPOOL/$TESTCLONE; then
  53. log_must zfs unmount $TESTDIR2
  54. fi
  55. [[ -d $TESTDIR2 ]] && \
  56. log_must rm -rf $TESTDIR2
  57. if datasetexists "$TESTPOOL/$TESTCLONE"; then
  58. log_must zfs destroy -f $TESTPOOL/$TESTCLONE
  59. fi
  60. if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then
  61. log_must zfs destroy -f $TESTPOOL/$TESTFS2@snapshot
  62. fi
  63. if datasetexists "$TESTPOOL/$TESTFS2"; then
  64. log_must zfs destroy -f $TESTPOOL/$TESTFS2
  65. fi
  66. }
  67. #
  68. # Main test routine.
  69. #
  70. # Given a mountpoint and file system this routine will attempt
  71. # to verify 'zfs unshare' is aware of legacy share.
  72. #
  73. function test_legacy_unshare # <mntp> <filesystem>
  74. {
  75. typeset mntp=$1
  76. typeset filesystem=$2
  77. log_must zfs set sharenfs=off $filesystem
  78. not_shared $mntp || \
  79. log_fail "'zfs set sharenfs=off' fails to make ZFS " \
  80. "filesystem $filesystem unshared."
  81. log_must eval "share_nfs $mntp"
  82. is_shared $mntp || \
  83. log_fail "'share' command fails to share ZFS file system."
  84. #
  85. # Verify 'zfs unshare <filesystem>' is aware of legacy share.
  86. #
  87. log_mustnot zfs unshare $filesystem
  88. is_shared $mntp || \
  89. log_fail "'zfs unshare <filesystem>' fails to be aware" \
  90. "of legacy share."
  91. #
  92. # Verify 'zfs unshare <filesystem>' is aware of legacy share.
  93. #
  94. log_mustnot zfs unshare $mntp
  95. is_shared $mntp || \
  96. log_fail "'zfs unshare <mountpoint>' fails to be aware" \
  97. "of legacy share."
  98. }
  99. set -A mntp_fs \
  100. "$TESTDIR" "$TESTPOOL/$TESTFS" \
  101. "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
  102. "$TESTDIR2" "$TESTPOOL/$TESTCLONE"
  103. log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share."
  104. log_onexit cleanup
  105. log_must zfs create $TESTPOOL/$TESTFS2
  106. log_must zfs snapshot $TESTPOOL/$TESTFS2@snapshot
  107. log_must zfs clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE
  108. log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE
  109. #
  110. # Invoke 'test_legacy_unshare' routine to verify.
  111. #
  112. typeset -i i=0
  113. while (( i < ${#mntp_fs[*]} )); do
  114. test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]}
  115. ((i = i + 2))
  116. done
  117. log_note "Verify 'zfs unshare -a' is aware of legacy share."
  118. #
  119. # set the 'sharenfs' property to 'off' for each filesystem
  120. #
  121. i=0
  122. while (( i < ${#mntp_fs[*]} )); do
  123. log_must zfs set sharenfs=off ${mntp_fs[((i + 1))]}
  124. not_shared ${mntp_fs[i]} || \
  125. log_fail "'zfs set sharenfs=off' unshares file system failed."
  126. ((i = i + 2))
  127. done
  128. #
  129. # Share each of the file systems via legacy share.
  130. #
  131. i=0
  132. while (( i < ${#mntp_fs[*]} )); do
  133. share_nfs ${mntp_fs[i]}
  134. is_shared ${mntp_fs[i]} || \
  135. log_fail "'share' shares ZFS filesystem failed."
  136. ((i = i + 2))
  137. done
  138. #
  139. # Verify that 'zfs unshare -a' is aware of legacy share
  140. #
  141. log_must zfs unshare -a
  142. #
  143. # verify ZFS filesystems are still shared
  144. #
  145. i=0
  146. while (( i < ${#mntp_fs[*]} )); do
  147. is_shared ${mntp_fs[i]} || \
  148. log_fail "'zfs unshare -a' fails to be aware of legacy share."
  149. ((i = i + 2))
  150. done
  151. log_pass "'zfs unshare [-a]' succeeds to be aware of legacy share."