d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER START
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# The contents of this file are subject to the terms of the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Common Development and Distribution License (the "License").
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You may not use this file except in compliance with the License.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# See the License for the specific language governing permissions
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# and limitations under the License.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER END
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Use is subject to license terms.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# This part of the test suite relies on variables being setup in the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# zpool_upgrade.cfg script. Those variables give us details about which
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# files make up the pool, and what the pool name is.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# A function to import a pool from files we have stored in the test suite
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# We import the pool, and create some random data in the pool.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $1 a version number we can use to get information about the pool
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/$pool_file.bz2 \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zpool import -d /$TESTPOOL $pool_name
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov for i in {1..1024} ; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy dd if=/dev/urandom of=/$pool_name/random.$i \
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov count=1 bs=1024 > /dev/null 2>&1
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# A function to check the contents of a pool, upgrade it to the current version
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# and then verify that the data is consistent after upgrading. Note that we're
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# not using "zpool status -x" to see if the pool is healthy, as it's possible
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# to also upgrade faulted, or degraded pools.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $1 a version number we can use to get information about the pool
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov log_note "Checking if we can upgrade from ZFS version $vers"
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov pre_upgrade_checksum=$(check_pool $pool_name pre)
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov post_upgrade_checksum=$(check_pool $pool_name post)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_note "Checking that there are no differences between checksum output"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must diff $pre_upgrade_checksum $post_upgrade_checksum
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy rm $pre_upgrade_checksum $post_upgrade_checksum
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# A function to destroy an upgraded pool, plus the files it was based on.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $1 a version number we can use to get information about the pool
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# This function does a basic sanity check on the pool by computing the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# checksums of all files in the pool, echoing the name of the file containing
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# the checksum results.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $1 the name of the pool
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $2 a flag we can use to determine when this check is being performed
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# (ie. pre or post pool-upgrade)
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy find /$pool -type f -exec cksum {} + > \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# This function simply checks that a pool has a particular version number
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# as reported by zdb and zpool upgrade -v
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $1 the name of the pool
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $2 the version of the pool we expect to see
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy actual=$(zdb -C $pool | sed -n 's/^.*version: \(.*\)$/\1/p')
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov if [[ $actual != $vers ]] ; then
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov log_fail "$pool: zdb reported version $actual, expected $vers"
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov if [[ $actual != $vers ]] ; then
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov log_fail "$pool: zpool reported version $actual, expected $vers"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# A simple function to get a random number between two bounds
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# probably not the most efficient for large ranges, but it's okay.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Note since we're using $RANDOM, 32767 is the largest number we
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# can accept as the upper bound.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $1 lower bound
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $2 upper bound
c2b09db8b5b01162dadf9205ddd83ccf4f7d5535Yuri Pankov while [[ $rand -lt $min ]] ; do