Add "compatibility" property for zpool feature sets

Property to allow sets of features to be specified; for compatibility
with specific versions / releases / external systems. Influences
the behavior of 'zpool upgrade' and 'zpool create'. Initial man
page changes and test cases included.

Brief synopsis:

zpool create -o compatibility=off|legacy|file[,file...] pool vdev...

compatibility = off : disable compatibility mode (enable all features)
compatibility = legacy : request that no features be enabled
compatibility = file[,file...] : read features from specified files.
Only features present in *all* files will be enabled on the
resulting pool. Filenames may be absolute, or relative to
/etc/zfs/compatibility.d or /usr/share/zfs/compatibility.d (/etc
checked first).

Only affects zpool create, zpool upgrade and zpool status.

ABI changes in libzfs:

* New function "zpool_load_compat" to load and parse compat sets.
* Add "zpool_compat_status_t" typedef for compatibility parse status.
* Add ZPOOL_PROP_COMPATIBILITY to the pool properties enum
* Add ZPOOL_STATUS_COMPATIBILITY_ERR to the pool status enum

An initial set of base compatibility sets are included in
cmd/zpool/compatibility.d, and the Makefile for cmd/zpool is
modified to install these in $pkgdatadir/compatibility.d and to
create symbolic links to a reasonable set of aliases.

Reviewed-by: ericloewe
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Colm Buckley <colm@tuatha.org>
Closes #11468
This commit is contained in:
Colm
2021-02-18 05:30:45 +00:00
committed by GitHub
parent 35ec51796f
commit 658fb8020f
48 changed files with 5621 additions and 2954 deletions
+5 -3
View File
@@ -344,7 +344,8 @@ tests = ['zpool_create_001_pos', 'zpool_create_002_pos',
'zpool_create_draid_003_pos', 'zpool_create_draid_004_pos',
'zpool_create_features_001_pos', 'zpool_create_features_002_pos',
'zpool_create_features_003_pos', 'zpool_create_features_004_neg',
'zpool_create_features_005_pos',
'zpool_create_features_005_pos', 'zpool_create_features_006_pos',
'zpool_create_features_007_pos', 'zpool_create_features_008_pos',
'create-o_ashift', 'zpool_create_tempname', 'zpool_create_dryrun_output']
tags = ['functional', 'cli_root', 'zpool_create']
@@ -468,7 +469,8 @@ tests = ['zpool_split_cliargs', 'zpool_split_devices',
tags = ['functional', 'cli_root', 'zpool_split']
[tests/functional/cli_root/zpool_status]
tests = ['zpool_status_001_pos', 'zpool_status_002_pos']
tests = ['zpool_status_001_pos', 'zpool_status_002_pos',
'zpool_status_features_001_pos']
tags = ['functional', 'cli_root', 'zpool_status']
[tests/functional/cli_root/zpool_sync]
@@ -491,7 +493,7 @@ tests = ['zpool_upgrade_001_pos', 'zpool_upgrade_002_pos',
'zpool_upgrade_003_pos', 'zpool_upgrade_004_pos',
'zpool_upgrade_005_neg', 'zpool_upgrade_006_neg',
'zpool_upgrade_007_pos', 'zpool_upgrade_008_pos',
'zpool_upgrade_009_neg']
'zpool_upgrade_009_neg', 'zpool_upgrade_features_001_pos']
tags = ['functional', 'cli_root', 'zpool_upgrade']
[tests/functional/cli_root/zpool_wait]
+1
View File
@@ -37,6 +37,7 @@
export ZEDLET_ETC_DIR=${ZEDLET_ETC_DIR:-@sysconfdir@/zfs/zed.d}
export ZEDLET_LIBEXEC_DIR=${ZEDLET_LIBEXEC_DIR:-@zfsexecdir@/zed.d}
export ZPOOL_SCRIPT_DIR=${ZPOOL_SCRIPT_DIR:-@sysconfdir@/zfs/zpool.d}
export ZPOOL_COMPAT_DIR=${ZPOOL_COMPAT_DIR:-@datadir@/zfs/compatibility.d}
# Define run length constants
export RT_LONG="3"
@@ -36,6 +36,9 @@ dist_pkgdata_SCRIPTS = \
zpool_create_features_003_pos.ksh \
zpool_create_features_004_neg.ksh \
zpool_create_features_005_pos.ksh \
zpool_create_features_006_pos.ksh \
zpool_create_features_007_pos.ksh \
zpool_create_features_008_pos.ksh \
create-o_ashift.ksh \
zpool_create_tempname.ksh \
zpool_create_dryrun_output.ksh
@@ -107,3 +107,84 @@ function save_dump_dev
fi
echo $dumpdev
}
#
# Verify a pools enabled features match the provided feature set.
# $1, pool name
# $2, feature set(s)
#
# check_feature_set $TESTPOOL set1 set2 set3 ...
#
function check_feature_set
{
typeset pool=$1
typeset feature_set=$2
shift
for set in "$@"; do
if test -e "$ZPOOL_COMPAT_DIR/$set"; then
file="$ZPOOL_COMPAT_DIR/$set"
else
log_fail "Missing feature file: $ZPOOL_COMPAT_DIR/$set"
fi
done
#
# Create a temporary file which contains all features which are
# common to the listed feature sets. This is used for comparison
# below to determine which features should be enabled.
#
typeset tmpfile=$(mktemp)
while read line; do
typeset flag=1
if [[ "$line" == "#*" ]]; then
continue
fi
for set in "$@"; do
if ! grep -q "$line" $ZPOOL_COMPAT_DIR/$set; then
flag=0
break;
fi
done
if [[ $flag -eq 1 ]]; then
echo "$line" >>$tmpfile
fi
done <"$file"
#
# Verify every enabled feature appears in the merged feature set.
# Verify every disabled feature does not.
#
for feature in $(zpool get all $pool | \
awk '$2 ~ /feature@/ { print $2 }'); do
state=$(get_pool_prop $feature $pool)
name=$(cut -d'@' -f2 <<<"$feature")
if [[ "$state" = "enabled" || "$state" = "active" ]]; then
if ! grep -q $name $tmpfile; then
cat $tmpfile
rm -f $tmpfile
log_fail "Enabled feature $name not " \
"in feature set file"
fi
elif [[ "$state" = "disabled" ]]; then
if grep -q $name $tmpfile; then
cat $tmpfile
rm -f $tmpfile
log_fail "Disabled feature $name is " \
"in feature set file"
fi
else
rm -f $tmpfile
log_fail "Feature $name in unknown state $state"
fi
done
log_note "Checked all features"
rm -f $tmpfile
}
@@ -0,0 +1,58 @@
#!/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) 2021 Lawrence Livermore National Security, LLC.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Verify '-o compatibility' reserved values 'off, legacy'
#
# STRATEGY:
# 1. Create a pool with '-o compatibility=off'
# 2. Create a pool with '-o compatibility=legacy'
# 3. Cannot create a pool with '-o compatibility=unknown'
#
verify_runnable "global"
function cleanup
{
datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL
}
log_onexit cleanup
log_assert "verify '-o compatibility' reserved values 'off, legacy'"
log_must zpool create -f -o compatibility=off $TESTPOOL $DISKS
log_must zpool destroy -f $TESTPOOL
log_must zpool create -f -o compatibility=legacy $TESTPOOL $DISKS
log_must zpool destroy -f $TESTPOOL
log_mustnot zpool create -f -o compatibility=unknown $TESTPOOL $DISKS
log_pass "verify '-o compatibility' reserved values 'off, legacy'"
@@ -0,0 +1,54 @@
#!/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) 2021 Lawrence Livermore National Security, LLC.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
#
# DESCRIPTION:
# Verify pools can be created with the expected feature set enabled.
#
# STRATEGY:
# 1. Create a pool with a known feature set.
# 2. Verify only those features are active/enabled.
#
verify_runnable "global"
function cleanup
{
datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL
}
log_onexit cleanup
log_assert "creates a pool with a specified feature set enabled"
log_must zpool create -f -o compatibility=compat-2020 $TESTPOOL $DISKS
check_feature_set $TESTPOOL compat-2020
log_must zpool destroy -f $TESTPOOL
log_pass "creates a pool with a specified feature set enabled"
@@ -0,0 +1,54 @@
#!/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) 2021 Lawrence Livermore National Security, LLC.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
#
# DESCRIPTION:
# Verify pools can be created with multiple feature sets.
#
# STRATEGY:
# 1. Create a pool with multiple feature sets.
# 2. Verify only the features common to both sets are enabled.
#
verify_runnable "global"
function cleanup
{
datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL
}
log_onexit cleanup
log_assert "creates a pool with multiple feature sets enabled"
log_must zpool create -f -o compatibility=freebsd-11.0,zol-0.8 $TESTPOOL $DISKS
check_feature_set $TESTPOOL freebsd-11.0 zol-0.8
log_must zpool destroy -f $TESTPOOL
log_pass "creates a pool with multiple feature sets enabled"
@@ -57,6 +57,7 @@ typeset -a properties=(
"leaked"
"multihost"
"autotrim"
"compatibility"
"feature@async_destroy"
"feature@empty_bpobj"
"feature@lz4_compress"
@@ -3,4 +3,5 @@ dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
zpool_status_001_pos.ksh \
zpool_status_002_pos.ksh
zpool_status_002_pos.ksh \
zpool_status_features_001_pos.ksh
@@ -0,0 +1,63 @@
#!/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) 2021 Lawrence Livermore National Security, LLC.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
#
# DESCRIPTION:
# Verify zpool status only recommends upgrading the pool when
# the enabled features don't match those in the feature set.
#
# STRATEGY:
# 1. Create a pool with a known feature set.
# 2. Verify there is no `zpool status` notice to upgrade the pool.
# 3. Set the pool compatibility to a newer feature set.
# 4. Verify there is a `zpool status` notice to upgrade the pool.
#
verify_runnable "global"
function cleanup
{
datasetexists $TESTPOOL1 && log_must zpool destroy $TESTPOOL1
rm -f $FILEDEV
}
FILEDEV="$TEST_BASE_DIR/filedev.$$"
log_onexit cleanup
log_assert "check 'zpool status' upgrade notice"
log_must truncate -s $MINVDEVSIZE $FILEDEV
log_must zpool create -f -o compatibility=compat-2018 $TESTPOOL1 $FILEDEV
log_mustnot check_pool_status $TESTPOOL1 "status" "features are not enabled"
log_must zpool set compatibility=compat-2020 $TESTPOOL1
log_must check_pool_status $TESTPOOL1 "status" "features are not enabled"
log_pass "check 'zpool status' upgrade notice"
@@ -12,7 +12,8 @@ dist_pkgdata_SCRIPTS = \
zpool_upgrade_006_neg.ksh \
zpool_upgrade_007_pos.ksh \
zpool_upgrade_008_pos.ksh \
zpool_upgrade_009_neg.ksh
zpool_upgrade_009_neg.ksh \
zpool_upgrade_features_001_pos.ksh
dist_pkgdata_DATA = \
zpool_upgrade.cfg \
@@ -0,0 +1,67 @@
#!/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) 2021 Lawrence Livermore National Security, LLC.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
#
# DESCRIPTION:
# Verify pools can be upgraded to known feature sets.
#
# STRATEGY:
# 1. Create a pool with a known feature set.
# 2. Verify only those features are active/enabled.
# 3. Upgrade the pool to a newer feature set.
# 4. Verify only those features are active/enabled.
#
verify_runnable "global"
function cleanup
{
datasetexists $TESTPOOL1 && log_must zpool destroy $TESTPOOL1
rm -f $FILEDEV
}
FILEDEV="$TEST_BASE_DIR/filedev.$$"
log_onexit cleanup
log_assert "verify pools can be upgraded to known feature sets."
log_must truncate -s $MINVDEVSIZE $FILEDEV
log_must zpool create -f -o compatibility=compat-2018 $TESTPOOL1 $FILEDEV
check_feature_set $TESTPOOL1 compat-2018
log_mustnot check_pool_status $TESTPOOL1 "status" "features are not enabled"
log_must zpool set compatibility=compat-2020 $TESTPOOL1
log_must check_pool_status $TESTPOOL1 "status" "features are not enabled"
log_must zpool upgrade $TESTPOOL1
check_feature_set $TESTPOOL1 compat-2020
log_mustnot check_pool_status $TESTPOOL1 "status" "features are not enabled"
log_pass "verify pools can be upgraded to known feature sets."