1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24#
25# Copyright (c) 2021 Lawrence Livermore National Security, LLC.
26#
27
28. $STF_SUITE/include/libtest.shlib
29
30#
31# DESCRIPTION:
32#	Verify '-o compatibility' property is updated in both the
33#	pool config MOS object and the cache file.
34#
35# STRATEGY:
36#	1. Create a pool with '-o compatibility=legacy', then verify
37#	   the property exists in the MOS config and cache file.
38#	2. Create a pool, set the 'compatibility=off' property, then
39#	   verify the property exists in the MOS config and cache file.
40#
41
42verify_runnable "global"
43
44function cleanup
45{
46	datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL
47	rm -f $CACHE_FILE
48}
49
50function check_config
51{
52	typeset propval=$1
53
54	poolval="$(zpool get -H -o value compatibility $TESTPOOL)"
55	if [ "$poolval" != "$propval" ]; then
56		log_fail "compatibility property set incorrectly $curval"
57	fi
58
59	if ! zdb -C -U $CACHE_FILE | grep "compatibility: '$propval'"; then
60		log_fail "compatibility property missing in cache file"
61	fi
62
63	if ! zdb -C -U $CACHE_FILE $TESTPOOL | grep "compatibility: '$propval'"; then
64		log_fail "compatibility property missing from MOS object"
65	fi
66}
67
68log_onexit cleanup
69
70log_assert "verify '-o compatibility' in MOS object and cache file"
71
72CACHE_FILE=$TEST_BASE_DIR/cachefile.$$
73
74# 1. Create a pool with '-o compatibility=legacy', then verify
75#    the property exists in the MOS config and cache file.
76log_must zpool create -f -o cachefile=$CACHE_FILE -o compatibility=legacy $TESTPOOL $DISKS
77log_must check_config legacy
78log_must zpool export -F $TESTPOOL
79log_must zpool import -c $CACHE_FILE $TESTPOOL
80log_must check_config legacy
81log_must zpool destroy -f $TESTPOOL
82
83# 2. Create a pool, set the 'compatibility=off' property, then
84#    verify the property exists in the MOS config and cache file.
85log_must zpool create -f -o cachefile=$CACHE_FILE $TESTPOOL $DISKS
86log_must zpool set compatibility=legacy $TESTPOOL
87log_must check_config legacy
88log_must zpool export -F $TESTPOOL
89log_must zpool import -c $CACHE_FILE $TESTPOOL
90log_must check_config legacy
91log_must zpool destroy -f $TESTPOOL
92
93log_pass "verify '-o compatibility' in MOS object and cache file"
94