1d583b39bSJohn Wren Kennedy# 2d583b39bSJohn Wren Kennedy# CDDL HEADER START 3d583b39bSJohn Wren Kennedy# 4d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the 5d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License"). 6d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License. 7d583b39bSJohn Wren Kennedy# 8d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 10d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions 11d583b39bSJohn Wren Kennedy# and limitations under the License. 12d583b39bSJohn Wren Kennedy# 13d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 14d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 16d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 17d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 18d583b39bSJohn Wren Kennedy# 19d583b39bSJohn Wren Kennedy# CDDL HEADER END 20d583b39bSJohn Wren Kennedy# 21d583b39bSJohn Wren Kennedy 22d583b39bSJohn Wren Kennedy# 23d583b39bSJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24d583b39bSJohn Wren Kennedy# Use is subject to license terms. 25d583b39bSJohn Wren Kennedy# 26d583b39bSJohn Wren Kennedy 27d583b39bSJohn Wren Kennedy# 28*ad309d3eSPrakash Surya# Copyright (c) 2012, 2017 by Delphix. All rights reserved. 29c2b09db8SYuri Pankov# Copyright 2015 Nexenta Systems, Inc. All rights reserved. 30d583b39bSJohn Wren Kennedy# 31d583b39bSJohn Wren Kennedy 32d583b39bSJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 33d583b39bSJohn Wren Kennedy. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg 34d583b39bSJohn Wren Kennedy 35d583b39bSJohn Wren Kennedy# This part of the test suite relies on variables being setup in the 36d583b39bSJohn Wren Kennedy# zpool_upgrade.cfg script. Those variables give us details about which 37d583b39bSJohn Wren Kennedy# files make up the pool, and what the pool name is. 38d583b39bSJohn Wren Kennedy 39d583b39bSJohn Wren Kennedy 40d583b39bSJohn Wren Kennedy# A function to import a pool from files we have stored in the test suite 41d583b39bSJohn Wren Kennedy# We import the pool, and create some random data in the pool. 42d583b39bSJohn Wren Kennedy# $1 a version number we can use to get information about the pool 43d583b39bSJohn Wren Kennedyfunction create_old_pool 44d583b39bSJohn Wren Kennedy{ 45c2b09db8SYuri Pankov typeset vers=$1 46c2b09db8SYuri Pankov typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES 47c2b09db8SYuri Pankov typeset -n pool_name=ZPOOL_VERSION_${vers}_NAME 48d583b39bSJohn Wren Kennedy 49c2b09db8SYuri Pankov log_note "Creating $pool_name from $pool_files" 50c2b09db8SYuri Pankov for pool_file in $pool_files; do 511d32ba66SJohn Wren Kennedy log_must bzcat \ 52d583b39bSJohn Wren Kennedy $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/$pool_file.bz2 \ 53d583b39bSJohn Wren Kennedy >/$TESTPOOL/$pool_file 54d583b39bSJohn Wren Kennedy done 551d32ba66SJohn Wren Kennedy log_must zpool import -d /$TESTPOOL $pool_name 56c2b09db8SYuri Pankov 57c2b09db8SYuri Pankov # Put some random contents into the pool 58c2b09db8SYuri Pankov for i in {1..1024} ; do 591d32ba66SJohn Wren Kennedy dd if=/dev/urandom of=/$pool_name/random.$i \ 60c2b09db8SYuri Pankov count=1 bs=1024 > /dev/null 2>&1 61d583b39bSJohn Wren Kennedy done 62d583b39bSJohn Wren Kennedy} 63d583b39bSJohn Wren Kennedy 64d583b39bSJohn Wren Kennedy 65d583b39bSJohn Wren Kennedy# A function to check the contents of a pool, upgrade it to the current version 66d583b39bSJohn Wren Kennedy# and then verify that the data is consistent after upgrading. Note that we're 67d583b39bSJohn Wren Kennedy# not using "zpool status -x" to see if the pool is healthy, as it's possible 68d583b39bSJohn Wren Kennedy# to also upgrade faulted, or degraded pools. 69d583b39bSJohn Wren Kennedy# $1 a version number we can use to get information about the pool 70c2b09db8SYuri Pankovfunction check_upgrade 71c2b09db8SYuri Pankov{ 72c2b09db8SYuri Pankov typeset vers=$1 73c2b09db8SYuri Pankov typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES 74c2b09db8SYuri Pankov typeset -n pool_name=ZPOOL_VERSION_${vers}_NAME 75c2b09db8SYuri Pankov typeset pre_upgrade_checksum 76c2b09db8SYuri Pankov typeset post_upgrade_checksum 77d583b39bSJohn Wren Kennedy 78c2b09db8SYuri Pankov log_note "Checking if we can upgrade from ZFS version $vers" 79c2b09db8SYuri Pankov pre_upgrade_checksum=$(check_pool $pool_name pre) 801d32ba66SJohn Wren Kennedy log_must zpool upgrade $pool_name 81c2b09db8SYuri Pankov post_upgrade_checksum=$(check_pool $pool_name post) 82d583b39bSJohn Wren Kennedy 83d583b39bSJohn Wren Kennedy log_note "Checking that there are no differences between checksum output" 841d32ba66SJohn Wren Kennedy log_must diff $pre_upgrade_checksum $post_upgrade_checksum 851d32ba66SJohn Wren Kennedy rm $pre_upgrade_checksum $post_upgrade_checksum 86d583b39bSJohn Wren Kennedy} 87d583b39bSJohn Wren Kennedy 88d583b39bSJohn Wren Kennedy# A function to destroy an upgraded pool, plus the files it was based on. 89d583b39bSJohn Wren Kennedy# $1 a version number we can use to get information about the pool 90c2b09db8SYuri Pankovfunction destroy_upgraded_pool 91c2b09db8SYuri Pankov{ 92c2b09db8SYuri Pankov typeset vers=$1 93c2b09db8SYuri Pankov typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES 94c2b09db8SYuri Pankov typeset -n pool_name=ZPOOL_VERSION_${vers}_NAME 95d583b39bSJohn Wren Kennedy 96*ad309d3eSPrakash Surya destroy_pool $pool_name 97c2b09db8SYuri Pankov for file in $pool_files; do 981d32ba66SJohn Wren Kennedy rm -f /$TESTPOOL/$file 99d583b39bSJohn Wren Kennedy done 100d583b39bSJohn Wren Kennedy} 101d583b39bSJohn Wren Kennedy 102d583b39bSJohn Wren Kennedy# This function does a basic sanity check on the pool by computing the 103d583b39bSJohn Wren Kennedy# checksums of all files in the pool, echoing the name of the file containing 104d583b39bSJohn Wren Kennedy# the checksum results. 105d583b39bSJohn Wren Kennedy# $1 the name of the pool 106d583b39bSJohn Wren Kennedy# $2 a flag we can use to determine when this check is being performed 107d583b39bSJohn Wren Kennedy# (ie. pre or post pool-upgrade) 108c2b09db8SYuri Pankovfunction check_pool 109c2b09db8SYuri Pankov{ 110c2b09db8SYuri Pankov typeset pool=$1 111c2b09db8SYuri Pankov typeset flag=$2 1121d32ba66SJohn Wren Kennedy find /$pool -type f -exec cksum {} + > \ 113c2b09db8SYuri Pankov /$TESTPOOL/pool-checksums.$pool.$flag 114c2b09db8SYuri Pankov echo /$TESTPOOL/pool-checksums.$pool.$flag 115d583b39bSJohn Wren Kennedy} 116d583b39bSJohn Wren Kennedy 117d583b39bSJohn Wren Kennedy# This function simply checks that a pool has a particular version number 118d583b39bSJohn Wren Kennedy# as reported by zdb and zpool upgrade -v 119d583b39bSJohn Wren Kennedy# $1 the name of the pool 120d583b39bSJohn Wren Kennedy# $2 the version of the pool we expect to see 121c2b09db8SYuri Pankovfunction check_poolversion 122c2b09db8SYuri Pankov{ 123c2b09db8SYuri Pankov typeset pool=$1 124c2b09db8SYuri Pankov typeset vers=$2 125c2b09db8SYuri Pankov typeset actual 126d583b39bSJohn Wren Kennedy 127d583b39bSJohn Wren Kennedy # check version using zdb 1281d32ba66SJohn Wren Kennedy actual=$(zdb -C $pool | sed -n 's/^.*version: \(.*\)$/\1/p') 129c2b09db8SYuri Pankov if [[ $actual != $vers ]] ; then 130c2b09db8SYuri Pankov log_fail "$pool: zdb reported version $actual, expected $vers" 131d583b39bSJohn Wren Kennedy fi 132d583b39bSJohn Wren Kennedy 133d583b39bSJohn Wren Kennedy # check version using zpool upgrade 1341d32ba66SJohn Wren Kennedy actual=$(zpool upgrade | grep $pool$ | \ 1351d32ba66SJohn Wren Kennedy awk '{print $1}' | sed -e 's/ //g') 136c2b09db8SYuri Pankov if [[ $actual != $vers ]] ; then 137c2b09db8SYuri Pankov log_fail "$pool: zpool reported version $actual, expected $vers" 138d583b39bSJohn Wren Kennedy fi 139d583b39bSJohn Wren Kennedy} 140d583b39bSJohn Wren Kennedy 141d583b39bSJohn Wren Kennedy# A simple function to get a random number between two bounds 142d583b39bSJohn Wren Kennedy# probably not the most efficient for large ranges, but it's okay. 143d583b39bSJohn Wren Kennedy# Note since we're using $RANDOM, 32767 is the largest number we 144d583b39bSJohn Wren Kennedy# can accept as the upper bound. 145d583b39bSJohn Wren Kennedy# $1 lower bound 146d583b39bSJohn Wren Kennedy# $2 upper bound 147c2b09db8SYuri Pankovfunction random 148c2b09db8SYuri Pankov{ 149c2b09db8SYuri Pankov typeset min=$1 150c2b09db8SYuri Pankov typeset max=$2 151c2b09db8SYuri Pankov typeset rand=0 152d583b39bSJohn Wren Kennedy 153c2b09db8SYuri Pankov while [[ $rand -lt $min ]] ; do 154c2b09db8SYuri Pankov rand=$(( $RANDOM % $max + 1)) 155d583b39bSJohn Wren Kennedy done 156d583b39bSJohn Wren Kennedy 157c2b09db8SYuri Pankov echo $rand 158d583b39bSJohn Wren Kennedy} 159