4 # Copyright (c) 2014 EMC Corp.
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 # The issue makes it possible for applications to get wrong EINTR
30 # or ERESTART (the later is not directly visible) when doing write
31 # to the file on suspended UFS volume. I.e. the thread is sleeping
32 # when fs is suspended, and process is signaled.
34 # Test scenario mostly by kib.
38 # https://people.freebsd.org/~pho/stress/log/pcatch.txt
40 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
41 [ -z "$DEBUG" ] && exit 0 # Waiting for fix
47 sed '1,/^EOF/d' < $here/$0 > pcatch.c
48 mycc -o pcatch -Wall -Wextra -O0 -g pcatch.c || exit 1
52 mount | grep -q "$mntpoint" && umount $mntpoint
53 mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart
54 mdconfig -a -t swap -s 1g -u $mdstart
55 bsdlabel -w md$mdstart auto
56 newfs $newfs_flags md${mdstart}$part > /dev/null
58 mount /dev/md${mdstart}$part $mntpoint
61 while [ $((`date '+%s'` - start)) -lt 120 ]; do
65 while mount | grep -q "on $mntpoint "; do
66 umount $mntpoint || sleep 1
68 mdconfig -d -u $mdstart
72 #include <sys/types.h>
73 #include <sys/ioctl.h>
74 #include <sys/mount.h>
77 #include <ufs/ffs/fs.h>
89 hand_sigaction(int signo __unused, siginfo_t *si __unused, void *c __unused)
100 if ((error = statfs(path, &s)) != 0)
101 err(1, "statfs %s", path);
102 fd = open("/dev/ufssuspend", O_RDWR);
103 if ((error = ioctl(fd, UFSSUSPEND, &s.f_fsid)) != 0)
104 err(1, "UFSSUSPEND");
106 if ((error = ioctl(fd, UFSRESUME, &s.f_fsid)) != 0)
118 char buf[80], file[80];
120 memset(&sa, 0, sizeof(sa));
121 sa.sa_sigaction = hand_sigaction;
122 if (sigaction(SIGUSR1, &sa, NULL) == -1)
125 snprintf(file, sizeof(file), "%s/file", mp);
126 if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1)
127 err(1, "open(%s). %s:%d", file, __FILE__, __LINE__);
131 if ((pid = fork()) == 0) {
132 if (write(fd, buf, sizeof(buf)) == -1)
137 if (kill(pid, SIGUSR1) == -1)
145 main(int argc, char *argv[])
149 errx(1, "Usage: %s <UFS mount point>", argv[0]);