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

https://github.com/adilger/zfs · Korn Shell · 130 lines · 46 code · 25 blank · 59 comment · 9 complexity · 6e50b4db5d329aad1d75b56b260163bd 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 2008 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 dataset which has a reservation set on it is destroyed,
  35. # the space consumed or reserved by that dataset should be released
  36. # back into the pool.
  37. #
  38. # STRATEGY:
  39. # 1) Create a filesystem, regular 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) Destroy the filesystem without resetting the reservation value.
  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 and sparse volume
  48. #
  49. verify_runnable "both"
  50. function cleanup {
  51. for obj in $OBJ_LIST; do
  52. datasetexists $obj && log_must_busy zfs destroy -f $obj
  53. done
  54. }
  55. log_assert "Verify space released when a dataset with reservation is destroyed"
  56. log_onexit cleanup
  57. log_must zfs create $TESTPOOL/$TESTFS2
  58. space_avail=`get_prop available $TESTPOOL`
  59. if ! is_global_zone ; then
  60. OBJ_LIST="$TESTPOOL/$TESTFS2"
  61. else
  62. OBJ_LIST="$TESTPOOL/$TESTFS2 \
  63. $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 refreservation=none $TESTPOOL/$TESTVOL
  70. log_must zfs set reservation=none $TESTPOOL/$TESTVOL
  71. log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
  72. fi
  73. # re-calculate space available.
  74. space_avail=`get_prop available $TESTPOOL`
  75. # Calculate a large but valid reservation value.
  76. resv_size_set=`expr $space_avail - $RESV_DELTA`
  77. for obj in $OBJ_LIST ; do
  78. space_avail=`get_prop available $TESTPOOL`
  79. space_used=`get_prop used $TESTPOOL`
  80. #
  81. # For regular (non-sparse) volumes the upper limit is determined
  82. # not by the space available in the pool but rather by the size
  83. # of the volume itself.
  84. #
  85. [[ $obj == $TESTPOOL/$TESTVOL ]] && \
  86. ((resv_size_set = vol_set_size - RESV_DELTA))
  87. log_must zfs set reservation=$resv_size_set $obj
  88. resv_size_get=`get_prop reservation $obj`
  89. if [[ $resv_size_set != $resv_size_get ]]; then
  90. log_fail "Reservation not the expected value " \
  91. "($resv_size_set != $resv_size_get)"
  92. fi
  93. log_must_busy zfs destroy -f $obj
  94. new_space_avail=`get_prop available $TESTPOOL`
  95. new_space_used=`get_prop used $TESTPOOL`
  96. #
  97. # Recent changes to metaslab logic have caused these tests to expand
  98. # outside of their previous tolerance. If this is discovered to be a
  99. # bug, rather than a side effect of some interactions, the reservation
  100. # should be halved again.
  101. #
  102. log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
  103. log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
  104. done
  105. log_pass "Space correctly released when dataset is destroyed"