From b8bec3fd2a8feb3a4de572eb15515d3764f92a35 Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Wed, 5 Aug 2020 17:44:44 +0000 Subject: [PATCH] Add a new test to confirm that the ZSTD feature flag is activated When the compression property on a dataset is set to zstd, the feature flag is not changed from 'enabled' to 'active' until the first block is born. If the pool is exported after `zfs set` but before a block is written then imported on a system with an older version of ZFS that does not understand ZSTD, it will cause the userland utilities to panic. Signed-off-by: Allan Jude --- .../cli_root/zdb/zdb_decompress_zstd.ksh | 0 .../zfs_set/zfs_set_feature_activation.ksh | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+) mode change 100644 => 100755 tests/zfs-tests/tests/functional/cli_root/zdb/zdb_decompress_zstd.ksh create mode 100755 tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_feature_activation.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_decompress_zstd.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_decompress_zstd.ksh old mode 100644 new mode 100755 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_feature_activation.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_feature_activation.ksh new file mode 100755 index 000000000000..c7d45843c0a6 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_feature_activation.ksh @@ -0,0 +1,83 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2020 The FreeBSD Foundation [1] +# +# [1] Portions of this software were developed by Allan Jude +# under sponsorship from the FreeBSD Foundation. + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: +# Setting the compression property to any of the zstd levels should activate +# the zstd feature flag. Destroying the last dataset using the zstd feature flag +# should revert the feature to the 'enabled' state. +# +# STRATEGY: +# 1. Create pool, then create a file system within it. +# 2. Check that the zstd feature flag is 'enabled'. +# 3. Setting the compression property to zstd. +# 4. Check that the zstd feature flag is now 'active'. +# 5. Destroy the dataset +# 6. Confirm that the feature flag reverts to the 'enabled' state. +# + +verify_runnable "both" + +log_assert "Setting compression=zstd should activate the"\ + "org.freebsd:zstd_compress feature flag, and destroying the last"\ + "dataset using that property, should revert the feature flag to"\ + "the enabled state." + +featureval="$(get_pool_prop feature@zstd_compress $TESTPOOL)" + +[[ "$featureval" == "disabled" ]] && \ + log_unsupported "ZSTD feature flag unsupposed" + +[[ "$featureval" == "active" ]] && \ + log_unsupported "ZSTD feature already active before test" + +random_level=$((RANDOM%19 + 1)) +log_note "Randomly selected ZSTD level: $random_level" + +log_must zfs create -o compress=zstd-$random_level $TESTPOOL/$TESTFS-zstd + +featureval="$(get_pool_prop feature@zstd_compress $TESTPOOL)" + +log_note "After zfs set, feature flag value is: $featureval" + +[[ "$featureval" == "active" ]] || + log_fail "ZSTD feature flag not activated" + +log_must zfs destroy $TESTPOOL/$TESTFS-zstd + +featureval="$(get_pool_prop feature@zstd_compress $TESTPOOL)" + +log_note "After zfs destroy, feature flag value is: $featureval" + +[[ "$featureval" == "enabled" ]] || + log_fail "ZSTD feature flag not deactivated" + +log_pass "Setting compression=zstd activated the feature flag, and"\ + "destroying the dataset deactivated it."