PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 149 lines | 65 code | 29 blank | 55 comment | 12 complexity | 0fbcf6145ac35bd34d1dbb6fb15391b5 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 set sharenfs' and 'zfs share' shares a given dataset.
  33. #
  34. # STRATEGY:
  35. # 1. Invoke 'zfs set sharenfs'.
  36. # 2. Verify that the file system is shared.
  37. # 3. Invoke 'zfs share'.
  38. # 4. Verify that the file system is shared.
  39. # 5. Verify that a shared filesystem cannot be shared again.
  40. # 6. Verify that share -a succeeds.
  41. #
  42. verify_runnable "global"
  43. set -A fs \
  44. "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
  45. "$TESTDIR2" "$TESTPOOL/$TESTFS-clone" \
  46. "$TESTDIR" "$TESTPOOL/$TESTFS"
  47. function cleanup
  48. {
  49. typeset -i i=0
  50. while (( i < ${#fs[*]} )); do
  51. log_must zfs set sharenfs=off ${fs[((i+1))]}
  52. unshare_fs ${fs[i]}
  53. ((i = i + 2))
  54. done
  55. if mounted $TESTPOOL/$TESTFS-clone; then
  56. log_must zfs unmount $TESTDIR2
  57. fi
  58. datasetexists $TESTPOOL/$TESTFS-clone && \
  59. log_must zfs destroy -f $TESTPOOL/$TESTFS-clone
  60. if snapexists "$TESTPOOL/$TESTFS@snapshot"; then
  61. log_must zfs destroy -f $TESTPOOL/$TESTFS@snapshot
  62. fi
  63. }
  64. #
  65. # Main test routine.
  66. #
  67. # Given a mountpoint and file system this routine will attempt
  68. # share the mountpoint and then verify it has been shared.
  69. #
  70. function test_share # mntp filesystem
  71. {
  72. typeset mntp=$1
  73. typeset filesystem=$2
  74. not_shared $mntp || \
  75. log_fail "File system $filesystem is already shared."
  76. log_must zfs set sharenfs=on $filesystem
  77. is_shared $mntp || \
  78. log_fail "File system $filesystem is not shared (set sharenfs)."
  79. #
  80. # Verify 'zfs share' works as well.
  81. #
  82. log_must zfs unshare $filesystem
  83. is_shared $mntp && \
  84. log_fail "File system $filesystem is still shared."
  85. log_must zfs share $filesystem
  86. is_shared $mntp || \
  87. log_fail "file system $filesystem is not shared (zfs share)."
  88. log_note "Sharing a shared file system fails."
  89. log_mustnot zfs share $filesystem
  90. }
  91. log_assert "Verify that 'zfs share' succeeds as root."
  92. log_onexit cleanup
  93. log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot
  94. log_must zfs clone $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS-clone
  95. log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS-clone
  96. typeset -i i=0
  97. while (( i < ${#fs[*]} )); do
  98. test_share ${fs[i]} ${fs[((i + 1))]}
  99. ((i = i + 2))
  100. done
  101. log_note "Verify 'zfs share -a' succeeds."
  102. #
  103. # Unshare each of the file systems.
  104. #
  105. i=0
  106. while (( i < ${#fs[*]} )); do
  107. unshare_fs ${fs[i]}
  108. ((i = i + 2))
  109. done
  110. #
  111. # Try a zfs share -a and verify all file systems are shared.
  112. #
  113. log_must zfs share -a
  114. i=0
  115. while (( i < ${#fs[*]} )); do
  116. is_shared ${fs[i]} || \
  117. log_fail "File system ${fs[i]} is not shared (share -a)"
  118. ((i = i + 2))
  119. done
  120. log_pass "'zfs share [ -a ] <filesystem>' succeeds as root."