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