1#!/bin/sh 2 3# 4# Copyright (c) 2017 Dell EMC Isilon 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 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. 15# 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 26# SUCH DAMAGE. 27# 28 29# Test scenario by Mark Johnston <markj@FreeBSD.org> 30# "physwr DL /tmp/graid1_2 /dev/mirror/test" seen. 31# Fixed by r307691. 32 33[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 34 35. ../default.cfg 36 37dir=/tmp 38odir=`pwd` 39cd $dir 40sed '1,/^EOF/d' < $odir/$0 > $dir/graid1_2.c 41mycc -o graid1_2 -Wall -Wextra -O0 -g graid1_2.c || exit 1 42rm -f graid1_2.c 43cd $odir 44 45gmirror load > /dev/null 2>&1 && unload=1 46[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; } 47old=`sysctl -n kern.geom.mirror.debug` 48sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 || 49 sysctl kern.geom.mirror.debug=$old > /dev/null 50 51md1=$mdstart 52md2=$((mdstart + 1)) 53s=0 54size=$((128 * 1024)) 55 56for u in $md1 $md2; do 57 dd if=/dev/zero of=/tmp/graid1_2_di$u bs=$size count=1 status=none 58 [ -c /dev/md$u ] && mdconfig -d -u $u 59 mdconfig -a -t vnode -f /tmp/graid1_2_di$u -u $u 60done 61gmirror label test /dev/md$md1 /dev/md$md2 || exit 1 62[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] && 63 sleep $((`sysctl -n kern.geom.mirror.timeout` + 1)) 64[ -c /dev/mirror/test ] || exit 1 65 66for i in `jot 150`; do /tmp/graid1_2 /dev/mirror/test; done & 67 68sleep 5 69start=`date '+%s'` 70while [ $((`date '+%s'` - start)) -lt 300 ]; do 71 gmirror rebuild test /dev/md$md1 72 sleep 2 73 n=0 74 while ps -lx | grep -v grep | grep graid1_2 | grep -q D; do 75 opid=$pid 76 pid=`pgrep graid1_2` 77 [ -z "$pid" -o "$pid" != "$opid" ] && n=0 78 sleep 1 79 n=$((n + 1)) 80 if [ $n -gt 180 ]; then 81 echo FAIL 82 ps -lx | grep -v grep | grep graid1_2 | grep D 83 exit 1 84 fi 85 done 86done 87kill $! 2>/dev/null 88pkill graid1_2 89wait 90 91while mount | grep $mntpoint | grep -q /mirror/; do 92 umount $mntpoint || sleep 1 93done 94gmirror stop test || s=2 95[ $unload ] && gmirror unload 96 97for u in $md2 $md1; do 98 mdconfig -d -u $u || s=4 99done 100rm -f /tmp/graid1_2 /tmp/graid1_2_di* 101exit $s 102EOF 103/* Write last sector on disk */ 104#include <err.h> 105#include <fcntl.h> 106#include <stdio.h> 107#include <stdlib.h> 108#include <time.h> 109#include <unistd.h> 110 111static char buf[512]; 112 113int 114main(int argc __unused, char *argv[]) 115{ 116 time_t start; 117 int fd; 118 119 if ((fd = open(argv[1], O_RDWR)) == -1) 120 err(1, "open(%s)", argv[1]); 121 start = time(NULL); 122 while (time(NULL) - start < 2) { 123 if (lseek(fd, 254 * sizeof(buf), SEEK_SET) == -1) 124 err(1, "seek"); 125 if (write(fd, buf, sizeof(buf)) != sizeof(buf)) 126 err(1, "write"); 127 } 128 close(fd); 129 130 return (0); 131} 132