diff --git a/tests/zfs-tests/tests/functional/quota/quota.kshlib b/tests/zfs-tests/tests/functional/quota/quota.kshlib index 5083415c8956..b4cfde020f3f 100644 --- a/tests/zfs-tests/tests/functional/quota/quota.kshlib +++ b/tests/zfs-tests/tests/functional/quota/quota.kshlib @@ -1,97 +1,104 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/quota/quota.cfg # BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg if is_linux; then readonly EDQUOT=122 elif is_freebsd; then readonly EDQUOT=69 else readonly EDQUOT=49 fi # # Function to fill the quota of a zfs filesystem # # $1 - The File system or container to fill. # $2 - The mountpoint to use. # function fill_quota { typeset FILESYSTEM="$1" typeset MNTPT="$2" log_must zfs set quota=$QUOTA_VALUE $FILESYSTEM typeset -i write_size=0 (( write_size = 2 * QUOTA_VALUE )) typeset -i zret=0 file_write -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \ -c $write_size -d 0 zret=$? [[ $zret -ne $EDQUOT ]] && \ log_fail "Returned error code: $zret. Expected: $EDQUOT." typeset -i file_size=`ls -lsk $MNTPT/$TESTFILE1 | awk '{ print $1 }'` typeset -i limit=0 (( file_size = file_size * 1024 )) (( limit = QUOTA_VALUE + TOLERANCE )) (( file_size > limit )) && \ log_fail "File was created larger than the quota value, aborting!!!" return 0 } # # Function attempts to write another file in a ZFS filesystem # that has already filled its quota # function exceed_quota { typeset FILESYSTEM="$1" typeset MNTPT="$2" log_must fill_quota $FILESYSTEM $MNTPT typeset -i write_size=0 (( write_size = 2 * QUOTA_VALUE )) typeset -i zret=0 # # Writing a file without API to access return code # log_note "Creating a file in a FS that has already exceeded its quota" file_write -o create -f $MNTPT/$TESTFILE2 \ -b $BLOCK_SIZE -c $write_size -d 0 zret=$? [[ $zret -ne $EDQUOT ]] && \ log_fail "Returned error code: $zret. Expected: $EDQUOT." return 0 } + +function reset_quota +{ + typeset FILESYSTEM="$1" + + log_must zfs set quota=none $FILESYSTEM +} diff --git a/tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh index d124cb26ae98..f01008a46bb1 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh @@ -1,77 +1,79 @@ #! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # # A ZFS file system quota limits the amount of pool space # available to a file system. Apply a quota and verify # that no more file creates are permitted. # # STRATEGY: # 1) Apply quota to ZFS file system # 2) Create a file which is larger than the set quota # 3) Verify that the resulting file size is less than the quota limit # verify_runnable "both" log_assert "Verify that file size is limited by the file system quota" # # cleanup to be used internally as otherwise quota assertions cannot be # run independently or out of order # function cleanup { [[ -e $TESTDIR/$TESTFILE1 ]] && \ log_must rm $TESTDIR/$TESTFILE1 # # Need to allow time for space to be released back to # pool, otherwise next test will fail trying to set a # quota which is less than the space used. # wait_freeing $TESTPOOL sync_pool $TESTPOOL + + reset_quota $TESTPOOL/$TESTFS } log_onexit cleanup # # Sets the quota value and attempts to fill it with a file # twice the size of the quota # log_must fill_quota $TESTPOOL/$TESTFS $TESTDIR log_pass "File size limited by quota" diff --git a/tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh index 3af005e874e9..bea2a5a68691 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh @@ -1,76 +1,78 @@ #! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # A zfs file system quota limits the amount of pool space # available to a given ZFS file system. Once exceeded, it is impossible # to write any more files to the file system. # # STRATEGY: # 1) Apply quota to the ZFS file system # 2) Exceed the quota # 3) Attempt to write another file # 4) Verify the attempt fails with error code EDQUOTA (linux 122, others 49) # # verify_runnable "both" log_assert "Verify that a file write cannot exceed the file system quota" # # cleanup to be used internally as otherwise quota assertions cannot be # run independently or out of order # function cleanup { [[ -e $TESTDIR/$TESTFILE1 ]] && \ log_must rm $TESTDIR/$TESTFILE1 [[ -e $TESTDIR/$TESTFILE2 ]] && \ log_must rm $TESTDIR/$TESTFILE2 wait_freeing $TESTPOOL sync_pool $TESTPOOL + + reset_quota $TESTPOOL/$TESTFS } log_onexit cleanup # # Fills the quota & attempts to write another file # log_must exceed_quota $TESTPOOL/$TESTFS $TESTDIR log_pass "Could not write file. Quota limit enforced as expected" diff --git a/tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh index de265813d55b..33f6421131fc 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh @@ -1,80 +1,82 @@ #! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # A ZFS file system quota limits the amount of pool space # available to a file system dataset. Apply a quota and verify # that no more file creates are permitted. # # NOTE: THis test applies to a dataset rather than a file system. # # STRATEGY: # 1) Apply quota to ZFS file system dataset # 2) Create a file which is larger than the set quota # 3) Verify that the resulting file size is less than the quota limit # verify_runnable "both" log_assert "Verify that file size is limited by the file system quota" \ "(dataset version)" # # cleanup to be used internally as otherwise quota assertions cannot be # run independently or out of order # function cleanup { [[ -e $TESTDIR1/$TESTFILE1 ]] && \ log_must rm $TESTDIR1/$TESTFILE1 # # Need to allow time for space to be released back to # pool, otherwise next test will fail trying to set a # quota which is less than the space used. # wait_freeing $TESTPOOL sync_pool $TESTPOOL + + reset_quota $TESTPOOL/$TESTCTR/$TESTFS1 } log_onexit cleanup # # Sets the quota value and attempts to fill it with a file # twice the size of the quota # log_must fill_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1 log_pass "File size limited by quota" diff --git a/tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh index 8f20b533da68..682d09f080a4 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh @@ -1,77 +1,79 @@ #! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # A zfs file system quota limits the amount of pool space # available to a given ZFS file system dataset. Once exceeded, it # is impossible to write any more files to the file system. # # STRATEGY: # 1) Apply quota to the ZFS file system dataset # 2) Exceed the quota # 3) Attempt to write another file # 4) Verify the attempt fails with error code EDQUOTA (linux 122, others 49) # # verify_runnable "both" log_assert "Verify that a file write cannot exceed the file system quota" \ "(dataset version)" # # cleanup to be used internally as otherwise quota assertions cannot be # run independently or out of order # function cleanup { [[ -e $TESTDIR1/$TESTFILE1 ]] && \ log_must rm $TESTDIR1/$TESTFILE1 [[ -e $TESTDIR1/$TESTFILE2 ]] && \ log_must rm $TESTDIR1/$TESTFILE2 wait_freeing $TESTPOOL sync_pool $TESTPOOL + + reset_quota $TESTPOOL/$TESTCTR/$TESTFS1 } log_onexit cleanup # # Fills the quota & attempts to write another file # log_must exceed_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1 log_pass "Could not write file. Quota limit enforced as expected" diff --git a/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh index fb3d97f486de..9c4db81ca270 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh @@ -1,74 +1,74 @@ #! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # # Verify that quota doesn't inherit its value from parent. # # STRATEGY: # 1) Set quota for parents # 2) Create a filesystem tree # 3) Verify that the 'quota' for descendent doesnot inherit the value. # ############################################################################### verify_runnable "both" function cleanup { datasetexists $fs_child && destroy_dataset $fs_child - log_must zfs set quota=$quota_val $fs + reset_quota $fs } log_onexit cleanup log_assert "Verify that quota does not inherit its value from parent." fs=$TESTPOOL/$TESTFS fs_child=$TESTPOOL/$TESTFS/$TESTFS space_avail=$(get_prop available $fs) quota_val=$(get_prop quota $fs) typeset -li quotasize=$space_avail ((quotasize = quotasize * 2 )) log_must zfs set quota=$quotasize $fs log_must zfs create $fs_child quota_space=$(get_prop quota $fs_child) [[ $quota_space == $quotasize ]] && \ log_fail "The quota of child dataset inherits its value from parent." log_pass "quota does not inherit its value from parent as expected." diff --git a/tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh b/tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh index 12105162c5b5..111d771188e3 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh @@ -1,71 +1,71 @@ #! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # # Can't set a quota to less than currently being used by the dataset. # # STRATEGY: # 1) Create a filesystem # 2) Set a quota on the filesystem that is lower than the space # currently in use. # 3) Verify that the attempt fails. # verify_runnable "both" log_assert "Verify cannot set quota lower than the space currently in use" function cleanup { - log_must zfs set quota=none $TESTPOOL/$TESTFS + reset_quota $TESTPOOL/$TESTFS } log_onexit cleanup typeset -i quota_integer_size=0 typeset invalid_size="123! @456 7#89 0\$ abc123% 123%s 12%s3 %c123 123%d %x123 12%p3 \ ^def456 789&ghi" typeset -i space_used=`get_prop used $TESTPOOL/$TESTFS` (( quota_integer_size = space_used - 1 )) quota_fp_size=${quota_integer_size}.123 for size in 0 -1 $quota_integer_size -$quota_integer_size $quota_fp_size -$quota_fp_size \ $invalid_size ; do log_mustnot zfs set quota=$size $TESTPOOL/$TESTFS done log_must zfs set quota=$space_used $TESTPOOL/$TESTFS log_pass "As expected cannot set quota lower than space currently in use"