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
23# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)reservation_013_pos.ksh	1.4	09/01/12 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/reservation/reservation.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: reservation_013_pos
40#
41# DESCRIPTION:
42#
43# Reservation properties on data objects should be preserved when the
44# pool within which they are contained is exported and then re-imported.
45#
46#
47# STRATEGY:
48# 1) Create a filesystem as dataset
49# 2) Create another filesystem at the same level
50# 3) Create a regular volume at the same level
51# 4) Create a sparse volume at the same level
52# 5) Create a filesystem within the dataset filesystem
53# 6) Set reservations on all filesystems
54# 7) Export the pool
55# 8) Re-import the pool
56# 9) Verify that the reservation settings are correct
57#
58# TESTABILITY: explicit
59#
60# TEST_AUTOMATION_LEVEL: automated
61#
62# CODING_STATUS: COMPLETED (2005-07-19)
63#
64# __stc_assertion_end
65#
66################################################################################
67
68verify_runnable "global"
69
70log_assert "Reservation properties preserved across exports and imports"
71
72OBJ_LIST="$TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1 \
73	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
74
75log_must $ZFS create $TESTPOOL/$TESTFS1
76log_must $ZFS create $TESTPOOL/$TESTFS1/$TESTFS2
77
78space_avail=`get_prop available $TESTPOOL`
79[[ $? -ne 0 ]] && \
80	log_fail "Unable to get space available property for $TESTPOOL"
81
82(( resv_set = space_avail / 8 ))
83resv_set=$(floor_volsize $resv_set)
84(( sparse_vol_set_size = space_avail * 8 ))
85sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
86reg_vol_blksz=8192
87
88# When initially created, a regular volume's refreservation property is set
89# equal to its size (unlike a sparse volume), so we don't need to set it
90# explicitly later on.  However, since the zfs command modifies the
91# reservation based on the volume size, it is necessary to test it separately.
92log_must $ZFS create -b $reg_vol_blksz -V $resv_set $TESTPOOL/$TESTVOL
93log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
94
95log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTFS
96log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTFS1
97log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTFS1/$TESTFS2
98log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTVOL2
99
100log_must $ZPOOL export $TESTPOOL
101
102typeset dir=$(get_device_dir $DISKS)
103log_must $ZPOOL import -d $dir $TESTPOOL
104
105alloc_vol_size=$(zvol_volsize_to_reservation $resv_set $reg_vol_blksz 1)
106resv_get=$(get_prop refreservation $TESTPOOL/$TESTVOL)
107[[ $resv_get != $alloc_vol_size ]] && \
108        log_fail "Reservation property for $TESTPOOL/$TESTVOL incorrect;" \
109		" expected $alloc_vol_size but got $resv_get"
110
111for obj in $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS1 \
112		$TESTPOOL/$TESTVOL2 $TESTPOOL/$TESTFS1/$TESTFS2
113do
114	resv_get=`get_prop refreservation $obj`
115
116	[[ $resv_get != $resv_set ]] && \
117		log_fail "Reservation property for $obj incorrect " \
118			" expected $resv_set but got $resv_get"
119done
120
121log_pass "Reservation properties preserved across exports and imports"
122