diff --git a/configure.ac b/configure.ac index b533126afd10..b310307824bd 100644 --- a/configure.ac +++ b/configure.ac @@ -273,6 +273,7 @@ AC_CONFIG_FILES([ tests/zfs-tests/tests/functional/sparse/Makefile tests/zfs-tests/tests/functional/threadsappend/Makefile tests/zfs-tests/tests/functional/tmpfile/Makefile + tests/zfs-tests/tests/functional/trim/Makefile tests/zfs-tests/tests/functional/truncate/Makefile tests/zfs-tests/tests/functional/userquota/Makefile tests/zfs-tests/tests/functional/upgrade/Makefile diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 69e317882850..b7ebcb3e6733 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -617,6 +617,9 @@ tests = ['sparse_001_pos'] [tests/functional/tmpfile] tests = ['tmpfile_001_pos', 'tmpfile_002_pos', 'tmpfile_003_pos'] +[tests/functional/trim] +tests = ['autotrim_001_pos', 'manualtrim_001_pos'] + [tests/functional/truncate] tests = ['truncate_001_pos', 'truncate_002_pos'] diff --git a/tests/zfs-tests/tests/functional/Makefile.am b/tests/zfs-tests/tests/functional/Makefile.am index a2d78f520821..bf7a33ae70cd 100644 --- a/tests/zfs-tests/tests/functional/Makefile.am +++ b/tests/zfs-tests/tests/functional/Makefile.am @@ -54,6 +54,7 @@ SUBDIRS = \ sparse \ threadsappend \ tmpfile \ + trim \ truncate \ upgrade \ userquota \ diff --git a/tests/zfs-tests/tests/functional/trim/Makefile.am b/tests/zfs-tests/tests/functional/trim/Makefile.am new file mode 100644 index 000000000000..a379bf898fd5 --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/Makefile.am @@ -0,0 +1,8 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/trim +dist_pkgdata_SCRIPTS = \ + setup.ksh \ + trim.cfg \ + trim.kshlib \ + cleanup.ksh \ + autotrim_001_pos.ksh \ + manualtrim_001_pos.ksh diff --git a/tests/zfs-tests/tests/functional/trim/autotrim_001_pos.ksh b/tests/zfs-tests/tests/functional/trim/autotrim_001_pos.ksh new file mode 100755 index 000000000000..fc74bb7bf570 --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/autotrim_001_pos.ksh @@ -0,0 +1,114 @@ +#!/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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# +# Copyright (c) 2013, 2014 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/trim/trim.cfg +. $STF_SUITE/tests/functional/trim/trim.kshlib + +set_tunable zfs_trim_min_ext_sz 4096 +set_tunable zfs_txgs_per_trim 2 + +function getsizemb +{ + typeset rval + + rval=$(du --block-size 1048576 -s "$1" | sed -e 's;[ ].*;;') + echo -n "$rval" +} + +function checkvdevs +{ + typeset vd sz + + for vd in $VDEVS; do + sz=$(getsizemb $vd) + log_note Size of $vd is $sz MB + log_must test $sz -le $SHRUNK_SIZE_MB + done +} + +function txgs +{ + typeset x + + # Run some txgs in order to let autotrim do its work. + # + for x in 1 2 3; do + log_must zfs snapshot $TRIMPOOL@snap + log_must zfs destroy $TRIMPOOL@snap + log_must zfs snapshot $TRIMPOOL@snap + log_must zfs destroy $TRIMPOOL@snap + done +} + +# +# Check various pool geometries: Create the pool, fill it, remove the test file, +# run some txgs, export the pool and verify that the vdevs shrunk. +# + +# +# raidz +# +for z in 1 2 3; do + setupvdevs + log_must zpool create -f $TRIMPOOL raidz$z $VDEVS + log_must zpool set autotrim=on $TRIMPOOL + log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w + log_must rm "/$TRIMPOOL/$TESTFILE" + txgs + log_must zpool export $TRIMPOOL + checkvdevs +done + +# +# mirror +# +setupvdevs +log_must zpool create -f $TRIMPOOL mirror $MIRROR_VDEVS_1 mirror $MIRROR_VDEVS_2 +log_must zpool set autotrim=on $TRIMPOOL +log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w +log_must rm "/$TRIMPOOL/$TESTFILE" +txgs +log_must zpool export $TRIMPOOL +checkvdevs + +# +# stripe +# +setupvdevs +log_must zpool create -f $TRIMPOOL $STRIPE_VDEVS +log_must zpool set autotrim=on $TRIMPOOL +log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w +log_must rm "/$TRIMPOOL/$TESTFILE" +txgs +log_must zpool export $TRIMPOOL +checkvdevs + +log_pass TRIM successfully shrunk vdevs diff --git a/tests/zfs-tests/tests/functional/trim/cleanup.ksh b/tests/zfs-tests/tests/functional/trim/cleanup.ksh new file mode 100755 index 000000000000..e8d1515e660a --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/cleanup.ksh @@ -0,0 +1,31 @@ +#!/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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/trim/trim.cfg + +rm -f $VDEVS diff --git a/tests/zfs-tests/tests/functional/trim/manualtrim_001_pos.ksh b/tests/zfs-tests/tests/functional/trim/manualtrim_001_pos.ksh new file mode 100755 index 000000000000..7603a85cfd26 --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/manualtrim_001_pos.ksh @@ -0,0 +1,100 @@ +#!/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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# +# Copyright (c) 2013, 2014 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/trim/trim.cfg +. $STF_SUITE/tests/functional/trim/trim.kshlib + +set_tunable zfs_trim_min_ext_sz 4096 + +function getsizemb +{ + typeset rval + + rval=$(du --block-size 1048576 -s "$1" | sed -e 's;[ ].*;;') + echo -n "$rval" +} + +function checkvdevs +{ + typeset vd sz + + for vd in $VDEVS; do + sz=$(getsizemb $vd) + log_note Size of $vd is $sz MB + log_must test $sz -le $SHRUNK_SIZE_MB + done +} + +function dotrim +{ + log_must rm "/$TRIMPOOL/$TESTFILE" + log_must zpool export $TRIMPOOL + log_must zpool import -d $VDEVDIR $TRIMPOOL + log_must zpool trim $TRIMPOOL + sleep 5 + log_must zpool export $TRIMPOOL +} + +# +# Check various pool geometries: Create the pool, fill it, remove the test file, +# perform a manual trim, export the pool and verify that the vdevs shrunk. +# + +# +# raidz +# +for z in 1 2 3; do + setupvdevs + log_must zpool create -f $TRIMPOOL raidz$z $VDEVS + log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w + dotrim + checkvdevs +done + +# +# mirror +# +setupvdevs +log_must zpool create -f $TRIMPOOL mirror $MIRROR_VDEVS_1 mirror $MIRROR_VDEVS_2 +log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w +dotrim +checkvdevs + +# +# stripe +# +setupvdevs +log_must zpool create -f $TRIMPOOL $STRIPE_VDEVS +log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w +dotrim +checkvdevs + +log_pass Manual TRIM successfully shrunk vdevs diff --git a/tests/zfs-tests/tests/functional/trim/setup.ksh b/tests/zfs-tests/tests/functional/trim/setup.ksh new file mode 100755 index 000000000000..feb9ef2ed7ea --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/setup.ksh @@ -0,0 +1,36 @@ +#!/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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/trim/trim.cfg +. $STF_SUITE/tests/functional/trim/trim.kshlib + +log_pass TRIM setup succeeded diff --git a/tests/zfs-tests/tests/functional/trim/trim.cfg b/tests/zfs-tests/tests/functional/trim/trim.cfg new file mode 100644 index 000000000000..a24ee4fb0fe6 --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/trim.cfg @@ -0,0 +1,60 @@ +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013 by Delphix. All rights reserved. +# + +# +# Parameters +# +TRIMPOOL=trimpool +VDEVDIR="/tmp" +VDEVS="/tmp/trim1.dev /tmp/trim2.dev /tmp/trim3.dev /tmp/trim4.dev /tmp/trim5.dev" +VDEV_SIZE=128m +TESTFILE=testfile +SHRUNK_SIZE_MB=12 + +NUM_WRITES=2048 +BLOCKSIZE=65536 + +# +# Computed values and parameters +# +function get_mirror_vdevs +{ + set -- $VDEVS + MIRROR_VDEVS_1="$1 $2" + MIRROR_VDEVS_2="$3 $4" +} +get_mirror_vdevs + +function get_stripe_vdevs +{ + set -- $VDEVS + STRIPE_VDEVS="$1 $2 $3 $4" +} +get_stripe_vdevs diff --git a/tests/zfs-tests/tests/functional/trim/trim.kshlib b/tests/zfs-tests/tests/functional/trim/trim.kshlib new file mode 100644 index 000000000000..041c1f0754b7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/trim/trim.kshlib @@ -0,0 +1,35 @@ +# +# 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. +# + +function set_tunable +{ + typeset tunable="$1" + typeset value="$2" + typeset zfs_tunables="/sys/module/zfs/parameters" + + [[ -z "$tunable" ]] && return 1 + [[ -z "$value" ]] && return 1 + [[ -f "$zfs_tunables/$tunable" ]] || return 1 + + echo -n "$value" > "$zfs_tunables/$tunable" + return "$?" +} + +function find_scsi_debug +{ + grep -H scsi_debug /sys/block/*/device/model | $AWK -F/ '{print $4}' | tr '\n' ' ' +} + +function setupvdevs +{ + log_must rm -f $VDEVS + log_must truncate -s 192m $VDEVS +}