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# ident	"@(#)zvol_swap_002_pos.ksh	1.4	09/05/19 SMI"
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/zvol/zvol_common.kshlib
32
33###############################################################################
34#
35# __stc_assertion_start
36#
37# ID: zvol_swap_002_pos
38#
39# DESCRIPTION:
40# Using a zvol as swap space, fill with files until ENOSPC returned.
41#
42# STRATEGY:
43# 1. Create a pool
44# 2. Create a zvol volume
45# 3. Add zvol to swap space
46# 4. Fill swap space until ENOSPC is returned
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2005-07-04)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58log_unsupported "Fill swap will cause system hang, hide this case temporarily."
59
60verify_runnable "global"
61
62function cleanup
63{
64	$RM -rf $TMPDIR/$TESTDIR
65
66	if is_swap_inuse $voldev ; then
67		log_must $SWAP -d $voldev
68	fi
69}
70
71log_assert "Using a zvol as swap space, fill with files until ENOSPC returned."
72
73if ! is_dumpswap_supported $TESTPOOL ; then
74	log_unsupported "ZVOLs as swap devices are not currently supported."
75fi
76
77log_onexit cleanup
78
79voldev=/dev/zvol/$TESTPOOL/$TESTVOL
80
81$SWAP -l | $GREP zvol
82if (( $? != 0 )) ; then
83	log_note "Add zvol volume as swap space"
84	log_must $SWAP -a $voldev
85fi
86
87typeset -i filenum=0
88typeset -i retval=0
89typeset testdir=$TMPDIR/$TESTDIR
90
91log_note "Attempt to fill $TMPDIR until ENOSPC is hit"
92fill_fs $testdir -1 100 $BLOCKSZ $NUM_WRITES
93retval=$?
94
95(( $retval != $ENOSPC )) && \
96    log_fail "ENOSPC was not returned, $retval was returned instead"
97
98log_pass "ENOSPC was returned as expected"
99