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