4 # Copyright (c) 2016 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 # Variation of the datamove2.sh, using NULLFS
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
38 sed '1,/^EOF/d' < $here/$0 > datamove5.c
39 mycc -o datamove5 -Wall -Wextra -O2 -g datamove5.c
44 [ -d $mp2 ] || mkdir $mp2
46 mount | grep -wq $mp2 && umount $mp2
47 mount | grep -wq $mp1 && umount $mp1
48 mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart
49 mdconfig -a -t swap -s 2g -u $mdstart || exit 1
50 bsdlabel -w md$mdstart auto
51 newfs $newfs_flags md${mdstart}$part > /dev/null
52 mount /dev/md${mdstart}$part $mp1
54 mount -t nullfs $opt $mp1 $mp2
58 su $testuser -c "cd $mp2; /tmp/datamove5"
61 while mount | grep -wq $mp2; do
62 umount $mp2 || sleep 1
64 while mount | grep $mp1 | grep -q /dev/md; do
65 umount $mp1 || sleep 1
67 mdconfig -d -u $mdstart
73 * Copyright (c) 2006, Stephan Uphoff <ups@freebsd.org>
74 * All rights reserved.
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
79 * 1. Redistributions of source code must retain the above copyright
80 * notice unmodified, this list of conditions, and the following
82 * 2. Redistributions in binary form must reproduce the above copyright
83 * notice, this list of conditions and the following disclaimer in the
84 * documentation and/or other materials provided with the distribution.
86 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
87 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
88 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
89 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
90 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
91 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
92 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
93 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
94 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
95 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 #include <sys/mman.h>
103 #include <sys/stat.h>
104 #include <sys/types.h>
105 #include <sys/wait.h>
108 int prepareFile(char *filename, int *fdp);
109 int mapBuffer (char **bufferp, int fd1, int fd2);
110 int startIO (int fd, char *buffer);
114 #define FILESIZE (32*1024)
115 char wbuffer [FILESIZE];
117 /* Create a FILESIZE sized file - then remove file data from the cache */
119 prepareFile(char *filename, int *fdp)
126 fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
131 len = write(fd, wbuffer, FILESIZE);
133 perror("Write failed");
138 perror("fsync failed");
141 addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
142 if (addr == MAP_FAILED) {
143 perror("Mmap failed");
146 status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC);
148 perror("Msync failed");
151 if (munmap(addr, FILESIZE) == -1) {
152 perror("munmap failed");
160 /* mmap a 2 page buffer - first page is from fd1, second page from fd2 */
162 mapBuffer(char **bufferp, int fd1, int fd2)
167 addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0);
168 if (addr == MAP_FAILED) {
169 perror("Mmap failed");
173 addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED |
176 if (addr == MAP_FAILED) {
177 perror("Mmap2 failed");
185 unmapBuffer(char *bufferp)
187 if (munmap(bufferp, pagesize * 2) == -1)
188 err(1, "unmap 1. buffer");
190 The following unmaps something random, which could trigger:
191 Program received signal SIGSEGV, Segmentation fault.
192 free (cp=0x28070000) at /usr/src/libexec/rtld-elf/malloc.c:311
196 if (munmap(bufferp + pagesize * 2, pagesize * 2) == -1)
197 err(1, "unmap 2. buffer");
202 startIO(int fd, char *buffer)
206 len = write(fd, buffer, 2 * pagesize);
208 perror("write failed");
218 int fdA, fdB, fdDelayA, fdDelayB;
221 char *bufferA, *bufferB;
224 pagesize = getpagesize();
226 for (i = 0; i < 1000; i++) {
227 if ((prepareFile("A", &fdA))
228 || (prepareFile("B", &fdB))
229 || (prepareFile("DelayA", &fdDelayA))
230 || (prepareFile("DelayB", &fdDelayB))
231 || (mapBuffer(&bufferA, fdDelayA, fdB))
232 || (mapBuffer(&bufferB, fdDelayB, fdA)))
238 status = startIO(fdA, bufferA);
245 status = startIO(fdB, bufferB);
246 if (wait(&status) == -1)
253 unmapBuffer(bufferA);
254 unmapBuffer(bufferB);