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) 2013 by Jinshan Xiong. No 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 that zfs upgrade for object count accounting works.
34*f67950b2SNasf-Fan# Since userobjaccounting is a per dataset feature, this test case
35*f67950b2SNasf-Fan# will create multiple dataset and try different upgrade method.
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 userobj accounting 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 % 1000 + 1))
52*f67950b2SNasf-Fanlog_must zfs create $TESTPOOL/fs1
53*f67950b2SNasf-Fanlog_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 1000 + 1))
54*f67950b2SNasf-Fanlog_must zfs create $TESTPOOL/fs2
55*f67950b2SNasf-Fanlog_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 1000 + 1))
56*f67950b2SNasf-Fanlog_must zfs umount $TESTPOOL/fs2
57*f67950b2SNasf-Fan
58*f67950b2SNasf-Fan# Make sure userobj accounting is disabled
59*f67950b2SNasf-Fanzfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
60*f67950b2SNasf-Fan	log_fail "userobj accounting should be disabled initially"
61*f67950b2SNasf-Fan
62*f67950b2SNasf-Fan# Upgrade zpool to support all features
63*f67950b2SNasf-Fanlog_must zpool upgrade $TESTPOOL
64*f67950b2SNasf-Fan
65*f67950b2SNasf-Fan# Make sure userobj accounting is disabled again
66*f67950b2SNasf-Fanzfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
67*f67950b2SNasf-Fan	log_fail "userobj accounting should be disabled after pool upgrade"
68*f67950b2SNasf-Fan
69*f67950b2SNasf-Fan# Create a file in fs1 should trigger dataset upgrade
70*f67950b2SNasf-Fanlog_must mkfile 1m $TESTDIR/fs1/tf
71*f67950b2SNasf-Fansync_pool
72*f67950b2SNasf-Fan
73*f67950b2SNasf-Fan# Make sure userobj accounting is working for fs1
74*f67950b2SNasf-Fanzfs userspace -o objused -H $TESTPOOL/fs1 | head -n 1 | grep -q "-" &&
75*f67950b2SNasf-Fan	log_fail "userobj accounting should be enabled for $TESTPOOL/fs1"
76*f67950b2SNasf-Fan
77*f67950b2SNasf-Fan# Mount a dataset should trigger upgrade
78*f67950b2SNasf-Fanlog_must zfs mount $TESTPOOL/fs2
79*f67950b2SNasf-Fansync_pool
80*f67950b2SNasf-Fan
81*f67950b2SNasf-Fan# Make sure userobj accounting is working for fs2
82*f67950b2SNasf-Fanzfs userspace -o objused -H $TESTPOOL/fs2 | head -n 1 | grep -q "-" &&
83*f67950b2SNasf-Fan	log_fail "userobj accounting should be enabled for $TESTPOOL/fs2"
84*f67950b2SNasf-Fan
85*f67950b2SNasf-Fan# All in all, after having been through this, the dataset for testpool
86*f67950b2SNasf-Fan# still shouldn't be upgraded
87*f67950b2SNasf-Fanzfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
88*f67950b2SNasf-Fan	log_fail "userobj accounting should be disabled for $TESTPOOL"
89*f67950b2SNasf-Fan
90*f67950b2SNasf-Fan# Manual upgrade root dataset
91*f67950b2SNasf-Fanlog_must zfs set version=current $TESTPOOL
92*f67950b2SNasf-Fanzfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" &&
93*f67950b2SNasf-Fan	log_fail "userobj accounting should be enabled for $TESTPOOL"
94*f67950b2SNasf-Fan
95*f67950b2SNasf-Fanlog_pass "all tests passed - what a lucky day!"
96