diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 1f8aca0d9..2b0894cf7 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -1009,12 +1009,20 @@ tags = ['functional', 'upgrade'] [tests/functional/userquota] tests = [ + 'defaultuserquota_001_pos', 'defaultuserquota_002_pos', + 'defaultuserquota_003_pos', 'defaultuserquota_004_neg', + 'defaultuserquota_005_pos', 'defaultuserquota_006_pos', + 'defaultuserquota_007_pos', 'defaultuserquota_008_pos', + 'defaultuserquota_009_pos', 'defaultuserquota_010_neg', + 'defaultuserquota_011_neg', 'defaultuserquota_012_neg', + 'defaultuserquota_013_neg', 'userquota_001_pos', 'userquota_002_pos', 'userquota_003_pos', 'userquota_004_pos', 'userquota_005_neg', 'userquota_006_pos', 'userquota_007_pos', 'userquota_008_pos', 'userquota_009_pos', 'userquota_010_pos', 'userquota_011_pos', 'userquota_012_neg', - 'userspace_001_pos', 'userspace_002_pos', 'userspace_encrypted', - 'userspace_send_encrypted', 'userspace_encrypted_13709'] + 'userspace_001_pos', 'userspace_002_pos', 'userspace_004_pos', + 'userspace_encrypted', 'userspace_send_encrypted', + 'userspace_encrypted_13709'] tags = ['functional', 'userquota'] [tests/functional/vdev_disk:Linux] diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 2df12ed63..ff82e0c83 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -226,7 +226,7 @@ tags = ['functional', 'user_namespace'] [tests/functional/userquota:Linux] tests = ['groupspace_001_pos', 'groupspace_002_pos', 'groupspace_003_pos', - 'userquota_013_pos', 'userspace_003_pos'] + 'groupspace_004_pos','userquota_013_pos', 'userspace_003_pos'] tags = ['functional', 'userquota'] [tests/functional/zvol/zvol_misc:Linux] diff --git a/tests/zfs-tests/tests/Makefile.am b/tests/zfs-tests/tests/Makefile.am index bce546d06..2f71783ba 100644 --- a/tests/zfs-tests/tests/Makefile.am +++ b/tests/zfs-tests/tests/Makefile.am @@ -2101,7 +2101,21 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \ functional/userquota/groupspace_001_pos.ksh \ functional/userquota/groupspace_002_pos.ksh \ functional/userquota/groupspace_003_pos.ksh \ + functional/userquota/groupspace_004_pos.ksh \ functional/userquota/setup.ksh \ + functional/userquota/defaultuserquota_001_pos.ksh \ + functional/userquota/defaultuserquota_002_pos.ksh \ + functional/userquota/defaultuserquota_003_pos.ksh \ + functional/userquota/defaultuserquota_004_neg.ksh \ + functional/userquota/defaultuserquota_005_pos.ksh \ + functional/userquota/defaultuserquota_006_pos.ksh \ + functional/userquota/defaultuserquota_007_pos.ksh \ + functional/userquota/defaultuserquota_008_pos.ksh \ + functional/userquota/defaultuserquota_009_pos.ksh \ + functional/userquota/defaultuserquota_010_neg.ksh \ + functional/userquota/defaultuserquota_011_neg.ksh \ + functional/userquota/defaultuserquota_012_neg.ksh \ + functional/userquota/defaultuserquota_013_neg.ksh \ functional/userquota/userquota_001_pos.ksh \ functional/userquota/userquota_002_pos.ksh \ functional/userquota/userquota_003_pos.ksh \ @@ -2118,6 +2132,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \ functional/userquota/userspace_001_pos.ksh \ functional/userquota/userspace_002_pos.ksh \ functional/userquota/userspace_003_pos.ksh \ + functional/userquota/userspace_004_pos.ksh \ functional/userquota/userspace_encrypted.ksh \ functional/userquota/userspace_send_encrypted.ksh \ functional/userquota/userspace_encrypted_13709.ksh \ diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_001_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_001_pos.ksh new file mode 100755 index 000000000..9a1a618e3 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_001_pos.ksh @@ -0,0 +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 2009 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/userquota/userquota_common.kshlib + +# +# +# DESCRIPTION: +# Check the basic function of defaultuserquota and defaultgroupquota +# +# +# STRATEGY: +# 1. Set defaultuserquota and exceed the quota size +# 2. The write operation should fail with "Disk quota exceeded" +# 3. Set defaultgroupquota and exceed the quota size +# 4. The write operation should fail with "Disk quota exceeded" +# +# + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "If write operation exceeds default{user|group}quota size, it will fail" + +mkmount_writable $QFS +log_note "Check the defaultuserquota" +log_must zfs set defaultuserquota=$UQUOTA_SIZE $QFS +log_must user_run $QUSER1 mkfile $UQUOTA_SIZE $QFILE +sync_pool +log_mustnot user_run $QUSER1 mkfile 1 $OFILE +cleanup_quota + +log_note "Check the defaultgroupquota" +log_must zfs set defaultgroupquota=$GQUOTA_SIZE $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile $GQUOTA_SIZE $QFILE +sync_pool +log_mustnot user_run $QUSER1 mkfile 1 $OFILE +log_mustnot user_run $QUSER2 mkfile 1 $OFILE +cleanup_quota + +log_pass "Write operation exceeded default{user|group}quota size, failed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_002_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_002_pos.ksh new file mode 100755 index 000000000..461a16cdc --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_002_pos.ksh @@ -0,0 +1,95 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# defaultuserquota and defaultgroupquota can be set during zpool or zfs creation" +# +# +# STRATEGY: +# 1. Set defaultuserquota and defaultgroupquota via "zpool -O or zfs create -o" +# + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL1; then + log_must zpool destroy $TESTPOOL1 + fi + + if [[ -f $pool_vdev ]]; then + rm -f $pool_vdev + fi +} + +log_onexit cleanup + +log_assert \ + "default{user|group}quota can be set during {zpool|zfs} create" + +typeset pool_vdev=$TEST_BASE_DIR/pool_dev.$$ + +log_must mkfile 500m $pool_vdev + +if poolexists $TESTPOOL1; then + zpool destroy $TESTPOOL1 +fi + +log_must zpool create \ + -O defaultuserquota=$UQUOTA_SIZE \ + -O defaultgroupquota=$GQUOTA_SIZE \ + $TESTPOOL1 $pool_vdev + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL1 > /dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL1 "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL1 "$GQUOTA_SIZE" + +log_must zfs create \ + -o defaultuserquota=$UQUOTA_SIZE \ + -o defaultgroupquota=$GQUOTA_SIZE \ + $TESTPOOL1/fs + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL1 > /dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL1/fs "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL1/fs "$GQUOTA_SIZE" + +log_pass \ + "default{user|group}quota can be set during {zpool|zfs} create" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_003_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_003_pos.ksh new file mode 100755 index 000000000..a09750ed1 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_003_pos.ksh @@ -0,0 +1,61 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# Check the basic function of set/get defaultuserquota and defaultgroupquota on fs +# +# +# STRATEGY: +# 1. Set defaultuserquota on fs and check output of zfs get +# 2. Set defaultgroupquota on fs and check output of zfs get +# + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the basic function of set/get default{user|group}quota on fs" + +log_note "Check zfs {set|get} default{user|group}quota" +log_must zfs set defaultuserquota=$UQUOTA_SIZE $QFS +log_must check_quota "defaultuserquota" $QFS "$UQUOTA_SIZE" + +log_must zfs set defaultgroupquota=$GQUOTA_SIZE $QFS +log_must check_quota "defaultgroupquota" $QFS "$GQUOTA_SIZE" + +log_pass "Check the basic function of zfs {set|get} default{user|group}quota passed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_004_neg.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_004_neg.ksh new file mode 100755 index 000000000..29182bc1e --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_004_neg.ksh @@ -0,0 +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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# Check invalid parameter handling of zfs set default{user|group}quota +# +# +# STRATEGY: +# 1. try to set invalid values with zfs set default{user|group}quota to fs +# 2. try to set valid values with zfs set default{user|group}quota to snapshots (an invalid operation) +# + +function cleanup +{ + datasetexists $snap_fs && destroy_dataset $snap_fs + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check invalid values for zfs set default{user|group}quota" +typeset snap_fs=$QFS@snap + +log_must zfs snapshot $snap_fs + +set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m" + +for size in "${sizes[@]}"; do + log_note "can not set default{user|group}quota with invalid size parameter" + log_mustnot zfs set defaultuserquota=$size $QFS + log_mustnot zfs set defaultgroupquota=$size $QFS +done + +log_note "can not set default{user|group}quota to snapshot $snap_fs" +log_mustnot zfs set defaultuserquota=100m $snap_fs +log_mustnot zfs set defaultgroupquota=100m $snap_fs + +log_pass "Check invalid values for zfs set default{user|group}quota passed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_005_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_005_pos.ksh new file mode 100755 index 000000000..0ad9e587b --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_005_pos.ksh @@ -0,0 +1,75 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# +# defaultuserquota/defaultgroupquota can be set beyond the fs quota +# defaultuserquota/defaultgroupquota can be set at a smaller size than its current usage. +# +# STRATEGY: +# 1. set quota to a fs and set a larger size of defaultuserquota and defaultgroupquota +# 2. write some data to the fs and set a smaller defaultuserquota and defaultgroupquota +# + +function cleanup +{ + log_must cleanup_quota + log_must zfs set quota=none $QFS +} + +log_onexit cleanup + +log_assert "Check set default{user|group}quota to larger than the quota size of a fs" + +log_must zfs set quota=200m $QFS +log_must zfs set defaultuserquota="$UQUOTA_SIZE" $QFS +log_must zfs set defaultgroupquota="$GQUOTA_SIZE" $QFS + +log_must check_quota "defaultuserquota" $QFS "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $QFS "$GQUOTA_SIZE" + +log_note "write some data to the $QFS" +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile 100000 $QFILE +sync_all_pools + +log_note "set default{user|group}quota at a smaller size than current usage" +log_must zfs set defaultuserquota=90000 $QFS +log_must zfs set defaultgroupquota=90000 $QFS + +log_must check_quota "defaultuserquota" $QFS 90000 +log_must check_quota "defaultgroupquota" $QFS 90000 + +log_pass "set default{user|group}quota to larger than quota size of a fs passed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_006_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_006_pos.ksh new file mode 100755 index 000000000..ec3837492 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_006_pos.ksh @@ -0,0 +1,60 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# +# zfs get all does print out defaultuserquota/defaultgroupquota +# +# STRATEGY: +# 1. set defaultuserquota and defaultgroupquota to a fs +# 2. check zfs get all fs +# + +function cleanup +{ + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check zfs get all will print out default{user|group}quota" + +log_must zfs set defaultuserquota=50m $QFS +log_must zfs set defaultgroupquota=100m $QFS + +log_must zfs get all $QFS | grep defaultuserquota +log_must zfs get all $QFS | grep defaultgroupquota + +log_pass "zfs get all will print out default{user|group}quota" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_007_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_007_pos.ksh new file mode 100755 index 000000000..629234583 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_007_pos.ksh @@ -0,0 +1,89 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# Check default{user|group}quota to snapshot such that: +# 1) can not set default{user|group}quota to snapshot directly +# 2) snapshot does not inherit the parent fs's default{user|group}quota +# (same behavior as Solaris) +# +# +# STRATEGY: +# 1. create a snapshot of a fs +# 2. set the default{user|group}quota to snapshot and expect fail +# 3. set default{user|group}quota to fs and check the snapshot +# 4. reset default{user|group}quota to fs and check the snapshot's value +# + +function cleanup +{ + datasetexists $snap_fs && destroy_dataset $snap_fs + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the snapshot's default{user|group}quota" +typeset snap_fs=$QFS@snap + +log_must zfs set defaultuserquota=$UQUOTA_SIZE $QFS +log_must check_quota "defaultuserquota" $QFS "$UQUOTA_SIZE" + +log_must zfs set defaultgroupquota=$GQUOTA_SIZE $QFS +log_must check_quota "defaultgroupquota" $QFS "$GQUOTA_SIZE" + +log_must zfs snapshot $snap_fs + +log_note "check the snapshot $snap_fs default{user|group}quota" +log_must check_quota "defaultuserquota" $snap_fs "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $snap_fs "$GQUOTA_SIZE" + +log_note "set default{user|group}quota to $snap_fs should fail" +log_mustnot zfs set defaultuserquota=$SNAP_QUOTA $snap_fs +log_mustnot zfs set defaultgroupquota=$SNAP_QUOTA $snap_fs + +log_note "change the parent filesystem's default{user|group}quota" +log_must zfs set defaultuserquota=$TEST_QUOTA $QFS +log_must zfs set defaultgroupquota=$TEST_QUOTA $QFS + +log_must check_quota "defaultuserquota" $QFS $TEST_QUOTA +log_must check_quota "defaultgroupquota" $QFS $TEST_QUOTA + +log_note "check the snapshot $snap_fs default{user|group}quota" +log_must check_quota "defaultuserquota" $snap_fs "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $snap_fs "$GQUOTA_SIZE" + +log_pass "Check the snapshot's default{user|group}quota passed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_008_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_008_pos.ksh new file mode 100755 index 000000000..74344a8a1 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_008_pos.ksh @@ -0,0 +1,77 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# Check defaultuserquota and defaultgroupquota being exceeded at the same time +# +# +# STRATEGY: +# 1. Set defaultuserquota and defaultgroupquota to a fs +# 2. write to exceed the defaultuserquota size to check the result +# 3. unset defaultuserquota +# 4. write (as a different user) to exceed the defaultgroupquota size to check the result +# + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "write in excess of any default{user|group}quota size fails" + +log_note "write to $QFS to make it exceed defaultuserquota ($GQUOTA_SIZE)" +log_must zfs set defaultuserquota=$GQUOTA_SIZE $QFS +log_must zfs set defaultgroupquota=$GQUOTA_SIZE $QFS + +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile $GQUOTA_SIZE $QFILE +sync_pool + +log_must eval "zfs get -p userused@$QUSER1 $QFS >/dev/null 2>&1" +log_must eval "zfs get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1" + +log_mustnot user_run $QUSER1 mkfile 1 $OFILE + +log_must zfs set defaultuserquota=none $QFS + +log_note "write to $QFS as $QUSER2 to make it exceed defaultgroupquota" +log_mustnot user_run $QUSER2 mkfile 1 $QFILE + +log_must eval "zfs get -p userused@$QUSER1 $QFS >/dev/null 2>&1" +log_must eval "zfs get -p userused@$QUSER2 $QFS >/dev/null 2>&1" +log_must eval "zfs get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1" + +log_pass "write in excess of any default{user|group}quota size failed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_009_pos.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_009_pos.ksh new file mode 100755 index 000000000..922d1bf27 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_009_pos.ksh @@ -0,0 +1,132 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# the defaultuserquota and defaultgroupquota will not change during zfs actions, such as +# snapshot,clone,rename,upgrade,send,receive. +# +# +# STRATEGY: +# 1. Create a pool, and create fs with preset default user,group quota +# 2. Check set default user|group quota via zfs snapshot|clone|list -o +# 3. Check the default user|group quota can not change during zfs rename|upgrade|promote +# 4. Check the default user|group quota can not change during zfs clone +# 5. Check the default user|group quota can not change during zfs send/receive +# + +function cleanup +{ + for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do + datasetexists $ds && destroy_dataset $ds -rRf + done +} + +log_onexit cleanup + +log_assert \ + "the default{user|group}quota don't change during zfs actions" + +cleanup + +log_must zfs create \ + -o defaultuserquota=$UQUOTA_SIZE \ + -o defaultgroupquota=$GQUOTA_SIZE \ + $TESTPOOL/fs + +log_must zfs snapshot $TESTPOOL/fs@snap +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL/fs@snap "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL/fs@snap "$GQUOTA_SIZE" + +log_note "clone fs gets its parent's default{user|group}quota initially" +log_must zfs clone \ + $TESTPOOL/fs@snap $TESTPOOL/fs-clone + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL/fs-clone "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL/fs-clone "$GQUOTA_SIZE" + +log_must eval "zfs list \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL/fs-clone >/dev/null 2>&1" + +log_note "zfs promote can not change the previously set default{user|group}quota" +log_must zfs promote $TESTPOOL/fs-clone + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL/fs-clone "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL/fs-clone "$GQUOTA_SIZE" + +log_note "zfs send receive can not change the previously set default{user|group}quota" +log_must zfs send $TESTPOOL/fs-clone@snap | zfs receive $TESTPOOL/fs-rev + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL/fs-rev "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL/fs-rev "$GQUOTA_SIZE" + +log_note "zfs rename can not change the previously set default{user|group}quota" +log_must zfs rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL/fs-rename "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL/fs-rename "$GQUOTA_SIZE" + +log_note "zfs upgrade can not change the previously set default{user|group}quota" +log_must zfs upgrade $TESTPOOL/fs-rename + +log_must eval "zfs list -r \ + -o defaultuserquota,defaultgroupquota \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "defaultuserquota" $TESTPOOL/fs-rename "$UQUOTA_SIZE" +log_must check_quota "defaultgroupquota" $TESTPOOL/fs-rename "$GQUOTA_SIZE" + +log_pass \ + "the default{user|group}quota don't change during zfs actions" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_010_neg.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_010_neg.ksh new file mode 100755 index 000000000..64296b5fc --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_010_neg.ksh @@ -0,0 +1,64 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# defaultuserquota and defaultgroupquota can not be set against snapshot +# +# +# STRATEGY: +# 1. Set defaultuserquota on snap +# 2. Set defaultgroupquota on snap +# + +function cleanup +{ + cleanup_quota + + datasetexists $snap_fs && destroy_dataset $snap_fs +} + +log_onexit cleanup + +typeset snap_fs=$QFS@snap +log_assert "Check setting default{user|group}quota on snapshot" + +log_note "Check can not set default{user|group}quota on snapshot" +log_must zfs snapshot $snap_fs + +log_mustnot zfs set defaultuserquota=$UQUOTA_SIZE $snap_fs + +log_mustnot zfs set defaultgroupquota=$GQUOTA_SIZE $snap_fs + +log_pass "Check setting default{user|group}quota on snapshot fails as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_011_neg.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_011_neg.ksh new file mode 100755 index 000000000..cebc5ce54 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_011_neg.ksh @@ -0,0 +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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2016 by Jinshan Xiong. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib + +# +# +# DESCRIPTION: +# Check the basic function of the defaultuserobjquota and defaultgroupobjquota +# +# +# STRATEGY: +# 1. Set defaultuserobjquota and overwrite the quota size +# 2. Creating new object should fail +# 3. Set defaultgroupobjquota and overwrite the quota size +# 4. Creating new object should fail +# +# + +function cleanup +{ + log_must rm -f ${QFILE}_* + cleanup_quota +} + +log_onexit cleanup + +log_assert "If creating object exceeds default{user|group}objquota count, it will fail" + +mkmount_writable $QFS +log_must zfs set xattr=sa $QFS + +log_note "Check the defaultuserobjquota" +log_must zfs set defaultuserobjquota=100 $QFS +log_must user_run $QUSER1 mkfiles ${QFILE}_1 100 +sync_pool +log_mustnot user_run $QUSER1 mkfile 1 $OFILE +cleanup_quota +log_must zfs set defaultuserobjquota=none $QFS + +log_note "Check the defaultgroupobjquota" +log_must zfs set defaultgroupobjquota=200 $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 mkfiles ${QFILE}_2 100 +sync_pool +log_mustnot user_run $QUSER2 mkfile 1 $OFILE + +cleanup +log_pass "Creating objects exceeds default{user|group}objquota count, it as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_012_neg.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_012_neg.ksh new file mode 100755 index 000000000..31658d9be --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_012_neg.ksh @@ -0,0 +1,87 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# +# DESCRIPTION: +# Check that defaultquotas can override the per user/group quota +# +# +# STRATEGY: +# 1. Set defaultuserquota and userquota (double then defaultuserquota) +# 2. The write operation should not fail when defaultuserquota is exceed +# 3. The write operation should fail when userquota is exceed +# 4. Set defaultgroupquota and group (double then defaultgroupquota) +# 5. The write operation should not fail when defaultgroupquota is exceed +# 6. The write operation should fail when group quota is exceed +# +# + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "If per user/group quota is able to override defaultquota, it will fail" + +log_note "Check the defaultuserquota" +log_must zfs set defaultuserquota=$UQUOTA_SIZE $QFS +log_must zfs set userquota@$QUSER1=$(($UQUOTA_SIZE * 2 + 1)) $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile $UQUOTA_SIZE $QFILE +sync_pool +log_must user_run $QUSER1 mkfile 1 $OFILE +sync_pool +log_must user_run $QUSER1 mkfile $UQUOTA_SIZE $QFILE2 +sync_pool +log_mustnot user_run $QUSER1 mkfile 1 $OFILE2 +cleanup_quota +zfs set defaultuserquota=none $QFS + +log_note "Check the defaultgroupquota" +log_must zfs set defaultgroupquota=$GQUOTA_SIZE $QFS +log_must zfs set groupquota@$QGROUP=$(($GQUOTA_SIZE * 2 + 1)) $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile $GQUOTA_SIZE $QFILE +sync_pool +log_must user_run $QUSER1 mkfile 1 $OFILE +sync_pool +log_must user_run $QUSER1 mkfile $GQUOTA_SIZE $QFILE2 +sync_pool +log_mustnot user_run $QUSER1 mkfile 1 $OFILE2 +cleanup_quota +zfs set defaultuserquota=none tank + +log_pass "Per User/Group quota override default quota, failed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/defaultuserquota_013_neg.ksh b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_013_neg.ksh new file mode 100755 index 000000000..586edf291 --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/defaultuserquota_013_neg.ksh @@ -0,0 +1,70 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# +# DESCRIPTION: +# Check that defaultuserquota is applicable to individual users +# +# +# STRATEGY: +# 1. Set defaultuserquota +# 2. Check that user1 is able to write up to defaultuserquota size +# 2. Check that request fails when user1 exceed2 defaultuserquota size +# 2. Check that user2 is able to write up to defaultuserquota size +# 2. Check that request fails when user2 exceed2 defaultuserquota size +# +# + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "If defaultuserquota is not applicable to individual users, it will fail" + +log_note "Check the defaultuserquota" +log_must zfs set defaultuserquota=$UQUOTA_SIZE $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile $UQUOTA_SIZE $QFILE +sync_pool +log_mustnot user_run $QUSER1 mkfile 1 $OFILE +log_must user_run $QUSER2 mkfile $UQUOTA_SIZE $QFILE2 +sync_pool +log_mustnot user_run $QUSER2 mkfile 1 $OFILE2 +sync_pool +cleanup_quota + +log_pass "defaultuserquota is not applicable to individual users, failed as expected" diff --git a/tests/zfs-tests/tests/functional/userquota/groupspace_004_pos.ksh b/tests/zfs-tests/tests/functional/userquota/groupspace_004_pos.ksh new file mode 100755 index 000000000..543e17edd --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/groupspace_004_pos.ksh @@ -0,0 +1,77 @@ +#!/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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# Check the user used and groupspace size in zfs groupspace +# +# +# STRATEGY: +# 1. set zfs defaultgroupquota to a fs +# 2. write some data to the fs with specified user and size +# 3. use zfs groupspace to check the used size and quota size +# + +function cleanup +{ + datasetexists $snapfs && destroy_dataset $snapfs + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the zfs groupspace used and quota" + +log_must zfs set defaultgroupquota=500m $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 mkfile 100m $QFILE + +sync_all_pools + +typeset snapfs=$QFS@snap + +log_must zfs snapshot $snapfs + +log_must eval "zfs groupspace $QFS >/dev/null 2>&1" +log_must eval "zfs groupspace $snapfs >/dev/null 2>&1" + +for fs in "$QFS" "$snapfs"; do + log_note "check the quota size in zfs groupspace $fs" + log_must eval "zfs groupspace $fs | grep $QGROUP | grep 500M" + + log_note "check the user used size in zfs groupspace $fs" + log_must eval "zfs groupspace $fs | grep $QGROUP | grep 100M" +done + +log_pass "Check the zfs groupspace used and defaultgroupquota pass as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/userquota.cfg b/tests/zfs-tests/tests/functional/userquota/userquota.cfg index 37e658dd9..4adb10b8f 100644 --- a/tests/zfs-tests/tests/functional/userquota/userquota.cfg +++ b/tests/zfs-tests/tests/functional/userquota/userquota.cfg @@ -42,6 +42,8 @@ export GQUOTA_SIZE=4000000 export QFS=$TESTPOOL/$TESTFS export QFILE=$TESTDIR/qf export OFILE=$TESTDIR/of +export QFILE2=$TESTDIR/qf2 +export OFILE2=$TESTDIR/of2 export SNAP_QUOTA=100m export TEST_QUOTA=88888 diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib b/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib index 87e94ac20..f6936164c 100644 --- a/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib +++ b/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib @@ -44,11 +44,17 @@ function cleanup_quota log_must zfs set userobjquota@$QUSER2=none $QFS log_must zfs set groupquota@$QGROUP=none $QFS log_must zfs set groupobjquota@$QGROUP=none $QFS + log_must zfs set defaultuserquota=none $QFS + log_must zfs set defaultuserobjquota=none $QFS + log_must zfs set defaultgroupquota=none $QFS + log_must zfs set defaultgroupobjquota=none $QFS recovery_writable $QFS fi [[ -f $QFILE ]] && log_must rm -f $QFILE [[ -f $OFILE ]] && log_must rm -f $OFILE + [[ -f $QFILE2 ]] && log_must rm -f $QFILE2 + [[ -f $OFILE2 ]] && log_must rm -f $OFILE2 sync_all_pools return 0 diff --git a/tests/zfs-tests/tests/functional/userquota/userspace_004_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userspace_004_pos.ksh new file mode 100755 index 000000000..9e8b0dfdf --- /dev/null +++ b/tests/zfs-tests/tests/functional/userquota/userspace_004_pos.ksh @@ -0,0 +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 2009 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/userquota/userquota_common.kshlib + +# +# DESCRIPTION: +# Check the user used size and defaultuserquota in zfs userspace +# +# +# STRATEGY: +# 1. set zfs defaultuserquota to a fs +# 2. write some data to the fs with specified user and size +# 3. use zfs userspace to check the used size and quota size +# + +function cleanup +{ + datasetexists $snapfs && destroy_dataset $snapfs + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the zfs userspace used and defaultuserquota" + +log_must zfs set defaultuserquota=100m $QFS + +mkmount_writable $QFS + +log_must user_run $QUSER1 mkfile 50m $QFILE +sync_all_pools + +typeset snapfs=$QFS@snap + +log_must zfs snapshot $snapfs + +log_must eval "zfs userspace $QFS >/dev/null 2>&1" +log_must eval "zfs userspace $snapfs >/dev/null 2>&1" + +for fs in "$QFS" "$snapfs"; do + log_note "check the defaultuserquota size in zfs userspace $fs" + log_must eval "zfs userspace $fs | grep $QUSER1 | grep 100M" + + log_note "check the user used size in zfs userspace $fs" + log_must eval "zfs userspace $fs | grep $QUSER1 | grep 50\\.\*M" +done + +log_pass "Check the zfs userspace used and defaultuserquota"