1f38cb554SJohn Wren Kennedy#!/bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
34f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
35f38cb554SJohn Wren Kennedy
36f38cb554SJohn Wren Kennedy#
37f38cb554SJohn Wren Kennedy# DESCRIPTION:
38f38cb554SJohn Wren Kennedy#	Verify set, export and destroy when cachefile is set on pool.
39f38cb554SJohn Wren Kennedy#
40f38cb554SJohn Wren Kennedy# STRATEGY:
41f38cb554SJohn Wren Kennedy#	1. Create two pools with one same cahcefile1.
42f38cb554SJohn Wren Kennedy#	2. Set cachefile of the two pools to another same cachefile2.
43f38cb554SJohn Wren Kennedy#	3. Verify cachefile1 not exist.
44f38cb554SJohn Wren Kennedy#	4. Export the two pools.
45f38cb554SJohn Wren Kennedy#	5. Verify cachefile2 not exist.
46f38cb554SJohn Wren Kennedy#	6. Import the two pools and set cachefile to cachefile2.
47f38cb554SJohn Wren Kennedy#	7. Destroy the two pools.
48f38cb554SJohn Wren Kennedy#	8. Verify cachefile2 not exist.
49f38cb554SJohn Wren Kennedy#
50f38cb554SJohn Wren Kennedy
51f38cb554SJohn Wren Kennedyverify_runnable "global"
52f38cb554SJohn Wren Kennedy
53f38cb554SJohn Wren Kennedyfunction cleanup
54f38cb554SJohn Wren Kennedy{
55f38cb554SJohn Wren Kennedy	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
56f38cb554SJohn Wren Kennedy	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
57f38cb554SJohn Wren Kennedy
58f38cb554SJohn Wren Kennedy	mntpnt=$(get_prop mountpoint $TESTPOOL)
59f38cb554SJohn Wren Kennedy	typeset -i i=0
60f38cb554SJohn Wren Kennedy	while ((i < 2)); do
61f38cb554SJohn Wren Kennedy		if [[ -e $mntpnt/vdev$i ]]; then
62*1d32ba66SJohn Wren Kennedy			log_must rm -f $mntpnt/vdev$i
63f38cb554SJohn Wren Kennedy		fi
64f38cb554SJohn Wren Kennedy		((i += 1))
65f38cb554SJohn Wren Kennedy	done
66f38cb554SJohn Wren Kennedy
67f38cb554SJohn Wren Kennedy	if poolexists $TESTPOOL ; then
68f38cb554SJohn Wren Kennedy		destroy_pool $TESTPOOL
69f38cb554SJohn Wren Kennedy	fi
70f38cb554SJohn Wren Kennedy
71f38cb554SJohn Wren Kennedy	for file in $CPATH1 $CPATH2 ; do
72f38cb554SJohn Wren Kennedy		if [[ -f $file ]] ; then
73*1d32ba66SJohn Wren Kennedy			log_must rm $file
74f38cb554SJohn Wren Kennedy		fi
75f38cb554SJohn Wren Kennedy	done
76f38cb554SJohn Wren Kennedy}
77f38cb554SJohn Wren Kennedy
78f38cb554SJohn Wren Kennedy
79f38cb554SJohn Wren Kennedylog_assert "Verify set, export and destroy when cachefile is set on pool."
80f38cb554SJohn Wren Kennedylog_onexit cleanup
81f38cb554SJohn Wren Kennedy
82*1d32ba66SJohn Wren Kennedylog_must zpool create $TESTPOOL $DISKS
83f38cb554SJohn Wren Kennedy
84f38cb554SJohn Wren Kennedymntpnt=$(get_prop mountpoint $TESTPOOL)
85f38cb554SJohn Wren Kennedytypeset -i i=0
86f38cb554SJohn Wren Kennedywhile ((i < 2)); do
87*1d32ba66SJohn Wren Kennedy	log_must mkfile $MINVDEVSIZE $mntpnt/vdev$i
88f38cb554SJohn Wren Kennedy	eval vdev$i=$mntpnt/vdev$i
89f38cb554SJohn Wren Kennedy	((i += 1))
90f38cb554SJohn Wren Kennedydone
91f38cb554SJohn Wren Kennedy
92*1d32ba66SJohn Wren Kennedylog_must zpool create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0
93f38cb554SJohn Wren Kennedylog_must pool_in_cache $TESTPOOL1 $CPATH1
94*1d32ba66SJohn Wren Kennedylog_must zpool create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1
95f38cb554SJohn Wren Kennedylog_must pool_in_cache $TESTPOOL2 $CPATH1
96f38cb554SJohn Wren Kennedy
97*1d32ba66SJohn Wren Kennedylog_must zpool set cachefile=$CPATH2 $TESTPOOL1
98f38cb554SJohn Wren Kennedylog_must pool_in_cache $TESTPOOL1 $CPATH2
99*1d32ba66SJohn Wren Kennedylog_must zpool set cachefile=$CPATH2 $TESTPOOL2
100f38cb554SJohn Wren Kennedylog_must pool_in_cache $TESTPOOL2 $CPATH2
101f38cb554SJohn Wren Kennedyif [[ -f $CPATH1 ]]; then
102f38cb554SJohn Wren Kennedy	log_fail "Verify set when cachefile is set on pool."
103f38cb554SJohn Wren Kennedyfi
104f38cb554SJohn Wren Kennedy
105*1d32ba66SJohn Wren Kennedylog_must zpool export $TESTPOOL1
106*1d32ba66SJohn Wren Kennedylog_must zpool export $TESTPOOL2
107f38cb554SJohn Wren Kennedyif [[ -f $CPATH2 ]]; then
108f38cb554SJohn Wren Kennedy	log_fail "Verify export when cachefile is set on pool."
109f38cb554SJohn Wren Kennedyfi
110f38cb554SJohn Wren Kennedy
111*1d32ba66SJohn Wren Kennedylog_must zpool import -d $mntpnt $TESTPOOL1
112*1d32ba66SJohn Wren Kennedylog_must zpool set cachefile=$CPATH2 $TESTPOOL1
113f38cb554SJohn Wren Kennedylog_must pool_in_cache $TESTPOOL1 $CPATH2
114*1d32ba66SJohn Wren Kennedylog_must zpool import -d $mntpnt $TESTPOOL2
115*1d32ba66SJohn Wren Kennedylog_must zpool set cachefile=$CPATH2 $TESTPOOL2
116f38cb554SJohn Wren Kennedylog_must pool_in_cache $TESTPOOL2 $CPATH2
117f38cb554SJohn Wren Kennedy
118*1d32ba66SJohn Wren Kennedylog_must zpool destroy $TESTPOOL1
119*1d32ba66SJohn Wren Kennedylog_must zpool destroy $TESTPOOL2
120f38cb554SJohn Wren Kennedyif [[ -f $CPATH2 ]]; then
121f38cb554SJohn Wren Kennedy	log_fail "Verify destroy when cachefile is set on pool."
122f38cb554SJohn Wren Kennedyfi
123f38cb554SJohn Wren Kennedy
124f38cb554SJohn Wren Kennedylog_pass "Verify set, export and destroy when cachefile is set on pool."
125