xref: /freebsd/tools/test/stress2/misc/zfs10.sh (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org>
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# sendfile() over zfs. No problems seen.
31
32[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
33[ `uname -m` = "i386" ] && exit 0
34[ `sysctl -n kern.kstack_pages` -lt 4 ] && exit 0
35
36. ../default.cfg
37
38[ `sysctl -n hw.physmem` -lt $(( 4 * 1024 * 1024 * 1024)) ] && exit 0
39kldstat -v | grep -q zfs.ko  || { kldload zfs.ko ||
40    exit 0; loaded=1; }
41
42u1=$mdstart
43u2=$((u1 + 1))
44zdir=/stress2_tank/test
45
46mdconfig -l | grep -q md$u1 && mdconfig -d -u $u1
47mdconfig -l | grep -q md$u2 && mdconfig -d -u $u2
48
49mdconfig -s 1g -u $u1 || exit 1
50mdconfig -s 1g -u $u2 || exit 1
51
52zpool list | egrep -q "^stress2_tank" && zpool destroy stress2_tank
53[ -d /stress2_tank ] && rm -rf /stress2_tank
54zpool create stress2_tank md$u1 md$u2 || exit 1
55zfs create stress2_tank/test || exit 1
56
57(cd ../testcases/swap; ./swap -t 5m -i 20 -l 100) &
58
59odir=`pwd`
60
61echo sendfile.sh
62cd /tmp
63sed '1,/^EOF/d' < $odir/sendfile.sh > sendfile.c
64mycc -o sendfile -Wall sendfile.c -pthread || exit 1
65rm -f sendfile.c
66cd $zdir
67
68in=inputFile
69out=outputFile
70
71for i in 1 2 3 4 8 16 1k 2k 3k 4k 5k 1m 2m 3m 4m 5m ; do
72	rm -f $in $out
73	dd if=/dev/random of=$in bs=$i count=1 status=none
74	/tmp/sendfile $in $out 12345
75	cmp $in $out || { echo FAIL; ls -l $in $out; }
76	rm -f $in $out
77done
78rm -f /tmp/sendfile
79
80echo sendfile4.sh
81cd /tmp
82sed '1,/^EOF/d' < $odir/sendfile4.sh > sendfile4.c
83mycc -o sendfile4 -Wall -Wextra -O2 sendfile4.c || exit
84rm -f sendfile4.c
85cd $zdir
86
87dd if=/dev/zero of=diskimage bs=1m count=6 status=none
88/tmp/sendfile4 diskimage || echo FAIL
89
90rm -f /tmp/sendfile4 diskimage
91
92echo sendfile5.sh
93cd /tmp
94sed '1,/^EOF/d' < $odir/sendfile5.sh > sendfile5.c
95mycc -o sendfile5 -Wall -Wextra -O2 sendfile5.c || exit
96rm -f sendfile5.c
97cd $zdir
98dd if=/dev/zero of=diskimage bs=1m count=1024 status=none
99/tmp/sendfile5 diskimage
100rm -f /tmp/sendfile5 diskimage
101
102echo sendfile8.sh
103cd /tmp
104sed '1,/^EOF/d' < $odir/sendfile8.sh > sendfile8.c
105mycc -o sendfile8 -Wall -Wextra -O2 sendfile8.c || exit
106rm -f sendfile8.c
107cd $zdir
108dd if=/dev/random of=in bs=1m count=50 status=none
109/tmp/sendfile8 in out 76543
110rm -f /tmp/sendfile8 in out
111
112echo sendfile9.sh
113cd /tmp
114sed '1,/^EOF/d' < $odir/sendfile9.sh > sendfile9.c
115mycc -o sendfile9 -Wall -Wextra -O2 sendfile9.c || exit
116rm -f sendfile9.c
117cd $zdir
118dd if=/dev/random of=in bs=1m count=50 status=none
119/tmp/sendfile9 in out 76543
120rm -f /tmp/sendfile9 in out
121
122echo sendfile12.sh
123cd /tmp
124sed '1,/^EOF/d' < $odir/sendfile12.sh > sendfile12.c
125mycc -o sendfile12 -Wall -Wextra -O2 sendfile12.c || exit
126rm -f sendfile12.c
127cd $zdir
128dd if=/dev/zero of=in bs=1m count=512 status=none
129/tmp/sendfile12 in out 76543
130rm -f /tmp/sendfile12 in out
131
132while pkill swap; do sleep .1; done
133wait
134
135cd $odir
136zfs destroy -r stress2_tank
137zpool destroy stress2_tank
138
139mdconfig -d -u $u1
140mdconfig -d -u $u2
141[ -n "$loaded" ] && kldunload zfs.ko
142exit 0
143