1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3# 4# CDDL HEADER START 5# 6# The contents of this file are subject to the terms of the 7# Common Development and Distribution License (the "License"). 8# You may not use this file except in compliance with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or https://opensource.org/licenses/CDDL-1.0. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23 24# 25# Copyright (c) 2017 by Fan Yong. All rights reserved. 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 46if ! lsattr -pd > /dev/null 2>&1; then 47 log_unsupported "Current lsattr does not support set/show project ID" 48fi 49 50log_assert "pool upgrade for projectquota should work" 51log_onexit cleanup_upgrade 52 53log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV 54 55log_must mkfiles $TESTDIR/tf $((RANDOM % 100 + 1)) 56log_must zfs create $TESTPOOL/fs1 57log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 100 + 1)) 58log_must zfs umount $TESTPOOL/fs1 59 60log_must zfs create $TESTPOOL/fs2 61log_must mkdir $TESTDIR/fs2/dir 62log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 100 + 1)) 63 64log_must zfs create $TESTPOOL/fs3 65log_must mkdir $TESTDIR/fs3/dir 66log_must mkfiles $TESTDIR/fs3/tf $((RANDOM % 100 + 1)) 67log_must set_xattr_stdin passwd $TESTDIR/fs3/dir < /etc/passwd 68 69# Make sure project quota is disabled 70zfs projectspace -o used $TESTPOOL | grep -q "USED" && 71 log_fail "project quota should be disabled initially" 72 73# set projectquota before upgrade will fail 74log_mustnot zfs set projectquota@100=100m $TESTDIR/fs3 75 76# set projectobjquota before upgrade will fail 77log_mustnot zfs set projectobjquota@100=1000 $TESTDIR/fs3 78 79# 'chattr -p' should fail before upgrade 80log_mustnot chattr -p 100 $TESTDIR/fs3/dir 81 82# 'chattr +P' should fail before upgrade 83log_mustnot chattr +P $TESTDIR/fs3/dir 84 85# Upgrade zpool to support all features 86log_must zpool upgrade $TESTPOOL 87 88# Double check project quota is disabled 89zfs projectspace -o used $TESTPOOL | grep -q "USED" && 90 log_fail "project quota should be disabled after pool upgrade" 91 92# Mount dataset should trigger upgrade 93log_must zfs mount $TESTPOOL/fs1 94log_must sleep 3 # upgrade done in the background so let's wait for a while 95zfs projectspace -o used $TESTPOOL/fs1 | grep -q "USED" || 96 log_fail "project quota should be enabled for $TESTPOOL/fs1" 97 98# Create file should trigger dataset upgrade 99log_must mkfile 1m $TESTDIR/fs2/dir/tf 100log_must sleep 3 # upgrade done in the background so let's wait for a while 101zfs projectspace -o used $TESTPOOL/fs2 | grep -q "USED" || 102 log_fail "project quota should be enabled for $TESTPOOL/fs2" 103 104# "lsattr -p" should NOT trigger upgrade 105log_must lsattr -p -d $TESTDIR/fs3/dir 106zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" && 107 log_fail "project quota should not active for $TESTPOOL/fs3" 108 109# 'chattr -p' should trigger dataset upgrade 110log_must chattr -p 100 $TESTDIR/fs3/dir 111log_must sleep 5 # upgrade done in the background so let's wait for a while 112zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" || 113 log_fail "project quota should be enabled for $TESTPOOL/fs3" 114dirino=$(stat -c '%i' $TESTDIR/fs3/dir) 115log_must zdb -ddddd $TESTPOOL/fs3 $dirino 116xattrdirino=$(zdb -ddddd $TESTPOOL/fs3 $dirino |grep -w "xattr" |awk '{print $2}') 117echo "xattrdirino: $xattrdirino" 118expectedcnt=1 119echo "expectedcnt: $expectedcnt" 120if [ "$xattrdirino" != "" ]; then 121 expectedcnt=$(($expectedcnt + 1)) 122 echo "expectedcnt: $expectedcnt" 123 log_must zdb -ddddd $TESTPOOL/fs3 $xattrdirino 124 xattrinocnt=$(zdb -ddddd $TESTPOOL/fs3 $xattrdirino |grep -w "(type:" |wc -l) 125 echo "xattrinocnt: $xattrinocnt" 126 expectedcnt=$(($expectedcnt + $xattrinocnt)) 127 echo "expectedcnt: $expectedcnt" 128fi 129cnt=$(get_prop projectobjused@100 $TESTPOOL/fs3) 130[[ $cnt -ne $expectedcnt ]] && 131 log_fail "projectquota accounting failed $cnt" 132 133# All in all, after having been through this, the dataset for testpool 134# still shouldn't be upgraded 135zfs projectspace -o used $TESTPOOL | grep -q "USED" && 136 log_fail "project quota should be disabled for $TESTPOOL" 137 138# Manual upgrade root dataset 139# uses an ioctl which will wait for the upgrade to be done before returning 140log_must zfs set version=current $TESTPOOL 141zfs projectspace -o used $TESTPOOL | grep -q "USED" || 142 log_fail "project quota should be enabled for $TESTPOOL" 143 144log_pass "Project Quota upgrade done" 145