mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-31 11:14:09 +03:00
Project Quota on ZFS
Project quota is a new ZFS system space/object usage accounting and enforcement mechanism. Similar as user/group quota, project quota is another dimension of system quota. It bases on the new object attribute - project ID. Project ID is a numerical value to indicate to which project an object belongs. An object only can belong to one project though you (the object owner or privileged user) can change the object project ID via 'chattr -p' or 'zfs project [-s] -p' explicitly. The object also can inherit the project ID from its parent when created if the parent has the project inherit flag (that can be set via 'chattr +P' or 'zfs project -s [-p]'). By accounting the spaces/objects belong to the same project, we can know how many spaces/objects used by the project. And if we set the upper limit then we can control the spaces/objects that are consumed by such project. It is useful when multiple groups and users cooperate for the same project, or a user/group needs to participate in multiple projects. Support the following commands and functionalities: zfs set projectquota@project zfs set projectobjquota@project zfs get projectquota@project zfs get projectobjquota@project zfs get projectused@project zfs get projectobjused@project zfs projectspace zfs allow projectquota zfs allow projectobjquota zfs allow projectused zfs allow projectobjused zfs unallow projectquota zfs unallow projectobjquota zfs unallow projectused zfs unallow projectobjused chattr +/-P chattr -p project_id lsattr -p This patch also supports tree quota based on the project quota via "zfs project" commands set as following: zfs project [-d|-r] <file|directory ...> zfs project -C [-k] [-r] <file|directory ...> zfs project -c [-0] [-d|-r] [-p id] <file|directory ...> zfs project [-p id] [-r] [-s] <file|directory ...> For "df [-i] $DIR" command, if we set INHERIT (project ID) flag on the $DIR, then the proejct [obj]quota and [obj]used values for the $DIR's project ID will be shown as the total/free (avail) resource. Keep the same behavior as EXT4/XFS does. Reviewed-by: Andreas Dilger <andreas.dilger@intel.com> Reviewed-by Ned Bass <bass6@llnl.gov> Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Fan Yong <fan.yong@intel.com> TEST_ZIMPORT_POOLS="zol-0.6.1 zol-0.6.2 master" Change-Id: Ib4f0544602e03fb61fd46a849d7ba51a6005693c Closes #6290
This commit is contained in:
committed by
Brian Behlendorf
parent
c03f04708c
commit
9c5167d19f
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user