]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/quota/quota.kshlib
Enable quota_002_pos, quota_004_pos and quota_005_pos
[mirror_zfs.git] / tests / zfs-tests / tests / functional / quota / quota.kshlib
CommitLineData
6bb24f4d
BB
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28# Copyright (c) 2013 by Delphix. All rights reserved.
29#
30
31. $STF_SUITE/tests/functional/quota/quota.cfg
32
33# BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg
34if is_linux; then
35 readonly EDQUOT=122
36else
37 readonly EDQUOT=49
38fi
39
40#
41# Function to fill the quota of a zfs filesystem
42#
43# $1 - The File system or container to fill.
44# $2 - The mountpoint to use.
45#
46function fill_quota
47{
48 typeset FILESYSTEM="$1"
49 typeset MNTPT="$2"
50
51 log_must $ZFS set quota=$QUOTA_VALUE $FILESYSTEM
52
53 typeset -i write_size=0
54 (( write_size = 2 * QUOTA_VALUE ))
55
56 typeset -i zret=0
57 $FILE_WRITE -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \
58 -c $write_size -d 0
59 zret=$?
bebd73f2 60 [[ $zret -ne $EDQUOT ]] && \
6bb24f4d
BB
61 log_fail "Returned error code: $zret. Expected: $EDQUOT."
62
21237e91 63 typeset -i file_size=`$LS -lsk $MNTPT/$TESTFILE1 | $AWK '{ print $1 }'`
6bb24f4d 64 typeset -i limit=0
21237e91 65 (( file_size = file_size * 1024 ))
6bb24f4d
BB
66 (( limit = QUOTA_VALUE + TOLERANCE ))
67 (( file_size > limit )) && \
68 log_fail "File was created larger than the quota value, aborting!!!"
69 return 0
70}
71
72#
73# Function attempts to write another file in a ZFS filesystem
74# that has already filled its quota
75#
76function exceed_quota
77{
78 typeset FILESYSTEM="$1"
79 typeset MNTPT="$2"
80
81 log_must fill_quota $FILESYSTEM $MNTPT
82 typeset -i write_size=0
83 (( write_size = 2 * QUOTA_VALUE ))
84 typeset -i zret=0
85 #
86 # Writing a file without API to access return code
87 #
88 log_note "Creating a file in a FS that has already exceeded its quota"
89 $FILE_WRITE -o create -f $MNTPT/$TESTFILE2 \
90 -b $BLOCK_SIZE -c $write_size -d 0
91 zret=$?
bebd73f2
AG
92 [[ $zret -ne $EDQUOT ]] && \
93 log_fail "Returned error code: $zret. Expected: $EDQUOT."
6bb24f4d
BB
94 return 0
95}