xref: /freebsd/tools/test/stress2/misc/zfs16.sh (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1#!/bin/sh
2
3# No problems seen
4
5[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
6kldstat -v | grep -q zfs.ko  || { kldload zfs.ko; loaded=1; } ||
7    exit 0
8
9. ../default.cfg
10
11here=`pwd`
12cd /tmp
13sed '1,/^EOF/d' < $here/datamove.sh > zfs16.c
14mycc -o zfs16 -Wall -O0 -g zfs16.c || exit 1
15rm -f zfs16.c
16
17mp1=/stress2_tank/test
18u1=$mdstart
19u2=$((u1 + 1))
20
21set -eu
22mdconfig -l | grep -q md$u1 && mdconfig -d -u $u1
23mdconfig -l | grep -q md$u2 && mdconfig -d -u $u2
24
25mdconfig -s 2g -u $u1
26mdconfig -s 2g -u $u2
27
28zpool list | egrep -q "^stress2_tank" && zpool destroy stress2_tank
29[ -d /stress2_tank ] && rm -rf /stress2_tank
30zpool create stress2_tank md$u1 md$u2
31zfs create stress2_tank/test
32set +e
33
34(cd $here/../testcases/swap; ./swap -t 2m -i 20 -l 100 -h > /dev/null) &
35sleep 2
36cd $mp1
37while pgrep -q swap; do
38	/tmp/zfs16; s=$?
39	rm -f /stress2_tank/test/*
40done
41cd $here
42while pkill swap; do sleep 1; done
43wait
44
45zfs umount stress2_tank/test
46zfs destroy -r stress2_tank
47zpool destroy stress2_tank
48mdconfig -d -u $u1
49mdconfig -d -u $u2
50rm -f /tmp/zfs16
51set +u
52[ $loaded ] && kldunload zfs.ko
53exit $s
54EOF
55#include <sys/types.h>
56#include <err.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <unistd.h>
60#include <fcntl.h>
61#include <sys/mman.h>
62#include <sys/param.h>
63#include <string.h>
64#include <unistd.h>
65#include <errno.h>
66
67#define SIZ  (500UL * 1024 * 1024)
68
69int
70main(int argc __unused, char *argv[])
71{
72	off_t hole;
73	size_t len;
74	int fd;
75	char *p, *path;
76
77	len = SIZ;
78
79	path = argv[1];
80	if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1)
81		err(1,"open()");
82	if (ftruncate(fd, len) == -1)
83		err(1, "ftruncate");
84	if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) ==
85			MAP_FAILED) {
86		if (errno == ENOMEM)
87			return (1);
88		err(1, "mmap(1)");
89	}
90	p[1 * 1024] = 1;
91	p[2 * 1024] = 1;
92	p[4 * 1024] = 1;
93
94	if (msync(p, len, MS_SYNC | MS_INVALIDATE) == -1)
95		err(1, "msync()");
96
97	if ((hole = lseek(fd, 0, SEEK_HOLE)) == -1)
98		err(1, "lseek(SEEK_HOLE)");
99	if (hole != SIZ)
100		printf("--> hole = %jd, file size=%jd\n",
101		    (intmax_t)hole, (intmax_t)SIZ);
102	close(fd);
103
104	return (hole == SIZ ? 0 : 1);
105}
106