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) 2020 The FreeBSD Foundation [1]
25#
26# [1] Portions of this software were developed by Allan Jude
27#     under sponsorship from the FreeBSD Foundation.
28
29. $STF_SUITE/include/libtest.shlib
30
31#
32# DESCRIPTION:
33# Setting the compression property to any of the zstd levels should activate
34# the zstd feature flag. Destroying the last dataset using the zstd feature flag
35# should revert the feature to the 'enabled' state.
36#
37# STRATEGY:
38# 1. Create pool, then create a file system within it.
39# 2. Check that the zstd feature flag is 'enabled'.
40# 3. Setting the compression property to zstd.
41# 4. Check that the zstd feature flag is now 'active'.
42# 5. Destroy the dataset
43# 6. Confirm that the feature flag reverts to the 'enabled' state.
44#
45
46verify_runnable "both"
47
48log_assert "Setting compression=zstd should activate the"\
49	"org.freebsd:zstd_compress feature flag, and destroying the last"\
50	"dataset using that property, should revert the feature flag to"\
51	"the enabled state."
52
53export VDEV_ZSTD="$TEST_BASE_DIR/vdev-zstd"
54
55function cleanup
56{
57	if poolexists $TESTPOOL-zstd ; then
58		destroy_pool $TESTPOOL-zstd
59	fi
60
61	rm $VDEV_ZSTD
62}
63log_onexit cleanup
64
65log_must truncate -s $SPA_MINDEVSIZE $VDEV_ZSTD
66log_must zpool create $TESTPOOL-zstd $VDEV_ZSTD
67
68featureval="$(get_pool_prop feature@zstd_compress $TESTPOOL-zstd)"
69
70[[ "$featureval" == "disabled" ]] && \
71	log_unsupported "ZSTD feature flag unsupposed"
72
73[[ "$featureval" == "active" ]] && \
74	log_unsupported "ZSTD feature already active before test"
75
76random_level=$((RANDOM%19 + 1))
77log_note "Randomly selected ZSTD level: $random_level"
78
79log_must zfs create -o compress=zstd-$random_level $TESTPOOL-zstd/$TESTFS-zstd
80
81featureval="$(get_pool_prop feature@zstd_compress $TESTPOOL-zstd)"
82
83log_note "After zfs set, feature flag value is: $featureval"
84
85[[ "$featureval" == "active" ]] ||
86	log_fail "ZSTD feature flag not activated"
87
88log_must zfs destroy $TESTPOOL-zstd/$TESTFS-zstd
89
90featureval="$(get_pool_prop feature@zstd_compress $TESTPOOL-zstd)"
91
92log_note "After zfs destroy, feature flag value is: $featureval"
93
94[[ "$featureval" == "enabled" ]] ||
95	log_fail "ZSTD feature flag not deactivated"
96
97log_pass "Setting compression=zstd activated the feature flag, and"\
98	"destroying the dataset deactivated it."
99