]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / upgrade / upgrade_userobj_001_pos.ksh
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 (c) 2017 Datto 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
44 verify_runnable "global"
45
46 log_assert "pool upgrade for userobj accounting should work"
47 log_onexit cleanup_upgrade
48
49 log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV
50
51 log_must mkfiles $TESTDIR/tf $((RANDOM % 1000 + 1))
52 log_must zfs create $TESTPOOL/fs1
53 log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 1000 + 1))
54 log_must zfs create $TESTPOOL/fs2
55 log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 1000 + 1))
56 log_must zfs umount $TESTPOOL/fs2
57
58 # Make sure userobj accounting is disabled
59 zfs 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
63 log_must zpool upgrade $TESTPOOL
64
65 # Make sure userobj accounting is disabled again
66 zfs 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
70 log_must mkfile 1m $TESTDIR/fs1/tf
71 log_must sleep 1 # upgrade done in the background so let's give it a sec
72
73 # Make sure userobj accounting is working for fs1
74 zfs 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
78 log_must zfs mount $TESTPOOL/fs2
79 log_must sleep 1 # upgrade done in the background so let's give it a sec
80
81 # Make sure userobj accounting is working for fs2
82 zfs 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
87 zfs 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
91 # uses an ioctl which will wait for the upgrade to be done before returning
92 log_must zfs set version=current $TESTPOOL
93 zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" &&
94         log_fail "userobj accounting should be enabled for $TESTPOOL"
95
96 log_pass "all tests passed - what a lucky day!"