12fae26bdSAlan Somers# vim: filetype=sh 22fae26bdSAlan Somers# 32fae26bdSAlan Somers# CDDL HEADER START 42fae26bdSAlan Somers# 52fae26bdSAlan Somers# The contents of this file are subject to the terms of the 62fae26bdSAlan Somers# Common Development and Distribution License (the "License"). 72fae26bdSAlan Somers# You may not use this file except in compliance with the License. 82fae26bdSAlan Somers# 92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing. 112fae26bdSAlan Somers# See the License for the specific language governing permissions 122fae26bdSAlan Somers# and limitations under the License. 132fae26bdSAlan Somers# 142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each 152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the 172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying 182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner] 192fae26bdSAlan Somers# 202fae26bdSAlan Somers# CDDL HEADER END 212fae26bdSAlan Somers# 222fae26bdSAlan Somers 232fae26bdSAlan Somers# 242fae26bdSAlan Somers# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 252fae26bdSAlan Somers# Use is subject to license terms. 262fae26bdSAlan Somers 272fae26bdSAlan Somers# BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg 282fae26bdSAlan Somersreadonly EDQUOT=69 292fae26bdSAlan Somers 302fae26bdSAlan Somers# 312fae26bdSAlan Somers# Function to fill the quota of a zfs filesystem 322fae26bdSAlan Somers# 332fae26bdSAlan Somers# $1 - The File system or container to fill. 342fae26bdSAlan Somers# $2 - The mountpoint to use. 352fae26bdSAlan Somers# 362fae26bdSAlan Somersfunction fill_quota 372fae26bdSAlan Somers{ 382fae26bdSAlan Somers typeset FILESYSTEM="$1" 392fae26bdSAlan Somers typeset MNTPT="$2" 402fae26bdSAlan Somers 412fae26bdSAlan Somers log_must $ZFS set quota=$QUOTA_VALUE $FILESYSTEM 422fae26bdSAlan Somers 432fae26bdSAlan Somers typeset -i write_size=0 442fae26bdSAlan Somers (( write_size = 2 * QUOTA_VALUE )) 452fae26bdSAlan Somers 462fae26bdSAlan Somers typeset -i zret=0 472fae26bdSAlan Somers $FILE_WRITE -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \ 482fae26bdSAlan Somers -c $write_size -d 0 492fae26bdSAlan Somers zret=$? 502fae26bdSAlan Somers [[ $zret -ne EDQUOT ]] && log_fail "Got error $zret; expected $EDQUOT" 512fae26bdSAlan Somers 522fae26bdSAlan Somers typeset -i file_size=`$LS -ls $MNTPT/$TESTFILE1 | $AWK '{ print $1 }'` 532fae26bdSAlan Somers typeset -i limit=0 542fae26bdSAlan Somers (( file_size = file_size * 512 )) 552fae26bdSAlan Somers (( limit = QUOTA_VALUE + TOLERANCE )) 562fae26bdSAlan Somers (( file_size > limit )) && \ 572fae26bdSAlan Somers log_fail "File was created larger than the quota value, aborting!!!" 582fae26bdSAlan Somers return 0 592fae26bdSAlan Somers} 602fae26bdSAlan Somers 612fae26bdSAlan Somers# 622fae26bdSAlan Somers# Function attempts to write another file in a ZFS filesystem 632fae26bdSAlan Somers# that has already filled its quota 642fae26bdSAlan Somers# 652fae26bdSAlan Somersfunction exceed_quota 662fae26bdSAlan Somers{ 672fae26bdSAlan Somers typeset FILESYSTEM="$1" 682fae26bdSAlan Somers typeset MNTPT="$2" 692fae26bdSAlan Somers 702fae26bdSAlan Somers log_must fill_quota $FILESYSTEM $MNTPT 712fae26bdSAlan Somers typeset -i write_size=0 722fae26bdSAlan Somers (( write_size = 2 * QUOTA_VALUE )) 732fae26bdSAlan Somers typeset -i zret=0 742fae26bdSAlan Somers # 752fae26bdSAlan Somers # Writing a file without API to access return code 762fae26bdSAlan Somers # 772fae26bdSAlan Somers log_note "Creating a file in a FS that has already exceeded its quota" 782fae26bdSAlan Somers $FILE_WRITE -o create -f $MNTPT/$TESTFILE2 \ 792fae26bdSAlan Somers -b $BLOCK_SIZE -c $write_size -d 0 802fae26bdSAlan Somers zret=$? 812fae26bdSAlan Somers [[ $zret -ne EDQUOT ]] && log_fail "Got error $zret; expected $EDQUOT" 822fae26bdSAlan Somers return 0 832fae26bdSAlan Somers} 84