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# Variation of nfs_halfpage.sh with a 2GB file. 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 56ls -l $file 57echo "Reboot now to trigger syncing disks loop." 58sleep 60 59 60rm $file 61for i in `jot 6`; do 62 mount | grep -q "on $mntpoint " || break 63 umount $mntpoint && break || sleep 10 64done 65[ $i -eq 6 ] && exit 1 66rm -f /tmp/nfs_halfpage 67 68exit 0 69EOF 70/* $Id: nfs_halfpage.c,v 1.2 2017/07/23 09:36:23 kostik Exp kostik $ */ 71 72#include <sys/types.h> 73#include <sys/fcntl.h> 74#include <sys/mman.h> 75#include <err.h> 76#include <unistd.h> 77 78int 79main(int argc __unused, char *argv[]) 80{ 81 off_t sz; 82 char *m; 83 int error, fd, pgsz; 84 85 pgsz = getpagesize(); 86 fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666); 87 if (fd == -1) 88 err(1, "open %s", argv[1]); 89 sz = pgsz / 4; 90 sz += 2LL * 1024 * 1024 * 1024; 91 error = lseek(fd, sz, SEEK_SET); 92 if (error == -1) 93 err(1, "lseek"); 94 error = write(fd, "a", 1); 95 if (error == -1) 96 err(1, "write"); 97 else if (error != 1) 98 errx(1, "short write"); 99 m = mmap(NULL, sz + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 100 if (m == MAP_FAILED) 101 err(1, "mmap"); 102 m[sz - 1] = 'x'; 103} 104