PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 132 lines | 38 code | 20 blank | 74 comment | 8 complexity | 4be42c073aef4ec03984bc99b7a597a9 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_001_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_001_pos
  36. #
  37. # DESCRIPTION:
  38. #
  39. # ZFS allows reservations to be set on filesystems and volumes, provided
  40. # the reservation is less than the space available in the pool.
  41. #
  42. # STRATEGY:
  43. # 1) Create a regular and sparse volume
  44. # (filesystem already created by default_setup)
  45. # 2) Get the space 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) Reset the reservation to 'none'
  50. # 6) Repeat steps 2-5 for both volume types
  51. #
  52. # TESTABILITY: explicit
  53. #
  54. # TEST_AUTOMATION_LEVEL: automated
  55. #
  56. # CODING_STATUS: COMPLETED (2005-07-19)
  57. #
  58. # __stc_assertion_end
  59. #
  60. ###############################################################################
  61. verify_runnable "both"
  62. log_assert "Verify that to set a reservation on a filesystem" \
  63. " or volume must use value smaller than space" \
  64. " available property of pool"
  65. space_avail=`get_prop available $TESTPOOL`
  66. if ! is_global_zone ; then
  67. OBJ_LIST=""
  68. else
  69. OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
  70. (( vol_set_size = space_avail / 4 ))
  71. vol_set_size=$(floor_volsize $vol_set_size)
  72. (( sparse_vol_set_size = space_avail * 4 ))
  73. sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
  74. #
  75. # Note that when creating a regular volume we are implicitly
  76. # setting a reservation upon it (i.e. the size of the volume)
  77. # which we reset back to zero initially.
  78. #
  79. log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
  80. log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
  81. if fs_prop_exist refreserv; then
  82. log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
  83. fi
  84. log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
  85. fi
  86. for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
  87. space_avail=`get_prop available $TESTPOOL`
  88. resv_size_set=`expr $space_avail - $RESV_DELTA`
  89. #
  90. # For a regular (non-sparse) volume the upper limit
  91. # for reservations is not determined by the space
  92. # available in the pool but rather by the size of
  93. # 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 zero_reservation $obj
  104. new_space_avail=`get_prop available $obj`
  105. #
  106. # Due to the way space is consumed and released by metadata we
  107. # can't do an exact check here, but we do do a basic sanity
  108. # check.
  109. #
  110. log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
  111. done
  112. log_pass "Successfully set reservation on filesystem and volume"