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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: snapshot_008_pos
33#
34# DESCRIPTION:
35# Verify that destroying snapshots returns space to the pool.
36#
37# STRATEGY:
38# 1. Create a file system and populate it while snapshotting.
39# 2. Destroy the snapshots and remove the files.
40# 3. Verify the space returns to the pool.
41#
42# TESTABILITY: explicit
43#
44# TEST_AUTOMATION_LEVEL: automated
45#
46# CODING_STATUS: COMPLETED (2005-09-29)
47#
48# __stc_assertion_end
49#
50################################################################################
51
52verify_runnable "both"
53
54function cleanup
55{
56	typeset -i i=1
57	while [[ $i -lt $COUNT ]]; do
58		snapexists $SNAPFS.$i
59		[[ $? -eq 0 ]] && \
60			log_must $ZFS destroy $SNAPFS.$i
61
62		(( i = i + 1 ))
63	done
64
65	[[ -e $TESTDIR ]] && \
66		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
67}
68
69log_assert "Verify that destroying snapshots returns space to the pool."
70
71log_onexit cleanup
72
73[[ -n $TESTDIR ]] && \
74    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
75
76typeset -i COUNT=10
77
78orig_size=`get_prop available $TESTPOOL`
79
80log_note "Populate the $TESTDIR directory"
81populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ ITER $SNAPFS
82
83typeset -i i=1
84while [[ $i -lt $COUNT ]]; do
85	log_must rm -f $TESTDIR/file.$i > /dev/null 2>&1
86	log_must $ZFS destroy $SNAPFS.$i
87
88	(( i = i + 1 ))
89done
90
91new_size=`get_prop available $TESTPOOL`
92
93typeset -i tolerance=0
94
95(( tolerance = new_size - orig_size))
96if (( tolerance > LIMIT )); then
97        log_fail "Space not freed. ($orig_size != $new_size)"
98fi
99
100log_pass "After destroying snapshots, the space is returned to the pool."
101