xref: /freebsd/tools/test/stress2/misc/nfs_halfpage.sh (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2017 Konstantin Belousov <kib@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[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
31. ../default.cfg
32
33# Regression test for:
34# Mark pages after EOF as clean after pageout.
35# https://reviews.freebsd.org/D11697
36# Committed as r321580 + r321581.
37
38dir=/tmp
39odir=`pwd`
40cd $dir
41sed '1,/^EOF/d' < $odir/$0 > $dir/nfs_halfpage.c
42mycc -o nfs_halfpage -Wall -Wextra -O0 -g nfs_halfpage.c || exit 1
43rm -f nfs_halfpage.c
44cd $odir
45
46[ -z "$nfs_export" ] && exit 0
47ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 ||
48    exit 0
49
50mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint
51mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint
52
53file=$mntpoint/nfs_halfpage.file
54/tmp/nfs_halfpage $file
55
56echo "Reboot now to trigger syncing disks loop."
57sleep 60
58
59rm $file
60for i in `jot 6`; do
61	mount | grep -q "on $mntpoint " || break
62	umount $mntpoint && break || sleep 10
63done
64[ $i -eq 6 ] && s=1 || s=0
65rm -f /tmp/nfs_halfpage
66
67exit $s
68EOF
69/* $Id: nfs_halfpage.c,v 1.2 2017/07/23 09:36:23 kostik Exp kostik $ */
70
71#include <sys/fcntl.h>
72#include <sys/mman.h>
73#include <err.h>
74#include <unistd.h>
75
76int
77main(int argc __unused, char *argv[])
78{
79	char *m;
80	int error, fd, pgsz, sz;
81
82	pgsz = getpagesize();
83	fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666);
84	if (fd == -1)
85		err(1, "open %s", argv[1]);
86	sz = pgsz / 4;
87	error = lseek(fd, sz, SEEK_SET);
88	if (error == -1)
89		err(1, "lseek");
90	error = write(fd, "a", 1);
91	if (error == -1)
92		err(1, "write");
93	else if (error != 1)
94		errx(1, "short write");
95	m = mmap(NULL, sz + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
96	if (m == MAP_FAILED)
97		err(1, "mmap");
98	m[0] = 'x';
99}
100