diff options
Diffstat (limited to 'scripts/zimport.sh')
-rwxr-xr-x | scripts/zimport.sh | 290 |
1 files changed, 171 insertions, 119 deletions
diff --git a/scripts/zimport.sh b/scripts/zimport.sh index da747b0ad..81e415805 100755 --- a/scripts/zimport.sh +++ b/scripts/zimport.sh @@ -53,23 +53,21 @@ # master Pass Pass Pass # installed Pass Pass Pass # -basedir="$(dirname $0)" +BASE_DIR=$(dirname "$0") SCRIPT_COMMON=common.sh -if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then -. "${basedir}/${SCRIPT_COMMON}" +if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then + . "${BASE_DIR}/${SCRIPT_COMMON}" else -echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 + echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 fi -PROG=zimport.sh - -SRC_TAGS="zfs-0.6.1 zfs-0.6.2 master" +SRC_TAGS="zfs-0.6.5.11 master" POOL_TAGS="all master" -TEST_DIR=`mktemp -u -d -p /var/tmp zimport.XXXXXXXX` -KEEP=0 -VERBOSE=0 -COLOR=1 +TEST_DIR=$(mktemp -u -d -p /var/tmp zimport.XXXXXXXX) +KEEP="no" +VERBOSE="no" +COLOR="yes" REPO="https://github.com/zfsonlinux" IMAGES_DIR="$SCRIPTDIR/zfs-images/" IMAGES_TAR="https://github.com/zfsonlinux/zfs-images/tarball/master" @@ -80,6 +78,11 @@ CONFIG_OPTIONS=${CONFIG_OPTIONS:-""} MAKE_LOG="make.log" MAKE_OPTIONS=${MAKE_OPTIONS:-"-s -j$(nproc)"} +COLOR_GREEN="\033[0;32m" +COLOR_RED="\033[0;31m" +COLOR_BROWN="\033[0;33m" +COLOR_RESET="\033[0m" + usage() { cat << EOF USAGE: @@ -109,13 +112,13 @@ while getopts 'hvckr:s:i:p:f:?' OPTION; do exit 1 ;; v) - VERBOSE=1 + VERBOSE="yes" ;; c) - COLOR=0 + COLOR="no" ;; k) - KEEP=1 + KEEP="yes" ;; r) REPO="$OPTARG" @@ -139,15 +142,51 @@ while getopts 'hvckr:s:i:p:f:?' OPTION; do esac done -# Initialize the test suite -init -check_modules || die "ZFS modules must be unloaded" +# +# Verify the module start is not loaded +# +if lsmod | grep zfs >/dev/null; then + echo "ZFS modules must be unloaded" + exit 1 +fi + +# +# Create a random directory tree of files and sub-directories to +# to act as a copy source for the various regression tests. +# +populate() { + local ROOT=$1 + local MAX_DIR_SIZE=$2 + local MAX_FILE_SIZE=$3 + + # shellcheck disable=SC2086 + mkdir -p $ROOT/{a,b,c,d,e,f,g}/{h,i} + DIRS=$(find "$ROOT") + + for DIR in $DIRS; do + COUNT=$((RANDOM % MAX_DIR_SIZE)) + + # shellcheck disable=SC2034 + for i in $(seq $COUNT); do + FILE=$(mktemp -p "$DIR") + SIZE=$((RANDOM % MAX_FILE_SIZE)) + dd if=/dev/urandom of="$FILE" bs=1k \ + count="$SIZE" &>/dev/null + done + done + + return 0 +} + +SRC_DIR=$(mktemp -d -p /var/tmp/ zfs.src.XXXXXXXX) +trap 'rm -Rf "$SRC_DIR"' INT TERM EXIT +populate "$SRC_DIR" 10 100 SRC_DIR="$TEST_DIR/src" SRC_DIR_SPL="$SRC_DIR/spl" SRC_DIR_ZFS="$SRC_DIR/zfs" -if [ $COLOR -eq 0 ]; then +if [ "$COLOR" = "no" ]; then COLOR_GREEN="" COLOR_BROWN="" COLOR_RED="" @@ -166,6 +205,11 @@ fail_nonewline() { echo -n -e "${COLOR_RED}Fail${COLOR_RESET}\t\t" } +fail() { + echo -e "${COLOR_RED}Fail${COLOR_RESET} ($1)" + exit "$1" +} + # # Set several helper variables which are derived from a source tag. # @@ -179,24 +223,22 @@ fail_nonewline() { src_set_vars() { local TAG=$1 - SPL_TAG=`echo $TAG | sed -e 's/zfs/spl/'` - SPL_DIR=$SRC_DIR_SPL/$SPL_TAG - SPL_URL=$REPO/spl/tarball/$SPL_TAG + SPL_TAG="${TAG//zfs/spl}" + SPL_DIR="$SRC_DIR_SPL/$SPL_TAG" + SPL_URL="$REPO/spl/tarball/$SPL_TAG" - ZFS_TAG=$TAG - ZFS_DIR=$SRC_DIR_ZFS/$ZFS_TAG - ZFS_URL=$REPO/zfs/tarball/$ZFS_TAG + ZFS_TAG="$TAG" + ZFS_DIR="$SRC_DIR_ZFS/$ZFS_TAG" + ZFS_URL="$REPO/zfs/tarball/$ZFS_TAG" if [ "$TAG" = "installed" ]; then - ZPOOL_CMD=`which zpool` - ZFS_CMD=`which zfs` + ZPOOL_CMD=$(which zpool) + ZFS_CMD=$(which zfs) ZFS_SH="/usr/share/zfs/zfs.sh" - ZPOOL_CREATE="/usr/share/zfs/zpool-create.sh" else ZPOOL_CMD="./cmd/zpool/zpool" ZFS_CMD="./cmd/zfs/zfs" ZFS_SH="./scripts/zfs.sh" - ZPOOL_CREATE="./scripts/zpool-create.sh" fi } @@ -220,8 +262,7 @@ pool_set_vars() { POOL_DIR=$TEST_DIR/pools/$POOL_TAG POOL_DIR_PRISTINE=$POOL_DIR/pristine POOL_DIR_COPY=$POOL_DIR/copy - POOL_DIR_SRC=`echo -n "$SRC_DIR_ZFS/"; \ - echo "$POOL_TAG" | sed -e 's/zol/zfs/'` + POOL_DIR_SRC="$SRC_DIR_ZFS/${POOL_TAG//zol/zfs}" } # @@ -230,46 +271,51 @@ pool_set_vars() { # extended as needed to create more realistic pools. # pool_create() { - pool_set_vars $1 - src_set_vars $1 + pool_set_vars "$1" + src_set_vars "$1" if [ "$POOL_TAG" != "installed" ]; then - cd $POOL_DIR_SRC + cd "$POOL_DIR_SRC" fi $ZFS_SH zfs="spa_config_path=$POOL_DIR_PRISTINE" || fail 1 # Create a file vdev RAIDZ pool. - FILEDIR="$POOL_DIR_PRISTINE" $ZPOOL_CREATE \ - -c file-raidz -p $POOL_TAG -v -x >/dev/null || fail 2 + truncate -s 1G \ + "$POOL_DIR_PRISTINE/vdev1" "$POOL_DIR_PRISTINE/vdev2" \ + "$POOL_DIR_PRISTINE/vdev3" "$POOL_DIR_PRISTINE/vdev4" + $ZPOOL_CMD create "$POOL_TAG" raidz \ + "$POOL_DIR_PRISTINE/vdev1" "$POOL_DIR_PRISTINE/vdev2" \ + "$POOL_DIR_PRISTINE/vdev3" "$POOL_DIR_PRISTINE/vdev4" # Create a pool/fs filesystem with some random contents. - $ZFS_CMD create $POOL_TAG/fs || fail 3 - populate /$POOL_TAG/fs/ 10 100 + $ZFS_CMD create "$POOL_TAG/fs" || fail 3 + populate "/$POOL_TAG/fs/" 10 100 # Snapshot that filesystem, clone it, remove the files/dirs, # replace them with new files/dirs. - $ZFS_CMD snap $POOL_TAG/fs@snap || fail 4 - $ZFS_CMD clone $POOL_TAG/fs@snap $POOL_TAG/clone || fail 5 + $ZFS_CMD snap "$POOL_TAG/fs@snap" || fail 4 + $ZFS_CMD clone "$POOL_TAG/fs@snap" "$POOL_TAG/clone" || fail 5 + # shellcheck disable=SC2086 rm -Rf /$POOL_TAG/clone/* || fail 6 - populate /$POOL_TAG/clone/ 10 100 + populate "/$POOL_TAG/clone/" 10 100 # Scrub the pool, delay slightly, then export it. It is now # somewhat interesting for testing purposes. - $ZPOOL_CMD scrub $POOL_TAG || fail 7 + $ZPOOL_CMD scrub "$POOL_TAG" || fail 7 sleep 10 - $ZPOOL_CMD export $POOL_TAG || fail 8 + $ZPOOL_CMD export "$POOL_TAG" || fail 8 $ZFS_SH -u || fail 9 } # If the zfs-images directory doesn't exist fetch a copy from Github then # cache it in the $TEST_DIR and update $IMAGES_DIR. -if [ ! -d $IMAGES_DIR ]; then +if [ ! -d "$IMAGES_DIR" ]; then IMAGES_DIR="$TEST_DIR/zfs-images" - mkdir -p $IMAGES_DIR - curl -sL $IMAGES_TAR | \ - tar -xz -C $IMAGES_DIR --strip-components=1 || fail 10 + mkdir -p "$IMAGES_DIR" + curl -sL "$IMAGES_TAR" | \ + tar -xz -C "$IMAGES_DIR" --strip-components=1 || fail 10 fi # Given the available images in the zfs-images directory substitute the @@ -277,8 +323,9 @@ fi for TAG in $POOL_TAGS; do if [ "$TAG" = "all" ]; then - ALL_TAGS=`ls $IMAGES_DIR | grep "tar.bz2" | \ - sed 's/.tar.bz2//' | tr '\n' ' '` + # shellcheck disable=SC2010 + ALL_TAGS=$(ls "$IMAGES_DIR" | grep "tar.bz2" | \ + sed 's/.tar.bz2//' | tr '\n' ' ') NEW_TAGS="$NEW_TAGS $ALL_TAGS" else NEW_TAGS="$NEW_TAGS $TAG" @@ -286,41 +333,41 @@ for TAG in $POOL_TAGS; do done POOL_TAGS="$NEW_TAGS" -if [ $VERBOSE -ne 0 ]; then +if [ "$VERBOSE" = "yes" ]; then echo "---------------------------- Options ----------------------------" echo "VERBOSE=$VERBOSE" echo "KEEP=$KEEP" echo "REPO=$REPO" - echo "SRC_TAGS="$SRC_TAGS"" - echo "POOL_TAGS="$POOL_TAGS"" + echo "SRC_TAGS=$SRC_TAGS" + echo "POOL_TAGS=$POOL_TAGS" echo "PATH=$TEST_DIR" echo fi -if [ ! -d $TEST_DIR ]; then - mkdir -p $TEST_DIR +if [ ! -d "$TEST_DIR" ]; then + mkdir -p "$TEST_DIR" fi -if [ ! -d $SRC_DIR ]; then - mkdir -p $SRC_DIR +if [ ! -d "$SRC_DIR" ]; then + mkdir -p "$SRC_DIR" fi # Print a header for all tags which are being tested. echo "--------------------- ZFS on Linux Source Versions --------------" printf "%-16s" " " for TAG in $SRC_TAGS; do - src_set_vars $TAG + src_set_vars "$TAG" if [ "$TAG" = "installed" ]; then - ZFS_VERSION=`modinfo zfs | awk '/version:/ { print $2; exit }'` + ZFS_VERSION=$(modinfo zfs | awk '/version:/ { print $2; exit }') if [ -n "$ZFS_VERSION" ]; then - printf "%-16s" $ZFS_VERSION + printf "%-16s" "$ZFS_VERSION" else - echo "ZFS is not installed\n" + echo -e "ZFS is not installed\n" fail fi else - printf "%-16s" $TAG + printf "%-16s" "$TAG" fi done echo -e "\n-----------------------------------------------------------------" @@ -331,29 +378,29 @@ echo -e "\n-----------------------------------------------------------------" # printf "%-16s" "Clone SPL" for TAG in $SRC_TAGS; do - src_set_vars $TAG + src_set_vars "$TAG" - if [ -d $SPL_DIR ]; then + if [ -d "$SPL_DIR" ]; then skip_nonewline elif [ "$SPL_TAG" = "installed" ]; then skip_nonewline else - cd $SRC_DIR + cd "$SRC_DIR" - if [ ! -d $SRC_DIR_SPL ]; then - mkdir -p $SRC_DIR_SPL + if [ ! -d "$SRC_DIR_SPL" ]; then + mkdir -p "$SRC_DIR_SPL" fi - git archive --format=tar --prefix=$SPL_TAG/ $SPL_TAG \ - -o $SRC_DIR_SPL/$SPL_TAG.tar &>/dev/nul || \ - rm $SRC_DIR_SPL/$SPL_TAG.tar - if [ -s $SRC_DIR_SPL/$SPL_TAG.tar ]; then - tar -xf $SRC_DIR_SPL/$SPL_TAG.tar -C $SRC_DIR_SPL - rm $SRC_DIR_SPL/$SPL_TAG.tar + git archive --format=tar --prefix="$SPL_TAG/ $SPL_TAG" \ + -o "$SRC_DIR_SPL/$SPL_TAG.tar" &>/dev/nul || \ + rm "$SRC_DIR_SPL/$SPL_TAG.tar" + if [ -s "$SRC_DIR_SPL/$SPL_TAG.tar" ]; then + tar -xf "$SRC_DIR_SPL/$SPL_TAG.tar" -C "$SRC_DIR_SPL" + rm "$SRC_DIR_SPL/$SPL_TAG.tar" echo -n -e "${COLOR_GREEN}Local${COLOR_RESET}\t\t" else - mkdir -p $SPL_DIR || fail 1 - curl -sL $SPL_URL | tar -xz -C $SPL_DIR \ + mkdir -p "$SPL_DIR" || fail 1 + curl -sL "$SPL_URL" | tar -xz -C "$SPL_DIR" \ --strip-components=1 || fail 2 echo -n -e "${COLOR_GREEN}Remote${COLOR_RESET}\t\t" fi @@ -367,29 +414,29 @@ printf "\n" # printf "%-16s" "Clone ZFS" for TAG in $SRC_TAGS; do - src_set_vars $TAG + src_set_vars "$TAG" - if [ -d $ZFS_DIR ]; then + if [ -d "$ZFS_DIR" ]; then skip_nonewline elif [ "$ZFS_TAG" = "installed" ]; then skip_nonewline else - cd $SRC_DIR + cd "$SRC_DIR" - if [ ! -d $SRC_DIR_ZFS ]; then - mkdir -p $SRC_DIR_ZFS + if [ ! -d "$SRC_DIR_ZFS" ]; then + mkdir -p "$SRC_DIR_ZFS" fi - git archive --format=tar --prefix=$ZFS_TAG/ $ZFS_TAG \ - -o $SRC_DIR_ZFS/$ZFS_TAG.tar &>/dev/nul || \ - rm $SRC_DIR_ZFS/$ZFS_TAG.tar - if [ -s $SRC_DIR_ZFS/$ZFS_TAG.tar ]; then - tar -xf $SRC_DIR_ZFS/$ZFS_TAG.tar -C $SRC_DIR_ZFS - rm $SRC_DIR_ZFS/$ZFS_TAG.tar + git archive --format=tar --prefix="$ZFS_TAG/ $ZFS_TAG" \ + -o "$SRC_DIR_ZFS/$ZFS_TAG.tar" &>/dev/nul || \ + rm "$SRC_DIR_ZFS/$ZFS_TAG.tar" + if [ -s "$SRC_DIR_ZFS/$ZFS_TAG.tar" ]; then + tar -xf "$SRC_DIR_ZFS/$ZFS_TAG.tar" -C "$SRC_DIR_ZFS" + rm "$SRC_DIR_ZFS/$ZFS_TAG.tar" echo -n -e "${COLOR_GREEN}Local${COLOR_RESET}\t\t" else - mkdir -p $ZFS_DIR || fail 1 - curl -sL $ZFS_URL | tar -xz -C $ZFS_DIR \ + mkdir -p "$ZFS_DIR" || fail 1 + curl -sL "$ZFS_URL" | tar -xz -C "$ZFS_DIR" \ --strip-components=1 || fail 2 echo -n -e "${COLOR_GREEN}Remote${COLOR_RESET}\t\t" fi @@ -400,18 +447,20 @@ printf "\n" # Build the listed tags printf "%-16s" "Build SPL" for TAG in $SRC_TAGS; do - src_set_vars $TAG + src_set_vars "$TAG" - if [ -f $SPL_DIR/module/spl/spl.ko ]; then + if [ -f "$SPL_DIR/module/spl/spl.ko" ]; then skip_nonewline elif [ "$SPL_TAG" = "installed" ]; then skip_nonewline else - cd $SPL_DIR + cd "$SPL_DIR" make distclean &>/dev/null - ./autogen.sh >>$CONFIG_LOG 2>&1 || fail 1 - ./configure $CONFIG_OPTIONS >>$CONFIG_LOG 2>&1 || fail 2 - make ${MAKE_OPTIONS} >>$MAKE_LOG 2>&1 || fail 3 + ./autogen.sh >>"$CONFIG_LOG" 2>&1 || fail 1 + # shellcheck disable=SC2086 + ./configure $CONFIG_OPTIONS >>"$CONFIG_LOG" 2>&1 || fail 2 + # shellcheck disable=SC2086 + make $MAKE_OPTIONS >>"$MAKE_LOG" 2>&1 || fail 3 pass_nonewline fi done @@ -420,19 +469,21 @@ printf "\n" # Build the listed tags printf "%-16s" "Build ZFS" for TAG in $SRC_TAGS; do - src_set_vars $TAG + src_set_vars "$TAG" - if [ -f $ZFS_DIR/module/zfs/zfs.ko ]; then + if [ -f "$ZFS_DIR/module/zfs/zfs.ko" ]; then skip_nonewline elif [ "$ZFS_TAG" = "installed" ]; then skip_nonewline else - cd $ZFS_DIR + cd "$ZFS_DIR" make distclean &>/dev/null - ./autogen.sh >>$CONFIG_LOG 2>&1 || fail 1 - ./configure --with-spl=$SPL_DIR $CONFIG_OPTIONS \ - >>$CONFIG_LOG 2>&1 || fail 2 - make ${MAKE_OPTIONS} >>$MAKE_LOG 2>&1 || fail 3 + ./autogen.sh >>"$CONFIG_LOG" 2>&1 || fail 1 + # shellcheck disable=SC2086 + ./configure --with-spl="$SPL_DIR" $CONFIG_OPTIONS \ + >>"$CONFIG_LOG" 2>&1 || fail 2 + # shellcheck disable=SC2086 + make $MAKE_OPTIONS >>"$MAKE_LOG" 2>&1 || fail 3 pass_nonewline fi done @@ -442,23 +493,23 @@ echo "-----------------------------------------------------------------" # Either create a new pool using 'zpool create', or alternately restore an # existing pool from another ZFS implementation for compatibility testing. for TAG in $POOL_TAGS; do - pool_set_vars $TAG + pool_set_vars "$TAG" SKIP=0 - printf "%-16s" $POOL_TAG - rm -Rf $POOL_DIR - mkdir -p $POOL_DIR_PRISTINE + printf "%-16s" "$POOL_TAG" + rm -Rf "$POOL_DIR" + mkdir -p "$POOL_DIR_PRISTINE" # Use the existing compressed image if available. - if [ -f $POOL_BZIP ]; then - tar -xjf $POOL_BZIP -C $POOL_DIR_PRISTINE \ + if [ -f "$POOL_BZIP" ]; then + tar -xjf "$POOL_BZIP" -C "$POOL_DIR_PRISTINE" \ --strip-components=1 || fail 1 # Use the installed version to create the pool. elif [ "$TAG" = "installed" ]; then - pool_create $TAG + pool_create "$TAG" # A source build is available to create the pool. - elif [ -d $POOL_DIR_SRC ]; then - pool_create $TAG + elif [ -d "$POOL_DIR_SRC" ]; then + pool_create "$TAG" else SKIP=1 fi @@ -471,35 +522,36 @@ for TAG in $POOL_TAGS; do continue fi - src_set_vars $TAG + src_set_vars "$TAG" if [ "$TAG" != "installed" ]; then - cd $ZFS_DIR + cd "$ZFS_DIR" fi $ZFS_SH zfs="spa_config_path=$POOL_DIR_COPY" - cp -a --sparse=always $POOL_DIR_PRISTINE \ - $POOL_DIR_COPY || fail 2 - POOL_NAME=`$ZPOOL_CMD import -d $POOL_DIR_COPY | \ - awk '/pool:/ { print $2; exit 0 }'` + cp -a --sparse=always "$POOL_DIR_PRISTINE" \ + "$POOL_DIR_COPY" || fail 2 + POOL_NAME=$($ZPOOL_CMD import -d "$POOL_DIR_COPY" | \ + awk '/pool:/ { print $2; exit 0 }') - $ZPOOL_CMD import -N -d $POOL_DIR_COPY $POOL_NAME &>/dev/null + $ZPOOL_CMD import -N -d "$POOL_DIR_COPY" \ + "$POOL_NAME" &>/dev/null if [ $? -ne 0 ]; then fail_nonewline ERROR=1 else - $ZPOOL_CMD export $POOL_NAME || fail 3 + $ZPOOL_CMD export "$POOL_NAME" || fail 3 pass_nonewline fi - rm -Rf $POOL_DIR_COPY + rm -Rf "$POOL_DIR_COPY" $ZFS_SH -u || fail 4 done printf "\n" done -if [ ! $KEEP ]; then - rm -Rf $TEST_DIR +if [ "$KEEP" = "no" ]; then + rm -Rf "$TEST_DIR" fi exit $ERROR |