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 https://opensource.org/licenses/CDDL-1.0. 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, 2016 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 36elif is_freebsd; then 37 readonly EDQUOT=69 38else 39 readonly EDQUOT=49 40fi 41 42# 43# Function to fill the quota of a zfs filesystem 44# 45# $1 - The File system or container to fill. 46# $2 - The mountpoint to use. 47# 48function fill_quota 49{ 50 typeset FILESYSTEM="$1" 51 typeset MNTPT="$2" 52 53 log_must zfs set quota=$QUOTA_VALUE $FILESYSTEM 54 55 typeset -i write_size=0 56 (( write_size = 2 * QUOTA_VALUE )) 57 58 typeset -i zret=0 59 file_write -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \ 60 -c $write_size -d 0 61 zret=$? 62 [[ $zret -ne $EDQUOT ]] && \ 63 log_fail "Returned error code: $zret. Expected: $EDQUOT." 64 65 typeset -i file_size=`ls -lsk $MNTPT/$TESTFILE1 | awk '{ print $1 }'` 66 typeset -i limit=0 67 (( file_size = file_size * 1024 )) 68 (( limit = QUOTA_VALUE + TOLERANCE )) 69 (( file_size > limit )) && \ 70 log_fail "File was created larger than the quota value, aborting!!!" 71 return 0 72} 73 74# 75# Function attempts to write another file in a ZFS filesystem 76# that has already filled its quota 77# 78function exceed_quota 79{ 80 typeset FILESYSTEM="$1" 81 typeset MNTPT="$2" 82 83 log_must fill_quota $FILESYSTEM $MNTPT 84 typeset -i write_size=0 85 (( write_size = 2 * QUOTA_VALUE )) 86 typeset -i zret=0 87 # 88 # Writing a file without API to access return code 89 # 90 log_note "Creating a file in a FS that has already exceeded its quota" 91 file_write -o create -f $MNTPT/$TESTFILE2 \ 92 -b $BLOCK_SIZE -c $write_size -d 0 93 zret=$? 94 [[ $zret -ne $EDQUOT ]] && \ 95 log_fail "Returned error code: $zret. Expected: $EDQUOT." 96 return 0 97} 98