xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/upgrade/upgrade_projectquota_001_pos.ksh (revision f52943a93040563107b95bccb9db87d9971ef47d)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2017 by Fan Yong. All rights reserved.
25# Copyright 2019 Joyent, Inc.
26#
27
28. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib
29
30#
31# DESCRIPTION:
32#
33# Check whether zfs upgrade for project quota works or not.
34# The project quota is per dataset based feature. This test
35# will create multiple datasets and try different upgrade methods.
36#
37# STRATEGY:
38# 1. Create a pool with all features disabled
39# 2. Create a few dataset for testing
40# 3. Make sure automatic upgrade work
41# 4. Make sure manual upgrade work
42#
43
44verify_runnable "global"
45
46log_assert "pool upgrade for projectquota should work"
47log_onexit cleanup_upgrade
48
49log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV
50
51log_must mkfiles $TESTDIR/tf $((RANDOM % 100 + 1))
52log_must zfs create $TESTPOOL/fs1
53log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 100 + 1))
54log_must zfs umount $TESTPOOL/fs1
55
56log_must zfs create $TESTPOOL/fs2
57log_must mkdir $TESTDIR/fs2/dir
58log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 100 + 1))
59
60log_must zfs create $TESTPOOL/fs3
61log_must mkdir $TESTDIR/fs3/dir
62log_must mkfiles $TESTDIR/fs3/tf $((RANDOM % 100 + 1))
63
64# Make sure project quota is disabled
65zfs projectspace -o used $TESTPOOL | grep -q "USED" &&
66	log_fail "project quota should be disabled initially"
67
68# set projectquota before upgrade will fail
69log_mustnot zfs set projectquota@100=100m $TESTDIR/fs3
70
71# set projectobjquota before upgrade will fail
72log_mustnot zfs set projectobjquota@100=1000 $TESTDIR/fs3
73
74# setting a project should fail before upgrade
75# log_mustnot chattr -p 100 $TESTDIR/fs3/dir
76log_mustnot zfs project -s -p 100 $TESTDIR/fs3/dir
77
78# Upgrade zpool to support all features
79log_must zpool upgrade $TESTPOOL
80
81# Double check project quota is disabled
82zfs projectspace -o used $TESTPOOL | grep -q "USED" &&
83	log_fail "project quota should be disabled after pool upgrade"
84
85# Mount dataset should trigger upgrade
86log_must zfs mount $TESTPOOL/fs1
87log_must sleep 3 # upgrade done in the background so let's wait for a while
88zfs projectspace -o used $TESTPOOL/fs1 | grep -q "USED" ||
89	log_fail "project quota should be enabled for $TESTPOOL/fs1"
90
91# Create file should trigger dataset upgrade
92log_must mkfile 1m $TESTDIR/fs2/dir/tf
93log_must sleep 3 # upgrade done in the background so let's wait for a while
94zfs projectspace -o used $TESTPOOL/fs2 | grep -q "USED" ||
95	log_fail "project quota should be enabled for $TESTPOOL/fs2"
96
97# reading projects should NOT trigger upgrade
98# log_must lsattr -p -d $TESTDIR/fs3/dir
99log_must eval "zfs project $TESTDIR/fs3/dir"
100zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" &&
101	log_fail "project quota should not active for $TESTPOOL/fs3"
102
103# setting a project should trigger dataset upgrade
104# log_must chattr -p 100 $TESTDIR/fs3/dir
105log_must zfs project -s -p 100 $TESTDIR/fs3/dir
106log_must sleep 5 # upgrade done in the background so let's wait for a while
107zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" ||
108	log_fail "project quota should be enabled for $TESTPOOL/fs3"
109cnt=$(zfs get -H projectobjused@100 $TESTPOOL/fs3 | awk '{print $3}')
110# if 'xattr=on', then 'cnt = 2'
111[[ $cnt -ne 1 ]] && [[ $cnt -ne 2 ]] &&
112	log_fail "projectquota accounting failed $cnt"
113
114# All in all, after having been through this, the dataset for testpool
115# still shouldn't be upgraded
116zfs projectspace -o used $TESTPOOL | grep -q "USED" &&
117	log_fail "project quota should be disabled for $TESTPOOL"
118
119# Manual upgrade root dataset
120# uses an ioctl which will wait for the upgrade to be done before returning
121log_must zfs set version=current $TESTPOOL
122zfs projectspace -o used $TESTPOOL | grep -q "USED" ||
123	log_fail "project quota should be enabled for $TESTPOOL"
124
125log_pass "Project Quota upgrade done"
126