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