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 https://opensource.org/licenses/CDDL-1.0. 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# 26 27. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib 28 29# 30# DESCRIPTION: 31# 32# Check whether zfs upgrade for project quota works or not. 33# The project quota is per dataset based feature, this test 34# will create multiple datasets and try different upgrade methods. 35# 36# STRATEGY: 37# 1. Create a pool with all features disabled 38# 2. Create a few dataset for testing 39# 3. Make sure automatic upgrade work 40# 4. Make sure manual upgrade work 41# 42 43verify_runnable "global" 44 45if ! lsattr -pd > /dev/null 2>&1; then 46 log_unsupported "Current lsattr does not support set/show project ID" 47fi 48 49log_assert "pool upgrade for projectquota should work" 50log_onexit cleanup_upgrade 51 52log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV 53 54log_must mkfiles $TESTDIR/tf $((RANDOM % 100 + 1)) 55log_must zfs create $TESTPOOL/fs1 56log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 100 + 1)) 57log_must zfs umount $TESTPOOL/fs1 58 59log_must zfs create $TESTPOOL/fs2 60log_must mkdir $TESTDIR/fs2/dir 61log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 100 + 1)) 62 63log_must zfs create $TESTPOOL/fs3 64log_must mkdir $TESTDIR/fs3/dir 65log_must mkfiles $TESTDIR/fs3/tf $((RANDOM % 100 + 1)) 66log_must set_xattr_stdin passwd $TESTDIR/fs3/dir < /etc/passwd 67 68# Make sure project quota is disabled 69zfs projectspace -o used $TESTPOOL | grep -q "USED" && 70 log_fail "project quota should be disabled initially" 71 72# set projectquota before upgrade will fail 73log_mustnot zfs set projectquota@100=100m $TESTDIR/fs3 74 75# set projectobjquota before upgrade will fail 76log_mustnot zfs set projectobjquota@100=1000 $TESTDIR/fs3 77 78# 'chattr -p' should fail before upgrade 79log_mustnot chattr -p 100 $TESTDIR/fs3/dir 80 81# 'chattr +P' should fail before upgrade 82log_mustnot chattr +P $TESTDIR/fs3/dir 83 84# Upgrade zpool to support all features 85log_must zpool upgrade $TESTPOOL 86 87# Double check project quota is disabled 88zfs projectspace -o used $TESTPOOL | grep -q "USED" && 89 log_fail "project quota should be disabled after pool upgrade" 90 91# Mount dataset should trigger upgrade 92log_must zfs mount $TESTPOOL/fs1 93log_must sleep 3 # upgrade done in the background so let's wait for a while 94zfs projectspace -o used $TESTPOOL/fs1 | grep -q "USED" || 95 log_fail "project quota should be enabled for $TESTPOOL/fs1" 96 97# Create file should trigger dataset upgrade 98log_must mkfile 1m $TESTDIR/fs2/dir/tf 99log_must sleep 3 # upgrade done in the background so let's wait for a while 100zfs projectspace -o used $TESTPOOL/fs2 | grep -q "USED" || 101 log_fail "project quota should be enabled for $TESTPOOL/fs2" 102 103# "lsattr -p" should NOT trigger upgrade 104log_must lsattr -p -d $TESTDIR/fs3/dir 105zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" && 106 log_fail "project quota should not active for $TESTPOOL/fs3" 107 108# 'chattr -p' should trigger dataset upgrade 109log_must chattr -p 100 $TESTDIR/fs3/dir 110log_must sleep 5 # upgrade done in the background so let's wait for a while 111zfs projectspace -o used $TESTPOOL/fs3 | grep -q "USED" || 112 log_fail "project quota should be enabled for $TESTPOOL/fs3" 113dirino=$(stat -c '%i' $TESTDIR/fs3/dir) 114log_must zdb -ddddd $TESTPOOL/fs3 $dirino 115xattrdirino=$(zdb -ddddd $TESTPOOL/fs3 $dirino |grep -w "xattr" |awk '{print $2}') 116echo "xattrdirino: $xattrdirino" 117expectedcnt=1 118echo "expectedcnt: $expectedcnt" 119if [ "$xattrdirino" != "" ]; then 120 expectedcnt=$(($expectedcnt + 1)) 121 echo "expectedcnt: $expectedcnt" 122 log_must zdb -ddddd $TESTPOOL/fs3 $xattrdirino 123 xattrinocnt=$(zdb -ddddd $TESTPOOL/fs3 $xattrdirino |grep -w "(type:" |wc -l) 124 echo "xattrinocnt: $xattrinocnt" 125 expectedcnt=$(($expectedcnt + $xattrinocnt)) 126 echo "expectedcnt: $expectedcnt" 127fi 128cnt=$(get_prop projectobjused@100 $TESTPOOL/fs3) 129[[ $cnt -ne $expectedcnt ]] && 130 log_fail "projectquota accounting failed $cnt" 131 132# All in all, after having been through this, the dataset for testpool 133# still shouldn't be upgraded 134zfs projectspace -o used $TESTPOOL | grep -q "USED" && 135 log_fail "project quota should be disabled for $TESTPOOL" 136 137# Manual upgrade root dataset 138# uses an ioctl which will wait for the upgrade to be done before returning 139log_must zfs set version=current $TESTPOOL 140zfs projectspace -o used $TESTPOOL | grep -q "USED" || 141 log_fail "project quota should be enabled for $TESTPOOL" 142 143log_pass "Project Quota upgrade done" 144