f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#!/bin/ksh -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/history/history_common.kshlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Create a scenario to verify the following zpool subcommands are logged.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create, destroy, add, remove, offline, online, attach, detach, replace,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# scrub, export, import, clear, upgrade.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. Create three virtual disk files and create a mirror.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2. Run and verify pool commands, with special casing for destroy/export.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3. Import a pool and upgrade it, verifying 'upgrade' was logged.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "global"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy destroy_pool $MPOOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy destroy_pool $upgrade_pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -d $import_dir ]] && rm -rf $import_dir
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for file in $VDEV1 $VDEV2 $VDEV3 $VDEV4; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -f $file ]] && rm -f $file
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "Verify zpool sub-commands which modify state are logged."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedymntpnt=$(get_prop mountpoint $TESTPOOL)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy(( $? != 0)) && log_fail "get_prop($TESTPOOL mountpoint)"
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyVDEV1=$mntpnt/vdev1; VDEV2=$mntpnt/vdev2;
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyVDEV3=$mntpnt/vdev3; VDEV4=$mntpnt/vdev4;
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must mkfile $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must mkfile $(($MINVDEVSIZE * 2)) $VDEV4
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool create $MPOOL mirror $VDEV1 $VDEV2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool add -f $MPOOL spare $VDEV3"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool remove $MPOOL $VDEV3"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool offline $MPOOL $VDEV1"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool online $MPOOL $VDEV1"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool attach $MPOOL $VDEV1 $VDEV4"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool detach $MPOOL $VDEV4"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool replace -f $MPOOL $VDEV1 $VDEV4"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool scrub $MPOOL"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool clear $MPOOL"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# For export and destroy, mimic the behavior of run_and_verify using two
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# commands since the history will be unavailable until the pool is imported
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# again.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedycommands=("zpool export $MPOOL" "zpool import -d $mntpnt $MPOOL"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zpool destroy $MPOOL" "zpool import -D -f -d $mntpnt $MPOOL")
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfor i in 0 2; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy cmd1="${commands[$i]}"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy cmd2="${commands[(($i + 1 ))]}"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zpool history $MPOOL > $OLD_HISTORY 2>/dev/null
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $cmd1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must $cmd2
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zpool history $MPOOL > $TMP_HISTORY 2>/dev/null
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy diff $OLD_HISTORY $TMP_HISTORY | grep "^> " | sed 's/^> //g' > \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy $NEW_HISTORY
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy grep "$(echo "$cmd1" | sed 's/\/usr\/sbin\///g')" $NEW_HISTORY \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy >/dev/null 2>&1 || log_fail "Didn't find \"$cmd1\" in pool history"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy grep "$(echo "$cmd2" | sed 's/\/usr\/sbin\///g')" $NEW_HISTORY \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy >/dev/null 2>&1 || log_fail "Didn't find \"$cmd2\" in pool history"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$MPOOL" "zpool split $MPOOL ${MPOOL}_split"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyimport_dir=/var/tmp/import_dir.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must mkdir $import_dir
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must cp $STF_SUITE/tests/functional/history/zfs-pool-v4.dat.Z $import_dir
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must uncompress $import_dir/zfs-pool-v4.dat.Z
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyupgrade_pool=$(zpool import -d $import_dir | grep "pool:" | awk '{print $2}')
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zpool import -d $import_dir $upgrade_pool
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify -p "$upgrade_pool" "zpool upgrade $upgrade_pool"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "zpool sub-commands which modify state are logged passed. "