xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/reservation/reservation_013_pos.sh (revision 1d32ba663e202c24a5a1f2e5aef83fffb447cb7f)
1f38cb554SJohn Wren Kennedy#!/usr/bin/bash -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/reservation/reservation.shlib
34f38cb554SJohn Wren Kennedy
35f38cb554SJohn Wren Kennedy#
36f38cb554SJohn Wren Kennedy# DESCRIPTION:
37f38cb554SJohn Wren Kennedy#
38f38cb554SJohn Wren Kennedy# Reservation properties on data objects should be preserved when the
39f38cb554SJohn Wren Kennedy# pool within which they are contained is exported and then re-imported.
40f38cb554SJohn Wren Kennedy#
41f38cb554SJohn Wren Kennedy#
42f38cb554SJohn Wren Kennedy# STRATEGY:
43f38cb554SJohn Wren Kennedy# 1) Create a filesystem as dataset
44f38cb554SJohn Wren Kennedy# 2) Create another filesystem at the same level
45f38cb554SJohn Wren Kennedy# 3) Create a regular volume at the same level
46f38cb554SJohn Wren Kennedy# 4) Create a sparse volume at the same level
47f38cb554SJohn Wren Kennedy# 5) Create a filesystem within the dataset filesystem
48f38cb554SJohn Wren Kennedy# 6) Set reservations on all filesystems
49f38cb554SJohn Wren Kennedy# 7) Export the pool
50f38cb554SJohn Wren Kennedy# 8) Re-import the pool
51f38cb554SJohn Wren Kennedy# 9) Verify that the reservation settings are correct
52f38cb554SJohn Wren Kennedy#
53f38cb554SJohn Wren Kennedy
54f38cb554SJohn Wren Kennedyverify_runnable "global"
55f38cb554SJohn Wren Kennedy
56f38cb554SJohn Wren Kennedylog_assert "Reservation properties preserved across exports and imports"
57f38cb554SJohn Wren Kennedy
58f38cb554SJohn Wren Kennedyfunction cleanup
59f38cb554SJohn Wren Kennedy{
60f38cb554SJohn Wren Kennedy	for obj in $OBJ_LIST; do
61*1d32ba66SJohn Wren Kennedy                datasetexists $obj && log_must zfs destroy -f $obj
62f38cb554SJohn Wren Kennedy        done
63f38cb554SJohn Wren Kennedy
64f38cb554SJohn Wren Kennedy	log_must zero_reservation $TESTPOOL/$TESTFS
65f38cb554SJohn Wren Kennedy}
66f38cb554SJohn Wren Kennedylog_onexit cleanup
67f38cb554SJohn Wren Kennedy
68f38cb554SJohn Wren KennedyOBJ_LIST="$TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
69f38cb554SJohn Wren Kennedy    $TESTPOOL/$TESTVOL2"
70f38cb554SJohn Wren Kennedy
71*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS1
72*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS1/$TESTFS2
73f38cb554SJohn Wren Kennedy
74f38cb554SJohn Wren Kennedyspace_avail=$(get_prop available $TESTPOOL)
75f38cb554SJohn Wren Kennedy[[ $? -ne 0 ]] && \
76f38cb554SJohn Wren Kennedy    log_fail "Unable to get space available property for $TESTPOOL"
77f38cb554SJohn Wren Kennedy
78f38cb554SJohn Wren Kennedy((resv_set = space_avail / 5))
79f38cb554SJohn Wren Kennedyresv_set=$(floor_volsize $resv_set)
80f38cb554SJohn Wren Kennedy((sparse_vol_set_size = space_avail * 5))
81f38cb554SJohn Wren Kennedysparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
82f38cb554SJohn Wren Kennedy
83f38cb554SJohn Wren Kennedy# When initially created, a regular volume's reservation property is set
84f38cb554SJohn Wren Kennedy# equal to its size (unlike a sparse volume), so we don't need to set it
85f38cb554SJohn Wren Kennedy# explictly later on
86*1d32ba66SJohn Wren Kennedylog_must zfs create -V $resv_set $TESTPOOL/$TESTVOL
87*1d32ba66SJohn Wren Kennedylog_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
88f38cb554SJohn Wren Kennedy
89*1d32ba66SJohn Wren Kennedylog_must zfs set reservation=$resv_set $TESTPOOL/$TESTFS
90*1d32ba66SJohn Wren Kennedylog_must zfs set reservation=$resv_set $TESTPOOL/$TESTFS1
91*1d32ba66SJohn Wren Kennedylog_must zfs set reservation=$resv_set $TESTPOOL/$TESTFS1/$TESTFS2
92*1d32ba66SJohn Wren Kennedylog_must zfs set reservation=$resv_set $TESTPOOL/$TESTVOL2
93f38cb554SJohn Wren Kennedy
94*1d32ba66SJohn Wren Kennedylog_must zpool export $TESTPOOL
95*1d32ba66SJohn Wren Kennedylog_must zpool import $TESTPOOL
96f38cb554SJohn Wren Kennedy
97f38cb554SJohn Wren Kennedyfor obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
98f38cb554SJohn Wren Kennedy
99f38cb554SJohn Wren Kennedy	if [[ $obj == $TESTPOOL/$TESTVOL ]]; then
100f38cb554SJohn Wren Kennedy		expected=$(volsize_to_reservation $obj $resv_set)
101f38cb554SJohn Wren Kennedy		found=$(get_prop refreservation $obj)
102f38cb554SJohn Wren Kennedy	else
103f38cb554SJohn Wren Kennedy		expected=$resv_set
104f38cb554SJohn Wren Kennedy		found=$(get_prop reservation $obj)
105f38cb554SJohn Wren Kennedy	fi
106f38cb554SJohn Wren Kennedy
107f38cb554SJohn Wren Kennedy	[[ $found != $expected ]] && \
108f38cb554SJohn Wren Kennedy	    log_fail "Reservation property for $obj incorrect. Expected " \
109f38cb554SJohn Wren Kennedy	    "$expected but got $found."
110f38cb554SJohn Wren Kennedydone
111f38cb554SJohn Wren Kennedy
112f38cb554SJohn Wren Kennedylog_pass "Reservation properties preserved across exports and imports"
113