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
33verify_runnable "both"
34
35function 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
43function cleanup
44{
45	destroy_dataset "$DATASET_TEST" "-Rf"
46	destroy_dataset "$DATASET_UTIL" "-Rf"
47	rm -f $ZSTREAM
48}
49
50log_assert "Verify 'filesystem_count' is handled correctly by various actions"
51log_onexit cleanup
52
53DATASET_TEST="$TESTPOOL/$TESTFS/filesystem_count_test"
54DATASET_UTIL="$TESTPOOL/$TESTFS/filesystem_count_util"
55ZSTREAM="$TEST_BASE_DIR/filesystem_count.$$"
56
57# 1. Verify 'zfs create' and 'zfs clone' increment 'filesystem_count' value
58setup
59log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
60log_must zfs create "$DATASET_TEST/create_clone"
61log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
62log_must zfs snapshot "$DATASET_TEST/create_clone@snap"
63log_must zfs clone "$DATASET_TEST/create_clone@snap" "$DATASET_TEST/clone"
64log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "2"
65cleanup
66
67# 2. Verify 'zfs destroy' decrements the value
68setup
69log_must zfs create "$DATASET_TEST/destroy"
70log_must zfs destroy "$DATASET_TEST/destroy"
71log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
72cleanup
73
74# 3. Verify 'zfs rename' updates counts across different hierarchies
75setup
76log_must zfs create "$DATASET_TEST/rename"
77log_must zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed"
78log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
79log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "1"
80cleanup
81
82# 4. Verify 'zfs promote' preserves counts within different hierarchies
83setup
84log_must zfs create "$DATASET_UTIL/promote"
85log_must zfs snapshot "$DATASET_UTIL/promote@snap"
86log_must zfs clone "$DATASET_UTIL/promote@snap" "$DATASET_TEST/promoted"
87log_must zfs promote "$DATASET_TEST/promoted"
88log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
89log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "1"
90cleanup
91
92# 5. Verify 'zfs receive' correct behaviour
93setup
94log_must zfs create "$DATASET_UTIL/send"
95log_must zfs snapshot "$DATASET_UTIL/send@snap1"
96log_must zfs snapshot "$DATASET_UTIL/send@snap2"
97log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
98log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
99log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
100log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM"
101log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
102log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
103cleanup
104
105# 6. Verify 'zfs rollback' does not update 'filesystem_count' value
106setup
107log_must zfs create "$DATASET_TEST/rollback"
108log_must zfs snapshot "$DATASET_TEST/rollback@snap"
109log_must zfs rollback "$DATASET_TEST/rollback@snap"
110log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
111cleanup
112
113# 7. Verify 'zfs diff' does not update 'filesystem_count' value
114setup
115log_must zfs create "$DATASET_TEST/diff"
116log_must zfs snapshot "$DATASET_TEST/diff@snap1"
117log_must zfs snapshot "$DATASET_TEST/diff@snap2"
118log_must zfs diff "$DATASET_TEST/diff@snap1" "$DATASET_TEST/diff@snap2"
119log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
120log_must zfs diff "$DATASET_TEST/diff@snap2"
121log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
122
123log_pass "'filesystem_count' property is handled correctly"
124