1eda14cbcSMatt Macy#!/usr/bin/env bash 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# Verify that an assortment of known good reference pools can be imported 416038816SMartin Matuska# using different versions of OpenZFS code. 5eda14cbcSMatt Macy# 6eda14cbcSMatt Macy# By default references pools for the major ZFS implementation will be 716038816SMartin Matuska# checked against the most recent OpenZFS 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# 42180f8225SMatt 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 57*bb2d13b6SMartin Matuskaif [[ -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" 71180f8225SMatt MacyREPO="https://github.com/openzfs" 72e92ffd9bSMartin MatuskaIMAGES_DIR="${BASE_DIR}/zfs-images/" 73180f8225SMatt 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) 10116038816SMartin Matuska -s <src-tag>... Verify OpenZFS 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 ;; 143e92ffd9bSMartin Matuska *) 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 16716038816SMartin Matuska mkdir -p "$ROOT"/{a,b,c,d,e,f,g}/{h,i} 168eda14cbcSMatt Macy DIRS=$(find "$ROOT") 169eda14cbcSMatt Macy 170eda14cbcSMatt Macy for DIR in $DIRS; do 171eda14cbcSMatt Macy COUNT=$((RANDOM % MAX_DIR_SIZE)) 172eda14cbcSMatt Macy 173e92ffd9bSMartin Matuska for _ in $(seq "$COUNT"); do 174eda14cbcSMatt Macy FILE=$(mktemp -p "$DIR") 175eda14cbcSMatt Macy SIZE=$((RANDOM % MAX_FILE_SIZE)) 176eda14cbcSMatt Macy dd if=/dev/urandom of="$FILE" bs=1k \ 177eda14cbcSMatt Macy count="$SIZE" &>/dev/null 178eda14cbcSMatt Macy done 179eda14cbcSMatt Macy done 180eda14cbcSMatt Macy 181eda14cbcSMatt Macy return 0 182eda14cbcSMatt Macy} 183eda14cbcSMatt Macy 184eda14cbcSMatt MacySRC_DIR=$(mktemp -d -p /var/tmp/ zfs.src.XXXXXXXX) 185eda14cbcSMatt Macytrap 'rm -Rf "$SRC_DIR"' INT TERM EXIT 186eda14cbcSMatt Macypopulate "$SRC_DIR" 10 100 187eda14cbcSMatt Macy 188eda14cbcSMatt MacySRC_DIR="$TEST_DIR/src" 189eda14cbcSMatt MacySRC_DIR_ZFS="$SRC_DIR/zfs" 190eda14cbcSMatt Macy 191*bb2d13b6SMartin Matuskaif [[ "$COLOR" = "no" ]]; then 192eda14cbcSMatt Macy COLOR_GREEN="" 193eda14cbcSMatt Macy COLOR_BROWN="" 194eda14cbcSMatt Macy COLOR_RED="" 195eda14cbcSMatt Macy COLOR_RESET="" 196eda14cbcSMatt Macyfi 197eda14cbcSMatt Macy 198eda14cbcSMatt Macypass_nonewline() { 199eda14cbcSMatt Macy echo -n -e "${COLOR_GREEN}Pass${COLOR_RESET}\t\t" 200eda14cbcSMatt Macy} 201eda14cbcSMatt Macy 202eda14cbcSMatt Macyskip_nonewline() { 203eda14cbcSMatt Macy echo -n -e "${COLOR_BROWN}Skip${COLOR_RESET}\t\t" 204eda14cbcSMatt Macy} 205eda14cbcSMatt Macy 206eda14cbcSMatt Macyfail_nonewline() { 207eda14cbcSMatt Macy echo -n -e "${COLOR_RED}Fail${COLOR_RESET}\t\t" 208eda14cbcSMatt Macy} 209eda14cbcSMatt Macy 210eda14cbcSMatt Macy# 211eda14cbcSMatt Macy# Log a failure message, cleanup, and return an error. 212eda14cbcSMatt Macy# 213eda14cbcSMatt Macyfail() { 214eda14cbcSMatt Macy echo -e "$PROG: $1" >&2 215eda14cbcSMatt Macy $ZFS_SH -u >/dev/null 2>&1 216eda14cbcSMatt Macy exit 1 217eda14cbcSMatt Macy} 218eda14cbcSMatt Macy 219eda14cbcSMatt Macy# 220eda14cbcSMatt Macy# Set several helper variables which are derived from a source tag. 221eda14cbcSMatt Macy# 222eda14cbcSMatt Macy# ZFS_TAG - The passed zfs-x.y.z tag 223eda14cbcSMatt Macy# ZFS_DIR - The zfs directory name 224eda14cbcSMatt Macy# ZFS_URL - The zfs github URL to fetch the tarball 225eda14cbcSMatt Macy# 226eda14cbcSMatt Macysrc_set_vars() { 227eda14cbcSMatt Macy local TAG=$1 228eda14cbcSMatt Macy 229eda14cbcSMatt Macy ZFS_TAG="$TAG" 230eda14cbcSMatt Macy ZFS_DIR="$SRC_DIR_ZFS/$ZFS_TAG" 231eda14cbcSMatt Macy ZFS_URL="$REPO/zfs/tarball/$ZFS_TAG" 232eda14cbcSMatt Macy 233*bb2d13b6SMartin Matuska if [[ "$TAG" = "installed" ]]; then 234eda14cbcSMatt Macy ZPOOL_CMD=$(command -v zpool) 235eda14cbcSMatt Macy ZFS_CMD=$(command -v zfs) 236eda14cbcSMatt Macy ZFS_SH="/usr/share/zfs/zfs.sh" 237eda14cbcSMatt Macy else 238716fd348SMartin Matuska ZPOOL_CMD="./zpool" 239716fd348SMartin Matuska ZFS_CMD="./zfs" 240eda14cbcSMatt Macy ZFS_SH="./scripts/zfs.sh" 241eda14cbcSMatt Macy fi 242eda14cbcSMatt Macy} 243eda14cbcSMatt Macy 244eda14cbcSMatt Macy# 245eda14cbcSMatt Macy# Set several helper variables which are derived from a pool name such 246eda14cbcSMatt Macy# as zol-0.6.x, zevo-1.1.1, etc. These refer to example pools from various 247eda14cbcSMatt Macy# ZFS implementations which are used to verify compatibility. 248eda14cbcSMatt Macy# 249eda14cbcSMatt Macy# POOL_TAG - The example pools name in scripts/zfs-images/. 250eda14cbcSMatt Macy# POOL_BZIP - The full path to the example bzip2 compressed pool. 251eda14cbcSMatt Macy# POOL_DIR - The top level test path for this pool. 252eda14cbcSMatt Macy# POOL_DIR_PRISTINE - The directory containing a pristine version of the pool. 253eda14cbcSMatt Macy# POOL_DIR_COPY - The directory containing a working copy of the pool. 254eda14cbcSMatt Macy# POOL_DIR_SRC - Location of a source build if it exists for this pool. 255eda14cbcSMatt Macy# 256eda14cbcSMatt Macypool_set_vars() { 257eda14cbcSMatt Macy local TAG=$1 258eda14cbcSMatt Macy 259eda14cbcSMatt Macy POOL_TAG=$TAG 260eda14cbcSMatt Macy POOL_BZIP=$IMAGES_DIR/$POOL_TAG.tar.bz2 261eda14cbcSMatt Macy POOL_DIR=$TEST_DIR/pools/$POOL_TAG 262eda14cbcSMatt Macy POOL_DIR_PRISTINE=$POOL_DIR/pristine 263eda14cbcSMatt Macy POOL_DIR_COPY=$POOL_DIR/copy 264eda14cbcSMatt Macy POOL_DIR_SRC="$SRC_DIR_ZFS/${POOL_TAG//zol/zfs}" 265eda14cbcSMatt Macy} 266eda14cbcSMatt Macy 267eda14cbcSMatt Macy# 268eda14cbcSMatt Macy# Construct a non-trivial pool given a specific version of the source. More 269eda14cbcSMatt Macy# interesting pools provide better test coverage so this function should 270eda14cbcSMatt Macy# extended as needed to create more realistic pools. 271eda14cbcSMatt Macy# 272eda14cbcSMatt Macypool_create() { 273eda14cbcSMatt Macy pool_set_vars "$1" 274eda14cbcSMatt Macy src_set_vars "$1" 275eda14cbcSMatt Macy 276*bb2d13b6SMartin Matuska if [[ "$POOL_TAG" != "installed" ]]; then 277eda14cbcSMatt Macy cd "$POOL_DIR_SRC" || fail "Failed 'cd $POOL_DIR_SRC'" 278eda14cbcSMatt Macy fi 279eda14cbcSMatt Macy 280eda14cbcSMatt Macy $ZFS_SH zfs="spa_config_path=$POOL_DIR_PRISTINE" || \ 281eda14cbcSMatt Macy fail "Failed to load kmods" 282eda14cbcSMatt Macy 283eda14cbcSMatt Macy # Create a file vdev RAIDZ pool. 284eda14cbcSMatt Macy truncate -s 1G \ 285eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev1" "$POOL_DIR_PRISTINE/vdev2" \ 286eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev3" "$POOL_DIR_PRISTINE/vdev4" || \ 287eda14cbcSMatt Macy fail "Failed 'truncate -s 1G ...'" 288eda14cbcSMatt Macy # shellcheck disable=SC2086 289eda14cbcSMatt Macy $ZPOOL_CMD create $POOL_CREATE_OPTIONS "$POOL_TAG" raidz \ 290eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev1" "$POOL_DIR_PRISTINE/vdev2" \ 291eda14cbcSMatt Macy "$POOL_DIR_PRISTINE/vdev3" "$POOL_DIR_PRISTINE/vdev4" || \ 292eda14cbcSMatt Macy fail "Failed '$ZPOOL_CMD create $POOL_CREATE_OPTIONS $POOL_TAG ...'" 293eda14cbcSMatt Macy 294eda14cbcSMatt Macy # Create a pool/fs filesystem with some random contents. 295eda14cbcSMatt Macy $ZFS_CMD create "$POOL_TAG/fs" || \ 296eda14cbcSMatt Macy fail "Failed '$ZFS_CMD create $POOL_TAG/fs'" 297eda14cbcSMatt Macy populate "/$POOL_TAG/fs/" 10 100 298eda14cbcSMatt Macy 299eda14cbcSMatt Macy # Snapshot that filesystem, clone it, remove the files/dirs, 300eda14cbcSMatt Macy # replace them with new files/dirs. 301eda14cbcSMatt Macy $ZFS_CMD snap "$POOL_TAG/fs@snap" || \ 302eda14cbcSMatt Macy fail "Failed '$ZFS_CMD snap $POOL_TAG/fs@snap'" 303eda14cbcSMatt Macy $ZFS_CMD clone "$POOL_TAG/fs@snap" "$POOL_TAG/clone" || \ 304eda14cbcSMatt Macy fail "Failed '$ZFS_CMD clone $POOL_TAG/fs@snap $POOL_TAG/clone'" 305eda14cbcSMatt Macy # shellcheck disable=SC2086 306eda14cbcSMatt Macy rm -Rf /$POOL_TAG/clone/* 307eda14cbcSMatt Macy populate "/$POOL_TAG/clone/" 10 100 308eda14cbcSMatt Macy 309eda14cbcSMatt Macy # Scrub the pool, delay slightly, then export it. It is now 310eda14cbcSMatt Macy # somewhat interesting for testing purposes. 311eda14cbcSMatt Macy $ZPOOL_CMD scrub "$POOL_TAG" || \ 312eda14cbcSMatt Macy fail "Failed '$ZPOOL_CMD scrub $POOL_TAG'" 313eda14cbcSMatt Macy sleep 10 314eda14cbcSMatt Macy $ZPOOL_CMD export "$POOL_TAG" || \ 315eda14cbcSMatt Macy fail "Failed '$ZPOOL_CMD export $POOL_TAG'" 316eda14cbcSMatt Macy 317eda14cbcSMatt Macy $ZFS_SH -u || fail "Failed to unload kmods" 318eda14cbcSMatt Macy} 319eda14cbcSMatt Macy 320eda14cbcSMatt Macy# If the zfs-images directory doesn't exist fetch a copy from Github then 321eda14cbcSMatt Macy# cache it in the $TEST_DIR and update $IMAGES_DIR. 322*bb2d13b6SMartin Matuskaif [[ ! -d "$IMAGES_DIR" ]]; then 323eda14cbcSMatt Macy IMAGES_DIR="$TEST_DIR/zfs-images" 324eda14cbcSMatt Macy mkdir -p "$IMAGES_DIR" 325eda14cbcSMatt Macy curl -sL "$IMAGES_TAR" | \ 326eda14cbcSMatt Macy tar -xz -C "$IMAGES_DIR" --strip-components=1 || \ 327eda14cbcSMatt Macy fail "Failed to download pool images" 328eda14cbcSMatt Macyfi 329eda14cbcSMatt Macy 330eda14cbcSMatt Macy# Given the available images in the zfs-images directory substitute the 331eda14cbcSMatt Macy# list of available images for the reserved keyword 'all'. 332eda14cbcSMatt Macyfor TAG in $POOL_TAGS; do 333eda14cbcSMatt Macy 334*bb2d13b6SMartin Matuska if [[ "$TAG" = "all" ]]; then 33516038816SMartin Matuska ALL_TAGS=$(echo "$IMAGES_DIR"/*.tar.bz2 | \ 33616038816SMartin Matuska sed "s|$IMAGES_DIR/||g;s|.tar.bz2||g") 337eda14cbcSMatt Macy NEW_TAGS="$NEW_TAGS $ALL_TAGS" 338eda14cbcSMatt Macy else 339eda14cbcSMatt Macy NEW_TAGS="$NEW_TAGS $TAG" 340eda14cbcSMatt Macy fi 341eda14cbcSMatt Macydone 342eda14cbcSMatt MacyPOOL_TAGS="$NEW_TAGS" 343eda14cbcSMatt Macy 344*bb2d13b6SMartin Matuskaif [[ "$VERBOSE" = "yes" ]]; then 345eda14cbcSMatt Macy echo "---------------------------- Options ----------------------------" 346eda14cbcSMatt Macy echo "VERBOSE=$VERBOSE" 347eda14cbcSMatt Macy echo "KEEP=$KEEP" 348eda14cbcSMatt Macy echo "REPO=$REPO" 349eda14cbcSMatt Macy echo "SRC_TAGS=$SRC_TAGS" 350eda14cbcSMatt Macy echo "POOL_TAGS=$POOL_TAGS" 351eda14cbcSMatt Macy echo "PATH=$TEST_DIR" 352eda14cbcSMatt Macy echo "POOL_CREATE_OPTIONS=$POOL_CREATE_OPTIONS" 353eda14cbcSMatt Macy echo 354eda14cbcSMatt Macyfi 355eda14cbcSMatt Macy 356*bb2d13b6SMartin Matuskaif [[ ! -d "$TEST_DIR" ]]; then 357eda14cbcSMatt Macy mkdir -p "$TEST_DIR" 358eda14cbcSMatt Macyfi 359eda14cbcSMatt Macy 360*bb2d13b6SMartin Matuskaif [[ ! -d "$SRC_DIR" ]]; then 361eda14cbcSMatt Macy mkdir -p "$SRC_DIR" 362eda14cbcSMatt Macyfi 363eda14cbcSMatt Macy 364eda14cbcSMatt Macy# Print a header for all tags which are being tested. 365180f8225SMatt Macyecho "------------------------ OpenZFS Source Versions ----------------" 366eda14cbcSMatt Macyprintf "%-16s" " " 367eda14cbcSMatt Macyfor TAG in $SRC_TAGS; do 368eda14cbcSMatt Macy src_set_vars "$TAG" 369eda14cbcSMatt Macy 370*bb2d13b6SMartin Matuska if [[ "$TAG" = "installed" ]]; then 371eda14cbcSMatt Macy ZFS_VERSION=$(modinfo zfs | awk '/version:/ { print $2; exit }') 372*bb2d13b6SMartin Matuska if [[ -n "$ZFS_VERSION" ]]; then 373eda14cbcSMatt Macy printf "%-16s" "$ZFS_VERSION" 374eda14cbcSMatt Macy else 375eda14cbcSMatt Macy fail "ZFS is not installed" 376eda14cbcSMatt Macy fi 377eda14cbcSMatt Macy else 378eda14cbcSMatt Macy printf "%-16s" "$TAG" 379eda14cbcSMatt Macy fi 380eda14cbcSMatt Macydone 381eda14cbcSMatt Macyecho -e "\n-----------------------------------------------------------------" 382eda14cbcSMatt Macy 383eda14cbcSMatt Macy# 384eda14cbcSMatt Macy# Attempt to generate the tarball from your local git repository, if that 385eda14cbcSMatt Macy# fails then attempt to download the tarball from Github. 386eda14cbcSMatt Macy# 387eda14cbcSMatt Macyprintf "%-16s" "Clone ZFS" 388eda14cbcSMatt Macyfor TAG in $SRC_TAGS; do 389eda14cbcSMatt Macy src_set_vars "$TAG" 390eda14cbcSMatt Macy 391*bb2d13b6SMartin Matuska if [[ -d "$ZFS_DIR" ]]; then 392eda14cbcSMatt Macy skip_nonewline 393*bb2d13b6SMartin Matuska elif [[ "$ZFS_TAG" = "installed" ]]; then 394eda14cbcSMatt Macy skip_nonewline 395eda14cbcSMatt Macy else 396eda14cbcSMatt Macy cd "$SRC_DIR" || fail "Failed 'cd $SRC_DIR'" 397eda14cbcSMatt Macy 398*bb2d13b6SMartin Matuska if [[ ! -d "$SRC_DIR_ZFS" ]]; then 399eda14cbcSMatt Macy mkdir -p "$SRC_DIR_ZFS" 400eda14cbcSMatt Macy fi 401eda14cbcSMatt Macy 402eda14cbcSMatt Macy git archive --format=tar --prefix="$ZFS_TAG/ $ZFS_TAG" \ 403eda14cbcSMatt Macy -o "$SRC_DIR_ZFS/$ZFS_TAG.tar" &>/dev/null || \ 404eda14cbcSMatt Macy rm "$SRC_DIR_ZFS/$ZFS_TAG.tar" 405*bb2d13b6SMartin Matuska if [[ -s "$SRC_DIR_ZFS/$ZFS_TAG.tar" ]]; then 406eda14cbcSMatt Macy tar -xf "$SRC_DIR_ZFS/$ZFS_TAG.tar" -C "$SRC_DIR_ZFS" 407eda14cbcSMatt Macy rm "$SRC_DIR_ZFS/$ZFS_TAG.tar" 408eda14cbcSMatt Macy echo -n -e "${COLOR_GREEN}Local${COLOR_RESET}\t\t" 409eda14cbcSMatt Macy else 410eda14cbcSMatt Macy mkdir -p "$ZFS_DIR" || fail "Failed to create $ZFS_DIR" 411eda14cbcSMatt Macy curl -sL "$ZFS_URL" | tar -xz -C "$ZFS_DIR" \ 412eda14cbcSMatt Macy --strip-components=1 || \ 413eda14cbcSMatt Macy fail "Failed to download $ZFS_URL" 414eda14cbcSMatt Macy echo -n -e "${COLOR_GREEN}Remote${COLOR_RESET}\t\t" 415eda14cbcSMatt Macy fi 416eda14cbcSMatt Macy fi 417eda14cbcSMatt Macydone 418eda14cbcSMatt Macyprintf "\n" 419eda14cbcSMatt Macy 420eda14cbcSMatt Macy# Build the listed tags 421eda14cbcSMatt Macyprintf "%-16s" "Build ZFS" 422eda14cbcSMatt Macyfor TAG in $SRC_TAGS; do 423eda14cbcSMatt Macy src_set_vars "$TAG" 424eda14cbcSMatt Macy 425*bb2d13b6SMartin Matuska if [[ -f "$ZFS_DIR/module/zfs/zfs.ko" ]]; then 426eda14cbcSMatt Macy skip_nonewline 427*bb2d13b6SMartin Matuska elif [[ "$ZFS_TAG" = "installed" ]]; then 428eda14cbcSMatt Macy skip_nonewline 429eda14cbcSMatt Macy else 430eda14cbcSMatt Macy cd "$ZFS_DIR" || fail "Failed 'cd $ZFS_DIR'" 431eda14cbcSMatt Macy make distclean &>/dev/null 432eda14cbcSMatt Macy ./autogen.sh >>"$CONFIG_LOG" 2>&1 || \ 433eda14cbcSMatt Macy fail "Failed ZFS 'autogen.sh'" 434eda14cbcSMatt Macy # shellcheck disable=SC2086 435eda14cbcSMatt Macy ./configure $CONFIG_OPTIONS >>"$CONFIG_LOG" 2>&1 || \ 436eda14cbcSMatt Macy fail "Failed ZFS 'configure $CONFIG_OPTIONS'" 437eda14cbcSMatt Macy # shellcheck disable=SC2086 438eda14cbcSMatt Macy make $MAKE_OPTIONS >>"$MAKE_LOG" 2>&1 || \ 439eda14cbcSMatt Macy fail "Failed ZFS 'make $MAKE_OPTIONS'" 440eda14cbcSMatt Macy pass_nonewline 441eda14cbcSMatt Macy fi 442eda14cbcSMatt Macydone 443eda14cbcSMatt Macyprintf "\n" 444eda14cbcSMatt Macyecho "-----------------------------------------------------------------" 445eda14cbcSMatt Macy 446eda14cbcSMatt Macy# Either create a new pool using 'zpool create', or alternately restore an 447eda14cbcSMatt Macy# existing pool from another ZFS implementation for compatibility testing. 448eda14cbcSMatt Macyfor TAG in $POOL_TAGS; do 449eda14cbcSMatt Macy pool_set_vars "$TAG" 450eda14cbcSMatt Macy SKIP=0 451eda14cbcSMatt Macy 452eda14cbcSMatt Macy printf "%-16s" "$POOL_TAG" 453eda14cbcSMatt Macy rm -Rf "$POOL_DIR" 454eda14cbcSMatt Macy mkdir -p "$POOL_DIR_PRISTINE" 455eda14cbcSMatt Macy 456eda14cbcSMatt Macy # Use the existing compressed image if available. 457*bb2d13b6SMartin Matuska if [[ -f "$POOL_BZIP" ]]; then 458eda14cbcSMatt Macy tar -xjf "$POOL_BZIP" -C "$POOL_DIR_PRISTINE" \ 459eda14cbcSMatt Macy --strip-components=1 || \ 460eda14cbcSMatt Macy fail "Failed 'tar -xjf $POOL_BZIP" 461eda14cbcSMatt Macy # Use the installed version to create the pool. 462*bb2d13b6SMartin Matuska elif [[ "$TAG" = "installed" ]]; then 463eda14cbcSMatt Macy pool_create "$TAG" 464eda14cbcSMatt Macy # A source build is available to create the pool. 465*bb2d13b6SMartin Matuska elif [[ -d "$POOL_DIR_SRC" ]]; then 466eda14cbcSMatt Macy pool_create "$TAG" 467eda14cbcSMatt Macy else 468eda14cbcSMatt Macy SKIP=1 469eda14cbcSMatt Macy fi 470eda14cbcSMatt Macy 471eda14cbcSMatt Macy # Verify 'zpool import' works for all listed source versions. 472eda14cbcSMatt Macy for SRC_TAG in $SRC_TAGS; do 473eda14cbcSMatt Macy 474*bb2d13b6SMartin Matuska if [[ "$SKIP" -eq 1 ]]; then 475eda14cbcSMatt Macy skip_nonewline 476eda14cbcSMatt Macy continue 477eda14cbcSMatt Macy fi 478eda14cbcSMatt Macy 479eda14cbcSMatt Macy src_set_vars "$SRC_TAG" 480*bb2d13b6SMartin Matuska if [[ "$SRC_TAG" != "installed" ]]; then 481eda14cbcSMatt Macy cd "$ZFS_DIR" || fail "Failed 'cd $ZFS_DIR'" 482eda14cbcSMatt Macy fi 483eda14cbcSMatt Macy $ZFS_SH zfs="spa_config_path=$POOL_DIR_COPY" 484eda14cbcSMatt Macy 485eda14cbcSMatt Macy cp -a --sparse=always "$POOL_DIR_PRISTINE" \ 486eda14cbcSMatt Macy "$POOL_DIR_COPY" || \ 487eda14cbcSMatt Macy fail "Failed to copy $POOL_DIR_PRISTINE to $POOL_DIR_COPY" 488eda14cbcSMatt Macy POOL_NAME=$($ZPOOL_CMD import -d "$POOL_DIR_COPY" | \ 489dae17134SMartin Matuska awk '/pool:/ { print $2; exit }') 490eda14cbcSMatt Macy 49116038816SMartin Matuska if ! $ZPOOL_CMD import -N -d "$POOL_DIR_COPY" 49216038816SMartin Matuska "$POOL_NAME" &>/dev/null; then 493eda14cbcSMatt Macy fail_nonewline 494eda14cbcSMatt Macy ERROR=1 495eda14cbcSMatt Macy else 496eda14cbcSMatt Macy $ZPOOL_CMD export "$POOL_NAME" || \ 497eda14cbcSMatt Macy fail "Failed to export pool" 498eda14cbcSMatt Macy pass_nonewline 499eda14cbcSMatt Macy fi 500eda14cbcSMatt Macy 501eda14cbcSMatt Macy rm -Rf "$POOL_DIR_COPY" 502eda14cbcSMatt Macy 503eda14cbcSMatt Macy $ZFS_SH -u || fail "Failed to unload kmods" 504eda14cbcSMatt Macy done 505eda14cbcSMatt Macy printf "\n" 506eda14cbcSMatt Macydone 507eda14cbcSMatt Macy 508*bb2d13b6SMartin Matuskaif [[ "$KEEP" = "no" ]]; then 509eda14cbcSMatt Macy rm -Rf "$TEST_DIR" 510eda14cbcSMatt Macyfi 511eda14cbcSMatt Macy 512e92ffd9bSMartin Matuskaexit "$ERROR" 513