/tests/zfs-tests/tests/functional/upgrade/upgrade_projectquota_001_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 128 lines · 51 code · 24 blank · 53 comment · 9 complexity · ac756eeb685be7560427ac2d50bb3e59 MD5 · raw file

  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 (c) 2017 by Fan Yong. All rights reserved.
  24. #
  25. . $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib
  26. #
  27. # DESCRIPTION:
  28. #
  29. # Check whether zfs upgrade for project quota works or not.
  30. # The project quota is per dataset based feature, this test
  31. # will create multiple datasets and try different upgrade methods.
  32. #
  33. # STRATEGY:
  34. # 1. Create a pool with all features disabled
  35. # 2. Create a few dataset for testing
  36. # 3. Make sure automatic upgrade work
  37. # 4. Make sure manual upgrade work
  38. #
  39. verify_runnable "global"
  40. if ! lsattr -pd > /dev/null 2>&1; then
  41. log_unsupported "Current lsattr does not support set/show project ID"
  42. fi
  43. log_assert "pool upgrade for projectquota should work"
  44. log_onexit cleanup_upgrade
  45. log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV
  46. log_must mkfiles $TESTDIR/tf $((RANDOM % 100 + 1))
  47. log_must zfs create $TESTPOOL/fs1
  48. log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 100 + 1))
  49. log_must zfs umount $TESTPOOL/fs1
  50. log_must zfs create $TESTPOOL/fs2
  51. log_must mkdir $TESTDIR/fs2/dir
  52. log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 100 + 1))
  53. log_must zfs create $TESTPOOL/fs3
  54. log_must mkdir $TESTDIR/fs3/dir
  55. log_must mkfiles $TESTDIR/fs3/tf $((RANDOM % 100 + 1))
  56. # Make sure project quota is disabled
  57. zfs projectspace -o used $TESTPOOL | grep -q "USED" &&
  58. log_fail "project quota should be disabled initially"
  59. # set projectquota before upgrade will fail
  60. log_mustnot zfs set projectquota@100=100m $TESTDIR/fs3
  61. # set projectobjquota before upgrade will fail
  62. log_mustnot zfs set projectobjquota@100=1000 $TESTDIR/fs3
  63. # 'chattr -p' should fail before upgrade
  64. log_mustnot chattr -p 100 $TESTDIR/fs3/dir
  65. # 'chattr +P' should fail before upgrade
  66. log_mustnot chattr +P $TESTDIR/fs3/dir
  67. # Upgrade zpool to support all features
  68. log_must zpool upgrade $TESTPOOL
  69. # Double check project quota is disabled
  70. zfs projectspace -o used $TESTPOOL | grep -q "USED" &&
  71. log_fail "project quota should be disabled after pool upgrade"
  72. # Mount dataset should trigger upgrade
  73. log_must zfs mount $TESTPOOL/fs1
  74. log_must sleep 3 # upgrade done in the background so let's wait for a while
  75. zfs projectspace -o used $TESTPOOL/fs1 | grep -q "USED" ||
  76. log_fail "project quota should be enabled for $TESTPOOL/fs1"
  77. # Create file should trigger dataset upgrade
  78. log_must mkfile 1m $TESTDIR/fs2/dir/tf
  79. log_must sleep 3 # upgrade done in the background so let's wait for a while
  80. zfs projectspace -o used $TESTPOOL/fs2 | grep -q "USED" ||
  81. log_fail "project quota should be enabled for $TESTPOOL/fs2"
  82. # "lsattr -p" should NOT trigger upgrade
  83. log_must lsattr -p -d $TESTDIR/fs3/dir
  84. zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" &&
  85. log_fail "project quota should not active for $TESTPOOL/fs3"
  86. # 'chattr -p' should trigger dataset upgrade
  87. log_must chattr -p 100 $TESTDIR/fs3/dir
  88. log_must sleep 5 # upgrade done in the background so let's wait for a while
  89. zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" ||
  90. log_fail "project quota should be enabled for $TESTPOOL/fs3"
  91. cnt=$(zfs get -H projectobjused@100 $TESTPOOL/fs3 | awk '{print $3}')
  92. # if 'xattr=on', then 'cnt = 2'
  93. [[ $cnt -ne 1 ]] && [[ $cnt -ne 2 ]] &&
  94. log_fail "projectquota accounting failed $cnt"
  95. # All in all, after having been through this, the dataset for testpool
  96. # still shouldn't be upgraded
  97. zfs projectspace -o used $TESTPOOL | grep -q "USED" &&
  98. log_fail "project quota should be disabled for $TESTPOOL"
  99. # Manual upgrade root dataset
  100. # uses an ioctl which will wait for the upgrade to be done before returning
  101. log_must zfs set version=current $TESTPOOL
  102. zfs projectspace -o used $TESTPOOL | grep -q "USED" ||
  103. log_fail "project quota should be enabled for $TESTPOOL"
  104. log_pass "Project Quota upgrade done"