xref: /freebsd/tools/test/stress2/misc/md8.sh (revision 8a272653d9fbd9fc37691c9aad6a05089b4ecb4d)
1#!/bin/sh
2
3#
4# Copyright (c) 2015 EMC Corp.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# Test of unmapped unaligned i/o over the vnode-backed md(4) volume.
30# "panic: vm_fault: fault on nofault entry, addr: fffffe07f302c000" seen.
31# https://people.freebsd.org/~pho/stress/log/md8.txt
32# Fixed in r292128.
33
34# Test scenario by kib@
35
36[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37[ -d /usr/src/sys ] || exit 0
38
39. ../default.cfg
40
41rm -f $diskimage
42dir=`dirname $diskimage`
43free=`df -k $dir | tail -1 | awk '{print $4}'`
44[ $((free / 1024)) -lt 50 ] && echo "Not enough disk space." && exit
45
46odir=`pwd`
47cd /tmp
48sed '1,/^EOF/d' < $odir/$0 > md8.c
49rm -f /tmp/md8
50mycc -o md8 -Wall -Wextra -g -O2 md8.c || exit 1
51rm -f md8.c
52
53cd $odir
54trap "rm -f $diskimage" EXIT INT
55dd if=/dev/zero of=$diskimage bs=1m count=50 status=none
56[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
57mdconfig -a -t vnode -f $diskimage -u $mdstart
58
59n=`sysctl -n hw.ncpu`
60n=$((n + 1))
61(cd /usr/src; make -j $n buildkernel > /dev/null 2>&1) &
62sleep 1
63/tmp/md8 /dev/md$mdstart
64kill $!
65wait
66
67mdconfig -d -u $mdstart
68rm -rf /tmp/md8
69exit 0
70EOF
71#include <sys/param.h>
72
73#include <err.h>
74#include <fcntl.h>
75#include <stdio.h>
76#include <stdlib.h>
77#include <unistd.h>
78
79#define LOOPS 2000
80
81void
82test(char *path)
83{
84	int fd;
85	char data[MAXPHYS + 512] __aligned(PAGE_SIZE);
86
87	if ((fd = open(path, O_RDONLY)) == -1)
88		err(1, "open(%s)", path);
89	if (read(fd, data + 512, MAXPHYS) != MAXPHYS)
90		err(1, "read");
91	close(fd);
92
93	if ((fd = open(path, O_WRONLY)) == -1)
94		err(1, "open(%s)", path);
95	if (write(fd, data + 512, MAXPHYS) != MAXPHYS)
96		err(1, "write");
97	close(fd);
98
99	if ((fd = open(path, O_RDONLY)) == -1)
100		err(1, "open(%s)", path);
101	if (read(fd, data + 512, MAXPHYS) != MAXPHYS)
102		err(1, "read");
103	close(fd);
104}
105
106int
107main(int argc, char *argv[])
108{
109	int i;
110	char *path;
111
112	if (argc != 2)
113		errx(1, "Usage: %s <path>", argv[0]);
114
115	path = argv[1];
116
117	for (i = 0; i < LOOPS; i++)
118		test(path);
119
120	return (0);
121}
122