diff --git a/tests/zfs-tests/tests/functional/block_cloning/block_cloning.kshlib b/tests/zfs-tests/tests/functional/block_cloning/block_cloning.kshlib index d59329d8748e..324fbecaef96 100644 --- a/tests/zfs-tests/tests/functional/block_cloning/block_cloning.kshlib +++ b/tests/zfs-tests/tests/functional/block_cloning/block_cloning.kshlib @@ -1,58 +1,60 @@ #!/bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2023, Klara Inc. # . $STF_SUITE/include/libtest.shlib function have_same_content { typeset hash1=$(xxh128digest $1) typeset hash2=$(xxh128digest $2) log_must [ "$hash1" = "$hash2" ] } # # get_same_blocks dataset1 path/to/file1 dataset2 path/to/file2 # # Returns a space-separated list of the indexes (starting at 0) of the L0 # blocks that are shared between both files (by first DVA and checksum). # Assumes that the two files have the same content, use have_same_content to # confirm that. # function get_same_blocks { KEY=$5 if [ ${#KEY} -gt 0 ]; then KEY="--key=$KEY" fi - typeset zdbout=${TMPDIR:-$TEST_BASE_DIR}/zdbout.$$ + typeset zdbout1=$(mktemp) + typeset zdbout2=$(mktemp) zdb $KEY -vvvvv $1 -O $2 | \ - awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout.a + awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout1 zdb $KEY -vvvvv $3 -O $4 | \ - awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout.b - echo $(sort -n $zdbout.a $zdbout.b | uniq -d | cut -f1 -d' ') + awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout2 + echo $(sort -n $zdbout1 $zdbout2 | uniq -d | cut -f1 -d' ') + rm -f $zdbout1 $zdbout2 } diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_test_race.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_test_race.ksh index 3a5793d0707d..a69f869911b2 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_test_race.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_test_race.ksh @@ -1,117 +1,115 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.cfg # # DESCRIPTION: # Verify parallel mount ordering is consistent. # # There was a bug in initial thread dispatching algorithm which put threads # under race condition which resulted in undefined mount order. The purpose # of this test is to verify `zfs unmount -a` succeeds (not `zfs mount -a` # succeeds, it always does) after `zfs mount -a`, which could fail if threads # race. See github.com/openzfs/zfs/issues/{8450,8833,8878} for details. # # STRATEGY: # 1. Create pools and filesystems. # 2. Set same mount point for >1 datasets. # 3. Unmount all datasets. # 4. Mount all datasets. # 5. Unmount all datasets (verify this succeeds). # verify_runnable "both" -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -MNTPT=$TMPDIR/zfs_mount_test_race_mntpt -DISK1="$TMPDIR/zfs_mount_test_race_disk1" -DISK2="$TMPDIR/zfs_mount_test_race_disk2" +DISKDIR=$(mktemp -d) +MNTPT=$DISKDIR/zfs_mount_test_race_mntpt +DISK1="$DISKDIR/zfs_mount_test_race_disk1" +DISK2="$DISKDIR/zfs_mount_test_race_disk2" TESTPOOL1=zfs_mount_test_race_tp1 TESTPOOL2=zfs_mount_test_race_tp2 export __ZFS_POOL_RESTRICT="$TESTPOOL1 $TESTPOOL2" log_must zfs $unmountall unset __ZFS_POOL_RESTRICT function cleanup { zpool destroy $TESTPOOL1 zpool destroy $TESTPOOL2 - rm -rf $MNTPT + rm -rf $DISKDIR rm -rf /$TESTPOOL1 rm -rf /$TESTPOOL2 - rm -f $DISK1 - rm -f $DISK2 export __ZFS_POOL_RESTRICT="$TESTPOOL1 $TESTPOOL2" log_must zfs $mountall unset __ZFS_POOL_RESTRICT } log_onexit cleanup log_note "Verify parallel mount ordering is consistent" log_must truncate -s $MINVDEVSIZE $DISK1 log_must truncate -s $MINVDEVSIZE $DISK2 log_must zpool create -f $TESTPOOL1 $DISK1 log_must zpool create -f $TESTPOOL2 $DISK2 log_must zfs create $TESTPOOL1/$TESTFS1 log_must zfs create $TESTPOOL2/$TESTFS2 log_must zfs set mountpoint=none $TESTPOOL1 log_must zfs set mountpoint=$MNTPT $TESTPOOL1/$TESTFS1 # Note that unmount can fail (due to race condition on `zfs mount -a`) with or # without `canmount=off`. The race has nothing to do with canmount property, # but turn it off for convenience of mount layout used in this test case. log_must zfs set canmount=off $TESTPOOL2 log_must zfs set mountpoint=$MNTPT $TESTPOOL2 # At this point, layout of datasets in two pools will look like below. # Previously, on next `zfs mount -a`, pthreads assigned to TESTFS1 and TESTFS2 # could race, and TESTFS2 usually (actually always) won in OpenZFS. # Note that the problem is how two or more threads could initially be assigned # to the same top level directory, not this specific layout. # This layout is just an example that can reproduce race, # and is also the layout reported in #8833. # # NAME MOUNTED MOUNTPOINT # ---------------------------------------------- # /$TESTPOOL1 no none # /$TESTPOOL1/$TESTFS1 yes $MNTPT # /$TESTPOOL2 no $MNTPT # /$TESTPOOL2/$TESTFS2 yes $MNTPT/$TESTFS2 # Apparently two datasets must be mounted. log_must ismounted $TESTPOOL1/$TESTFS1 log_must ismounted $TESTPOOL2/$TESTFS2 # This unmount always succeeds, because potential race hasn't happened yet. log_must zfs unmount -a # This mount always succeeds, whether threads are under race condition or not. log_must zfs mount -a # Verify datasets are mounted (TESTFS2 fails if the race broke mount order). log_must ismounted $TESTPOOL1/$TESTFS1 log_must ismounted $TESTPOOL2/$TESTFS2 # Verify unmount succeeds (fails if the race broke mount order). log_must zfs unmount -a log_pass "Verify parallel mount ordering is consistent passed" diff --git a/tests/zfs-tests/tests/functional/fault/suspend_resume_single.ksh b/tests/zfs-tests/tests/functional/fault/suspend_resume_single.ksh index 22831d28adaf..5d7583307cf6 100755 --- a/tests/zfs-tests/tests/functional/fault/suspend_resume_single.ksh +++ b/tests/zfs-tests/tests/functional/fault/suspend_resume_single.ksh @@ -1,101 +1,101 @@ #!/bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or https://opensource.org/licenses/CDDL-1.0. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2024, Klara Inc. # . $STF_SUITE/include/libtest.shlib -DATAFILE="$TMPDIR/datafile" +DATAFILE=$(mktemp) function cleanup { zpool clear $TESTPOOL destroy_pool $TESTPOOL unload_scsi_debug - rm -f $DATA_FILE + rm -f $DATAFILE } log_onexit cleanup log_assert "ensure single-disk pool resumes properly after suspend and clear" # create a file, and take a checksum, so we can compare later log_must dd if=/dev/urandom of=$DATAFILE bs=128K count=1 typeset sum1=$(xxh128digest $DATAFILE) # make a debug device that we can "unplug" load_scsi_debug 100 1 1 1 '512b' sd=$(get_debug_device) # create a single-device pool log_must zpool create $TESTPOOL $sd log_must zpool sync # "pull" the disk log_must eval "echo offline > /sys/block/$sd/device/state" # copy data onto the pool. it'll appear to succeed, but only be in memory log_must cp $DATAFILE /$TESTPOOL/file # wait until sync starts, and the pool suspends log_note "waiting for pool to suspend" typeset -i tries=10 until [[ $(kstat_pool $TESTPOOL state) == "SUSPENDED" ]] ; do if ((tries-- == 0)); then log_fail "pool didn't suspend" fi sleep 1 done # return the disk log_must eval "echo running > /sys/block/$sd/device/state" # clear the error states, which should reopen the vdev, get the pool back # online, and replay the failed IO log_must zpool clear $TESTPOOL # wait a while for everything to sync out. if something is going to go wrong, # this is where it will happen log_note "giving pool time to settle and complete txg" sleep 7 # if the pool suspended, then everything is bad if [[ $(kstat_pool $TESTPOOL state) == "SUSPENDED" ]] ; then log_fail "pool suspended" fi # export the pool, to make sure it exports clean, and also to clear the file # out of the cache log_must zpool export $TESTPOOL # import the pool log_must zpool import $TESTPOOL # sum the file we wrote earlier typeset sum2=$(xxh128digest /$TESTPOOL/file) # make sure the checksums match log_must test "$sum1" = "$sum2" log_pass "single-disk pool resumes properly after disk suspend and clear" diff --git a/tests/zfs-tests/tests/functional/removal/removal_check_space.ksh b/tests/zfs-tests/tests/functional/removal/removal_check_space.ksh index dec692ada47f..da953c0793ea 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_check_space.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_check_space.ksh @@ -1,44 +1,44 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -log_must mkfile $MINVDEVSIZE $TMPDIR/dsk1 -log_must mkfile $MINVDEVSIZE $TMPDIR/dsk2 -DISKS="$TMPDIR/dsk1 $TMPDIR/dsk2" -REMOVEDISK=$TMPDIR/dsk1 +DISKDIR=$(mktemp -d) +log_must mkfile $MINVDEVSIZE $DISKDIR/dsk1 +log_must mkfile $MINVDEVSIZE $DISKDIR/dsk2 +DISKS="$DISKDIR/dsk1 $DISKDIR/dsk2" +REMOVEDISK=$DISKDIR/dsk1 log_must default_setup_noexit "$DISKS" function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR } log_onexit cleanup # Write a little more than half the pool. log_must dd if=/dev/urandom of=/$TESTDIR/$TESTFILE0 bs=$((2**20)) \ count=$((MINVDEVSIZE / (1024 * 1024))) -log_mustnot zpool remove $TESTPOOL $TMPDIR/dsk1 +log_mustnot zpool remove $TESTPOOL $DISKDIR/dsk1 log_pass "Removal will not succeed if insufficient space." diff --git a/tests/zfs-tests/tests/functional/removal/removal_multiple_indirection.ksh b/tests/zfs-tests/tests/functional/removal/removal_multiple_indirection.ksh index 6c52fd7819ae..f6e229c6ae24 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_multiple_indirection.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_multiple_indirection.ksh @@ -1,93 +1,93 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib # # DESCRIPTION: # # For device removal a file's contents should transfer # completely from one disk to another. That should remain # to be the case even if multiple levels of indirection # are introduced as we remove more and more devices. # # STRATEGY: # # 1. We create a file of size 128k and we save its contents # in a local variable. # 2. We set the limit of the maximum copied segment size of # removals to 32k, so during removal our 128k file will # be split to 4 blocks. # 3. We start removing disks and adding them back in a loop. # This way the file is moved around and introduces split # blocks. # 4. The loop itself tests that we don't have any problem # when removing many devices. Within the loop we test # that the files contents remain the same across transfers. # -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -log_must mkfile $(($MINVDEVSIZE * 2)) $TMPDIR/dsk1 -log_must mkfile $(($MINVDEVSIZE * 2)) $TMPDIR/dsk2 -DISKS="$TMPDIR/dsk1 $TMPDIR/dsk2" -REMOVEDISK=$TMPDIR/dsk1 +DISKDIR=$(mktemp -d) +log_must mkfile $(($MINVDEVSIZE * 2)) $DISKDIR/dsk1 +log_must mkfile $(($MINVDEVSIZE * 2)) $DISKDIR/dsk2 +DISKS="$DISKDIR/dsk1 $DISKDIR/dsk2" +REMOVEDISK=$DISKDIR/dsk1 log_must default_setup_noexit "$DISKS" function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR # reset REMOVE_MAX_SEGMENT to 1M set_tunable32 REMOVE_MAX_SEGMENT 1048576 } log_onexit cleanup # set REMOVE_MAX_SEGMENT to 32k log_must set_tunable32 REMOVE_MAX_SEGMENT 32768 log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=128k count=1 FILE_CONTENTS=$(<$TESTDIR/$TESTFILE0) log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] for i in {1..10}; do - log_must zpool remove $TESTPOOL $TMPDIR/dsk1 + log_must zpool remove $TESTPOOL $DISKDIR/dsk1 log_must wait_for_removal $TESTPOOL - log_mustnot vdevs_in_pool $TESTPOOL $TMPDIR/dsk1 - log_must zpool add $TESTPOOL $TMPDIR/dsk1 + log_mustnot vdevs_in_pool $TESTPOOL $DISKDIR/dsk1 + log_must zpool add $TESTPOOL $DISKDIR/dsk1 log_must zinject -a log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] - log_must zpool remove $TESTPOOL $TMPDIR/dsk2 + log_must zpool remove $TESTPOOL $DISKDIR/dsk2 log_must wait_for_removal $TESTPOOL - log_mustnot vdevs_in_pool $TESTPOOL $TMPDIR/dsk2 - log_must zpool add $TESTPOOL $TMPDIR/dsk2 + log_mustnot vdevs_in_pool $TESTPOOL $DISKDIR/dsk2 + log_must zpool add $TESTPOOL $DISKDIR/dsk2 log_must zinject -a log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] done log_pass "File contents transferred completely from one disk to another." diff --git a/tests/zfs-tests/tests/functional/removal/removal_reservation.ksh b/tests/zfs-tests/tests/functional/removal/removal_reservation.ksh index bf0c202ecbf2..daa56c453ba4 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_reservation.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_reservation.ksh @@ -1,63 +1,63 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2017 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -log_must mkfile 1g $TMPDIR/dsk1 -log_must mkfile 1g $TMPDIR/dsk2 -DISKS="$TMPDIR/dsk1 $TMPDIR/dsk2" -REMOVEDISK=$TMPDIR/dsk1 +DISKDIR=$(mktemp -d) +log_must mkfile 1g $DISKDIR/dsk1 +log_must mkfile 1g $DISKDIR/dsk2 +DISKS="$DISKDIR/dsk1 $DISKDIR/dsk2" +REMOVEDISK=$DISKDIR/dsk1 default_setup_noexit "$DISKS" function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR } log_onexit cleanup log_must zfs set compression=off $TESTPOOL/$TESTFS # Write a little under half the pool. log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**9)) # # Start a writing thread to ensure the removal will take a while. # This will automatically die when we destroy the pool. # start_random_writer $TESTDIR/$TESTFILE1 function callback { # Attempt to write more than the new pool will be able to handle. file_write -o create -f $TESTDIR/$TESTFILE2 -b $((2**20)) -c $((2**9)) zret=$? ENOSPC=28 log_note "file_write returned $zret" (( $zret == $ENOSPC )) || log_fail "Did not get ENOSPC during removal." } log_must attempt_during_removal $TESTPOOL $REMOVEDISK callback log_pass "Removal properly sets reservation." diff --git a/tests/zfs-tests/tests/functional/removal/removal_with_add.ksh b/tests/zfs-tests/tests/functional/removal/removal_with_add.ksh index 7ec6c8675074..18cef3ed4219 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_with_add.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_with_add.ksh @@ -1,48 +1,48 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2017 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -log_must mkfile 1g $TMPDIR/dsk1 -log_must mkfile 1g $TMPDIR/dsk2 +DISKDIR=$(mktemp -d) +log_must mkfile 1g $DISKDIR/dsk1 +log_must mkfile 1g $DISKDIR/dsk2 function cleanup { default_cleanup_noexit - log_must rm -f $TMPDIR/dsk1 $TMPDIR/dsk2 + log_must rm -rf $DISKDIR } default_setup_noexit "$DISKS" log_onexit cleanup function callback { - log_mustnot zpool attach -f $TESTPOOL $TMPDIR/dsk1 $TMPDIR/dsk2 + log_mustnot zpool attach -f $TESTPOOL $DISKDIR/dsk1 $DISKDIR/dsk2 log_mustnot zpool add -f $TESTPOOL \ - raidz $TMPDIR/dsk1 $TMPDIR/dsk2 - log_must zpool add -f $TESTPOOL $TMPDIR/dsk1 + raidz $DISKDIR/dsk1 $DISKDIR/dsk2 + log_must zpool add -f $TESTPOOL $DISKDIR/dsk1 return 0 } test_removal_with_operation callback log_pass "Removal can only add normal disks." diff --git a/tests/zfs-tests/tests/functional/removal/removal_with_errors.ksh b/tests/zfs-tests/tests/functional/removal/removal_with_errors.ksh index be7364eb2b0d..c83189d01bdd 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_with_errors.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_with_errors.ksh @@ -1,115 +1,115 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2017 by Delphix. All rights reserved. # Copyright (c) 2018 by Lawrence Livermore National Security, LLC. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib # # DESCRIPTION: # # This test ensures the device removal is cancelled when hard IO # errors are encountered during the removal process. This is done # to ensure that when removing a device all of the data is copied. # # STRATEGY: # # 1. We create a pool with enough redundancy such that IO errors # will not result in the pool being suspended. # 2. We write some test data to the pool. # 3. We inject READ errors in to one half of the top-level mirror-0 # vdev which is being removed. Then we start the removal process. # 4. Verify that the injected read errors cause the removal of # mirror-0 to be cancelled and that mirror-0 has not been removed. # 5. Clear the read fault injection. # 6. Repeat steps 3-6 above except inject WRITE errors on one of # child vdevs in the destination mirror-1. # 7. Lastly verify the pool data is still intact. # -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -DISK0=$TMPDIR/dsk0 -DISK1=$TMPDIR/dsk1 -DISK2=$TMPDIR/dsk2 -DISK3=$TMPDIR/dsk3 +DISKDIR=$(mktemp -d) +DISK0=$DISKDIR/dsk0 +DISK1=$DISKDIR/dsk1 +DISK2=$DISKDIR/dsk2 +DISK3=$DISKDIR/dsk3 log_must truncate -s $MINVDEVSIZE $DISK0 $DISK1 log_must truncate -s $((MINVDEVSIZE * 4)) $DISK2 $DISK3 function cleanup { log_must zinject -c all default_cleanup_noexit - log_must rm -f $DISK0 $DISK1 $DISK2 $DISK3 + log_must rm -rf $DISKDIR } function wait_for_removing_cancel { typeset pool=$1 log_must zpool wait -t remove $pool # # The pool state changes before the TXG finishes syncing; wait for # the removal to be completed on disk. # sync_pool log_mustnot is_pool_removed $pool return 0 } default_setup_noexit "mirror $DISK0 $DISK1 mirror $DISK2 $DISK3" log_onexit cleanup log_must zfs set compression=off $TESTPOOL FILE_CONTENTS="Leeloo Dallas mul-ti-pass." echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**8)) # Flush the ARC to minimize cache effects. log_must zpool export $TESTPOOL -log_must zpool import -d $TMPDIR $TESTPOOL +log_must zpool import -d $DISKDIR $TESTPOOL # Verify that unexpected read errors automatically cancel the removal. log_must zinject -d $DISK0 -e io -T all -f 100 $TESTPOOL log_must zpool remove $TESTPOOL mirror-0 log_must wait_for_removing_cancel $TESTPOOL log_must vdevs_in_pool $TESTPOOL mirror-0 log_must zinject -c all # Flush the ARC to minimize cache effects. log_must zpool export $TESTPOOL -log_must zpool import -d $TMPDIR $TESTPOOL +log_must zpool import -d $DISKDIR $TESTPOOL # Verify that unexpected write errors automatically cancel the removal. log_must zinject -d $DISK3 -e io -T all -f 100 $TESTPOOL log_must zpool remove $TESTPOOL mirror-0 log_must wait_for_removing_cancel $TESTPOOL log_must vdevs_in_pool $TESTPOOL mirror-0 log_must zinject -c all log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must dd if=$TESTDIR/$TESTFILE1 of=/dev/null log_pass "Device not removed due to unexpected errors." diff --git a/tests/zfs-tests/tests/functional/removal/removal_with_faulted.ksh b/tests/zfs-tests/tests/functional/removal/removal_with_faulted.ksh index 44d222860b80..b3f6a486b3c5 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_with_faulted.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_with_faulted.ksh @@ -1,104 +1,104 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2017 by Delphix. All rights reserved. # Copyright (c) 2018 by Lawrence Livermore National Security, LLC. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib # # DESCRIPTION: # # This test ensures that even when child vdevs are unavailable the # device removal process copies from readable source children to # writable destination children. This may be different than the # default mapping which preferentially pairs up source and destination # child vdevs based on their child ids. # # Default Mapping: # mirror-0 mirror-1 # DISK0 (child 0) ------> DISK2 (child 0) # DISK1 (child 1) ------> DISK3 (child 1) # # We want to setup a scenario where the default mapping would make # it impossible to copy any data during the removal process. This # is done by faulting both the mirror-0 (child 0) source vdev and # mirror-1 (child 1) destination vdev. As shown below the default # mapping cannot be used due to the FAULTED vdevs. Verify that an # alternate mapping is selected and all the readable data is copied. # # Default Mapping (BAD): # mirror-0 mirror-1 # DISK0 (FAULTED) ------> DISK2 # DISK1 ----------------> DISK3 (FAULTED) # # Required Mapping (GOOD): # mirror-0 mirror-1 # DISK0 (FAULTED) +---> DISK2 # DISK1 ------------+ DISK3 (FAULTED) # # STRATEGY: # # 1. We create a pool with two top-level mirror vdevs. # 2. We write some test data to the pool. # 3. We fault two children to force the scenario described above. # 4. We remove the mirror-0 device. # 5. We verify that the device has been removed and that all of the # data is still intact. # -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -DISK0=$TMPDIR/dsk0 -DISK1=$TMPDIR/dsk1 -DISK2=$TMPDIR/dsk2 -DISK3=$TMPDIR/dsk3 +DISKDIR=$(mktemp -d) +DISK0=$DISKDIR/dsk0 +DISK1=$DISKDIR/dsk1 +DISK2=$DISKDIR/dsk2 +DISK3=$DISKDIR/dsk3 log_must truncate -s $MINVDEVSIZE $DISK0 $DISK1 log_must truncate -s $((MINVDEVSIZE * 4)) $DISK2 $DISK3 function cleanup { default_cleanup_noexit - log_must rm -f $DISK0 $DISK1 $DISK2 $DISK3 + log_must rm -rf $DISKDIR } default_setup_noexit "mirror $DISK0 $DISK1 mirror $DISK2 $DISK3" log_onexit cleanup log_must zpool offline -f $TESTPOOL $DISK0 log_must zpool offline -f $TESTPOOL $DISK3 FILE_CONTENTS="Leeloo Dallas mul-ti-pass." echo $FILE_CONTENTS >$TESTDIR/$TESTFILE0 log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**7)) sync_pool $TESTPOOL log_must zpool remove $TESTPOOL mirror-0 log_must wait_for_removal $TESTPOOL log_mustnot vdevs_in_pool $TESTPOOL mirror-0 verify_pool $TESTPOOL log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ] log_must dd if=$TESTDIR/$TESTFILE1 of=/dev/null log_pass "Can remove with faulted vdevs" diff --git a/tests/zfs-tests/tests/functional/removal/removal_with_indirect.ksh b/tests/zfs-tests/tests/functional/removal/removal_with_indirect.ksh index 2a7878f4a2d5..dbbf50dd306f 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_with_indirect.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_with_indirect.ksh @@ -1,57 +1,56 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} - -DISK1="$TMPDIR/dsk1" -DISK2="$TMPDIR/dsk2" -DISK3="$TMPDIR/dsk3" -DISK4="$TMPDIR/dsk4" +DISKDIR=$(mktemp -d) +DISK1="$DISKDIR/dsk1" +DISK2="$DISKDIR/dsk2" +DISK3="$DISKDIR/dsk3" +DISK4="$DISKDIR/dsk4" DISKS="$DISK1 $DISK2 $DISK3 $DISK4" log_must mkfile $(($MINVDEVSIZE * 2)) $DISK1 log_must mkfile $(($MINVDEVSIZE * 2)) $DISK2 log_must mkfile $(($MINVDEVSIZE * 2)) $DISK3 log_must mkfile $(($MINVDEVSIZE * 2)) $DISK4 function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR } # Build a zpool with 2 mirror vdevs log_must default_setup_noexit "mirror $DISK1 $DISK2 mirror $DISK3 $DISK4" log_onexit cleanup # Remove one of the mirrors log_must zpool remove $TESTPOOL mirror-1 log_must wait_for_removal $TESTPOOL # Attempt to add a single-device vdev, shouldn't work log_mustnot zpool add $TESTPOOL $DISK3 # Force it, should work log_must zpool add -f $TESTPOOL $DISK3 log_pass "Prevented from adding a non-mirror vdev on a mirrored zpool w/ indirect vdevs" diff --git a/tests/zfs-tests/tests/functional/removal/removal_with_zdb.ksh b/tests/zfs-tests/tests/functional/removal/removal_with_zdb.ksh index 5c469259a9ef..5edb9cd931f2 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_with_zdb.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_with_zdb.ksh @@ -1,78 +1,78 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2017 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -zdbout=${TMPDIR:-$TEST_BASE_DIR}/zdbout.$$ +zdbout=$(mktemp) if is_linux; then log_unsupported "ZDB fails during concurrent pool activity." fi function cleanup { default_cleanup_noexit log_must rm -f $zdbout } default_setup_noexit "$DISKS" log_onexit cleanup FIRSTDISK=${DISKS%% *} DISKPATH=/dev case $FIRSTDISK in /*) DISKPATH=$(dirname $FIRSTDISK) ;; esac function callback { typeset count=$1 typeset zdbstat log_must zpool set cachefile=none $TESTPOOL zdb -e -p $DISKPATH -cudi $TESTPOOL >$zdbout 2>&1 zdbstat=$? log_must zpool set cachefile= $TESTPOOL if [[ $zdbstat != 0 ]]; then log_note "Output: zdb -e -p $DISKPATH -cudi $TESTPOOL" cat $zdbout log_note "zdb detected errors with exist status $zdbstat." fi log_note "zdb -e -p $DISKPATH -cudi $TESTPOOL >zdbout 2>&1" return 0 } test_removal_with_operation callback log_must zpool set cachefile=none $TESTPOOL zdb -e -p $DISKPATH -cudi $TESTPOOL >$zdbout 2>&1 zdbstat=$? log_must zpool set cachefile= $TESTPOOL if [[ $zdbstat != 0 ]]; then log_note "Output following removal: zdb -cudi $TESTPOOL" cat $zdbout log_fail "zdb detected errors with exit status " \ "$zdbstat following removal." fi log_pass "Can use zdb during removal" diff --git a/tests/zfs-tests/tests/functional/removal/remove_attach_mirror.ksh b/tests/zfs-tests/tests/functional/removal/remove_attach_mirror.ksh index cdbd962025cf..ff177c5311d6 100755 --- a/tests/zfs-tests/tests/functional/removal/remove_attach_mirror.ksh +++ b/tests/zfs-tests/tests/functional/removal/remove_attach_mirror.ksh @@ -1,75 +1,74 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2020, George Amanakis. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib # # DESCRIPTION: # Resilvering results in no CKSUM errors in pools with indirect vdevs. # # STRATEGY: # 1. Create a pool with two top-vdevs # 2. Write some files # 3. Remove one of the top-vdevs # 4. Reattach it to make a mirror # command -v fio > /dev/null || log_unsupported "fio missing" -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} - -DISK1="$TMPDIR/dsk1" -DISK2="$TMPDIR/dsk2" +DISKDIR=$(mktemp -d) +DISK1="$DISKDIR/dsk1" +DISK2="$DISKDIR/dsk2" DISKS="$DISK1 $DISK2" # fio options export DIRECTORY=/$TESTPOOL export NUMJOBS=16 export RUNTIME=10 export PERF_RANDSEED=1234 export PERF_COMPPERCENT=66 export PERF_COMPCHUNK=0 export BLOCKSIZE=4K export SYNC_TYPE=0 export DIRECT=1 export FILE_SIZE=128M log_must mkfile 4g $DISK1 log_must mkfile 4g $DISK2 function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR } log_must zpool create -O recordsize=4k $TESTPOOL $DISK1 $DISK2 log_onexit cleanup log_must fio $FIO_SCRIPTS/mkfiles.fio log_must fio $FIO_SCRIPTS/sequential_reads.fio log_must zpool remove -w $TESTPOOL $DISK2 log_must zpool attach -w $TESTPOOL $DISK1 $DISK2 verify_pool $TESTPOOL log_pass "Resilvering results in no CKSUM errors with indirect vdevs" diff --git a/tests/zfs-tests/tests/functional/removal/remove_expanded.ksh b/tests/zfs-tests/tests/functional/removal/remove_expanded.ksh index 5ee55e9a9d3e..b4374c5cec51 100755 --- a/tests/zfs-tests/tests/functional/removal/remove_expanded.ksh +++ b/tests/zfs-tests/tests/functional/removal/remove_expanded.ksh @@ -1,89 +1,89 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib # # BACKGROUND: # # ztest hit an issue where it ran zdb and zdb failed because # it couldn't access some indirect mappings at the end of a # vdev. The issue was that the vdev's ms_shift had changed after # it was removed by the addition of another vdev. This test is # a regression test for ensuring this case doesn't come up again. # -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -DISK0=$TMPDIR/dsk0 -DISK1=$TMPDIR/dsk1 -DISK2=$TMPDIR/dsk2 +DISKDIR=$(mktemp -d) +DISK0=$DISKDIR/dsk0 +DISK1=$DISKDIR/dsk1 +DISK2=$DISKDIR/dsk2 log_must truncate -s $MINVDEVSIZE $DISK0 log_must truncate -s $(($MINVDEVSIZE * 3)) $DISK1 log_must truncate -s $MINVDEVSIZE $DISK2 function cleanup { default_cleanup_noexit - log_must rm -f $DISK0 $DISK1 $DISK2 + log_must rm -rf $DISKDIR } # # Setup the pool with one disk . # log_must default_setup_noexit "$DISK0" log_onexit cleanup # # Expand vdev. # log_must truncate -s $(($MINVDEVSIZE * 2)) $DISK0 log_must zpool reopen $TESTPOOL log_must zpool online -e $TESTPOOL $DISK0 # # Fill up the whole vdev. # dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=8M # # Add another vdev and remove the first vdev creating indirect # mappings for nearly all the allocatable space from the first # vdev. Wait for removal to finish. # log_must zpool add $TESTPOOL $DISK1 log_must zpool remove $TESTPOOL $DISK0 log_must wait_for_removal $TESTPOOL # # Add a new vdev that will trigger a change in the config. # Run sync once to ensure that the config actually changed. # log_must zpool add $TESTPOOL $DISK2 sync_all_pools # # Ensure that zdb does not find any problems with this. # log_must zdb $TESTPOOL log_pass "Removal of expanded vdev doesn't cause any problems." diff --git a/tests/zfs-tests/tests/functional/removal/remove_mirror.ksh b/tests/zfs-tests/tests/functional/removal/remove_mirror.ksh index a62479f2a1e4..ba288a1f6e81 100755 --- a/tests/zfs-tests/tests/functional/removal/remove_mirror.ksh +++ b/tests/zfs-tests/tests/functional/removal/remove_mirror.ksh @@ -1,58 +1,57 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} - -DISK1="$TMPDIR/dsk1" -DISK2="$TMPDIR/dsk2" -DISK3="$TMPDIR/dsk3" +DISKDIR=$(mktemp -d) +DISK1="$DISKDIR/dsk1" +DISK2="$DISKDIR/dsk2" +DISK3="$DISKDIR/dsk3" DISKS="$DISK1 $DISK2 $DISK3" log_must mkfile $(($MINVDEVSIZE * 2)) $DISK1 log_must mkfile $(($MINVDEVSIZE * 2)) $DISK2 log_must mkfile $(($MINVDEVSIZE * 2)) $DISK3 function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR } log_must default_setup_noexit "$DISK1 mirror $DISK2 $DISK3" log_onexit cleanup # Attempt to remove the non mirrored disk. log_must zpool remove $TESTPOOL $DISK1 # Attempt to remove one of the disks in the mirror. log_mustnot zpool remove $TESTPOOL $DISK2 log_must wait_for_removal $TESTPOOL # Add back the first disk. # We use -f as we're adding a single vdev to zpool with only mirrors. log_must zpool add -f $TESTPOOL $DISK1 # Now attempt to remove the mirror. log_must zpool remove $TESTPOOL mirror-1 log_pass "Removal will succeed for top level vdev(s)." diff --git a/tests/zfs-tests/tests/functional/removal/remove_raidz.ksh b/tests/zfs-tests/tests/functional/removal/remove_raidz.ksh index 98d4536a148d..e9db5e92b0a3 100755 --- a/tests/zfs-tests/tests/functional/removal/remove_raidz.ksh +++ b/tests/zfs-tests/tests/functional/removal/remove_raidz.ksh @@ -1,50 +1,50 @@ #! /bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2014, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib -TMPDIR=${TMPDIR:-$TEST_BASE_DIR} -log_must mkfile $MINVDEVSIZE $TMPDIR/dsk1 -log_must mkfile $MINVDEVSIZE $TMPDIR/dsk2 -log_must mkfile $MINVDEVSIZE $TMPDIR/dsk3 -DISKS1="$TMPDIR/dsk1" -DISKS2="$TMPDIR/dsk2 $TMPDIR/dsk3" +DISKDIR=$(mktemp -d) +log_must mkfile $MINVDEVSIZE $DISKDIR/dsk1 +log_must mkfile $MINVDEVSIZE $DISKDIR/dsk2 +log_must mkfile $MINVDEVSIZE $DISKDIR/dsk3 +DISKS1="$DISKDIR/dsk1" +DISKS2="$DISKDIR/dsk2 $DISKDIR/dsk3" DISKS="$DISKS1 $DISKS2" function cleanup { default_cleanup_noexit - log_must rm -f $DISKS + log_must rm -rf $DISKDIR } log_must default_setup_noexit "$DISKS1 raidz $DISKS2" log_onexit cleanup # Attempt to remove the non raidz disk. -log_mustnot zpool remove $TESTPOOL $TMPDIR/dsk1 +log_mustnot zpool remove $TESTPOOL $DISKDIR/dsk1 # Attempt to remove one of the raidz disks. -log_mustnot zpool remove $TESTPOOL $TMPDIR/dsk2 +log_mustnot zpool remove $TESTPOOL $DISKDIR/dsk2 # Attempt to remove the raidz. log_mustnot zpool remove $TESTPOOL raidz1-1 log_pass "Removal will not succeed if there is a top level mirror."