xref: /freebsd/tools/test/stress2/misc/zfs13.sh (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5#
6# Copyright (c) 2021 Peter Holm
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# Sparse files test.
31# Delayed write observed.
32# Related to:
33# Bug 256205 - ZFS: data corruption with SEEK_HOLE/SEEK_DATA on dirty files ...
34
35[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
36kldstat -v | grep -q zfs.ko  || { kldload zfs.ko; loaded=1; } ||
37    exit 0
38
39. ../default.cfg
40
41here=`pwd`
42cd /tmp
43mycc -o /tmp/lsholes -Wall -Wextra -O0 -g $here/../tools/lsholes.c || exit 1
44
45log1=/tmp/zfs13.sh.1.log
46log2=/tmp/zfs13.sh.2.log
47mp1=/stress2_tank/test
48u1=$mdstart
49u2=$((u1 + 1))
50
51set -e
52mdconfig -l | grep -q md$u1 && mdconfig -d -u $u1
53mdconfig -l | grep -q md$u2 && mdconfig -d -u $u2
54
55mdconfig -s 2g -u $u1
56mdconfig -s 2g -u $u2
57
58zpool list | egrep -q "^stress2_tank" && zpool destroy stress2_tank
59[ -d /stress2_tank ] && rm -rf /stress2_tank
60zpool create stress2_tank md$u1 md$u2
61zfs create stress2_tank/test
62set +e
63
64cd $mp1
65dd if=/etc/passwd conv=notrunc oseek=32k of=output status=none
66ls -ls | grep output | tee $log1
67/tmp/lsholes output
68sleep 10
69ls -ls | grep output | tee $log2
70/tmp/lsholes output
71cd $here
72
73zfs umount stress2_tank/test
74zfs destroy -r stress2_tank
75zpool destroy stress2_tank
76mdconfig -d -u $u1
77mdconfig -d -u $u2
78cmp -s $log1 $log2
79s=$?
80rm -f /tmp/lsholes $log1 $log2
81[ $loaded ] && kldunload zfs.ko
82exit $s
83