diff options
Diffstat (limited to 'tests')
35 files changed, 2210 insertions, 17 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 43dd5cb1f..da9c791f9 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -616,6 +616,16 @@ tags = ['functional', 'poolversion'] tests = ['privilege_001_pos', 'privilege_002_pos'] tags = ['functional', 'privilege'] +[tests/functional/projectquota] +tests = ['projectid_001_pos', 'projectid_002_pos', 'projectid_003_pos', + 'projectquota_001_pos', 'projectquota_002_pos', 'projectquota_003_pos', + 'projectquota_004_neg', 'projectquota_005_pos', 'projectquota_006_pos', + 'projectquota_007_pos', 'projectquota_008_pos', 'projectquota_009_pos', + 'projectspace_001_pos', 'projectspace_002_pos', 'projectspace_003_pos', + 'projectspace_004_pos', + 'projecttree_001_pos', 'projecttree_002_pos', 'projecttree_003_neg' ] +tags = ['functional', 'projectquota'] + [tests/functional/quota] tests = ['quota_001_pos', 'quota_002_pos', 'quota_003_pos', 'quota_004_pos', 'quota_005_pos', 'quota_006_neg'] @@ -728,7 +738,7 @@ tests = ['truncate_001_pos', 'truncate_002_pos', 'truncate_timestamps'] tags = ['functional', 'truncate'] [tests/functional/upgrade] -tests = [ 'upgrade_userobj_001_pos' ] +tests = ['upgrade_userobj_001_pos', 'upgrade_projectquota_001_pos'] tags = ['functional', 'upgrade'] [tests/functional/userquota] diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index e6f04060c..4aede9f09 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -65,6 +65,7 @@ export SYSTEM_FILES='arp logname losetup ls + lsattr lsblk lsmod lsscsi diff --git a/tests/zfs-tests/tests/functional/Makefile.am b/tests/zfs-tests/tests/functional/Makefile.am index 1e9bbd4a4..9df1d8e3e 100644 --- a/tests/zfs-tests/tests/functional/Makefile.am +++ b/tests/zfs-tests/tests/functional/Makefile.am @@ -43,6 +43,7 @@ SUBDIRS = \ pool_names \ poolversion \ privilege \ + projectquota \ quota \ raidz \ redundancy \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg index 1e184db82..d5791372d 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg @@ -79,5 +79,6 @@ if is_linux; then "feature@large_dnode" "feature@userobj_accounting" "feature@encryption" + "feature@project_quota" ) fi diff --git a/tests/zfs-tests/tests/functional/privilege/setup.ksh b/tests/zfs-tests/tests/functional/privilege/setup.ksh index d8e79d1a2..badd83bed 100755 --- a/tests/zfs-tests/tests/functional/privilege/setup.ksh +++ b/tests/zfs-tests/tests/functional/privilege/setup.ksh @@ -31,6 +31,10 @@ . $STF_SUITE/include/libtest.shlib +if is_linux; then + log_unsupported "Requires pfexec command" +fi + ZFS_USER=zfsrbac USES_NIS=false diff --git a/tests/zfs-tests/tests/functional/projectquota/Makefile.am b/tests/zfs-tests/tests/functional/projectquota/Makefile.am new file mode 100644 index 000000000..4abfda0d2 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/Makefile.am @@ -0,0 +1,25 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/projectquota +dist_pkgdata_SCRIPTS = \ + projectquota.cfg \ + projectquota_common.kshlib \ + setup.ksh \ + cleanup.ksh \ + projectid_001_pos.ksh \ + projectid_002_pos.ksh \ + projectid_003_pos.ksh \ + projectquota_001_pos.ksh \ + projectquota_002_pos.ksh \ + projectquota_003_pos.ksh \ + projectquota_004_neg.ksh \ + projectquota_005_pos.ksh \ + projectquota_006_pos.ksh \ + projectquota_007_pos.ksh \ + projectquota_008_pos.ksh \ + projectquota_009_pos.ksh \ + projectspace_001_pos.ksh \ + projectspace_002_pos.ksh \ + projectspace_003_pos.ksh \ + projectspace_004_pos.ksh \ + projecttree_001_pos.ksh \ + projecttree_002_pos.ksh \ + projecttree_003_neg.ksh diff --git a/tests/zfs-tests/tests/functional/projectquota/cleanup.ksh b/tests/zfs-tests/tests/functional/projectquota/cleanup.ksh new file mode 100755 index 000000000..0440e3d8a --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/cleanup.ksh @@ -0,0 +1,37 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +log_must cleanup_projectquota +log_must del_user $PUSER +log_must del_group $PGROUP +default_cleanup diff --git a/tests/zfs-tests/tests/functional/projectquota/projectid_001_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectid_001_pos.ksh new file mode 100755 index 000000000..5f56d885c --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectid_001_pos.ksh @@ -0,0 +1,103 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# +# DESCRIPTION: +# Check project ID/flags can be set/inherited properly +# +# +# STRATEGY: +# 1. Create a regular file and a directroy. +# 2. Set project ID on both directroy and regular file. +# 3. New created subdir or regular file should inherit its parent's +# project ID if its parent has project inherit flag. +# 4. New created subdir should inherit its parent project's inherit flag. +# + +function cleanup +{ + log_must rm -f $PRJFILE + log_must rm -rf $PRJDIR +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check project ID/flags can be set/inherited properly" + +log_must touch $PRJFILE +log_must mkdir $PRJDIR + +log_must chattr -p $PRJID1 $PRJFILE +log_must eval "lsattr -p $PRJFILE | grep $PRJID1 | grep '\- '" +log_must chattr -p $PRJID1 $PRJDIR +log_must eval "lsattr -pd $PRJDIR | grep $PRJID1 | grep '\- '" + +log_must chattr +P $PRJDIR +log_must eval "lsattr -pd $PRJDIR | grep $PRJID1 | grep '\-P '" + +# "-1" is invalid project ID, should be denied +log_mustnot chattr -p -1 $PRJFILE +log_must eval "lsattr -p $PRJFILE | grep $PRJID1 | grep '\- '" + +log_must mkdir $PRJDIR/dchild +log_must eval "lsattr -pd $PRJDIR/dchild | grep $PRJID1 | grep '\-P '" +log_must touch $PRJDIR/fchild +log_must eval "lsattr -p $PRJDIR/fchild | grep $PRJID1" + +log_must touch $PRJDIR/dchild/foo +log_must eval "lsattr -p $PRJDIR/dchild/foo | grep $PRJID1" + +# not support project ID/flag on symlink +log_must ln -s $PRJDIR/dchild/foo $PRJDIR/dchild/s_foo +log_mustnot lsattr -p $PRJDIR/dchild/s_foo +log_mustnot chattr -p 123 $PRJDIR/dchild/s_foo +log_mustnot chattr +P $PRJDIR/dchild/s_foo + +# not support project ID/flag on block special file +log_must mknod $PRJDIR/dchild/b_foo b 124 124 +log_mustnot lsattr -p $PRJDIR/dchild/b_foo +log_mustnot chattr -p 123 $PRJDIR/dchild/b_foo +log_mustnot chattr +P $PRJDIR/dchild/b_foo + +# not support project ID/flag on character special file +log_must mknod $PRJDIR/dchild/c_foo c 125 125 +log_mustnot lsattr -p $PRJDIR/dchild/c_foo +log_mustnot chattr -p 123 $PRJDIR/dchild/c_foo +log_mustnot chattr +P $PRJDIR/dchild/c_foo + +log_pass "Check project ID/flags can be set/inherited properly" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectid_002_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectid_002_pos.ksh new file mode 100755 index 000000000..1a402e298 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectid_002_pos.ksh @@ -0,0 +1,88 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# +# DESCRIPTION: +# Project ID affects POSIX behavior +# +# +# STRATEGY: +# 1. Create three directories +# 2. Set tdir1 and tdir3 project ID as PRJID1, +# set tdir2 project ID as PRJID2. +# 3. Create regular file under tdir1. It inherits tdir1 proejct ID. +# 4. Hardlink from tdir1's child to tdir2 should be denied, +# move tdir1's child to tdir2 will be object recreated. +# 5. Hardlink from tdir1's child to tdir3 should succeed. +# + +function cleanup +{ + log_must rm -rf $PRJDIR1 + log_must rm -rf $PRJDIR2 + log_must rm -rf $PRJDIR3 +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Project ID affects POSIX behavior" + +log_must mkdir $PRJDIR1 +log_must mkdir $PRJDIR2 +log_must mkdir $PRJDIR3 +log_must mkdir $PRJDIR3/dir + +log_must chattr +P -p $PRJID1 $PRJDIR1 +log_must chattr +P -p $PRJID2 $PRJDIR2 + +log_must touch $PRJDIR1/tfile1 +log_must touch $PRJDIR1/tfile2 +log_must eval "lsattr -p $PRJDIR1/tfile1 | grep $PRJID1" + +log_mustnot ln $PRJDIR1/tfile1 $PRJDIR2/tfile2 + +log_must mv $PRJDIR1/tfile1 $PRJDIR2/tfile2 +log_must eval "lsattr -p $PRJDIR2/tfile2 | grep $PRJID2" + +log_must mv $PRJDIR3/dir $PRJDIR2/ +log_must eval "lsattr -dp $PRJDIR2/dir | grep $PRJID2" + +log_must chattr +P -p $PRJID1 $PRJDIR3 +log_must ln $PRJDIR1/tfile2 $PRJDIR3/tfile3 + +log_pass "Project ID affects POSIX behavior" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectid_003_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectid_003_pos.ksh new file mode 100755 index 000000000..d6dbaafc2 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectid_003_pos.ksh @@ -0,0 +1,81 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. Fan rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check changing project ID for the file with directory-based +# extended attributes. +# +# +# STRATEGY: +# 1. create new file with default project ID +# 2. set non-ACL extended attributes on the file +# 3. use zfs projectspace to check the object usage +# 4. change the file's project ID +# 5. use zfs projectspace to check the object usage again +# + +function cleanup +{ + log_must rm -f $PRJGUARD + log_must rm -f $PRJFILE +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check changing project ID with directory-based extended attributes" + +log_must zfs set xattr=on $QFS + +log_must touch $PRJGUARD +log_must chattr -p $PRJID1 $PRJGUARD +log_must touch $PRJFILE +log_must setfattr -n trusted.ea1 -v val1 $PRJFILE +log_must setfattr -n trusted.ea2 -v val2 $PRJFILE +log_must setfattr -n trusted.ea3 -v val3 $PRJFILE + +sync_pool +typeset prj_bef=$(project_obj_count $QFS $PRJID1) + +log_must chattr -p $PRJID1 $PRJFILE +sync_pool +typeset prj_aft=$(project_obj_count $QFS $PRJID1) + +[[ $prj_aft -ge $((prj_bef + 5)) ]] || + log_fail "new value ($prj_aft) is NOT 5 largr than old one ($prj_bef)" + +log_pass "Changing project ID with directory-based extended attributes pass" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota.cfg b/tests/zfs-tests/tests/functional/projectquota/projectquota.cfg new file mode 100644 index 000000000..564ab3ef9 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota.cfg @@ -0,0 +1,46 @@ +# +# 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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +export PUSER=puser +export PGROUP=pgroup + +export PRJID1=1001 +export PRJID2=1002 + +export QFS=$TESTPOOL/$TESTFS +export PRJFILE=$TESTDIR/tfile +export PRJGUARD=$TESTDIR/guard +export PRJDIR=$TESTDIR/tdir +export PRJDIR1=$TESTDIR/tdir1 +export PRJDIR2=$TESTDIR/tdir2 +export PRJDIR3=$TESTDIR/tdir3 + +export PQUOTA_LIMIT=1000000 +export PQUOTA_OBJLIMIT=1000 diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_001_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_001_pos.ksh new file mode 100755 index 000000000..3f8c3d68c --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_001_pos.ksh @@ -0,0 +1,88 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# +# DESCRIPTION: +# Check the basic function of the project{obj}quota +# +# +# STRATEGY: +# 1. Set projectquota and overwrite the quota size. +# 2. The write operation should fail with Disc quota exceeded +# 3. Set projectobjquota and overcreate the quota size. +# 4. More create should fail with Disc quota exceeded +# 5. More chattr to such project should fail with Disc quota exceeded +# + +function cleanup +{ + cleanup_projectquota +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "If operation overwrite project{obj}quota size, it will fail" + +mkmount_writable $QFS + +log_note "Check the projectquota@$PRJID1" +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID1 $PRJDIR + +log_must zfs set projectquota@$PRJID1=$PQUOTA_LIMIT $QFS +log_must user_run $PUSER mkfile $PQUOTA_LIMIT $PRJDIR/qf +sync_pool +log_mustnot user_run $PUSER mkfile 1 $PRJDIR/of + +log_must rm -rf $PRJDIR + +log_note "Check the projectobjquota@$PRJID2" +log_must zfs set xattr=sa $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID2 $PRJDIR + +log_must zfs set projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $QFS +log_must user_run $PUSER mkfiles $PRJDIR/qf_ $((PQUOTA_OBJLIMIT - 1)) +sync_pool +log_mustnot user_run $PUSER mkfile 1 $PRJDIR/of + +log_must user_run $PUSER touch $PRJFILE +log_must user_run $PUSER chattr -p 123 $PRJFILE +log_mustnot user_run $PUSER chattr -p $PRJID2 $PRJFILE + +log_pass "Operation overwrite project{obj}quota size failed as expect" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_002_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_002_pos.ksh new file mode 100755 index 000000000..c03619060 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_002_pos.ksh @@ -0,0 +1,86 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# The project{obj}quota can be set during zpool or zfs creation +# +# +# STRATEGY: +# 1. Set project{obj}quota 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 "The project{obj}quota can be set during zpool,zfs creation" + +typeset pool_vdev=/var/tmp/pool_dev.$$ + +log_must mkfile 500m $pool_vdev + +if poolexists $TESTPOOL1; then + zpool destroy $TESTPOOL1 +fi + +log_must zpool create -O projectquota@$PRJID1=$PQUOTA_LIMIT \ + -O projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $TESTPOOL1 $pool_vdev + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL1 > /dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL1 "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL1 "$PQUOTA_OBJLIMIT" + +log_must zfs create -o projectquota@$PRJID1=$PQUOTA_LIMIT \ + -o projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $TESTPOOL1/fs + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL1 > /dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL1/fs "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL1/fs "$PQUOTA_OBJLIMIT" + +log_pass "The project{obj}quota can be set during zpool,zfs creation" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_003_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_003_pos.ksh new file mode 100755 index 000000000..06f360d30 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_003_pos.ksh @@ -0,0 +1,98 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check the basic function project{obj}used +# +# +# STRATEGY: +# 1. Write data to fs with some project then check the project{obj}used +# + +function cleanup +{ + cleanup_projectquota +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check the basic function of project{obj}used" + +sync_pool +typeset project_used=$(get_value "projectused@$PRJID1" $QFS) +typeset file_size='10m' + +if [[ $project_used != 0 ]]; then + log_fail "FAIL: projectused is $project_used, should be 0" +fi + +mkmount_writable $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID1 $PRJDIR +log_must user_run $PUSER mkfile $file_size $PRJDIR/qf +sync_pool +project_used=$(get_value "projectused@$PRJID1" $QFS) +# get_value() reads the exact byte value which is slightly more than 10m +if [[ "$(($project_used/1024/1024))m" != "$file_size" ]]; then + log_note "project $PRJID1 used is $project_used" + log_fail "projectused for project $PRJID1 expected to be $file_size, " \ + "not $project_used" +fi + +log_must rm -rf $PRJDIR +typeset project_obj_used=$(get_value "projectobjused@$PRJID2" $QFS) +typeset file_count=100 + +if [[ $project_obj_used != 0 ]]; then + log_fail "FAIL: projectobjused is $project_obj_used, should be 0" +fi + +log_must zfs set xattr=sa $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID2 $PRJDIR +# $PRJDIR has already used one object with the $PRJID2 +log_must user_run $PUSER mkfiles $PRJDIR/qf_ $((file_count - 1)) +sync_pool +project_obj_used=$(get_value "projectobjused@$PRJID2" $QFS) +if [[ $project_obj_used != $file_count ]]; then + log_note "project $PRJID2 used is $project_obj_used" + log_fail "projectobjused for project $PRJID2 expected to be " \ + "$file_count, not $project_obj_used" +fi + +log_pass "Check the basic function of project{obj}used pass as expect" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_004_neg.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_004_neg.ksh new file mode 100755 index 000000000..df0eda7d7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_004_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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check the invalid parameter of zfs set project{obj}quota +# +# +# STRATEGY: +# 1. check the invalid zfs set project{obj}quota to fs +# 2. check the valid zfs set project{obj}quota to snapshots +# + +function cleanup +{ + if datasetexists $snap_fs; then + log_must zfs destroy $snap_fs + fi + + log_must cleanup_projectquota +} + +log_onexit cleanup + +log_assert "Check the invalid parameter of zfs set project{obj}quota" +typeset snap_fs=$QFS@snap + +log_must zfs snapshot $snap_fs + +set -A no_prjs "mms1234" "ss@#" "root-122" "-1" +for prj in "${no_prjs[@]}"; do + log_mustnot zfs set projectquota@$prj=100m $QFS +done + +log_note "can set all numberic id even that id is not existed" +log_must zfs set projectquota@12345678=100m $QFS + +set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m" +for size in "${sizes[@]}"; do + log_note "can not set projectquota with invalid size parameter" + log_mustnot zfs set projectquota@$PRJID1=$size $QFS +done + +log_note "can not set projectquota to snapshot $snap_fs" +log_mustnot zfs set projectquota@$PRJID1=100m $snap_fs + +for prj in "${no_prjs[@]}"; do + log_mustnot zfs set projectobjquota@$prj=100 $QFS +done + +log_note "can not set projectobjquota with invalid size parameter" +log_mustnot zfs set projectobjquota@$PRJID2=100msfsd $QFS + +log_note "can not set projectobjquota to snapshot $snap_fs" +log_mustnot zfs set projectobjquota@$PRJID2=100m $snap_fs + +log_pass "Check the invalid parameter of zfs set project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh new file mode 100755 index 000000000..b52f302f7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh @@ -0,0 +1,68 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check the invalid parameter of zfs get project{obj}quota +# +# +# STRATEGY: +# 1. check the invalid zfs get project{obj}quota to fs +# 2. check the valid zfs get project{obj}quota to snapshots +# + +function cleanup +{ + if datasetexists $snap_fs; then + log_must zfs destroy $snap_fs + fi + + log_must cleanup_projectquota +} + +log_onexit cleanup + +log_assert "Check the invalid parameter of zfs get project{obj}quota" +typeset snap_fs=$QFS@snap + +log_must zfs snapshot $snap_fs + +set -A no_prjs "mms1234" "ss@#" "root-122" +for prj in "${no_prjs[@]}"; do + log_must eval "zfs get projectquota@$prj $QFS >/dev/null 2>&1" + log_must eval "zfs get projectquota@$prj $snap_fs >/dev/null 2>&1" + log_must eval "zfs get projectobjquota@$prj $QFS >/dev/null 2>&1" + log_must eval "zfs get projectobjquota@$prj $snap_fs >/dev/null 2>&1" +done + +log_pass "Check the invalid parameter of zfs get project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_006_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_006_pos.ksh new file mode 100755 index 000000000..6b375d407 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_006_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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Projectquota can be set beyond the fs quota. +# Pprojectquota can be set at a smaller size than its current usage. +# +# STRATEGY: +# 1. set quota to a fs and set a larger size of projectquota +# 2. write some data to the fs and set a smaller projectquota +# + +function cleanup +{ + log_must cleanup_projectquota + log_must zfs set quota=none $QFS +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check set projectquota to larger than the quota size of a fs" + +log_must zfs set quota=200m $QFS +log_must zfs set projectquota@$PRJID1=500m $QFS + +log_must zfs get projectquota@$PRJID1 $QFS + +log_note "write some data to the $QFS" +mkmount_writable $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID1 $PRJDIR +log_must user_run $PUSER mkfile 100m $PRJDIR/qf +sync + +log_note "set projectquota at a smaller size than it current usage" +log_must zfs set projectquota@$PRJID1=90m $QFS + +log_must zfs get projectquota@$PRJID1 $QFS + +log_pass "set projectquota to larger than quota size of a fs" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_007_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_007_pos.ksh new file mode 100755 index 000000000..3572e0118 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_007_pos.ksh @@ -0,0 +1,58 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# zfs get all <fs> does not print out project{obj}quota +# +# STRATEGY: +# 1. set project{obj}quota to a fs +# 2. check zfs get all fs +# + +function cleanup +{ + log_must cleanup_projectquota +} + +log_onexit cleanup + +log_assert "Check zfs get all will not print out project{obj}quota" + +log_must zfs set projectquota@$PRJID1=50m $QFS +log_must zfs set projectobjquota@$PRJID2=100 $QFS + +log_mustnot eval "zfs get all $QFS | grep projectquota" +log_mustnot eval "zfs get all $QFS | grep projectobjquota" + +log_pass "zfs get all will not print out project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh new file mode 100755 index 000000000..365b5627e --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh @@ -0,0 +1,91 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check project{obj}quota to snapshot that: +# 1) can not set project{obj}quota to snapshot directly +# 2) snapshot can inherit the parent fs's project{obj}quota +# 3) the project{obj}quota will not change even the parent quota changed. +# +# +# STRATEGY: +# 1. create a snapshot of a fs +# 2. set the project{obj}quota to snapshot and expect fail +# 3. set project{obj}quota to fs and check the snapshot +# 4. re-set project{obj}quota to fs and check the snapshot's value +# + +function cleanup +{ + if datasetexists $snap_fs; then + log_must zfs destroy $snap_fs + fi + + log_must cleanup_projectquota +} + +log_onexit cleanup + +log_assert "Check the snapshot's project{obj}quota" +typeset snap_fs=$QFS@snap + + +log_must zfs set projectquota@$PRJID1=$PQUOTA_LIMIT $QFS +log_must check_quota "projectquota@$PRJID1" $QFS "$PQUOTA_LIMIT" + +log_must zfs set projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $QFS +log_must check_quota "projectobjquota@$PRJID2" $QFS "$PQUOTA_OBJLIMIT" + +log_must zfs snapshot $snap_fs + +log_note "check the snapshot $snap_fs project{obj}quota" +log_must check_quota "projectquota@$PRJID1" $snap_fs "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $snap_fs "$PQUOTA_OBJLIMIT" + +log_note "set project{obj}quota to $snap_fs which will fail" +log_mustnot zfs set projectquota@$PRJID1=100m $snap_fs +log_mustnot zfs set projectobjquota@$PRJID2=100 $snap_fs + +log_note "change the parent's project{obj}quota" +log_must zfs set projectquota@$PRJID1=$((PQUOTA_LIMIT * 2)) $QFS +log_must zfs set projectobjquota@$PRJID2=50 $QFS + +log_must check_quota "projectquota@$PRJID1" $QFS $((PQUOTA_LIMIT * 2)) +log_must check_quota "projectobjquota@$PRJID2" $QFS 50 + +log_note "check the snapshot $snap_fs project{obj}quota" +log_must check_quota "projectquota@$PRJID1" $snap_fs "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $snap_fs "$PQUOTA_OBJLIMIT" + +log_pass "Check the snapshot's project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh new file mode 100755 index 000000000..a867b538c --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh @@ -0,0 +1,131 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# The project{obj}quota will not change during zfs actions, such as +# snapshot,clone,rename,upgrade,send,receive. +# +# +# STRATEGY: +# 1. Create a pool, and create fs with preset project{obj}quota +# 2. Check set project{obj}quota via zfs snapshot|clone|list -o +# 3. Check the project{obj}quota can not change during zfs +# rename|upgrade|promote +# 4. Check the project{obj}quota can not change during zfs clone +# 5. Check the project{obj}quota can not change during zfs send/receive +# + +function cleanup +{ + for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do + if datasetexists $ds; then + log_must zfs destroy -rRf $ds + fi + done +} + +log_onexit cleanup + +log_assert "the project{obj}quota can't change during zfs actions" + +cleanup + +log_must zfs create -o projectquota@$PRJID1=$PQUOTA_LIMIT \ + -o projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $TESTPOOL/fs + +log_must zfs snapshot $TESTPOOL/fs@snap +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs@snap "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs@snap \ + "$PQUOTA_OBJLIMIT" + + +log_note "clone fs gets its parent's project{obj}quota initially" +log_must zfs clone -o projectquota@$PRJID1=$PQUOTA_LIMIT \ + -o projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT \ + $TESTPOOL/fs@snap $TESTPOOL/fs-clone + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-clone "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-clone \ + "$PQUOTA_OBJLIMIT" + +log_must eval "zfs list -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL/fs-clone >/dev/null 2>&1" + +log_note "zfs promote can not change the previously set project{obj}quota" +log_must zfs promote $TESTPOOL/fs-clone + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-clone "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-clone \ + "$PQUOTA_OBJLIMIT" + +log_note "zfs send receive can not change the previously set project{obj}quota" +log_must zfs send $TESTPOOL/fs-clone@snap | zfs receive $TESTPOOL/fs-rev + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-rev "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-rev \ + "$PQUOTA_OBJLIMIT" + +log_note "zfs rename can not change the previously set project{obj}quota" +log_must zfs rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-rename "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-rename \ + "$PQUOTA_OBJLIMIT" + +log_note "zfs upgrade can not change the previously set project{obj}quota" +log_must zfs upgrade $TESTPOOL/fs-rename + +log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-rename "$PQUOTA_LIMIT" +log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-rename \ + "$PQUOTA_OBJLIMIT" + +log_pass "the project{obj}quota can't change during zfs actions" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_common.kshlib b/tests/zfs-tests/tests/functional/projectquota/projectquota_common.kshlib new file mode 100644 index 000000000..23f7c2a50 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_common.kshlib @@ -0,0 +1,101 @@ +# +# 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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/projectquota/projectquota.cfg + +# +# reset the projectquota and delete temporary files +# +function cleanup_projectquota +{ + if datasetexists $QFS; then + typeset mntp=$(get_prop mountpoint $QFS) + + log_must zfs set projectquota@$PRJID1=none $QFS + log_must zfs set projectobjquota@$PRJID1=none $QFS + log_must zfs set projectquota@$PRJID2=none $QFS + log_must zfs set projectobjquota@$PRJID2=none $QFS + log_must chmod 0755 $mntp + fi + + [[ -f $PRJFILE ]] && log_must rm -f $PRJFILE + [[ -d $PRJDIR ]] && log_must rm -rf $PRJDIR + [[ -d $PRJDIR1 ]] && log_must rm -rf $PRJDIR1 + [[ -d $PRJDIR2 ]] && log_must rm -rf $PRJDIR2 + [[ -d $PRJDIR3 ]] && log_must rm -rf $PRJDIR3 + sync + + return 0 +} + +function mkmount_writable +{ + typeset fs=$1 + typeset mntp=$(get_prop mountpoint $fs) + log_must chmod 0777 $mntp +} + +function check_quota +{ + typeset fs=$2 + typeset prop=$1 + typeset expected=$3 + typeset value=$(get_prop $prop $fs) + + if (($value != $expected)); then + return 1 + fi +} + +function get_value +{ + typeset prop_val + typeset prop=$1 + typeset dataset=$2 + + prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null) + if [[ $? -ne 0 ]]; then + log_note "Unable to get $prop property for dataset $dataset" + return 1 + fi + + echo $prop_val +} + +function project_obj_count +{ + typeset fs=$1 + typeset prj=$2 + typeset cnt=$(zfs projectspace -oname,objused $fs | + awk /$prj/'{print $2}') + [[ "$cnt" == "-" ]] && cnt=0 || true + echo $cnt +} diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh new file mode 100755 index 000000000..a84ff9f89 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh @@ -0,0 +1,93 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. Fan rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check the zfs projectspace with kinds of parameters +# +# +# STRATEGY: +# 1. set zfs projectspace to a fs +# 2. write some data to the fs with specified project ID +# 3. use zfs projectspace with all possible parameters to check the result +# 4. use zfs projectspace with some bad parameters to check the result +# + +function cleanup +{ + if datasetexists $snap_fs; then + log_must zfs destroy $snap_fs + fi + + log_must cleanup_projectquota +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check the zfs projectspace with all possible parameters" + +set -A good_params -- "-H" "-p" "-o type,name,used,quota" "-o name,used,quota" \ + "-o used,quota" "-o objused" "-o quota" "-s type" "-s name" "-s used" \ + "-s quota" "-S type" "-S name" "-S used" "-S quota" + +typeset snap_fs=$QFS@snap + +log_must zfs set projectquota@$PRJID1=100m $QFS +log_must zfs set projectobjquota@$PRJID1=100 $QFS +mkmount_writable $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID1 $PRJDIR +log_must user_run $PUSER mkfile 50m $PRJDIR/qf +sync + +log_must zfs snapshot $snap_fs + +for param in "${good_params[@]}"; do + log_must eval "zfs projectspace $param $QFS >/dev/null 2>&1" + log_must eval "zfs projectspace $param $snap_fs >/dev/null 2>&1" +done + +log_assert "Check the zfs projectspace with some bad parameters" + +set -A bad_params -- "-i" "-n" "-P" "-t posixuser" + +for param in "${bad_params[@]}"; do + log_mustnot eval "zfs projectspace $param $QFS >/dev/null 2>&1" + log_mustnot eval "zfs projectspace $param $snap_fs >/dev/null 2>&1" +done + +log_pass "zfs projectspace with kinds of parameters pass" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh new file mode 100755 index 000000000..216855e94 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh @@ -0,0 +1,85 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check the project used size and quota in zfs projectspace +# +# +# STRATEGY: +# 1. set zfs projectquota to a fs +# 2. write some data to the fs with specified project and size +# 3. use zfs projectspace to check the used size and quota size +# + +function cleanup +{ + if datasetexists $snapfs; then + log_must zfs destroy $snapfs + fi + + log_must cleanup_projectquota +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check the zfs projectspace used and quota" + +log_must zfs set projectquota@$PRJID1=100m $QFS + +mkmount_writable $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID1 $PRJDIR +log_must user_run $PUSER mkfile 50m $PRJDIR/qf +sync + +typeset snapfs=$QFS@snap + +log_must zfs snapshot $snapfs + +log_must eval "zfs projectspace $QFS >/dev/null 2>&1" +log_must eval "zfs projectspace $snapfs >/dev/null 2>&1" + +for fs in "$QFS" "$snapfs"; do + log_note "check the quota size in zfs projectspace $fs" + log_must eval "zfs projectspace $fs | grep $PRJID1 | grep 100M" + + log_note "check the project used size in zfs projectspace $fs" + log_must eval "zfs projectspace $fs | grep $PRJID1 | grep 50\\.\*M" +done + +log_pass "Check the zfs projectspace used and quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh new file mode 100755 index 000000000..629b3b3e5 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh @@ -0,0 +1,118 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check the project used object accounting in zfs projectspace +# +# +# STRATEGY: +# 1. create a bunch of files by specific project +# 2. use zfs projectspace to check the used objects +# 3. change the project ID of test files and verify object count +# 4. delete files and verify object count +# + +function cleanup +{ + if datasetexists $snapfs; then + log_must zfs destroy $snapfs + fi + + log_must cleanup_projectquota +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check the zfs projectspace object used" + +mkmount_writable $QFS +log_must zfs set xattr=sa $QFS +log_must user_run $PUSER mkdir $PRJDIR1 +log_must user_run $PUSER mkdir $PRJDIR2 +log_must chattr +P -p $PRJID1 $PRJDIR1 +log_must chattr +P -p $PRJID2 $PRJDIR2 + +((prj_cnt1 = RANDOM % 100 + 2)) +((prj_cnt2 = RANDOM % 100 + 2)) + +log_must user_run $PUSER mkfiles $PRJDIR1/qf $((prj_cnt1 - 1)) +log_must user_run $PUSER mkfiles $PRJDIR2/qf $((prj_cnt2 - 1)) +sync_pool + +typeset snapfs=$QFS@snap + +log_must zfs snapshot $snapfs + +log_must eval "zfs projectspace $QFS >/dev/null 2>&1" +log_must eval "zfs projectspace $snapfs >/dev/null 2>&1" + +for fs in "$QFS" "$snapfs"; do + log_note "check the project used objects in zfs projectspace $fs" + prjused=$(project_obj_count $fs $PRJID1) + [[ $prjused -eq $prj_cnt1 ]] || + log_fail "($PRJID1) expected $prj_cnt1, got $prjused" + prjused=$(project_obj_count $fs $PRJID2) + [[ $prjused -eq $prj_cnt2 ]] || + log_fail "($PRJID2) expected $prj_cnt2, got $prjused" +done + +log_note "change the project of files" +log_must chattr -p $PRJID2 $PRJDIR1/qf* +sync_pool + +prjused=$(project_obj_count $QFS $PRJID1) +[[ $prjused -eq 1 ]] || + log_fail "expected 1 for project $PRJID1, got $prjused" + +prjused=$(project_obj_count $snapfs $PRJID1) +[[ $prjused -eq $prj_cnt1 ]] || + log_fail "expected $prj_cnt1 for $PRJID1 in snapfs, got $prjused" + +prjused=$(project_obj_count $QFS $PRJID2) +[[ $prjused -eq $((prj_cnt1 + prj_cnt2 - 1)) ]] || + log_fail "($PRJID2) expected $((prj_cnt1 + prj_cnt2 - 1)), got $prjused" + +log_note "file removal" +log_must rm -rf $PRJDIR1 +sync_pool + +prjused=$(project_obj_count $QFS $PRJID1) +[[ $prjused -eq 0 ]] || log_fail "expected 0 for $PRJID1, got $prjused" + +cleanup +log_pass "Check the zfs projectspace object used" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh new file mode 100755 index 000000000..494d7f3b7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh @@ -0,0 +1,76 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. Fan rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# DESCRIPTION: +# Check 'df' command on the directory with INHERIT (project ID) flag +# +# +# STRATEGY: +# 1. set project [obj]quota on the directory +# 2. set project ID and inherit flag on the directoty +# 3. run 'df [-i]' on the directory and check the result +# + +function cleanup +{ + if datasetexists $snap_fs; then + log_must zfs destroy $snap_fs + fi + + log_must cleanup_projectquota +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check 'df' on dir with inherit project shows the project quota/used" + +log_must zfs set projectquota@$PRJID1=100m $QFS +log_must zfs set projectobjquota@$PRJID1=100 $QFS +mkmount_writable $QFS +log_must user_run $PUSER mkdir $PRJDIR +log_must chattr +P -p $PRJID1 $PRJDIR +log_must user_run $PUSER mkfile 50m $PRJDIR/qf +sync_pool + +total=$(df $PRJDIR | tail -n 1 | awk '{ print $2 }') +[[ $total -eq 102400 ]] || log_fail "expect '102400' resource, but got '$total'" + +used=$(df -i $PRJDIR | tail -n 1 | awk '{ print $5 }') +[[ "$used" == "2%" ]] || log_fail "expect '2%' used, but got '$used'" + +log_pass "'df' on the directory with inherit project ID flag pass as expect" diff --git a/tests/zfs-tests/tests/functional/projectquota/projecttree_001_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projecttree_001_pos.ksh new file mode 100755 index 000000000..570e6a8ac --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projecttree_001_pos.ksh @@ -0,0 +1,98 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# +# DESCRIPTION: +# Check 'zfs project' is compatible with chattr/lsattr +# +# +# STRATEGY: +# Verify the following: +# 1. "zfs project -p" behaviours the same as "chattr -p" +# 2. "zfs project" behaviours the same as "lsattr -p" +# 3. "zfs project -d" behaviours the same as "lsattr -p -d" +# 4. "zfs project -s" behaviours the same as "chattr +P" +# 5. "zfs project -s -p" behaviours the same as "chattr +P -p" +# 6. "zfs project -C" behaviours the same as "chattr -P" +# + +function cleanup +{ + log_must rm -rf $PRJDIR +} + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_onexit cleanup + +log_assert "Check 'zfs project' is compatible with chattr/lsattr" + +log_must mkdir $PRJDIR +log_must mkdir $PRJDIR/a1 +log_must mkdir $PRJDIR/a2 +log_must touch $PRJDIR/a3 + +log_must chattr -p $PRJID1 $PRJDIR/a3 +log_must eval "zfs project $PRJDIR/a3 | grep '$PRJID1 \-'" + +log_must zfs project -p $PRJID2 $PRJDIR/a3 +log_must eval "lsattr -p $PRJDIR/a3 | grep $PRJID2 | grep '\- '" + +log_must chattr -p $PRJID1 $PRJDIR/a1 +log_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 \-'" + +log_must zfs project -p $PRJID2 $PRJDIR/a1 +log_must eval "lsattr -pd $PRJDIR/a1 | grep $PRJID2 | grep '\- '" + +log_must chattr +P $PRJDIR/a2 +log_must eval "zfs project -d $PRJDIR/a2 | grep '0 P'" + +log_must zfs project -s $PRJDIR/a2 +log_must eval "lsattr -pd $PRJDIR/a2 | grep 0 | grep '\-P '" + +log_must chattr +P -p $PRJID1 $PRJDIR/a1 +log_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 P'" + +log_must zfs project -s -p $PRJID2 $PRJDIR/a2 +log_must eval "lsattr -pd $PRJDIR/a2 | grep $PRJID2 | grep '\-P '" + +log_must chattr -P $PRJDIR/a1 +log_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 \-'" + +log_must zfs project -C -k $PRJDIR/a2 +log_must eval "lsattr -pd $PRJDIR/a2 | grep $PRJID2 | grep '\- '" + +log_pass "Check 'zfs project' is compatible with chattr/lsattr" diff --git a/tests/zfs-tests/tests/functional/projectquota/projecttree_002_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projecttree_002_pos.ksh new file mode 100755 index 000000000..4008811a1 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projecttree_002_pos.ksh @@ -0,0 +1,120 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# +# DESCRIPTION: +# Check project ID/flag can be operated via "zfs project" +# +# +# STRATEGY: +# 1. Create a tree with 4 level directories. +# 2. Set project ID on both directroy and regular file via +# "zfs project -p". +# 3. Check the project ID via "zfs project". +# 4. Set project inherit flag on kinds of level directories (and its +# descendants for some)) via "zfs project -s [-r]". +# 5. Check the project ID and inherit flag via "zfs project -r". +# 6. Clear the project inherit flag from some directories (and its +# descendants for some) via "zfs project -C [-r]". +# 7. Check the project ID and inherit flag via "zfs project -r". +# + +function cleanup +{ + log_must rm -rf $PRJDIR +} + +log_onexit cleanup + +log_assert "Check project ID/flag can be operated via 'zfs project'" + +log_must mkdir $PRJDIR + +log_must mkdir $PRJDIR/a1 +log_must mkdir $PRJDIR/b1 +log_must touch $PRJDIR/c1 + +log_must mkdir $PRJDIR/a1/a2 +log_must mkdir $PRJDIR/a1/b2 +log_must touch $PRJDIR/a1/c2 + +log_must mkdir $PRJDIR/b1/a2 +log_must mkdir $PRJDIR/b1/b2 +log_must touch $PRJDIR/b1/c2 + +log_must mkdir $PRJDIR/a1/a2/a3 +log_must mkdir $PRJDIR/a1/a2/b3 +log_must touch $PRJDIR/a1/a2/c3 + +log_must mkdir $PRJDIR/b1/a2/a3 + +log_must touch $PRJDIR/a1/a2/a3/c4 +log_must touch $PRJDIR/a1/a2/a3/d4 + +log_must zfs project -p $PRJID1 $PRJDIR/a1/c2 +log_must eval "zfs project $PRJDIR/a1/c2 | grep $PRJID1" + +log_must zfs project -p $PRJID2 $PRJDIR/a1/a2/a3 +log_must eval "zfs project -d $PRJDIR/a1/a2/a3 | grep $PRJID2" + +log_must zfs project -s $PRJDIR/b1/a2 +log_must eval "zfs project -d $PRJDIR/b1/a2 | grep ' P '" +log_must eval "zfs project -d $PRJDIR/b1/a2/a3 | grep ' \- '" + +log_must zfs project -s -r -p $PRJID2 $PRJDIR/a1/a2 +log_must zfs project -c -r $PRJDIR/a1/a2 +log_must eval "zfs project -d $PRJDIR/a1/a2/a3 | grep ' P '" +log_must eval "zfs project $PRJDIR/a1/a2/a3/c4 | grep $PRJID2" + +log_must zfs project -C $PRJDIR/a1/a2/a3 +log_must eval "zfs project -cr $PRJDIR/a1/a2 | grep 'inherit flag is not set'" +log_must eval "zfs project $PRJDIR/a1/a2/a3/c4 | grep $PRJID2 | grep -v not" +log_must zfs project -p 123 $PRJDIR/a1/a2/a3/c4 +log_must eval "zfs project -c -r $PRJDIR/a1/a2 | grep 123 | grep 'not set'" +log_mustnot eval "zfs project -cr -p 123 $PRJDIR/a1/a2 | grep c4 | grep -v not" + +log_must zfs project -C -r $PRJDIR/a1/a2/a3 +log_must eval "zfs project -cr $PRJDIR/a1/a2 | grep a3 | grep 'not set'" +log_must eval "zfs project -cr $PRJDIR/a1/a2 | grep d4 | grep 'not set'" +log_must eval "zfs project $PRJDIR/a1/a2/a3/d4 | grep '0 \-'" + +log_must eval \ + "zfs project -cr -0 $PRJDIR/a1/a2 | xargs -0 zfs project -s -p $PRJID2" +log_mustnot eval "zfs project -cr $PRJDIR/a1/a2 | grep a3 | grep 'not set'" +log_mustnot eval "zfs project -cr $PRJDIR/a1/a2 | grep d4 | grep 'not set'" + +log_must zfs project -C -r -k $PRJDIR/a1/a2 +log_must eval "zfs project -d $PRJDIR/a1/a2/b3 | grep '$PRJID2 \- '" + +log_pass "Check project ID/flag can be operated via 'zfs project'" diff --git a/tests/zfs-tests/tests/functional/projectquota/projecttree_003_neg.ksh b/tests/zfs-tests/tests/functional/projectquota/projecttree_003_neg.ksh new file mode 100755 index 000000000..33382fdbe --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/projecttree_003_neg.ksh @@ -0,0 +1,103 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +# +# +# DESCRIPTION: +# Check 'zfs project' invalid options combinations +# +# +# STRATEGY: +# Verify the following: +# 1. "-c" only supports "-d", "-p", "-r" and "-0". +# 2. "-C" only supports "-r" and "-k". +# 3. "-s" only supports "-r" and "-p". +# 4. "-c", "-C" and "-s" can NOT be specified together. +# 5. "-d" can overwirte former "-r". +# 6. "-r" can overwirte former "-d". +# 7. "-0" must be together with "-c". +# 8. "-d" must be on directory. +# 9. "-r" must be on directory. +# 10. "-p" must be together with "-c -r" or "-s". +# + +function cleanup +{ + log_must rm -rf $PRJDIR +} + +log_onexit cleanup + +log_assert "Check 'zfs project' invalid options combinations" + +log_must mkdir $PRJDIR +log_must mkdir $PRJDIR/a1 +log_must touch $PRJDIR/a2 + +log_mustnot zfs project -c +log_mustnot zfs project -c -k $PRJDIR/a1 +log_mustnot zfs project -c -C $PRJDIR/a1 +log_mustnot zfs project -c -s $PRJDIR/a1 +log_must zfs project -c -d -r $PRJDIR/a1 +log_must zfs project -c -r -d $PRJDIR/a1 +log_mustnot zfs project -c -d $PRJDIR/a2 +log_mustnot zfs project -c -r $PRJDIR/a2 + +log_mustnot zfs project -C +log_mustnot zfs project -C -c $PRJDIR/a1 +log_mustnot zfs project -C -d $PRJDIR/a1 +log_mustnot zfs project -C -p 100 $PRJDIR/a1 +log_mustnot zfs project -C -s $PRJDIR/a1 +log_mustnot zfs project -C -r -0 $PRJDIR/a1 +log_mustnot zfs project -C -0 $PRJDIR/a1 + +log_mustnot zfs project -s +log_mustnot zfs project -s -d $PRJDIR/a1 +log_mustnot zfs project -s -k $PRJDIR/a1 +log_mustnot zfs project -s -r -0 $PRJDIR/a1 +log_mustnot zfs project -s -0 $PRJDIR/a1 +log_mustnot zfs project -s -r $PRJDIR/a2 + +log_mustnot zfs project -p 100 +log_mustnot zfs project -p -1 $PRJDIR/a2 +log_mustnot zfs project -p 100 -d $PRJDIR/a1 +log_mustnot zfs project -p 100 -k $PRJDIR/a1 +log_mustnot zfs project -p 100 -0 $PRJDIR/a1 +log_mustnot zfs project -p 100 -r -0 $PRJDIR/a1 + +log_mustnot zfs project +log_mustnot zfs project -0 $PRJDIR/a2 +log_mustnot zfs project -k $PRJDIR/a2 +log_mustnot zfs project -S $PRJDIR/a1 + +log_pass "Check 'zfs project' invalid options combinations" diff --git a/tests/zfs-tests/tests/functional/projectquota/setup.ksh b/tests/zfs-tests/tests/functional/projectquota/setup.ksh new file mode 100755 index 000000000..c81b300e5 --- /dev/null +++ b/tests/zfs-tests/tests/functional/projectquota/setup.ksh @@ -0,0 +1,56 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib + +verify_runnable "both" + +del_user $PUSER +del_group $PGROUP +log_must add_group $PGROUP +log_must add_user $PGROUP $PUSER + +# +# Verify the test user can execute the zfs utilities. This may not +# be possible due to default permissions on the user home directory. +# This can be resolved granting group read access. +# +# chmod 0750 $HOME +# +user_run $PUSER zfs list +if [ $? -ne 0 ]; then + log_unsupported "Test user $PUSER cannot execute zfs utilities" +fi + +DISK=${DISKS%% *} +default_setup_noexit $DISK + +log_pass diff --git a/tests/zfs-tests/tests/functional/upgrade/Makefile.am b/tests/zfs-tests/tests/functional/upgrade/Makefile.am index 31034342f..ee1b92846 100644 --- a/tests/zfs-tests/tests/functional/upgrade/Makefile.am +++ b/tests/zfs-tests/tests/functional/upgrade/Makefile.am @@ -1,5 +1,7 @@ pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/upgrade dist_pkgdata_SCRIPTS = \ + upgrade_common.kshlib \ setup.ksh \ cleanup.ksh \ - upgrade_userobj_001_pos.ksh + upgrade_userobj_001_pos.ksh \ + upgrade_projectquota_001_pos.ksh diff --git a/tests/zfs-tests/tests/functional/upgrade/cleanup.ksh b/tests/zfs-tests/tests/functional/upgrade/cleanup.ksh index 19f4de24a..1f0c9b63d 100755 --- a/tests/zfs-tests/tests/functional/upgrade/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/upgrade/cleanup.ksh @@ -33,12 +33,10 @@ # Copyright (c) 2016 by Jinshan Xiong. No rights reserved. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib verify_runnable "global" -log_must zpool destroy $TESTPOOL - -log_must rm /tmp/zpool_upgrade_test.dat +log_must rm -f $TMPDEV default_cleanup diff --git a/tests/zfs-tests/tests/functional/upgrade/setup.ksh b/tests/zfs-tests/tests/functional/upgrade/setup.ksh index c3b89b304..c25d25df6 100755 --- a/tests/zfs-tests/tests/functional/upgrade/setup.ksh +++ b/tests/zfs-tests/tests/functional/upgrade/setup.ksh @@ -33,12 +33,11 @@ # Copyright (c) 2016 by Jinshan Xiong. No rights reserved. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib verify_runnable "global" # create a pool without any features -log_must mkfile 128m /tmp/zpool_upgrade_test.dat -log_must zpool create -d -m $TESTDIR $TESTPOOL /tmp/zpool_upgrade_test.dat +log_must mkfile 128m $TMPDEV log_pass diff --git a/tests/zfs-tests/tests/functional/upgrade/upgrade_common.kshlib b/tests/zfs-tests/tests/functional/upgrade/upgrade_common.kshlib new file mode 100644 index 000000000..2ff0cb7eb --- /dev/null +++ b/tests/zfs-tests/tests/functional/upgrade/upgrade_common.kshlib @@ -0,0 +1,41 @@ +# +# 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 http://www.opensolaris.org/os/licensing. +# 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) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +export TMPDEV=/tmp/zpool_upgrade_test.dat + +function cleanup_upgrade +{ + datasetexists $TESTPOOL/fs1 && log_must zfs destroy $TESTPOOL/fs1 + datasetexists $TESTPOOL/fs2 && log_must zfs destroy $TESTPOOL/fs2 + datasetexists $TESTPOOL/fs3 && log_must zfs destroy $TESTPOOL/fs3 + datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL +} diff --git a/tests/zfs-tests/tests/functional/upgrade/upgrade_projectquota_001_pos.ksh b/tests/zfs-tests/tests/functional/upgrade/upgrade_projectquota_001_pos.ksh new file mode 100755 index 000000000..27449ad1b --- /dev/null +++ b/tests/zfs-tests/tests/functional/upgrade/upgrade_projectquota_001_pos.ksh @@ -0,0 +1,128 @@ +#!/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 http://www.opensolaris.org/os/licensing. +# 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 (c) 2017 by Fan Yong. All rights reserved. +# + +. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib + +# +# DESCRIPTION: +# +# Check whether zfs upgrade for project quota works or not. +# The project quota is per dataset based feature, this test +# will create multiple datasets and try different upgrade methods. +# +# STRATEGY: +# 1. Create a pool with all features disabled +# 2. Create a few dataset for testing +# 3. Make sure automatic upgrade work +# 4. Make sure manual upgrade work +# + +verify_runnable "global" + +if ! lsattr -pd > /dev/null 2>&1; then + log_unsupported "Current e2fsprogs does not support set/show project ID" +fi + +log_assert "pool upgrade for projectquota should work" +log_onexit cleanup_upgrade + +log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV + +log_must mkfiles $TESTDIR/tf $((RANDOM % 100 + 1)) +log_must zfs create $TESTPOOL/fs1 +log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 100 + 1)) +log_must zfs umount $TESTPOOL/fs1 + +log_must zfs create $TESTPOOL/fs2 +log_must mkdir $TESTDIR/fs2/dir +log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 100 + 1)) + +log_must zfs create $TESTPOOL/fs3 +log_must mkdir $TESTDIR/fs3/dir +log_must mkfiles $TESTDIR/fs3/tf $((RANDOM % 100 + 1)) + +# Make sure project quota is disabled +zfs projectspace -o used $TESTPOOL | grep -q "USED" && + log_fail "project quota should be disabled initially" + +# set projectquota before upgrade will fail +log_mustnot zfs set projectquota@100=100m $TESTDIR/fs3 + +# set projectobjquota before upgrade will fail +log_mustnot zfs set projectobjquota@100=1000 $TESTDIR/fs3 + +# 'chattr -p' should fail before upgrade +log_mustnot chattr -p 100 $TESTDIR/fs3/dir + +# 'chattr +P' should fail before upgrade +log_mustnot chattr +P $TESTDIR/fs3/dir + +# Upgrade zpool to support all features +log_must zpool upgrade $TESTPOOL + +# Double check project quota is disabled +zfs projectspace -o used $TESTPOOL | grep -q "USED" && + log_fail "project quota should be disabled after pool upgrade" + +# Mount dataset should trigger upgrade +log_must zfs mount $TESTPOOL/fs1 +log_must sleep 3 # upgrade done in the background so let's wait for a while +zfs projectspace -o used $TESTPOOL/fs1 | grep -q "USED" || + log_fail "project quota should be enabled for $TESTPOOL/fs1" + +# Create file should trigger dataset upgrade +log_must mkfile 1m $TESTDIR/fs2/dir/tf +log_must sleep 3 # upgrade done in the background so let's wait for a while +zfs projectspace -o used $TESTPOOL/fs2 | grep -q "USED" || + log_fail "project quota should be enabled for $TESTPOOL/fs2" + +# "lsattr -p" should NOT trigger upgrade +log_must lsattr -p -d $TESTDIR/fs3/dir +zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" && + log_fail "project quota should not active for $TESTPOOL/fs3" + +# 'chattr -p' should trigger dataset upgrade +log_must chattr -p 100 $TESTDIR/fs3/dir +log_must sleep 5 # upgrade done in the background so let's wait for a while +zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" || + log_fail "project quota should be enabled for $TESTPOOL/fs3" +cnt=$(zfs get -H projectobjused@100 $TESTPOOL/fs3 | awk '{print $3}') +# if 'xattr=on', then 'cnt = 2' +[[ $cnt -ne 1 ]] && [[ $cnt -ne 2 ]] && + log_fail "projectquota accounting failed $cnt" + +# All in all, after having been through this, the dataset for testpool +# still shouldn't be upgraded +zfs projectspace -o used $TESTPOOL | grep -q "USED" && + log_fail "project quota should be disabled for $TESTPOOL" + +# Manual upgrade root dataset +# uses an ioctl which will wait for the upgrade to be done before returning +log_must zfs set version=current $TESTPOOL +zfs projectspace -o used $TESTPOOL | grep -q "USED" || + log_fail "project quota should be enabled for $TESTPOOL" + +log_pass "Project Quota upgrade done" diff --git a/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh b/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh index dda594f4e..b437a0cdf 100755 --- a/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh @@ -25,7 +25,7 @@ # Copyright (c) 2017 Datto Inc. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib # # DESCRIPTION: @@ -41,16 +41,12 @@ # 4. Make sure manual upgrade work # -function cleanup -{ - datasetexists $TESTPOOL/fs1 && log_must zfs destroy $TESTPOOL/fs1 - datasetexists $TESTPOOL/fs2 && log_must zfs destroy $TESTPOOL/fs2 -} - verify_runnable "global" log_assert "pool upgrade for userobj accounting should work" -log_onexit cleanup +log_onexit cleanup_upgrade + +log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV log_must mkfiles $TESTDIR/tf $((RANDOM % 1000 + 1)) log_must zfs create $TESTPOOL/fs1 |