/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 118 lines · 44 code · 22 blank · 52 comment · 9 complexity · 623cf8420ef4048f2388c56f217bef66 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 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/reservation/reservation.shlib
  31. #
  32. # DESCRIPTION:
  33. #
  34. # When a reservation property of a filesystem, regular volume
  35. # or sparse volume is set to 'none' the space previously consumed by the
  36. # reservation should be released back to the pool
  37. #
  38. # STRATEGY:
  39. # 1) Create a filesystem, regular volume and sparse volume
  40. # 2) Get the space used and available in the pool
  41. # 3) Set a reservation on the filesystem less than the space available.
  42. # 4) Verify that the 'reservation' property for the filesystem has
  43. # the correct value.
  44. # 5) Reset the reservation value back to zero (or 'none')
  45. # 6) Verify that the space used and available totals for the pool have
  46. # changed by the expected amounts (within tolerances).
  47. # 7) Repeat steps 3-6 for a regular volume, sparse volume
  48. #
  49. verify_runnable "both"
  50. log_assert "Verify space released when reservation on a dataset is set "\
  51. "to 'none'"
  52. function cleanup
  53. {
  54. for obj in $OBJ_LIST; do
  55. datasetexists $obj && log_must zfs destroy -f $obj
  56. done
  57. }
  58. log_onexit cleanup
  59. space_avail=`get_prop available $TESTPOOL`
  60. if ! is_global_zone ; then
  61. OBJ_LIST=""
  62. else
  63. OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
  64. ((vol_set_size = space_avail / 4))
  65. vol_set_size=$(floor_volsize $vol_set_size)
  66. ((sparse_vol_set_size = space_avail * 4))
  67. sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
  68. log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL
  69. log_must zfs set reservation=none $TESTPOOL/$TESTVOL
  70. log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
  71. fi
  72. space_avail=`get_prop available $TESTPOOL`
  73. space_used=`get_prop used $TESTPOOL`
  74. # Calculate a large but valid reservation value.
  75. resv_size_set=`expr $space_avail - $RESV_DELTA`
  76. for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
  77. #
  78. # For regular (non-sparse) volumes the upper limit is determined
  79. # not by the space available in the pool but rather by the size
  80. # of the volume itself.
  81. #
  82. [[ $obj == $TESTPOOL/$TESTVOL ]] && \
  83. ((resv_size_set = vol_set_size - RESV_DELTA))
  84. log_must zfs set reservation=$resv_size_set $obj
  85. resv_size_get=`get_prop reservation $obj`
  86. if [[ $resv_size_set != $resv_size_get ]]; then
  87. log_fail "Reservation not the expected value "\
  88. "($resv_size_set != $resv_size_get)"
  89. fi
  90. log_must zfs set reservation=none $obj
  91. new_space_avail=`get_prop available $TESTPOOL`
  92. new_space_used=`get_prop used $TESTPOOL`
  93. log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
  94. log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
  95. done
  96. log_pass "Space correctly released when dataset reservation set to 'none'"