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