]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh
New upstream version 0.7.2
[mirror_zfs-debian.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/include/libtest.shlib
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 function cleanup
45 {
46 datasetexists $TESTPOOL/fs1 && log_must zfs destroy $TESTPOOL/fs1
47 datasetexists $TESTPOOL/fs2 && log_must zfs destroy $TESTPOOL/fs2
48 }
49
50 verify_runnable "global"
51
52 log_assert "pool upgrade for userobj accounting should work"
53 log_onexit cleanup
54
55 log_must mkfiles $TESTDIR/tf $((RANDOM % 1000 + 1))
56 log_must zfs create $TESTPOOL/fs1
57 log_must mkfiles $TESTDIR/fs1/tf $((RANDOM % 1000 + 1))
58 log_must zfs create $TESTPOOL/fs2
59 log_must mkfiles $TESTDIR/fs2/tf $((RANDOM % 1000 + 1))
60 log_must zfs umount $TESTPOOL/fs2
61
62 # Make sure userobj accounting is disabled
63 zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
64 log_fail "userobj accounting should be disabled initially"
65
66 # Upgrade zpool to support all features
67 log_must zpool upgrade $TESTPOOL
68
69 # Make sure userobj accounting is disabled again
70 zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
71 log_fail "userobj accounting should be disabled after pool upgrade"
72
73 # Create a file in fs1 should trigger dataset upgrade
74 log_must mkfile 1m $TESTDIR/fs1/tf
75 log_must sleep 1 # upgrade done in the background so let's give it a sec
76
77 # Make sure userobj accounting is working for fs1
78 zfs userspace -o objused -H $TESTPOOL/fs1 | head -n 1 | grep -q "-" &&
79 log_fail "userobj accounting should be enabled for $TESTPOOL/fs1"
80
81 # Mount a dataset should trigger upgrade
82 log_must zfs mount $TESTPOOL/fs2
83 log_must sleep 1 # upgrade done in the background so let's give it a sec
84
85 # Make sure userobj accounting is working for fs2
86 zfs userspace -o objused -H $TESTPOOL/fs2 | head -n 1 | grep -q "-" &&
87 log_fail "userobj accounting should be enabled for $TESTPOOL/fs2"
88
89 # All in all, after having been through this, the dataset for testpool
90 # still shouldn't be upgraded
91 zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
92 log_fail "userobj accounting should be disabled for $TESTPOOL"
93
94 # Manual upgrade root dataset
95 # uses an ioctl which will wait for the upgrade to be done before returning
96 log_must zfs set version=current $TESTPOOL
97 zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" &&
98 log_fail "userobj accounting should be enabled for $TESTPOOL"
99
100 log_pass "all tests passed - what a lucky day!"