PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/reservation/reservation_004_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 131 lines | 42 code | 22 blank | 67 comment | 8 complexity | ff8b35f44b142f612a3844ccb801990b MD5 | raw file
  1. #! /usr/local/bin/ksh93 -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. # $FreeBSD$
  23. #
  24. # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)reservation_004_pos.ksh 1.3 08/02/27 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. . $STF_SUITE/tests/reservation/reservation.kshlib
  31. ###############################################################################
  32. #
  33. # __stc_assertion_start
  34. #
  35. # ID: reservation_004_pos
  36. #
  37. # DESCRIPTION:
  38. #
  39. # When a dataset which has a reservation set on it is destroyed,
  40. # the space consumed or reserved by that dataset should be released
  41. # back into the pool.
  42. #
  43. # STRATEGY:
  44. # 1) Create a filesystem, regular and sparse volume
  45. # 2) Get the space used and available in the pool
  46. # 3) Set a reservation on the filesystem less than the space available.
  47. # 4) Verify that the 'reservation' property for the filesystem has
  48. # the correct value.
  49. # 5) Destroy the filesystem without resetting the reservation value.
  50. # 6) Verify that the space used and available totals for the pool have
  51. # changed by the expected amounts (within tolerances).
  52. # 7) Repeat steps 3-6 for a regular volume and sparse volume
  53. #
  54. # TESTABILITY: explicit
  55. #
  56. # TEST_AUTOMATION_LEVEL: automated
  57. #
  58. # CODING_STATUS: COMPLETED (2005-07-19)
  59. #
  60. # __stc_assertion_end
  61. #
  62. ################################################################################
  63. verify_runnable "both"
  64. log_assert "Verify space released when a dataset with reservation is destroyed"
  65. log_must $ZFS create $TESTPOOL/$TESTFS2
  66. space_avail=`get_prop available $TESTPOOL`
  67. if ! is_global_zone ; then
  68. OBJ_LIST="$TESTPOOL/$TESTFS2"
  69. else
  70. OBJ_LIST="$TESTPOOL/$TESTFS2 \
  71. $TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
  72. (( vol_set_size = space_avail / 4 ))
  73. vol_set_size=$(floor_volsize $vol_set_size)
  74. (( sparse_vol_set_size = space_avail * 4 ))
  75. sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
  76. log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
  77. if fs_prop_exist refreserv; then
  78. log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
  79. fi
  80. log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
  81. log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
  82. fi
  83. # re-calculate space available.
  84. space_avail=`get_prop available $TESTPOOL`
  85. # Calculate a large but valid reservation value.
  86. resv_size_set=`expr $space_avail - $RESV_DELTA`
  87. for obj in $OBJ_LIST ; do
  88. space_avail=`get_prop available $TESTPOOL`
  89. space_used=`get_prop used $TESTPOOL`
  90. #
  91. # For regular (non-sparse) volumes the upper limit is determined
  92. # not by the space available in the pool but rather by the size
  93. # of the volume itself.
  94. #
  95. [[ $obj == $TESTPOOL/$TESTVOL ]] && \
  96. (( resv_size_set = vol_set_size - RESV_DELTA ))
  97. log_must $ZFS set reservation=$resv_size_set $obj
  98. resv_size_get=`get_prop reservation $obj`
  99. if [[ $resv_size_set != $resv_size_get ]]; then
  100. log_fail "Reservation not the expected value " \
  101. "($resv_size_set != $resv_size_get)"
  102. fi
  103. log_must $ZFS destroy -f $obj
  104. new_space_avail=`get_prop available $TESTPOOL`
  105. new_space_used=`get_prop used $TESTPOOL`
  106. log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
  107. log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
  108. done
  109. log_pass "Space correctly released when dataset is destroyed"