]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/limits/filesystem_count.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / limits / filesystem_count.ksh
1 #!/bin/ksh -p
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source.  A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15 #
16
17 . $STF_SUITE/include/libtest.shlib
18
19 #
20 # DESCRIPTION:
21 # ZFS 'filesystem_count' property is handled correctly by various actions
22 #
23 # STRATEGY:
24 # 1. Verify 'zfs create' and 'zfs clone' increment 'filesystem_count' value
25 # 2. Verify 'zfs destroy' decrements the value
26 # 3. Verify 'zfs rename' updates counts across different hierarchies
27 # 4. Verify 'zfs promote' preserves counts within different hierarchies
28 # 5. Verify 'zfs receive' correct behaviour
29 # 6. Verify 'zfs rollback' does not update 'filesystem_count' value
30 # 7. Verify 'zfs diff' does not update 'filesystem_count' value
31 #
32
33 verify_runnable "both"
34
35 function setup
36 {
37         log_must zfs create "$DATASET_TEST"
38         log_must zfs create "$DATASET_UTIL"
39         # Set filesystem_limit just to activate the filesystem_count property
40         log_must zfs set filesystem_limit=100 "$DATASET_TEST"
41 }
42
43 function cleanup
44 {
45         destroy_dataset "$DATASET_TEST" "-Rf"
46         destroy_dataset "$DATASET_UTIL" "-Rf"
47         rm -f $ZSTREAM
48 }
49
50 log_assert "Verify 'filesystem_count' is handled correctly by various actions"
51 log_onexit cleanup
52
53 DATASET_TEST="$TESTPOOL/$TESTFS/filesystem_count_test"
54 DATASET_UTIL="$TESTPOOL/$TESTFS/filesystem_count_util"
55 ZSTREAM="$TEST_BASE_DIR/filesystem_count.$$"
56
57 # 1. Verify 'zfs create' and 'zfs clone' increment 'filesystem_count' value
58 setup
59 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
60 log_must zfs create "$DATASET_TEST/create_clone"
61 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
62 log_must zfs snapshot "$DATASET_TEST/create_clone@snap"
63 log_must zfs clone "$DATASET_TEST/create_clone@snap" "$DATASET_TEST/clone"
64 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "2"
65 cleanup
66
67 # 2. Verify 'zfs destroy' decrements the value
68 setup
69 log_must zfs create "$DATASET_TEST/destroy"
70 log_must zfs destroy "$DATASET_TEST/destroy"
71 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
72 cleanup
73
74 # 3. Verify 'zfs rename' updates counts across different hierarchies
75 setup
76 log_must zfs create "$DATASET_TEST/rename"
77 log_must zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed"
78 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
79 log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "1"
80 cleanup
81
82 # 4. Verify 'zfs promote' preserves counts within different hierarchies
83 setup
84 log_must zfs create "$DATASET_UTIL/promote"
85 log_must zfs snapshot "$DATASET_UTIL/promote@snap"
86 log_must zfs clone "$DATASET_UTIL/promote@snap" "$DATASET_TEST/promoted"
87 log_must zfs promote "$DATASET_TEST/promoted"
88 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
89 log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "1"
90 cleanup
91
92 # 5. Verify 'zfs receive' correct behaviour
93 setup
94 log_must zfs create "$DATASET_UTIL/send"
95 log_must zfs snapshot "$DATASET_UTIL/send@snap1"
96 log_must zfs snapshot "$DATASET_UTIL/send@snap2"
97 log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
98 log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
99 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
100 log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM"
101 log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
102 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
103 cleanup
104
105 # 6. Verify 'zfs rollback' does not update 'filesystem_count' value
106 setup
107 log_must zfs create "$DATASET_TEST/rollback"
108 log_must zfs snapshot "$DATASET_TEST/rollback@snap"
109 log_must zfs rollback "$DATASET_TEST/rollback@snap"
110 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
111 cleanup
112
113 # 7. Verify 'zfs diff' does not update 'filesystem_count' value
114 setup
115 log_must zfs create "$DATASET_TEST/diff"
116 log_must zfs snapshot "$DATASET_TEST/diff@snap1"
117 log_must zfs snapshot "$DATASET_TEST/diff@snap2"
118 log_must zfs diff "$DATASET_TEST/diff@snap1" "$DATASET_TEST/diff@snap2"
119 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
120 log_must zfs diff "$DATASET_TEST/diff@snap2"
121 log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
122
123 log_pass "'filesystem_count' property is handled correctly"