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) 2012 by Delphix. All rights reserved.
25#
26
27. $STF_SUITE/include/libtest.shlib
28. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
29
30#################################################################################
31#
32#  Pool can be imported with active read-only compatible features. If a feature
33#  is read-only compatible but also inactive its property status should be
34#  "inactive" rather than "readonly".
35#
36#  1. Create new pool.
37#  2. Export and inject variety of unsupported features.
38#  3. Try to import read-write, this should fail. The error should only list
39#     the active read-only compatible feature and mention "readonly=on".
40#  4. Import the pool in read-only mode.
41#  5. Verify values of unsupported@ properties.
42#
43################################################################################
44
45verify_runnable "global"
46
47enabled_features="com.test:xxx_unsup0 com.test:xxx_unsup2"
48active_features="com.test:xxx_unsup1 com.test:xxx_unsup3"
49
50function cleanup
51{
52	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
53
54	log_must $RM $VDEV0
55	log_must $MKFILE $FILE_SIZE $VDEV0
56}
57
58log_assert "Pool with active read-only compatible features can be imported."
59log_onexit cleanup
60
61log_must $ZPOOL create $TESTPOOL1 $VDEV0
62log_must $ZPOOL export $TESTPOOL1
63
64for feature in $enabled_features $active_features; do
65	log_must $ZHACK -d $DEVICE_DIR feature enable -r $TESTPOOL1 $feature
66done
67
68for feature in $active_features; do
69	log_must $ZHACK -d $DEVICE_DIR feature ref $TESTPOOL1 $feature
70done
71
72log_mustnot $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
73
74# error message should mention "readonly"
75log_must eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 | $GREP readonly"
76log_mustnot poolexists $TESTPOOL1
77
78for feature in $enabled_features; do
79	log_mustnot eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 \
80	    | $GREP $feature"
81	log_mustnot poolexists $TESTPOOL1
82done
83
84for feature in $active_features; do
85	log_must eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 \
86	    | $GREP $feature"
87	log_mustnot poolexists $TESTPOOL1
88done
89
90log_must $ZPOOL import -o readonly=on -d $DEVICE_DIR $TESTPOOL1
91
92for feature in $enabled_features; do
93	state=$($ZPOOL list -Ho unsupported@$feature $TESTPOOL1)
94        if [[ "$state" != "inactive" ]]; then
95		log_fail "unsupported@$feature is '$state'"
96        fi
97done
98
99for feature in $active_features; do
100	state=$($ZPOOL list -Ho unsupported@$feature $TESTPOOL1)
101        if [[ "$state" != "readonly" ]]; then
102		log_fail "unsupported@$feature is '$state'"
103        fi
104done
105
106log_pass
107