]>
Commit | Line | Data |
---|---|---|
6bb24f4d BB |
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 | # | |
24 | # Copyright 2009 Sun Microsystems, Inc. All rights reserved. | |
25 | # Use is subject to license terms. | |
26 | # | |
27 | ||
28 | # | |
c1d9abf9 | 29 | # Copyright (c) 2013, 2016 by Delphix. All rights reserved. |
6bb24f4d BB |
30 | # |
31 | ||
32 | . $STF_SUITE/include/libtest.shlib | |
33 | . $STF_SUITE/tests/functional/reservation/reservation.shlib | |
34 | ||
35 | # | |
36 | # DESCRIPTION: | |
37 | # | |
38 | # Setting a reservation reserves a defined minimum amount of space for | |
39 | # a dataset, and prevents other datasets using that space. Verify that | |
40 | # reducing the reservation on a filesystem allows other datasets in | |
41 | # the pool to use that space. | |
42 | # | |
43 | # STRATEGY: | |
44 | # 1) Create multiple filesystems | |
45 | # 2) Set reservations on all bar one of the filesystems | |
46 | # 3) Fill up the one non-reserved filesystem | |
47 | # 4) Reduce one of the reservations and verify can write more | |
48 | # data into the non-reserved filesystem | |
49 | # | |
50 | ||
51 | verify_runnable "both" | |
52 | ||
53 | log_assert "Verify reducing reservation allows other datasets to use space" | |
54 | ||
55 | function cleanup | |
56 | { | |
57 | typeset -i loop=0 | |
58 | while (($loop < $RESV_NUM_FS)); do | |
59 | datasetexists $TESTPOOL/${TESTFS}$loop && \ | |
c1d9abf9 | 60 | log_must zfs destroy -f $TESTPOOL/${TESTFS}$loop |
6bb24f4d | 61 | |
c1d9abf9 | 62 | [[ -d ${TESTDIR}$loop ]] && log_must rm -r ${TESTDIR}$loop |
6bb24f4d BB |
63 | |
64 | ((loop = loop + 1)) | |
65 | done | |
66 | } | |
67 | ||
68 | log_onexit cleanup | |
69 | ||
70 | log_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR | |
71 | ||
72 | space_avail=`get_prop available $TESTPOOL` | |
73 | space_used=`get_prop used $TESTPOOL` | |
74 | ||
75 | # | |
76 | # To make sure this test doesn't take too long to execute on | |
77 | # large pools, we calculate a reservation setting which when | |
78 | # applied to all bar one of the filesystems (RESV_NUM_FS-1) will | |
79 | # ensure we have RESV_FREE_SPACE left free in the pool, which we will | |
80 | # be able to quickly fill. | |
81 | # | |
82 | resv_space_avail=`expr $space_avail - $RESV_FREE_SPACE` | |
83 | num_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied | |
84 | resv_size_set=`expr $resv_space_avail / $num_resv_fs` | |
85 | ||
86 | # | |
87 | # We set the reservations now, rather than when we created the filesystems | |
88 | # to allow us to take into account space used by the filsystem metadata | |
89 | # | |
90 | # Note we don't set a reservation on the first filesystem we created, | |
91 | # hence num=1 rather than zero below. | |
92 | # | |
93 | typeset -i num=1 | |
94 | while (($num < $RESV_NUM_FS)); do | |
c1d9abf9 | 95 | log_must zfs set reservation=$resv_size_set $TESTPOOL/$TESTFS$num |
6bb24f4d BB |
96 | ((num = num + 1)) |
97 | done | |
98 | ||
99 | space_avail_still=`get_prop available $TESTPOOL` | |
100 | ||
101 | fill_size=`expr $space_avail_still + $RESV_TOLERANCE` | |
102 | write_count=`expr $fill_size / $BLOCK_SIZE` | |
103 | ||
104 | # Now fill up the first filesystem (which doesn't have a reservation set | |
105 | # and thus will use up whatever free space is left in the pool). | |
106 | num=0 | |
107 | log_note "Writing to $TESTDIR$num/$TESTFILE1" | |
108 | ||
c1d9abf9 | 109 | file_write -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \ |
6bb24f4d BB |
110 | -c $write_count -d 0 |
111 | ret=$? | |
112 | if (($ret != $ENOSPC)); then | |
113 | log_fail "Did not get ENOSPC as expected (got $ret)." | |
114 | fi | |
115 | ||
116 | # Remove the reservation on one of the other filesystems and verify | |
117 | # can write more data to the original non-reservation filesystem. | |
118 | num=1 | |
c1d9abf9 | 119 | log_must zfs set reservation=none $TESTPOOL/${TESTFS}$num |
6bb24f4d | 120 | num=0 |
c1d9abf9 JWK |
121 | log_must file_write -o create -f ${TESTDIR}$num/$TESTFILE2 \ |
122 | -b $(getconf PAGESIZE) -c 1000 -d 0 | |
6bb24f4d BB |
123 | |
124 | log_pass "reducing reservation allows other datasets to use space" |