1eda14cbcSMatt Macy#!/bin/ksh -p
2eda14cbcSMatt Macy#
3eda14cbcSMatt Macy# CDDL HEADER START
4eda14cbcSMatt Macy#
5eda14cbcSMatt Macy# The contents of this file are subject to the terms of the
6eda14cbcSMatt Macy# Common Development and Distribution License (the "License").
7eda14cbcSMatt Macy# You may not use this file except in compliance with the License.
8eda14cbcSMatt Macy#
9eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*271171e0SMartin Matuska# or https://opensource.org/licenses/CDDL-1.0.
11eda14cbcSMatt Macy# See the License for the specific language governing permissions
12eda14cbcSMatt Macy# and limitations under the License.
13eda14cbcSMatt Macy#
14eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each
15eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the
17eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying
18eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner]
19eda14cbcSMatt Macy#
20eda14cbcSMatt Macy# CDDL HEADER END
21eda14cbcSMatt Macy#
22eda14cbcSMatt Macy
23eda14cbcSMatt Macy#
24eda14cbcSMatt Macy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25eda14cbcSMatt Macy# Use is subject to license terms.
26eda14cbcSMatt Macy
27eda14cbcSMatt Macy#
28eda14cbcSMatt Macy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29eda14cbcSMatt Macy#
30eda14cbcSMatt Macy
31eda14cbcSMatt Macy. $STF_SUITE/tests/functional/history/history_common.kshlib
32eda14cbcSMatt Macy
33eda14cbcSMatt Macy#
34eda14cbcSMatt Macy# DESCRIPTION:
35eda14cbcSMatt Macy#	Create a scenario to verify the following zpool subcommands are logged.
36eda14cbcSMatt Macy#	create, destroy, add, remove, offline, online, attach, detach, replace,
37eda14cbcSMatt Macy#	scrub, export, import, clear, upgrade.
38eda14cbcSMatt Macy#
39eda14cbcSMatt Macy# STRATEGY:
40eda14cbcSMatt Macy#	1. Create three virtual disk files and create a mirror.
41eda14cbcSMatt Macy#	2. Run and verify pool commands, with special casing for destroy/export.
42eda14cbcSMatt Macy#	3. Import a pool and upgrade it, verifying 'upgrade' was logged.
43eda14cbcSMatt Macy#
44eda14cbcSMatt Macy
45eda14cbcSMatt Macyverify_runnable "global"
46eda14cbcSMatt Macy
47eda14cbcSMatt Macyfunction cleanup
48eda14cbcSMatt Macy{
49eda14cbcSMatt Macy	destroy_pool $MPOOL
50eda14cbcSMatt Macy	destroy_pool $upgrade_pool
51eda14cbcSMatt Macy
52eda14cbcSMatt Macy	[[ -d $import_dir ]] && rm -rf $import_dir
53eda14cbcSMatt Macy	for file in $VDEV1 $VDEV2 $VDEV3 $VDEV4; do
54eda14cbcSMatt Macy		[[ -f $file ]] && rm -f $file
55eda14cbcSMatt Macy	done
56eda14cbcSMatt Macy}
57eda14cbcSMatt Macy
58eda14cbcSMatt Macylog_assert "Verify zpool sub-commands which modify state are logged."
59eda14cbcSMatt Macylog_onexit cleanup
60eda14cbcSMatt Macy
61eda14cbcSMatt Macymntpnt=$(get_prop mountpoint $TESTPOOL)
62eda14cbcSMatt MacyVDEV1=$mntpnt/vdev1; VDEV2=$mntpnt/vdev2;
63eda14cbcSMatt MacyVDEV3=$mntpnt/vdev3; VDEV4=$mntpnt/vdev4;
64eda14cbcSMatt Macy
65eda14cbcSMatt Macylog_must mkfile $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3
66eda14cbcSMatt Macylog_must mkfile $(($MINVDEVSIZE * 2)) $VDEV4
67eda14cbcSMatt Macy
68eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool create $MPOOL mirror $VDEV1 $VDEV2"
69eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool add -f $MPOOL spare $VDEV3"
70eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool remove $MPOOL $VDEV3"
71eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool offline $MPOOL $VDEV1"
72eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool online $MPOOL $VDEV1"
73eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool attach $MPOOL $VDEV1 $VDEV4"
74eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool detach $MPOOL $VDEV4"
75eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool replace -f $MPOOL $VDEV1 $VDEV4"
76eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool scrub $MPOOL"
77eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool clear $MPOOL"
78eda14cbcSMatt Macy
79eda14cbcSMatt Macy# For export and destroy, mimic the behavior of run_and_verify using two
80eda14cbcSMatt Macy# commands since the history will be unavailable until the pool is imported
81eda14cbcSMatt Macy# again.
82eda14cbcSMatt Macycommands=("zpool export $MPOOL" "zpool import -d $mntpnt $MPOOL"
83eda14cbcSMatt Macy    "zpool destroy $MPOOL" "zpool import -D -f -d $mntpnt $MPOOL")
84eda14cbcSMatt Macyfor i in 0 2; do
85eda14cbcSMatt Macy	cmd1="${commands[$i]}"
86eda14cbcSMatt Macy	cmd2="${commands[(($i + 1 ))]}"
87eda14cbcSMatt Macy
88eda14cbcSMatt Macy	zpool history $MPOOL > $OLD_HISTORY 2>/dev/null
89eda14cbcSMatt Macy	log_must $cmd1
90eda14cbcSMatt Macy	log_must $cmd2
91eda14cbcSMatt Macy	zpool history $MPOOL > $TMP_HISTORY 2>/dev/null
92eda14cbcSMatt Macy	diff $OLD_HISTORY $TMP_HISTORY | grep "^> " | sed 's/^> //g' > \
93eda14cbcSMatt Macy	    $NEW_HISTORY
94eda14cbcSMatt Macy        if is_linux; then
95eda14cbcSMatt Macy		grep "$(echo "$cmd1" | sed 's/^.*\/\(zpool .*\).*$/\1/')" \
96eda14cbcSMatt Macy		    $NEW_HISTORY >/dev/null 2>&1 || \
97eda14cbcSMatt Macy		    log_fail "Didn't find \"$cmd1\" in pool history"
98eda14cbcSMatt Macy		grep "$(echo "$cmd2" | sed 's/^.*\/\(zpool .*\).*$/\1/')" \
99eda14cbcSMatt Macy		    $NEW_HISTORY >/dev/null 2>&1 || \
100eda14cbcSMatt Macy		    log_fail "Didn't find \"$cmd2\" in pool history"
101eda14cbcSMatt Macy        else
102eda14cbcSMatt Macy		grep "$(echo "$cmd1" | sed 's/\/usr\/sbin\///g')" \
103eda14cbcSMatt Macy		    $NEW_HISTORY >/dev/null 2>&1 || \
104eda14cbcSMatt Macy		    log_fail "Didn't find \"$cmd1\" in pool history"
105eda14cbcSMatt Macy		grep "$(echo "$cmd2" | sed 's/\/usr\/sbin\///g')" \
106eda14cbcSMatt Macy		    $NEW_HISTORY >/dev/null 2>&1 || \
107eda14cbcSMatt Macy		    log_fail "Didn't find \"$cmd2\" in pool history"
108eda14cbcSMatt Macy        fi
109eda14cbcSMatt Macydone
110eda14cbcSMatt Macy
111eda14cbcSMatt Macyrun_and_verify -p "$MPOOL" "zpool split $MPOOL ${MPOOL}_split"
112eda14cbcSMatt Macy
113eda14cbcSMatt Macyimport_dir=$TEST_BASE_DIR/import_dir.$$
114eda14cbcSMatt Macylog_must mkdir $import_dir
115eda14cbcSMatt Macylog_must cp $STF_SUITE/tests/functional/history/zfs-pool-v4.dat.Z $import_dir
116eda14cbcSMatt Macylog_must uncompress $import_dir/zfs-pool-v4.dat.Z
117eda14cbcSMatt Macyupgrade_pool=$(zpool import -d $import_dir | awk '/pool:/ { print $2 }')
118eda14cbcSMatt Macylog_must zpool import -d $import_dir $upgrade_pool
119eda14cbcSMatt Macyrun_and_verify -p "$upgrade_pool" "zpool upgrade $upgrade_pool"
120eda14cbcSMatt Macy
121eda14cbcSMatt Macylog_pass "zpool sub-commands which modify state are logged passed. "
122