diff options
Diffstat (limited to 'sys/contrib/openzfs/tests/zfs-tests')
22 files changed, 818 insertions, 7 deletions
diff --git a/sys/contrib/openzfs/tests/zfs-tests/cmd/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/cmd/Makefile.am index d1c29fcd1c62..7ec4cb6190a8 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/cmd/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/cmd/Makefile.am @@ -20,6 +20,7 @@ SUBDIRS = \ mmap_exec \ mmap_libaio \ mmap_seek \ + mmap_sync \ mmapwrite \ nvlist_to_lua \ randwritecomp \ diff --git a/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/.gitignore b/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/.gitignore new file mode 100644 index 000000000000..c721f472ba44 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/.gitignore @@ -0,0 +1 @@ +/mmap_sync diff --git a/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/Makefile.am new file mode 100644 index 000000000000..313e8db5c0f4 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/Makefile.am @@ -0,0 +1,6 @@ +include $(top_srcdir)/config/Rules.am + +pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin + +pkgexec_PROGRAMS = mmap_sync +mmap_sync_SOURCES = mmap_sync.c diff --git a/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/mmap_sync.c b/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/mmap_sync.c new file mode 100644 index 000000000000..226e71be2f57 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/cmd/mmap_sync/mmap_sync.c @@ -0,0 +1,152 @@ +/* + * 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 http://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 + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <fcntl.h> +#include <unistd.h> +#include <time.h> + +static void +cleanup(char *file) +{ + (void) remove(file); +} + +int +main(int argc, char *argv[]) +{ + char *testdir = getenv("TESTDIR"); + if (!testdir) { + fprintf(stderr, "environment variable TESTDIR not set\n"); + return (1); + } + + struct stat st; + umask(0); + if (stat(testdir, &st) != 0 && + mkdir(testdir, 0777) != 0) { + perror("mkdir"); + return (1); + } + + if (argc > 3) { + fprintf(stderr, "usage: %s " + "[run time in mins] " + "[max msync time in ms]\n", argv[0]); + return (1); + } + + int run_time_mins = 1; + if (argc >= 2) { + run_time_mins = atoi(argv[1]); + } + + int max_msync_time_ms = 1000; + if (argc >= 3) { + max_msync_time_ms = atoi(argv[2]); + } + + char filepath[512]; + filepath[0] = '\0'; + char *file = &filepath[0]; + + (void) snprintf(file, 512, "%s/msync_file", testdir); + + const int LEN = 8; + cleanup(file); + + int fd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | + S_IRGRP | S_IROTH); + + if (fd == -1) { + (void) fprintf(stderr, "%s: %s: ", argv[0], file); + perror("open"); + return (1); + } + + if (ftruncate(fd, LEN) != 0) { + perror("ftruncate"); + cleanup(file); + return (1); + } + + void *ptr = mmap(NULL, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + if (ptr == MAP_FAILED) { + perror("mmap"); + cleanup(file); + return (1); + } + + struct timeval tstart; + gettimeofday(&tstart, NULL); + + long long x = 0LL; + + for (;;) { + *((long long *)ptr) = x; + x++; + + struct timeval t1, t2; + gettimeofday(&t1, NULL); + if (msync(ptr, LEN, MS_SYNC|MS_INVALIDATE) != 0) { + perror("msync"); + cleanup(file); + return (1); + } + + gettimeofday(&t2, NULL); + + double elapsed = (t2.tv_sec - t1.tv_sec) * 1000.0; + elapsed += ((t2.tv_usec - t1.tv_usec) / 1000.0); + if (elapsed > max_msync_time_ms) { + fprintf(stderr, "slow msync: %f ms\n", elapsed); + if (munmap(ptr, LEN) != 0) + perror("munmap"); + cleanup(file); + return (1); + } + + double elapsed_start = (t2.tv_sec - tstart.tv_sec) * 1000.0; + elapsed_start += ((t2.tv_usec - tstart.tv_usec) / 1000.0); + if (elapsed_start > run_time_mins * 60 * 1000) { + break; + } + } + + if (munmap(ptr, LEN) != 0) { + perror("munmap"); + cleanup(file); + return (1); + } + + if (close(fd) != 0) { + perror("close"); + } + + cleanup(file); + return (0); +} diff --git a/sys/contrib/openzfs/tests/zfs-tests/include/commands.cfg b/sys/contrib/openzfs/tests/zfs-tests/include/commands.cfg index 78802c9fb942..8ac38dfd8934 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/include/commands.cfg +++ b/sys/contrib/openzfs/tests/zfs-tests/include/commands.cfg @@ -207,6 +207,7 @@ export ZFSTEST_FILES='badsend mmap_exec mmap_libaio mmap_seek + mmap_sync mmapwrite nvlist_to_lua randfree_file diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/Makefile.am index 7cffb2eac450..82fd9f340269 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/Makefile.am @@ -14,7 +14,9 @@ dist_pkgdata_SCRIPTS = \ alloc_class_010_pos.ksh \ alloc_class_011_neg.ksh \ alloc_class_012_pos.ksh \ - alloc_class_013_pos.ksh + alloc_class_013_pos.ksh \ + alloc_class_014_neg.ksh \ + alloc_class_015_pos.ksh dist_pkgdata_DATA = \ alloc_class.cfg \ diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh index 2ce22a624291..790a47f26576 100755 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh @@ -42,7 +42,8 @@ log_must display_status "$TESTPOOL" log_must zfs create -o dedup=on -V 2G $TESTPOOL/$TESTVOL -log_must eval "new_fs $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL >/dev/null 2>&1" +block_device_wait "$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL" +log_must eval "new_fs $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL >/dev/null" sync_pool log_must zpool list -v $TESTPOOL diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_014_neg.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_014_neg.ksh new file mode 100755 index 000000000000..1b52014fd2d9 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_014_neg.ksh @@ -0,0 +1,38 @@ +#!/bin/ksh -p + +# +# 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. +# + +. $STF_SUITE/tests/functional/alloc_class/alloc_class.kshlib + +# +# DESCRIPTION: +# Setting the special_small_blocks property greater than recordsize fails. +# + +verify_runnable "global" + +claim="Setting the special_small_blocks property greater than recordsize fails" + +log_assert $claim +log_onexit cleanup +log_must disk_setup + +for size in 512 4096 32768 131072 524288 1048576 +do + let bigger=$size*2 + log_mustnot zpool create -O recordsize=$size \ + -O special_small_blocks=$bigger \ + $TESTPOOL raidz $ZPOOL_DISKS special mirror \ + $CLASS_DISK0 $CLASS_DISK1 +done + +log_pass $claim diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_015_pos.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_015_pos.ksh new file mode 100755 index 000000000000..49c468af6702 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/alloc_class/alloc_class_015_pos.ksh @@ -0,0 +1,45 @@ +#!/bin/ksh -p + +# +# 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. +# + +. $STF_SUITE/tests/functional/alloc_class/alloc_class.kshlib + +# +# DESCRIPTION: +# Can set special_small_blocks property less than or equal to recordsize. +# + +verify_runnable "global" + +claim="Can set special_small_blocks property less than or equal to recordsize" + +log_assert $claim +log_onexit cleanup +log_must disk_setup + +for size in 8192 32768 131072 524288 1048576 +do + let smaller=$size/2 + log_must zpool create -O recordsize=$size \ + -O special_small_blocks=$smaller \ + $TESTPOOL raidz $ZPOOL_DISKS special mirror \ + $CLASS_DISK0 $CLASS_DISK1 + log_must zpool destroy -f "$TESTPOOL" + + log_must zpool create -O recordsize=$size \ + -O special_small_blocks=$size \ + $TESTPOOL raidz $ZPOOL_DISKS special mirror \ + $CLASS_DISK0 $CLASS_DISK1 + log_must zpool destroy -f "$TESTPOOL" +done + +log_pass $claim diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am index a8c9a31dcfdc..4230ec5575f6 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am @@ -12,6 +12,7 @@ dist_pkgdata_SCRIPTS = \ import_cachefile_paths_changed.ksh \ import_cachefile_shared_device.ksh \ import_devices_missing.ksh \ + import_log_missing.ksh \ import_paths_changed.ksh \ import_rewind_config_changed.ksh \ import_rewind_device_replaced.ksh \ diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/import_log_missing.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/import_log_missing.ksh new file mode 100755 index 000000000000..f12cac78540f --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/import_log_missing.ksh @@ -0,0 +1,75 @@ +#!/bin/ksh -p + +# +# 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. +# + +. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib + +# +# DESCRIPTION: +# Import with missing log device should not remove spare/cache. +# +# STRATEGY: +# 1. Create a pool. +# 2. Add spare, cache and log devices to the pool. +# 3. Export the pool. +# 4. Remove the log device. +# 5. Import the pool with -m flag. +# 6. Verify that spare and cache are still present in the pool. +# + +verify_runnable "global" + +log_onexit cleanup + +function test_missing_log +{ + typeset poolcreate="$1" + typeset cachevdev="$2" + typeset sparevdev="$3" + typeset logvdev="$4" + typeset missingvdev="$4" + + log_note "$0: pool '$poolcreate', adding $cachevdev, $sparevdev," \ + "$logvdev then moving away $missingvdev." + + log_must zpool create $TESTPOOL1 $poolcreate + + log_must zpool add $TESTPOOL1 cache $cachevdev spare $sparevdev \ + log $logvdev + + log_must_busy zpool export $TESTPOOL1 + + log_must mv $missingvdev $BACKUP_DEVICE_DIR + + log_must zpool import -m -d $DEVICE_DIR $TESTPOOL1 + + CACHE_PRESENT=$(zpool status -v $TESTPOOL1 | grep $cachevdev) + + SPARE_PRESENT=$(zpool status -v $TESTPOOL1 | grep $sparevdev) + + if [ -z "$CACHE_PRESENT"] || [ -z "SPARE_PRESENT"] + then + log_fail "cache/spare vdev missing after importing with missing" \ + "log device" + fi + + # Cleanup + log_must zpool destroy $TESTPOOL1 + + log_note "" +} + +log_must mkdir -p $BACKUP_DEVICE_DIR + +test_missing_log "$VDEV0" "$VDEV1" "$VDEV2" "$VDEV3" + +log_pass "zpool import succeeded with missing log device" diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/Makefile.am index 3968902ec36d..483c1c2f5914 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/Makefile.am @@ -10,6 +10,7 @@ dist_pkgdata_SCRIPTS = \ zpool_initialize_start_and_cancel_neg.ksh \ zpool_initialize_start_and_cancel_pos.ksh \ zpool_initialize_suspend_resume.ksh \ + zpool_initialize_uninit.ksh \ zpool_initialize_unsupported_vdevs.ksh \ zpool_initialize_verify_checksums.ksh \ zpool_initialize_verify_initialized.ksh diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_uninit.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_uninit.ksh new file mode 100755 index 000000000000..17f776cfbc20 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_uninit.ksh @@ -0,0 +1,141 @@ +#!/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) 2016 by Delphix. All rights reserved. +# Copyright (C) 2023 Lawrence Livermore National Security, LLC. +# +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_initialize/zpool_initialize.kshlib + +# +# DESCRIPTION: +# Starting, stopping, uninitializing, and restart an initialize works. +# +# STRATEGY: +# 1. Create a one-disk pool. +# 2. Verify uninitialize succeeds for uninitialized pool. +# 3. Verify pool wide cancel|suspend + uninit +# a. Start initializing and verify that initializing is active. +# b. Verify uninitialize fails when actively initializing. +# c. Cancel or suspend initializing and verify that initializing is not active. +# d. Verify uninitialize succeeds after being cancelled. +# 4. Verify per-disk cancel|suspend + uninit +# + +DISK1="$(echo $DISKS | cut -d' ' -f1)" +DISK2="$(echo $DISKS | cut -d' ' -f2)" +DISK3="$(echo $DISKS | cut -d' ' -f3)" + +function status_check # pool disk1-state disk2-state disk3-state +{ + typeset pool="$1" + typeset disk1_state="$2" + typeset disk2_state="$3" + typeset disk3_state="$4" + + state=$(zpool status -i "$pool" | grep "$DISK1" | grep "$disk1_state") + if [[ -z "$state" ]]; then + log_fail "DISK1 state; expected='$disk1_state' got '$state'" + fi + + state=$(zpool status -i "$pool" | grep "$DISK2" | grep "$disk2_state") + if [[ -z "$state" ]]; then + log_fail "DISK2 state; expected='$disk2_state' got '$state'" + fi + + state=$(zpool status -i "$pool" | grep "$DISK3" | grep "$disk3_state") + if [[ -z "$state" ]]; then + log_fail "DISK3 state; expected='$disk3_state' got '$state'" + fi +} + +function status_check_all # pool disk-state +{ + typeset pool="$1" + typeset disk_state="$2" + + status_check "$pool" "$disk_state" "$disk_state" "$disk_state" +} + +# 1. Create a one-disk pool. +log_must zpool create -f $TESTPOOL $DISK1 $DISK2 $DISK3 +status_check_all $TESTPOOL "uninitialized" + +# 2. Verify uninitialize succeeds for uninitialized pool. +log_must zpool initialize -u $TESTPOOL +status_check_all $TESTPOOL "uninitialized" + +# 3. Verify pool wide cancel + uninit +log_must zpool initialize $TESTPOOL +status_check_all $TESTPOOL "[[:digit:]]* initialized" + +log_mustnot zpool initialize -u $TESTPOOL +status_check_all $TESTPOOL "[[:digit:]]* initialized" + +log_must zpool initialize -c $TESTPOOL +status_check_all $TESTPOOL "uninitialized" + +log_must zpool initialize -u $TESTPOOL +status_check_all $TESTPOOL "uninitialized" + +# 3. Verify pool wide suspend + uninit +log_must zpool initialize $TESTPOOL +status_check_all $TESTPOOL "[[:digit:]]* initialized" + +log_mustnot zpool initialize -u $TESTPOOL +status_check_all $TESTPOOL "[[:digit:]]* initialized" + +log_must zpool initialize -s $TESTPOOL +status_check_all $TESTPOOL "suspended" + +log_must zpool initialize -u $TESTPOOL +status_check_all $TESTPOOL "uninitialized" + +# 4. Verify per-disk cancel|suspend + uninit +log_must zpool initialize $TESTPOOL +status_check_all $TESTPOOL "[[:digit:]]* initialized" + +log_must zpool initialize -c $TESTPOOL $DISK1 +log_must zpool initialize -s $TESTPOOL $DISK2 +log_mustnot zpool initialize -u $TESTPOOL $DISK3 +status_check $TESTPOOL "uninitialized" "suspended" "[[:digit:]]* initialized" + +log_must zpool initialize -u $TESTPOOL $DISK1 +status_check $TESTPOOL "uninitialized" "suspended" "[[:digit:]]* initialized" + +log_must zpool initialize -u $TESTPOOL $DISK2 +status_check $TESTPOOL "uninitialized" "uninitialized" "[[:digit:]]* initialized" + +log_must zpool initialize $TESTPOOL $DISK1 +status_check $TESTPOOL "[[:digit:]]* initialized" "uninitialized" "[[:digit:]]* initialized" + +log_must zpool initialize $TESTPOOL $DISK2 +status_check_all $TESTPOOL "[[:digit:]]* initialized" + +log_must zpool initialize -s $TESTPOOL +status_check_all $TESTPOOL "suspended" + +log_must zpool initialize -u $TESTPOOL $DISK1 $DISK2 $DISK3 +status_check_all $TESTPOOL "uninitialized" + +log_pass "Initialize start + cancel/suspend + uninit + start works" diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/Makefile.am index 2cec5335fbae..7ca9e81c1867 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/Makefile.am @@ -3,7 +3,8 @@ dist_pkgdata_SCRIPTS = \ setup.ksh \ cleanup.ksh \ zpool_resilver_bad_args.ksh \ - zpool_resilver_restart.ksh + zpool_resilver_restart.ksh \ + zpool_resilver_concurrent.ksh dist_pkgdata_DATA = \ zpool_resilver.cfg diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/zpool_resilver_concurrent.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/zpool_resilver_concurrent.ksh new file mode 100755 index 000000000000..4c3b09796869 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_resilver/zpool_resilver_concurrent.ksh @@ -0,0 +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 http://www.opensolaris.org/os/licensing. +# 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 Hewlett Packard Enterprise Development LP. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib + +# +# DESCRIPTION: +# Verify 'zpool clear' doesn't cause concurrent resilvers +# +# STRATEGY: +# 1. Create N(10) virtual disk files. +# 2. Create draid pool based on the virtual disk files. +# 3. Fill the filesystem with directories and files. +# 4. Force-fault 2 vdevs and verify distributed spare is kicked in. +# 5. Free the distributed spare by replacing the faulty drive. +# 6. Run zpool clear and verify that it does not initiate 2 resilvers +# concurrently while distributed spare gets kicked in. +# + +verify_runnable "global" + +typeset -ir devs=10 +typeset -ir nparity=1 +typeset -ir ndata=8 +typeset -ir dspare=1 + +function cleanup +{ + poolexists "$TESTPOOL" && destroy_pool "$TESTPOOL" + + for i in {0..$devs}; do + log_must rm -f "$BASEDIR/vdev$i" + done + + for dir in $BASEDIR; do + if [[ -d $dir ]]; then + log_must rm -rf $dir + fi + done + + zed_stop + zed_cleanup +} + +log_assert "Verify zpool clear on draid pool doesn't cause concurrent resilvers" +log_onexit cleanup + +setup_test_env $TESTPOOL draid${nparity}:${ndata}d:${dspare}s $devs + +# ZED needed for sequential resilver +zed_setup +log_must zed_start + +log_must zpool offline -f $TESTPOOL $BASEDIR/vdev5 +log_must wait_vdev_state $TESTPOOL draid1-0-0 "ONLINE" 60 +log_must zpool wait -t resilver $TESTPOOL +log_must zpool offline -f $TESTPOOL $BASEDIR/vdev6 + +log_must zpool labelclear -f $BASEDIR/vdev5 +log_must zpool labelclear -f $BASEDIR/vdev6 + +log_must zpool replace -w $TESTPOOL $BASEDIR/vdev5 +sync_pool $TESTPOOL + +log_must zpool events -c +log_must zpool clear $TESTPOOL +log_must wait_vdev_state $TESTPOOL draid1-0-0 "ONLINE" 60 +log_must zpool wait -t resilver $TESTPOOL +log_must zpool wait -t scrub $TESTPOOL + +nof_resilver=$(zpool events | grep -c resilver_start) +if [ $nof_resilver = 1 ] ; then + log_must verify_pool $TESTPOOL + log_pass "zpool clear on draid pool doesn't cause concurrent resilvers" +else + log_fail "FAIL: sequential and healing resilver initiated concurrently" +fi diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_pos.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_pos.ksh index fbb0c291046c..19781137d3ca 100755 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_pos.ksh +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_pos.ksh @@ -35,7 +35,7 @@ DISK1=${DISKS%% *} log_must zpool create -f $TESTPOOL $DISK1 -log_must zpool trim $TESTPOOL +log_must zpool trim -r 1 $TESTPOOL [[ -z "$(trim_progress $TESTPOOL $DISK1)" ]] && \ log_fail "TRIM did not start" diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/Makefile.am index b26791ee7ce0..526405954c08 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/Makefile.am @@ -2,10 +2,12 @@ pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/mmap dist_pkgdata_SCRIPTS = \ setup.ksh \ cleanup.ksh \ + mmap_mixed.ksh \ mmap_read_001_pos.ksh \ mmap_write_001_pos.ksh \ mmap_libaio_001_pos.ksh \ - mmap_seek_001_pos.ksh + mmap_seek_001_pos.ksh \ + mmap_sync_001_pos.ksh dist_pkgdata_DATA = \ mmap.cfg diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_mixed.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_mixed.ksh new file mode 100755 index 000000000000..6c8246d48acf --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_mixed.ksh @@ -0,0 +1,86 @@ +#!/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 by Lawrence Livermore National Security, LLC. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/mmap/mmap.cfg + +# +# DESCRIPTION: +# Verify mixed buffered and mmap IO. +# +# STRATEGY: +# 1. Create an empty file. +# 2. Start a background buffered read/write fio to the file. +# 3. Start a background mmap read/write fio to the file. +# + +verify_runnable "global" + +function cleanup +{ + log_must rm -f "$tmp_file" +} + +log_assert "Verify mixed buffered and mmap IO" + +log_onexit cleanup + +mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS) +tmp_file=$mntpnt/file +bs=$((128 * 1024)) +blocks=64 +size=$((bs * blocks)) +runtime=60 + +log_must dd if=/dev/zero of=$tmp_file bs=$bs count=$blocks + +# Buffered IO writes +log_must eval "fio --filename=$tmp_file --name=buffer-write \ + --rw=randwrite --size=$size --bs=$bs --direct=0 --numjobs=1 \ + --ioengine=sync --fallocate=none --group_reporting --minimal \ + --runtime=$runtime --time_based --norandommap &" + +# Buffered IO reads +log_must eval "fio --filename=$tmp_file --name=buffer-read \ + --rw=randread --size=$size --bs=$bs --direct=0 --numjobs=1 \ + --ioengine=sync --fallocate=none --group_reporting --minimal \ + --runtime=$runtime --time_based --norandommap &" + +# mmap IO writes +log_must eval "fio --filename=$tmp_file --name=mmap-write \ + --rw=randwrite --size=$size --bs=$bs --numjobs=1 \ + --ioengine=mmap --fallocate=none --group_reporting --minimal \ + --runtime=$runtime --time_based --norandommap &" + +# mmap IO reads +log_must eval "fio --filename=$tmp_file --name=mmap-read \ + --rw=randread --size=$size --bs=$bs --numjobs=1 \ + --ioengine=mmap --fallocate=none --group_reporting --minimal \ + --runtime=$runtime --time_based --norandommap &" + +log_must wait + +log_pass "Verfied mixed buffered and mmap IO" diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_sync_001_pos.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_sync_001_pos.ksh new file mode 100755 index 000000000000..b764d6607ba6 --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_sync_001_pos.ksh @@ -0,0 +1,63 @@ +#!/bin/ksh -p + +# +# 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) 2015, 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: +# msync()s of mmap()'ed file should complete quickly during +# background dirty page writebacks by the kernel. +# + +function cleanup +{ + log_must eval "echo $saved_vm_dirty_expire_centisecs > /proc/sys/vm/dirty_expire_centisecs" + log_must eval "echo $saved_vm_dirty_background_ratio > /proc/sys/vm/dirty_background_ratio" + log_must eval "echo $saved_vm_dirty_writeback_centisecs > /proc/sys/vm/dirty_writeback_centisecs" + + # revert to some sensible defaults if the values we saved + # were incorrect due to a previous run being interrupted + if [ $(</proc/sys/vm/dirty_expire_centisecs) -eq 1 ]; then + log_must eval "echo 3000 > /proc/sys/vm/dirty_expire_centisecs" + fi + + if [ $(</proc/sys/vm/dirty_background_ratio) -eq 0 ]; then + log_must eval "echo 10 > /proc/sys/vm/dirty_background_ratio" + fi + + if [ $(</proc/sys/vm/dirty_writeback_centisecs) -eq 1 ]; then + log_must eval "echo 500 > /proc/sys/vm/dirty_writeback_centisecs" + fi +} + +if ! is_linux; then + log_unsupported "Only supported on Linux, requires /proc/sys/vm/ tunables" +fi + +log_onexit cleanup +log_assert "Run the tests for mmap_sync" + +read -r saved_vm_dirty_expire_centisecs < /proc/sys/vm/dirty_expire_centisecs +read -r saved_vm_dirty_background_ratio < /proc/sys/vm/dirty_background_ratio +read -r saved_vm_dirty_writeback_centisecs < /proc/sys/vm/dirty_writeback_centisecs + +log_must eval "echo 1 > /proc/sys/vm/dirty_expire_centisecs" +log_must eval "echo 1 > /proc/sys/vm/dirty_background_bytes" +log_must eval "echo 1 > /proc/sys/vm/dirty_writeback_centisecs" + +log_must mmap_sync +log_pass "mmap_sync tests passed." diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/Makefile.am index d80d2124e291..2cedf03d3d69 100644 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/Makefile.am +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/Makefile.am @@ -25,6 +25,7 @@ dist_pkgdata_SCRIPTS = \ rsend_022_pos.ksh \ rsend_024_pos.ksh \ send_encrypted_files.ksh \ + send_encrypted_freeobjects.ksh \ send_encrypted_hierarchy.ksh \ send_encrypted_props.ksh \ send_encrypted_truncated_files.ksh \ diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send-c_volume.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send-c_volume.ksh index 988ed91b9918..1bf234823459 100755 --- a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send-c_volume.ksh +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send-c_volume.ksh @@ -29,6 +29,7 @@ function cleanup { + rm $BACKDIR/copy log_must_busy zfs destroy -r $vol cleanup_pool $POOL2 } @@ -60,7 +61,9 @@ log_must eval "zfs recv -d $POOL2 <$BACKDIR/full" verify_stream_size $BACKDIR/full $vol verify_stream_size $BACKDIR/full $vol2 -md5=$(dd if=$voldev2 bs=1024k count=$megs 2>/dev/null | md5digest) +block_device_wait $voldev2 +log_must dd if=$voldev2 of=$BACKDIR/copy bs=1024k count=$megs +md5=$(md5digest $BACKDIR/copy) [[ $md5 = $md5_1 ]] || log_fail "md5 mismatch: $md5 != $md5_1" # Repeat, for an incremental send @@ -72,7 +75,9 @@ log_must eval "zfs recv -d $POOL2 <$BACKDIR/inc" verify_stream_size $BACKDIR/inc $vol 90 $vol@snap verify_stream_size $BACKDIR/inc $vol2 90 $vol2@snap -md5=$(dd skip=$megs if=$voldev2 bs=1024k count=$megs 2>/dev/null | md5digest) +block_device_wait $voldev2 +log_must dd skip=$megs if=$voldev2 of=$BACKDIR/copy bs=1024k count=$megs +md5=$(md5digest $BACKDIR/copy) [[ $md5 = $md5_2 ]] || log_fail "md5 mismatch: $md5 != $md5_2" log_pass "Verify compressed send works with volumes" diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send_encrypted_freeobjects.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send_encrypted_freeobjects.ksh new file mode 100755 index 000000000000..92451bd1ab6f --- /dev/null +++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send_encrypted_freeobjects.ksh @@ -0,0 +1,87 @@ +#!/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) 2017 by Lawrence Livermore National Security, LLC. +# Copyright (c) 2023 by Findity AB +# + +. $STF_SUITE/tests/functional/rsend/rsend.kshlib + +# +# Description: +# Verify that receiving a raw encrypted stream, with a FREEOBJECTS +# removing all existing objects in a block followed by an OBJECT write +# to the same block, does not result in a panic. +# +# Strategy: +# 1. Create a new encrypted filesystem +# 2. Create file f1 as the first object in some block (here object 128) +# 3. Take snapshot A +# 4. Create file f2 as the second object in the same block (here object 129) +# 5. Delete f1 +# 6. Take snapshot B +# 7. Receive a full raw encrypted send of A +# 8. Receive an incremental raw send of B +# +verify_runnable "both" + +function create_object_with_num +{ + file=$1 + num=$2 + + tries=100 + for ((i=0; i<$tries; i++)); do + touch $file + onum=$(ls -li $file | awk '{print $1}') + + if [[ $onum -ne $num ]] ; then + rm -f $file + else + break + fi + done + if [[ $i -eq $tries ]]; then + log_fail "Failed to create object with number $num" + fi +} + +log_assert "FREEOBJECTS followed by OBJECT in encrypted stream does not crash" + +sendds=sendencfods +recvds=recvencfods +keyfile=/$POOL/keyencfods +f1=/$POOL/$sendds/f1 +f2=/$POOL/$sendds/f2 + +log_must eval "echo 'password' > $keyfile" + +# +# xattr=sa and dnodesize=legacy for sequential object numbers, see +# note in send_freeobjects.ksh. +# +log_must zfs create -o xattr=sa -o dnodesize=legacy -o encryption=on \ + -o keyformat=passphrase -o keylocation=file://$keyfile $POOL/$sendds + +create_object_with_num $f1 128 +log_must zfs snap $POOL/$sendds@A +create_object_with_num $f2 129 +log_must rm $f1 +log_must zfs snap $POOL/$sendds@B + +log_must eval "zfs send -w $POOL/$sendds@A | zfs recv $POOL/$recvds" +log_must eval "zfs send -w -i $POOL/$sendds@A $POOL/$sendds@B |" \ + "zfs recv $POOL/$recvds" + +log_pass "FREEOBJECTS followed by OBJECT in encrypted stream did not crash" |