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
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/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# zpool history will truncate on small pools, leaving pool creation intact
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens# 1. Create a test pool on a file.
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens# 2. Loop 300 times to set and remove compression to test dataset.
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens# 3. Make sure 'zpool history' output is truncated
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens# 4. Verify that the initial pool creation is preserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "global"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy datasetexists $spool && log_must zpool destroy $spool
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -f $VDEV0 ]] && log_must rm -f $VDEV0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -f $TMPFILE ]] && log_must rm -f $TMPFILE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "zpool history limitation test."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedymntpnt=$(get_prop mountpoint $TESTPOOL)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy(( $? != 0 )) && log_fail "get_prop mountpoint $TESTPOOL"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew AhrensVDEV0=$mntpnt/vdev0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must mkfile $MINVDEVSIZE $VDEV0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyspool=smallpool.$$; sfs=smallfs.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zpool create $spool $VDEV0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs create $spool/$sfs
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedytypeset -i orig_count=$(zpool history $spool | wc -l)
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedytypeset orig_md5=$(zpool history $spool | head -2 | md5sum | \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy awk '{print $1}')
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i i=0
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrenswhile ((i < 300)); do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs set compression=off $spool/$sfs
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs set compression=on $spool/$sfs
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs set compression=off $spool/$sfs
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs set compression=on $spool/$sfs
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs set compression=off $spool/$sfs
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((i += 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyTMPFILE=/tmp/spool.$$
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyzpool history $spool >$TMPFILE
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedytypeset -i entry_count=$(wc -l $TMPFILE | awk '{print $1}')
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedytypeset final_md5=$(head -2 $TMPFILE | md5sum | awk '{print $1}')
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedygrep 'zpool create' $TMPFILE >/dev/null 2>&1 ||
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "'zpool create' was not found in pool history"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedygrep 'zfs create' $TMPFILE >/dev/null 2>&1 &&
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "'zfs create' was found in pool history"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedygrep 'zfs set compress' $TMPFILE >/dev/null 2>&1 ||
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "'zfs set compress' was found in pool history"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Verify that the creation of the pool was preserved in the history.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif [[ $orig_md5 != $final_md5 ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "zpool creation history was not preserved."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "zpool history limitation test passed."