4 # Copyright (c) 2011 Peter Holm <pho@FreeBSD.org>
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 # Copy of suj20.sh, but with test user as non root.
30 # "panic: handle_disk_write_complete: Unknown type freedep" seen.
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
36 # Scenario by mckusick@
38 # create a bunch of files/directories
40 # remove many (but not all) of those files/directories
41 # create some new files/directories in what remains of those
42 # original files/directories.
43 # create another snapshot
45 # remove many (somewhat different) of those files/directories
46 # create some new files/directories in what remains of those
47 # remaining files/directories.
48 # create a new snapshot
49 # remove oldest snapshot
54 mksnap_ffs $1 $2 2>&1 | grep -v "Resource temporarily unavailable"
55 [ ! -s $2 ] && rm -f $2 || return 0
63 sed '1,/^EOF/d' < $here/$0 > suj21.c
64 mycc -o suj21 -Wall -Wextra -g -O2 suj21.c
67 mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint
68 mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart
70 mdconfig -a -t swap -s 1g -u $mdstart
71 bsdlabel -w md$mdstart auto
72 newfs -j md${mdstart}$part > /dev/null
73 mount /dev/md${mdstart}$part $mntpoint
77 su $testuser -c '/tmp/suj21'
78 snap $mntpoint $mntpoint/.snap/snap1
79 su $testuser -c '/tmp/suj21 prune'
80 snap $mntpoint $mntpoint/.snap/snap2
81 su $testuser -c '/tmp/suj21'
83 su $testuser -c '/tmp/suj21 prune'
84 su $testuser -c '/tmp/suj21'
85 snap $mntpoint $mntpoint/.snap/snap$((i + 2))
86 sn=`ls -tU $mntpoint/.snap | tail -1`
87 rm -f $mntpoint/.snap/$sn
91 while mount | grep -q $mntpoint; do
92 umount $mntpoint || sleep 1
94 mdconfig -d -u $mdstart
98 #include <sys/types.h>
104 #include <sys/stat.h>
107 static char buf[4096];
117 for (d = 0; d < ND; d++) {
118 snprintf(name, sizeof(name), "d%03d", d);
119 if (mkdir(name, 00700) == -1 && errno != EEXIST)
120 err(1, "mkdir(%s)", name);
121 if (chdir(name) == -1)
122 err(1, "chdir(%s)", name);
123 for (f = 0; f < NF; f++) {
124 if (arc4random() % 100 < 33)
126 snprintf(name, sizeof(name), "f%03d", f);
127 if ((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1)
128 err(1, "open(%s)", name);
129 n = arc4random() % 10;
130 for (i = 0; i < n; i++) {
131 if (write(fd, buf, sizeof(buf)) != sizeof(buf))
136 if (chdir("..") == -1)
137 err(1, "chdir(%s)", "..");
147 for (d = 0; d < ND; d++) {
148 snprintf(name, sizeof(name), "d%03d", d);
149 if (chdir(name) == -1)
150 err(1, "chdir(%s)", name);
151 for (f = 0; f < NF; f++) {
152 if (arc4random() % 100 < 33)
154 snprintf(name, sizeof(name), "f%03d", f);
155 if (unlink(name) == -1 && errno != ENOENT)
156 err(1, "unlink(%s)", name);
158 if (chdir("..") == -1)
159 err(1, "chdir(%s)", "..");
161 for (d = 0; d < ND; d++) {
162 if (arc4random() % 100 > 10)
164 snprintf(name, sizeof(name), "rm -rf d%03d", d);
170 main(int argc, char **argv __unused)