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