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 2009 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 zfs subcommands are logged.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# create, destroy, clone, rename, snapshot, rollback, set, inherit,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# receive, promote, hold and release.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. Verify that all the zfs commands listed (barring send) produce an
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# entry in the pool history.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "global"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -f $tmpfile ]] && rm -f $tmpfile
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -f $tmpfile2 ]] && rm -f $tmpfile2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy datasetexists $dataset && zfs destroy -Rf $dataset
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy rm -rf /history.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "Verify zfs sub-commands which modify state are logged."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfssnap=$fs@fssnap; fssnap2=$fs@fssnap2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvolsnap=$vol@volsnap; volsnap2=$vol@volsnap2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytmpfile=/tmp/tmpfile.$$ ; tmpfile2=/tmp/tmpfile2.$$
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# property value property value
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyprops=(
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy quota 64M recordsize 512
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy reservation 32M reservation none
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy mountpoint /history.$$ mountpoint legacy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy mountpoint none sharenfs on
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy sharenfs off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy compression on compression off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy compression lzjb aclmode discard
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy aclmode groupmask aclmode passthrough
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy atime on atime off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy devices on devices off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy exec on exec off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy setuid on setuid off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy readonly on readonly off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy zoned on zoned off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snapdir hidden snapdir visible
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy aclinherit discard aclinherit noallow
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy aclinherit secure aclinherit passthrough
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy canmount off canmount on
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy xattr on xattr off
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy compression gzip compression gzip-$((RANDOM%9 + 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy copies $((RANDOM%3 + 1))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs create $fs"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Set all the property for filesystem
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedywhile ((i < ${#props[@]})) ; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy run_and_verify "zfs set ${props[$i]}=${props[((i+1))]} $fs"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # quota, reservation, canmount can not be inherited.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy #
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ ${props[$i]} != "quota" && ${props[$i]} != "reservation" && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ${props[$i]} != "canmount" ]];
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy run_and_verify "zfs inherit ${props[$i]} $fs"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((i += 2))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs create -V 64M $vol"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs set volsize=32M $vol"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs snapshot $fssnap"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs hold tag $fssnap"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs release tag $fssnap"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs snapshot $volsnap"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs snapshot $fssnap2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs snapshot $volsnap2"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Send isn't logged...
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs send -i $fssnap $fssnap2 > $tmpfile
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs send -i $volsnap $volsnap2 > $tmpfile2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Verify that's true
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyzpool history $TESTPOOL | grep 'zfs send' >/dev/null 2>&1 && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "'zfs send' found in history of \"$TESTPOOL\""
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs destroy $fssnap2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs destroy $volsnap2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs receive $fs < $tmpfile"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs receive $vol < $tmpfile2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs rollback -r $fssnap"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs rollback -r $volsnap"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs clone $fssnap $fsclone"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs clone $volsnap $volclone"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs rename $fs $newfs"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs rename $vol $newvol"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs promote $fsclone"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs promote $volclone"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs destroy $newfs"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs destroy $newvol"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs destroy -rf $fsclone"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyrun_and_verify "zfs destroy -rf $volclone"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "zfs sub-commands which modify state are logged passed."