1eda14cbcSMatt Macy#!/usr/bin/env bash 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# Verify that an assortment of known good reference pools can be imported 4eda14cbcSMatt Macy# using different versions of the ZoL code. 5eda14cbcSMatt Macy# 6eda14cbcSMatt Macy# By default references pools for the major ZFS implementation will be 7eda14cbcSMatt Macy# checked against the most recent ZoL tags and the master development branch. 8eda14cbcSMatt Macy# Alternate tags or branches may be verified with the '-s <src-tag> option. 9eda14cbcSMatt Macy# Passing the keyword "installed" will instruct the script to test whatever 10eda14cbcSMatt Macy# version is installed. 11eda14cbcSMatt Macy# 12eda14cbcSMatt Macy# Preferentially a reference pool is used for all tests. However, if one 13eda14cbcSMatt Macy# does not exist and the pool-tag matches one of the src-tags then a new 14eda14cbcSMatt Macy# reference pool will be created using binaries from that source build. 15eda14cbcSMatt Macy# This is particularly useful when you need to test your changes before 16eda14cbcSMatt Macy# opening a pull request. The keyword 'all' can be used as short hand 17eda14cbcSMatt Macy# refer to all available reference pools. 18eda14cbcSMatt Macy# 19eda14cbcSMatt Macy# New reference pools may be added by placing a bzip2 compressed tarball 20eda14cbcSMatt Macy# of the pool in the scripts/zfs-images directory and then passing 21eda14cbcSMatt Macy# the -p <pool-tag> option. To increase the test coverage reference pools 22eda14cbcSMatt Macy# should be collected for all the major ZFS implementations. Having these 23eda14cbcSMatt Macy# pools easily available is also helpful to the developers. 24eda14cbcSMatt Macy# 25eda14cbcSMatt Macy# Care should be taken to run these tests with a kernel supported by all 26eda14cbcSMatt Macy# the listed tags. Otherwise build failure will cause false positives. 27eda14cbcSMatt Macy# 28eda14cbcSMatt Macy# 29eda14cbcSMatt Macy# EXAMPLES: 30eda14cbcSMatt Macy# 31eda14cbcSMatt Macy# The following example will verify the zfs-0.6.2 tag, the master branch, 32eda14cbcSMatt Macy# and the installed zfs version can correctly import the listed pools. 33eda14cbcSMatt Macy# Note there is no reference pool available for master and installed but 34eda14cbcSMatt Macy# because binaries are available one is automatically constructed. The 35eda14cbcSMatt Macy# working directory is also preserved between runs (-k) preventing the 36eda14cbcSMatt Macy# need to rebuild from source for multiple runs. 37eda14cbcSMatt Macy# 38eda14cbcSMatt Macy# zimport.sh -k -f /var/tmp/zimport \ 39eda14cbcSMatt Macy# -s "zfs-0.6.2 master installed" \ 40eda14cbcSMatt Macy# -p "zevo-1.1.1 zol-0.6.2 zol-0.6.2-173 master installed" 41eda14cbcSMatt Macy# 42*180f8225SMatt Macy# ------------------------ OpenZFS Source Versions ---------------- 43eda14cbcSMatt Macy# zfs-0.6.2 master 0.6.2-175_g36eb554 44eda14cbcSMatt Macy# ----------------------------------------------------------------- 45eda14cbcSMatt Macy# Clone ZFS Local Local Skip 46eda14cbcSMatt Macy# Build ZFS Pass Pass Skip 47eda14cbcSMatt Macy# ----------------------------------------------------------------- 48eda14cbcSMatt Macy# zevo-1.1.1 Pass Pass Pass 49eda14cbcSMatt Macy# zol-0.6.2 Pass Pass Pass 50eda14cbcSMatt Macy# zol-0.6.2-173 Fail Pass Pass 51eda14cbcSMatt Macy# master Pass Pass Pass 52eda14cbcSMatt Macy# installed Pass Pass Pass 53eda14cbcSMatt Macy# 54eda14cbcSMatt Macy 55eda14cbcSMatt MacyBASE_DIR=$(dirname "$0") 56eda14cbcSMatt MacySCRIPT_COMMON=common.sh 57eda14cbcSMatt Macyif [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then 58eda14cbcSMatt Macy . "${BASE_DIR}/${SCRIPT_COMMON}" 59eda14cbcSMatt Macyelse 60eda14cbcSMatt Macy echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 61eda14cbcSMatt Macyfi 62eda14cbcSMatt Macy 63eda14cbcSMatt MacyPROG=zimport.sh 64eda14cbcSMatt MacySRC_TAGS="zfs-0.6.5.11 master" 65eda14cbcSMatt MacyPOOL_TAGS="all master" 66eda14cbcSMatt MacyPOOL_CREATE_OPTIONS= 67eda14cbcSMatt MacyTEST_DIR=$(mktemp -u -d -p /var/tmp zimport.XXXXXXXX) 68eda14cbcSMatt MacyKEEP="no" 69eda14cbcSMatt MacyVERBOSE="no" 70eda14cbcSMatt MacyCOLOR="yes" 71*180f8225SMatt MacyREPO="https://github.com/openzfs" 72eda14cbcSMatt MacyIMAGES_DIR="$SCRIPTDIR/zfs-images/" 73*180f8225SMatt MacyIMAGES_TAR="https://github.com/openzfs/zfs-images/tarball/master" 74eda14cbcSMatt MacyERROR=0 75eda14cbcSMatt Macy 76eda14cbcSMatt MacyCONFIG_LOG="configure.log" 77eda14cbcSMatt MacyCONFIG_OPTIONS=${CONFIG_OPTIONS:-""} 78eda14cbcSMatt MacyMAKE_LOG="make.log" 79eda14cbcSMatt MacyMAKE_OPTIONS=${MAKE_OPTIONS:-"-s -j$(nproc)"} 80eda14cbcSMatt Macy 81eda14cbcSMatt MacyCOLOR_GREEN="\033[0;32m" 82eda14cbcSMatt MacyCOLOR_RED="\033[0;31m" 83eda14cbcSMatt MacyCOLOR_BROWN="\033[0;33m" 84eda14cbcSMatt MacyCOLOR_RESET="\033[0m" 85eda14cbcSMatt Macy 86eda14cbcSMatt Macyusage() { 87eda14cbcSMatt Macycat << EOF 88eda14cbcSMatt MacyUSAGE: 89eda14cbcSMatt Macyzimport.sh [hvl] [-r repo] [-s src-tag] [-i pool-dir] [-p pool-tag] 90eda14cbcSMatt Macy [-f path] [-o options] 91eda14cbcSMatt Macy 92eda14cbcSMatt MacyDESCRIPTION: 93eda14cbcSMatt Macy ZPOOL import verification tests 94eda14cbcSMatt Macy 95eda14cbcSMatt MacyOPTIONS: 96eda14cbcSMatt Macy -h Show this message 97eda14cbcSMatt Macy -v Verbose 98eda14cbcSMatt Macy -c No color 99eda14cbcSMatt Macy -k Keep temporary directory 100eda14cbcSMatt Macy -r <repo> Source repository ($REPO) 101eda14cbcSMatt Macy -s <src-tag>... Verify ZoL versions with the listed tags 102eda14cbcSMatt Macy -i <pool-dir> Pool image directory 103eda14cbcSMatt Macy -p <pool-tag>... Verify pools created with the listed tags 104eda14cbcSMatt Macy -f <path> Temporary directory to use 105eda14cbcSMatt Macy -o <options> Additional options to pass to 'zpool create' 106eda14cbcSMatt Macy 107eda14cbcSMatt MacyEOF 108eda14cbcSMatt Macy} 109eda14cbcSMatt Macy 110eda14cbcSMatt Macywhile getopts 'hvckr:s:i:p:f:o:?' OPTION; do 111eda14cbcSMatt Macy case $OPTION in 112eda14cbcSMatt Macy h) 113eda14cbcSMatt Macy usage 114eda14cbcSMatt Macy exit 1 115eda14cbcSMatt Macy ;; 116eda14cbcSMatt Macy v) 117eda14cbcSMatt Macy VERBOSE="yes" 118eda14cbcSMatt Macy ;; 119eda14cbcSMatt Macy c) 120eda14cbcSMatt Macy COLOR="no" 121eda14cbcSMatt Macy ;; 122eda14cbcSMatt Macy k) 123eda14cbcSMatt Macy KEEP="yes" 124eda14cbcSMatt Macy ;; 125eda14cbcSMatt Macy r) 126eda14cbcSMatt Macy REPO="$OPTARG" 127eda14cbcSMatt Macy ;; 128eda14cbcSMatt Macy s) 129eda14cbcSMatt Macy SRC_TAGS="$OPTARG" 130eda14cbcSMatt Macy ;; 131eda14cbcSMatt Macy i) 132eda14cbcSMatt Macy IMAGES_DIR="$OPTARG" 133eda14cbcSMatt Macy ;; 134eda14cbcSMatt Macy p) 135eda14cbcSMatt Macy POOL_TAGS="$OPTARG" 136eda14cbcSMatt Macy ;; 137eda14cbcSMatt Macy f) 138eda14cbcSMatt Macy TEST_DIR="$OPTARG" 139eda14cbcSMatt Macy ;; 140eda14cbcSMatt Macy o) 141eda14cbcSMatt Macy POOL_CREATE_OPTIONS="$OPTARG" 142eda14cbcSMatt Macy ;; 143eda14cbcSMatt Macy ?) 144eda14cbcSMatt Macy usage 145eda14cbcSMatt Macy exit 1 146eda14cbcSMatt Macy ;; 147eda14cbcSMatt Macy esac 148eda14cbcSMatt Macydone 149eda14cbcSMatt Macy 150eda14cbcSMatt Macy# 151eda14cbcSMatt Macy# Verify the module start is not loaded 152eda14cbcSMatt Macy# 153eda14cbcSMatt Macyif lsmod | grep zfs >/dev/null; then 154eda14cbcSMatt Macy echo "ZFS modules must be unloaded" 155eda14cbcSMatt Macy exit 1 156eda14cbcSMatt Macyfi 157eda14cbcSMatt Macy 158eda14cbcSMatt Macy# 159eda14cbcSMatt Macy# Create a random directory tree of files and sub-directories to 160eda14cbcSMatt Macy# to act as a copy source for the various regression tests. 161eda14cbcSMatt Macy# 162eda14cbcSMatt Macypopulate() { 163eda14cbcSMatt Macy local ROOT=$1 164eda14cbcSMatt Macy local MAX_DIR_SIZE=$2 165eda14cbcSMatt Macy local MAX_FILE_SIZE=$3 166eda14cbcSMatt Macy 167eda14cbcSMatt Macy # shellcheck disable=SC2086 168eda14cbcSMatt Macy mkdir -p $ROOT/{a,b,c,d,e,f,g}/{h,i} 169eda14cbcSMatt Macy DIRS=$(find "$ROOT") 170eda14cbcSMatt Macy 171eda14cbcSMatt Macy for DIR in $DIRS; do 172eda14cbcSMatt Macy COUNT=$((RANDOM % MAX_DIR_SIZE)) 173eda14cbcSMatt Macy 174eda14cbcSMatt Macy # shellcheck disable=SC2034 175eda14cbcSMatt Macy for i in $(seq $COUNT); do 176eda14cbcSMatt Macy FILE=$(mktemp -p "$DIR") 177eda14cbcSMatt Macy SIZE=$((RANDOM % MAX_FILE_SIZE)) 178eda14cbcSMatt Macy dd if=/dev/urandom of="$FILE" bs=1k \ 179eda14cbcSMatt Macy count="$SIZE" &>/dev/null 180eda14cbcSMatt Macy done 181eda14cbcSMatt Macy done 182eda14cbcSMatt Macy 183eda14cbcSMatt Macy return 0 184eda14cbcSMatt Macy} 185eda14cbcSMatt Macy 186eda14cbcSMatt MacySRC_DIR=$(mktemp -d -p /var/tmp/ zfs.src.XXXXXXXX) 187eda14cbcSMatt Macytrap 'rm -Rf "$SRC_DIR"' INT TERM EXIT 188eda14cbcSMatt Macypopulate "$SRC_DIR" 10 100 189eda14cbcSMatt Macy 190eda14cbcSMatt MacySRC_DIR="$TEST_DIR/src" 191eda14cbcSMatt MacySRC_DIR_ZFS="$SRC_DIR/zfs" 192eda14cbcSMatt Macy 193eda14cbcSMatt Macyif [ "$COLOR" = "no" ]; then 194eda14cbcSMatt Macy COLOR_GREEN="" 195eda14cbcSMatt Macy COLOR_BROWN="" 196eda14cbcSMatt Macy COLOR_RED="" 197eda14cbcSMatt Macy COLOR_RESET="" 198eda14cbcSMatt Macyfi 199eda14cbcSMatt Macy 200eda14cbcSMatt Macypass_nonewline() { 201eda14cbcSMatt Macy echo -n -e "${COLOR_GREEN}Pass${COLOR_RESET}\t\t" 202eda14cbcSMatt Macy} 203eda14cbcSMatt Macy 204eda14cbcSMatt Macyskip_nonewline() { 205eda14cbcSMatt Macy echo -n -e "${COLOR_BROWN}Skip${COLOR_RESET}\t\t" 206eda14cbcSMatt Macy} 207eda14cbcSMatt Macy 208eda14cbcSMatt Macyfail_nonewline() { 209eda14cbcSMatt Macy echo -n -e "${COLOR_RED}Fail${COLOR_RESET}\t\t" 210eda14cbcSMatt Macy} 211eda14cbcSMatt Macy 212eda14cbcSMatt Macy# 213eda14cbcSMatt Macy# Log a failure message, cleanup, and return an error. 214eda14cbcSMatt Macy# 215eda14cbcSMatt Macyfail() { 216eda14cbcSMatt Macy echo -e "$PROG: $1" >&2 217eda14cbcSMatt Macy $ZFS_SH -u >/dev/null 2>&1 218eda14cbcSMatt Macy exit 1 219eda14cbcSMatt Macy} 220eda14cbcSMatt Macy 221eda14cbcSMatt Macy# 222eda14cbcSMatt Macy# Set several helper variables which are derived from a source tag. 223eda14cbcSMatt Macy# 224eda14cbcSMatt Macy# ZFS_TAG - The passed zfs-x.y.z tag 225eda14cbcSMatt Macy# ZFS_DIR - The zfs directory name 226eda14cbcSMatt Macy# ZFS_URL - The zfs github URL to fetch the tarball 227eda14cbcSMatt Macy# 228eda14cbcSMatt Macysrc_set_vars() { 229eda14cbcSMatt Macy local TAG=$1 230eda14cbcSMatt Macy 231eda14cbcSMatt Macy ZFS_TAG="$TAG" 232eda14cbcSMatt Macy ZFS_DIR="$SRC_DIR_ZFS/$ZFS_TAG" 233eda14cbcSMatt Macy ZFS_URL="$REPO/zfs/tarball/$ZFS_TAG" 234eda14cbcSMatt Macy 235eda14cbcSMatt Macy if [ "$TAG" = "installed" ]; then 236eda14cbcSMatt Macy ZPOOL_CMD=$(command -v zpool) 237eda14cbcSMatt Macy ZFS_CMD=$(command -v zfs) 238eda14cbcSMatt Macy ZFS_SH="/usr/share/zfs/zfs.sh" 239eda14cbcSMatt Macy else 240eda14cbcSMatt Macy ZPOOL_CMD="./cmd/zpool/zpool" 241eda14cbcSMatt Macy ZFS_CMD="./cmd/zfs/zfs" 242eda14cbcSMatt Macy ZFS_SH="./scripts/zfs.sh" 243eda14cbcSMatt Macy fi 244eda14cbcSMatt Macy} 245eda14cbcSMatt Macy 246eda14cbcSMatt Macy# 247eda14cbcSMatt Macy# Set several helper variables which are derived from a pool name such 248eda14cbcSMatt Macy# as zol-0.6.x, zevo-1.1.1, etc. These refer to example pools from various 249eda14cbcSMatt Macy# ZFS implementations which are used to verify compatibility. 250eda14cbcSMatt Macy# 251eda14cbcSMatt Macy# POOL_TAG - The example pools name in scripts/zfs-images/. 252eda14cbcSMatt Macy# POOL_BZIP - The full path to the example bzip2 compressed pool. 253eda14cbcSMatt Macy# POOL_DIR - The top level test path for this pool. 254eda14cbcSMatt Macy# POOL_DIR_PRISTINE - The directory containing a pristine version of the pool. 255eda14cbcSMatt Macy# POOL_DIR_COPY - The directory containing a working copy of the pool. 256eda14cbcSMatt Macy# POOL_DIR_SRC - Location of a source build if it exists for this pool. 257eda14cbcSMatt Macy# 258eda14cbcSMatt Macypool_set_vars() { 259eda14cbcSMatt Macy local TAG=$1 260eda14cbcSMatt Macy 261eda14cbcSMatt Macy POOL_TAG=$TAG 262eda14cbcSMatt Macy POOL_BZIP=$IMAGES_DIR/$POOL_TAG.tar.bz2 263eda14cbcSMatt Macy POOL_DIR=$TEST_DIR/pools/$POOL_TAG 264eda14cbcSMatt Macy POOL_DIR_PRISTINE=$POOL_DIR/pristine 265eda14cbcSMatt Macy POOL_DIR_COPY=$POOL_DIR/copy 266eda14cbcSMatt Macy POOL_DIR_SRC="$SRC_DIR_ZFS/${POOL_TAG//zol/zfs}" 267eda14cbcSMatt Macy} 268eda14cbcSMatt Macy 269eda14cbcSMatt Macy# 270eda14cbcSMatt Macy# Construct a non-trivial pool given a specific version of the source. More 271eda14cbcSMatt Macy# interesting pools provide better test coverage so this function should 272eda14cbcSMatt Macy# extended as needed to create more realistic pools. 273eda14cbcSMatt Macy# 274eda14cbcSMatt Macypool_create() { 275eda14cbcSMatt Macy pool_set_vars "$1" 276eda14cbcSMatt Macy src_set_vars "$1" 277eda14cbcSMatt Macy 278eda14cbcSMatt Macy if [ "$POOL_TAG" != "installed" ]; then 279eda14cbcSMatt Macy cd "$POOL_DIR_SRC" || fail "Failed 'cd $POOL_DIR_SRC'" 280eda14cbcSMatt Macy fi 281eda14cbcSMatt Macy 282eda14cbcSMatt Macy $ZFS_SH zfs="spa_config_path=$POOL_DIR_PRISTINE" || \ 283eda14cbcSMatt Macy fail "Failed to load kmods" 284eda14cbcSMatt Macy 285eda14cbcSMatt Macy # Create a file vdev RAIDZ pool. 286eda14cbcSMatt Macy truncate -s 1G \ 287eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev1" "$POOL_DIR_PRISTINE/vdev2" \ 288eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev3" "$POOL_DIR_PRISTINE/vdev4" || \ 289eda14cbcSMatt Macy fail "Failed 'truncate -s 1G ...'" 290eda14cbcSMatt Macy # shellcheck disable=SC2086 291eda14cbcSMatt Macy $ZPOOL_CMD create $POOL_CREATE_OPTIONS "$POOL_TAG" raidz \ 292eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev1" "$POOL_DIR_PRISTINE/vdev2" \ 293eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev3" "$POOL_DIR_PRISTINE/vdev4" || \ 294eda14cbcSMatt Macy fail "Failed '$ZPOOL_CMD create $POOL_CREATE_OPTIONS $POOL_TAG ...'" 295eda14cbcSMatt Macy 296eda14cbcSMatt Macy # Create a pool/fs filesystem with some random contents. 297eda14cbcSMatt Macy $ZFS_CMD create "$POOL_TAG/fs" || \ 298eda14cbcSMatt Macy fail "Failed '$ZFS_CMD create $POOL_TAG/fs'" 299eda14cbcSMatt Macy populate "/$POOL_TAG/fs/" 10 100 300eda14cbcSMatt Macy 301eda14cbcSMatt Macy # Snapshot that filesystem, clone it, remove the files/dirs, 302eda14cbcSMatt Macy # replace them with new files/dirs. 303eda14cbcSMatt Macy $ZFS_CMD snap "$POOL_TAG/fs@snap" || \ 304eda14cbcSMatt Macy fail "Failed '$ZFS_CMD snap $POOL_TAG/fs@snap'" 305eda14cbcSMatt Macy $ZFS_CMD clone "$POOL_TAG/fs@snap" "$POOL_TAG/clone" || \ 306eda14cbcSMatt Macy fail "Failed '$ZFS_CMD clone $POOL_TAG/fs@snap $POOL_TAG/clone'" 307eda14cbcSMatt Macy # shellcheck disable=SC2086 308eda14cbcSMatt Macy rm -Rf /$POOL_TAG/clone/* 309eda14cbcSMatt Macy populate "/$POOL_TAG/clone/" 10 100 310eda14cbcSMatt Macy 311eda14cbcSMatt Macy # Scrub the pool, delay slightly, then export it. It is now 312eda14cbcSMatt Macy # somewhat interesting for testing purposes. 313eda14cbcSMatt Macy $ZPOOL_CMD scrub "$POOL_TAG" || \ 314eda14cbcSMatt Macy fail "Failed '$ZPOOL_CMD scrub $POOL_TAG'" 315eda14cbcSMatt Macy sleep 10 316eda14cbcSMatt Macy $ZPOOL_CMD export "$POOL_TAG" || \ 317eda14cbcSMatt Macy fail "Failed '$ZPOOL_CMD export $POOL_TAG'" 318eda14cbcSMatt Macy 319eda14cbcSMatt Macy $ZFS_SH -u || fail "Failed to unload kmods" 320eda14cbcSMatt Macy} 321eda14cbcSMatt Macy 322eda14cbcSMatt Macy# If the zfs-images directory doesn't exist fetch a copy from Github then 323eda14cbcSMatt Macy# cache it in the $TEST_DIR and update $IMAGES_DIR. 324eda14cbcSMatt Macyif [ ! -d "$IMAGES_DIR" ]; then 325eda14cbcSMatt Macy IMAGES_DIR="$TEST_DIR/zfs-images" 326eda14cbcSMatt Macy mkdir -p "$IMAGES_DIR" 327eda14cbcSMatt Macy curl -sL "$IMAGES_TAR" | \ 328eda14cbcSMatt Macy tar -xz -C "$IMAGES_DIR" --strip-components=1 || \ 329eda14cbcSMatt Macy fail "Failed to download pool images" 330eda14cbcSMatt Macyfi 331eda14cbcSMatt Macy 332eda14cbcSMatt Macy# Given the available images in the zfs-images directory substitute the 333eda14cbcSMatt Macy# list of available images for the reserved keyword 'all'. 334eda14cbcSMatt Macyfor TAG in $POOL_TAGS; do 335eda14cbcSMatt Macy 336eda14cbcSMatt Macy if [ "$TAG" = "all" ]; then 337eda14cbcSMatt Macy # shellcheck disable=SC2010 338eda14cbcSMatt Macy ALL_TAGS=$(ls "$IMAGES_DIR" | grep "tar.bz2" | \ 339eda14cbcSMatt Macy sed 's/.tar.bz2//' | tr '\n' ' ') 340eda14cbcSMatt Macy NEW_TAGS="$NEW_TAGS $ALL_TAGS" 341eda14cbcSMatt Macy else 342eda14cbcSMatt Macy NEW_TAGS="$NEW_TAGS $TAG" 343eda14cbcSMatt Macy fi 344eda14cbcSMatt Macydone 345eda14cbcSMatt MacyPOOL_TAGS="$NEW_TAGS" 346eda14cbcSMatt Macy 347eda14cbcSMatt Macyif [ "$VERBOSE" = "yes" ]; then 348eda14cbcSMatt Macy echo "---------------------------- Options ----------------------------" 349eda14cbcSMatt Macy echo "VERBOSE=$VERBOSE" 350eda14cbcSMatt Macy echo "KEEP=$KEEP" 351eda14cbcSMatt Macy echo "REPO=$REPO" 352eda14cbcSMatt Macy echo "SRC_TAGS=$SRC_TAGS" 353eda14cbcSMatt Macy echo "POOL_TAGS=$POOL_TAGS" 354eda14cbcSMatt Macy echo "PATH=$TEST_DIR" 355eda14cbcSMatt Macy echo "POOL_CREATE_OPTIONS=$POOL_CREATE_OPTIONS" 356eda14cbcSMatt Macy echo 357eda14cbcSMatt Macyfi 358eda14cbcSMatt Macy 359eda14cbcSMatt Macyif [ ! -d "$TEST_DIR" ]; then 360eda14cbcSMatt Macy mkdir -p "$TEST_DIR" 361eda14cbcSMatt Macyfi 362eda14cbcSMatt Macy 363eda14cbcSMatt Macyif [ ! -d "$SRC_DIR" ]; then 364eda14cbcSMatt Macy mkdir -p "$SRC_DIR" 365eda14cbcSMatt Macyfi 366eda14cbcSMatt Macy 367eda14cbcSMatt Macy# Print a header for all tags which are being tested. 368*180f8225SMatt Macyecho "------------------------ OpenZFS Source Versions ----------------" 369eda14cbcSMatt Macyprintf "%-16s" " " 370eda14cbcSMatt Macyfor TAG in $SRC_TAGS; do 371eda14cbcSMatt Macy src_set_vars "$TAG" 372eda14cbcSMatt Macy 373eda14cbcSMatt Macy if [ "$TAG" = "installed" ]; then 374eda14cbcSMatt Macy ZFS_VERSION=$(modinfo zfs | awk '/version:/ { print $2; exit }') 375eda14cbcSMatt Macy if [ -n "$ZFS_VERSION" ]; then 376eda14cbcSMatt Macy printf "%-16s" "$ZFS_VERSION" 377eda14cbcSMatt Macy else 378eda14cbcSMatt Macy fail "ZFS is not installed" 379eda14cbcSMatt Macy fi 380eda14cbcSMatt Macy else 381eda14cbcSMatt Macy printf "%-16s" "$TAG" 382eda14cbcSMatt Macy fi 383eda14cbcSMatt Macydone 384eda14cbcSMatt Macyecho -e "\n-----------------------------------------------------------------" 385eda14cbcSMatt Macy 386eda14cbcSMatt Macy# 387eda14cbcSMatt Macy# Attempt to generate the tarball from your local git repository, if that 388eda14cbcSMatt Macy# fails then attempt to download the tarball from Github. 389eda14cbcSMatt Macy# 390eda14cbcSMatt Macyprintf "%-16s" "Clone ZFS" 391eda14cbcSMatt Macyfor TAG in $SRC_TAGS; do 392eda14cbcSMatt Macy src_set_vars "$TAG" 393eda14cbcSMatt Macy 394eda14cbcSMatt Macy if [ -d "$ZFS_DIR" ]; then 395eda14cbcSMatt Macy skip_nonewline 396eda14cbcSMatt Macy elif [ "$ZFS_TAG" = "installed" ]; then 397eda14cbcSMatt Macy skip_nonewline 398eda14cbcSMatt Macy else 399eda14cbcSMatt Macy cd "$SRC_DIR" || fail "Failed 'cd $SRC_DIR'" 400eda14cbcSMatt Macy 401eda14cbcSMatt Macy if [ ! -d "$SRC_DIR_ZFS" ]; then 402eda14cbcSMatt Macy mkdir -p "$SRC_DIR_ZFS" 403eda14cbcSMatt Macy fi 404eda14cbcSMatt Macy 405eda14cbcSMatt Macy git archive --format=tar --prefix="$ZFS_TAG/ $ZFS_TAG" \ 406eda14cbcSMatt Macy -o "$SRC_DIR_ZFS/$ZFS_TAG.tar" &>/dev/null || \ 407eda14cbcSMatt Macy rm "$SRC_DIR_ZFS/$ZFS_TAG.tar" 408eda14cbcSMatt Macy if [ -s "$SRC_DIR_ZFS/$ZFS_TAG.tar" ]; then 409eda14cbcSMatt Macy tar -xf "$SRC_DIR_ZFS/$ZFS_TAG.tar" -C "$SRC_DIR_ZFS" 410eda14cbcSMatt Macy rm "$SRC_DIR_ZFS/$ZFS_TAG.tar" 411eda14cbcSMatt Macy echo -n -e "${COLOR_GREEN}Local${COLOR_RESET}\t\t" 412eda14cbcSMatt Macy else 413eda14cbcSMatt Macy mkdir -p "$ZFS_DIR" || fail "Failed to create $ZFS_DIR" 414eda14cbcSMatt Macy curl -sL "$ZFS_URL" | tar -xz -C "$ZFS_DIR" \ 415eda14cbcSMatt Macy --strip-components=1 || \ 416eda14cbcSMatt Macy fail "Failed to download $ZFS_URL" 417eda14cbcSMatt Macy echo -n -e "${COLOR_GREEN}Remote${COLOR_RESET}\t\t" 418eda14cbcSMatt Macy fi 419eda14cbcSMatt Macy fi 420eda14cbcSMatt Macydone 421eda14cbcSMatt Macyprintf "\n" 422eda14cbcSMatt Macy 423eda14cbcSMatt Macy# Build the listed tags 424eda14cbcSMatt Macyprintf "%-16s" "Build ZFS" 425eda14cbcSMatt Macyfor TAG in $SRC_TAGS; do 426eda14cbcSMatt Macy src_set_vars "$TAG" 427eda14cbcSMatt Macy 428eda14cbcSMatt Macy if [ -f "$ZFS_DIR/module/zfs/zfs.ko" ]; then 429eda14cbcSMatt Macy skip_nonewline 430eda14cbcSMatt Macy elif [ "$ZFS_TAG" = "installed" ]; then 431eda14cbcSMatt Macy skip_nonewline 432eda14cbcSMatt Macy else 433eda14cbcSMatt Macy cd "$ZFS_DIR" || fail "Failed 'cd $ZFS_DIR'" 434eda14cbcSMatt Macy make distclean &>/dev/null 435eda14cbcSMatt Macy ./autogen.sh >>"$CONFIG_LOG" 2>&1 || \ 436eda14cbcSMatt Macy fail "Failed ZFS 'autogen.sh'" 437eda14cbcSMatt Macy # shellcheck disable=SC2086 438eda14cbcSMatt Macy ./configure $CONFIG_OPTIONS >>"$CONFIG_LOG" 2>&1 || \ 439eda14cbcSMatt Macy fail "Failed ZFS 'configure $CONFIG_OPTIONS'" 440eda14cbcSMatt Macy # shellcheck disable=SC2086 441eda14cbcSMatt Macy make $MAKE_OPTIONS >>"$MAKE_LOG" 2>&1 || \ 442eda14cbcSMatt Macy fail "Failed ZFS 'make $MAKE_OPTIONS'" 443eda14cbcSMatt Macy pass_nonewline 444eda14cbcSMatt Macy fi 445eda14cbcSMatt Macydone 446eda14cbcSMatt Macyprintf "\n" 447eda14cbcSMatt Macyecho "-----------------------------------------------------------------" 448eda14cbcSMatt Macy 449eda14cbcSMatt Macy# Either create a new pool using 'zpool create', or alternately restore an 450eda14cbcSMatt Macy# existing pool from another ZFS implementation for compatibility testing. 451eda14cbcSMatt Macyfor TAG in $POOL_TAGS; do 452eda14cbcSMatt Macy pool_set_vars "$TAG" 453eda14cbcSMatt Macy SKIP=0 454eda14cbcSMatt Macy 455eda14cbcSMatt Macy printf "%-16s" "$POOL_TAG" 456eda14cbcSMatt Macy rm -Rf "$POOL_DIR" 457eda14cbcSMatt Macy mkdir -p "$POOL_DIR_PRISTINE" 458eda14cbcSMatt Macy 459eda14cbcSMatt Macy # Use the existing compressed image if available. 460eda14cbcSMatt Macy if [ -f "$POOL_BZIP" ]; then 461eda14cbcSMatt Macy tar -xjf "$POOL_BZIP" -C "$POOL_DIR_PRISTINE" \ 462eda14cbcSMatt Macy --strip-components=1 || \ 463eda14cbcSMatt Macy fail "Failed 'tar -xjf $POOL_BZIP" 464eda14cbcSMatt Macy # Use the installed version to create the pool. 465eda14cbcSMatt Macy elif [ "$TAG" = "installed" ]; then 466eda14cbcSMatt Macy pool_create "$TAG" 467eda14cbcSMatt Macy # A source build is available to create the pool. 468eda14cbcSMatt Macy elif [ -d "$POOL_DIR_SRC" ]; then 469eda14cbcSMatt Macy pool_create "$TAG" 470eda14cbcSMatt Macy else 471eda14cbcSMatt Macy SKIP=1 472eda14cbcSMatt Macy fi 473eda14cbcSMatt Macy 474eda14cbcSMatt Macy # Verify 'zpool import' works for all listed source versions. 475eda14cbcSMatt Macy for SRC_TAG in $SRC_TAGS; do 476eda14cbcSMatt Macy 477eda14cbcSMatt Macy if [ $SKIP -eq 1 ]; then 478eda14cbcSMatt Macy skip_nonewline 479eda14cbcSMatt Macy continue 480eda14cbcSMatt Macy fi 481eda14cbcSMatt Macy 482eda14cbcSMatt Macy src_set_vars "$SRC_TAG" 483eda14cbcSMatt Macy if [ "$SRC_TAG" != "installed" ]; then 484eda14cbcSMatt Macy cd "$ZFS_DIR" || fail "Failed 'cd $ZFS_DIR'" 485eda14cbcSMatt Macy fi 486eda14cbcSMatt Macy $ZFS_SH zfs="spa_config_path=$POOL_DIR_COPY" 487eda14cbcSMatt Macy 488eda14cbcSMatt Macy cp -a --sparse=always "$POOL_DIR_PRISTINE" \ 489eda14cbcSMatt Macy "$POOL_DIR_COPY" || \ 490eda14cbcSMatt Macy fail "Failed to copy $POOL_DIR_PRISTINE to $POOL_DIR_COPY" 491eda14cbcSMatt Macy POOL_NAME=$($ZPOOL_CMD import -d "$POOL_DIR_COPY" | \ 492eda14cbcSMatt Macy awk '/pool:/ { print $2; exit 0 }') 493eda14cbcSMatt Macy 494eda14cbcSMatt Macy $ZPOOL_CMD import -N -d "$POOL_DIR_COPY" \ 495eda14cbcSMatt Macy "$POOL_NAME" &>/dev/null 496eda14cbcSMatt Macy # shellcheck disable=SC2181 497eda14cbcSMatt Macy if [ $? -ne 0 ]; then 498eda14cbcSMatt Macy fail_nonewline 499eda14cbcSMatt Macy ERROR=1 500eda14cbcSMatt Macy else 501eda14cbcSMatt Macy $ZPOOL_CMD export "$POOL_NAME" || \ 502eda14cbcSMatt Macy fail "Failed to export pool" 503eda14cbcSMatt Macy pass_nonewline 504eda14cbcSMatt Macy fi 505eda14cbcSMatt Macy 506eda14cbcSMatt Macy rm -Rf "$POOL_DIR_COPY" 507eda14cbcSMatt Macy 508eda14cbcSMatt Macy $ZFS_SH -u || fail "Failed to unload kmods" 509eda14cbcSMatt Macy done 510eda14cbcSMatt Macy printf "\n" 511eda14cbcSMatt Macydone 512eda14cbcSMatt Macy 513eda14cbcSMatt Macyif [ "$KEEP" = "no" ]; then 514eda14cbcSMatt Macy rm -Rf "$TEST_DIR" 515eda14cbcSMatt Macyfi 516eda14cbcSMatt Macy 517eda14cbcSMatt Macyexit $ERROR 518