/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh

https://github.com/adilger/zfs · Korn Shell · 139 lines · 84 code · 13 blank · 42 comment · 9 complexity · 6272a45575d7bb09c8e68b5346b219d9 MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # This file and its contents are supplied under the terms of the
  4. # Common Development and Distribution License ("CDDL"), version 1.0.
  5. # You may only use this file in accordance with the terms of version
  6. # 1.0 of the CDDL.
  7. #
  8. # A full copy of the text of the CDDL should have accompanied this
  9. # source. A copy of the CDDL is also available via the Internet at
  10. # http://www.illumos.org/license/CDDL.
  11. #
  12. #
  13. # Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
  14. #
  15. . $STF_SUITE/include/libtest.shlib
  16. . $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
  17. #
  18. # DESCRIPTION:
  19. # ZFS 'filesystem_limit' is enforced when executing various actions
  20. # NOTE: the limit should *not* be enforced if the user is allowed to change it.
  21. #
  22. # STRATEGY:
  23. # 1. Verify 'zfs create' and 'zfs clone' cannot exceed the filesystem_limit
  24. # 2. Verify 'zfs rename' cannot move filesystems exceeding the limit
  25. # 3. Verify 'zfs receive' cannot exceed the limit
  26. #
  27. verify_runnable "both"
  28. #
  29. # The has_capability() function was first exported in the 4.10 Linux kernel
  30. # then backported to some LTS kernels. Prior to this change there was no
  31. # mechanism to perform the needed permission check. Therefore, this test
  32. # is expected to fail on older kernels and is skipped.
  33. #
  34. if is_linux; then
  35. if [[ $(linux_version) -lt $(linux_version "4.10") ]]; then
  36. log_unsupported "Requires has_capability() kernel function"
  37. fi
  38. fi
  39. function setup
  40. {
  41. # We can't delegate 'mount' privs under Linux: to avoid issues with
  42. # commands that may need to (re)mount datasets we set mountpoint=none
  43. if is_linux; then
  44. log_must zfs create -o mountpoint=none "$DATASET_TEST"
  45. log_must zfs create -o mountpoint=none "$DATASET_UTIL"
  46. else
  47. log_must zfs create "$DATASET_TEST"
  48. log_must zfs create "$DATASET_UTIL"
  49. fi
  50. if is_freebsd; then
  51. # Ensure our non-root user has the permission to create the
  52. # mountpoints and mount the filesystems.
  53. sysctl vfs.usermount=1
  54. log_must chmod 777 $(get_prop mountpoint "$DATASET_TEST")
  55. log_must chmod 777 $(get_prop mountpoint "$DATASET_UTIL")
  56. fi
  57. log_must zfs allow -d -l $STAFF1 'create,mount,rename,clone,receive' \
  58. "$DATASET_TEST"
  59. log_must zfs allow -d -l $STAFF1 'create,mount,rename,clone,receive' \
  60. "$DATASET_UTIL"
  61. }
  62. function cleanup
  63. {
  64. if is_freebsd; then
  65. sysctl vfs.usermount=0
  66. fi
  67. destroy_dataset "$DATASET_TEST" "-Rf"
  68. destroy_dataset "$DATASET_UTIL" "-Rf"
  69. rm -f $ZSTREAM
  70. }
  71. log_assert "Verify 'filesystem_limit' is enforced executing various actions"
  72. log_onexit cleanup
  73. DATASET_TEST="$TESTPOOL/$TESTFS/filesystem_limit_test"
  74. DATASET_UTIL="$TESTPOOL/$TESTFS/filesystem_limit_util"
  75. ZSTREAM="$TEST_BASE_DIR/filesystem_limit.$$"
  76. # 1. Verify 'zfs create' and 'zfs clone' cannot exceed the filesystem_limit
  77. setup
  78. # NOTE: we allow 'canmount' to the non-root user so we can use 'log_must' with
  79. # 'user_run zfs create -o canmount=off' successfully
  80. log_must zfs allow -d -l $STAFF1 'canmount' "$DATASET_TEST"
  81. log_must zfs set filesystem_limit=1 "$DATASET_TEST"
  82. log_must user_run $STAFF1 zfs create -o canmount=off "$DATASET_TEST/create"
  83. log_mustnot user_run $STAFF1 zfs create -o canmount=off "$DATASET_TEST/create_exceed"
  84. log_mustnot datasetexists "$DATASET_TEST/create_exceed"
  85. log_must zfs set filesystem_limit=2 "$DATASET_TEST"
  86. log_must zfs snapshot "$DATASET_TEST/create@snap"
  87. log_must user_run $STAFF1 zfs clone -o canmount=off "$DATASET_TEST/create@snap" "$DATASET_TEST/clone"
  88. log_mustnot user_run $STAFF1 zfs clone -o canmount=off "$DATASET_TEST/create@snap" "$DATASET_TEST/clone_exceed"
  89. log_mustnot datasetexists "$DATASET_TEST/clone_exceed"
  90. log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "2"
  91. # Verify filesystem_limit is *not* enforced for users allowed to change it
  92. log_must zfs create "$DATASET_TEST/create_notenforced_root"
  93. log_must zfs allow -l $STAFF1 'filesystem_limit' "$DATASET_TEST"
  94. log_must user_run $STAFF1 zfs create -o canmount=off "$DATASET_TEST/create_notenforced_user"
  95. log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "4"
  96. cleanup
  97. # 2. Verify 'zfs rename' cannot move filesystems exceeding the limit
  98. setup
  99. log_must zfs set filesystem_limit=0 "$DATASET_UTIL"
  100. log_must zfs create "$DATASET_TEST/rename"
  101. log_mustnot user_run $STAFF1 zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed"
  102. log_mustnot datasetexists "$DATASET_UTIL/renamed"
  103. log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "0"
  104. # Verify filesystem_limit is *not* enforced for users allowed to change it
  105. log_must zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed_notenforced_root"
  106. log_must zfs rename "$DATASET_UTIL/renamed_notenforced_root" "$DATASET_TEST/rename"
  107. log_must zfs allow -l $STAFF1 'filesystem_limit' "$DATASET_UTIL"
  108. log_must user_run $STAFF1 zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed_notenforced_user"
  109. log_must datasetexists "$DATASET_UTIL/renamed_notenforced_user"
  110. cleanup
  111. # 3. Verify 'zfs receive' cannot exceed the limit
  112. setup
  113. log_must zfs set filesystem_limit=0 "$DATASET_TEST"
  114. log_must zfs create "$DATASET_UTIL/send"
  115. log_must zfs snapshot "$DATASET_UTIL/send@snap1"
  116. log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
  117. log_mustnot user_run $STAFF1 eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
  118. log_mustnot datasetexists "$DATASET_TEST/received"
  119. log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
  120. # Verify filesystem_limit is *not* enforced for users allowed to change it
  121. log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
  122. log_must zfs destroy -r "$DATASET_TEST/received"
  123. log_must zfs allow -l $STAFF1 'filesystem_limit' "$DATASET_TEST"
  124. log_must user_run $STAFF1 eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
  125. log_must datasetexists "$DATASET_TEST/received"
  126. log_pass "'filesystem_limit' property is enforced"