4 # Copyright (c) 2017 Dell EMC Isilon
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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
29 # Test nfsv4 delegations. Scenario suggestion by kib.
30 # "(nfsdelegation), uid 0, was killed: text file modification" seen.
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37 [ -z "$nfs_export" ] && exit 0
38 ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 ||
43 sed '1,/^EOF/d' < $here/$0 > nfsdelegation.c
44 mycc -o nfsdelegation -Wall -Wextra -O0 nfsdelegation.c || exit 1
47 [ `sysctl -n sysctl vfs.timestamp_precision` -ne 3 ] &&
48 echo "vfs.timestamp_precision must be set to 3"
49 [ "`sysctl -ni vfs.nfsd.issue_delegations`" != "1" ] &&
50 { echo "vfs.nfsd.issue_delegations is not enabled"; exit 0; }
51 pgrep -q nfscbd || { echo "nfscbd is not running"; exit 0; }
53 mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint
55 opt="$opt -o nolockd -o nfsv4"
56 mount $opt $nfs_export $mntpoint || exit 1
59 wdir=$mntpoint/nfsdelegation.`jot -rc 8 a z | tr -d '\n'`/nfsdelegation
60 mkdir -p $wdir || exit 1
64 (cd $wdir; /tmp/nfsdelegation) &
65 while kill -0 $! 2>/dev/null; do
66 r=`nfsstat -ec | grep -A1 Delegs | tail -1 | awk '{print $5}'`
67 [ $r -gt $delegs ] && { delegs=$r; break; }
70 [ $delegs -eq 0 ] && { echo "No delegations detected"; s=2; }
74 while mount | grep "$mntpoint " | grep -q nfs; do
77 tail -3 /var/log/messages | grep -m1 nfsdelegation: && s=2
78 rm -f /tmp/nfsdelegation
81 #include <sys/param.h>
95 #define INPUTFILE "/bin/sleep"
98 static volatile u_int *share;
107 char *cmdline[3], *dst, file[128], help[80];
112 for (i = 0; i < LOOPS; i++) {
113 sprintf(file,"nfsdelegation.p%05d.%05d", pid, i);
116 snprintf(help, sizeof(help), "cp %s %s; chmod 777 %s", INPUTFILE, file, file);
119 if ((epid = fork()) == 0) {
121 while (share[idx] == 0)
123 if (execve(cmdline[0], cmdline, NULL) == -1)
127 if ((fdout = open(file, O_RDWR)) < 0)
128 err(1, "open(%s)", file);
129 if (fstat(fdout, &statbuf) < 0)
130 err(1, "fstat error");
132 if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE |
133 MAP_PRIVATE, MAP_SHARED, fdout, 0)) == (caddr_t) - 1)
134 err(1, "mmap error for output");
136 dst[statbuf.st_size] = 1;
139 if (munmap(dst, statbuf.st_size) == -1)
142 if (waitpid(epid, NULL, 0) != epid)
143 err(1, "waitpid(%d)", epid);
156 if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE,
157 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
159 for (i = 0; i < PARALLEL; i++) {
164 for (i = 0; i < PARALLEL; i++) {