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) 2021 Lawrence Livermore National Security, LLC.
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31#	Verify '-o compatibility' property is updated in both the
32#	pool config MOS object and the cache file.
33#
34# STRATEGY:
35#	1. Create a pool with '-o compatibility=legacy', then verify
36#	   the property exists in the MOS config and cache file.
37#	2. Create a pool, set the 'compatibility=off' property, then
38#	   verify the property exists in the MOS config and cache file.
39#
40
41verify_runnable "global"
42
43function cleanup
44{
45	datasetexists $TESTPOOL && log_must zpool destroy $TESTPOOL
46	rm -f $CACHE_FILE
47}
48
49function check_config
50{
51	typeset propval=$1
52
53	poolval="$(zpool get -H -o value compatibility $TESTPOOL)"
54	if [ "$poolval" != "$propval" ]; then
55		log_fail "compatibility property set incorrectly $curval"
56	fi
57
58	if ! zdb -C -U $CACHE_FILE | grep "compatibility: '$propval'"; then
59		log_fail "compatibility property missing in cache file"
60	fi
61
62	if ! zdb -C -U $CACHE_FILE $TESTPOOL | grep "compatibility: '$propval'"; then
63		log_fail "compatibility property missing from MOS object"
64	fi
65}
66
67log_onexit cleanup
68
69log_assert "verify '-o compatibility' in MOS object and cache file"
70
71CACHE_FILE=$TEST_BASE_DIR/cachefile.$$
72
73# 1. Create a pool with '-o compatibility=legacy', then verify
74#    the property exists in the MOS config and cache file.
75log_must zpool create -f -o cachefile=$CACHE_FILE -o compatibility=legacy $TESTPOOL $DISKS
76log_must check_config legacy
77log_must zpool export -F $TESTPOOL
78log_must zpool import -c $CACHE_FILE $TESTPOOL
79log_must check_config legacy
80log_must zpool destroy -f $TESTPOOL
81
82# 2. Create a pool, set the 'compatibility=off' property, then
83#    verify the property exists in the MOS config and cache file.
84log_must zpool create -f -o cachefile=$CACHE_FILE $TESTPOOL $DISKS
85log_must zpool set compatibility=legacy $TESTPOOL
86log_must check_config legacy
87log_must zpool export -F $TESTPOOL
88log_must zpool import -c $CACHE_FILE $TESTPOOL
89log_must check_config legacy
90log_must zpool destroy -f $TESTPOOL
91
92log_pass "verify '-o compatibility' in MOS object and cache file"
93