1#!/bin/sh 2 3# Regression test for: 4# bf13db086b84 - main - Mostly revert a5970a529c2d95271: Make files opened 5# with O_PATH to not block non-forced unmount 6 7# Based on a scenario by: ambrisko 8 9[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 10 11. ../default.cfg 12 13here=`pwd` 14mp1=$mntpoint 15mp2=${mntpoint}$mdstart 16 17set -e 18mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint 19mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 20mdconfig -a -t swap -s 1g -u $mdstart || exit 1 21newfs $newfs_flags md$mdstart > /dev/null 22mount /dev/md$mdstart $mntpoint 23chmod 777 $mntpoint 24 25mkdir -p $mp2 26mount_nullfs -o nocache $mp1 $mp2 27set +e 28cat > /tmp/nullfs29.c <<EOF 29#include <sys/stat.h> 30#include <err.h> 31#include <errno.h> 32#include <fcntl.h> 33#include <stdio.h> 34#include <stdlib.h> 35#include <unistd.h> 36 37int 38main(void) { 39 int new_dir, new_file, ret; 40 struct stat sb; 41 char *dir = "test2"; 42 char *path= "test2/what2"; 43 44 if (mkdir(dir, 0755) == -1) 45 err(1, "mkdir(test2)"); 46 new_dir = openat(AT_FDCWD, dir, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_PATH, 0700); 47 if (new_dir == -1) 48 err(1, "openat(%s)", dir); 49 50 ret = fstatat(new_dir, "what2", &sb, AT_SYMLINK_NOFOLLOW); 51 if (ret == 0) 52 errx(1, "Expected fstatat() to fail"); 53 if (ret == -1 && errno != ENOENT) 54 err(1, "fstatat(%s)", dir); 55 56 close(new_dir); 57 new_file = openat(AT_FDCWD, path, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0644); 58 if (new_file== -1) 59 err(1, "openat(%s)", path); 60} 61 62EOF 63mycc -o /tmp/nullfs29 -Wall -Wextra -O2 /tmp/nullfs29.c || exit 1 64cd $mp2 65/tmp/nullfs29; s=$? 66cd $here 67umount $mp2 68 69n=0 70while mount | grep $mp1 | grep -q /dev/md; do 71 umount $mp1 || sleep 1 72 n=$((n + 1)) 73 [ $n -gt 30 ] && { echo FAIL; s=2; } 74done 75mdconfig -d -u $mdstart 76rm -f /tmp/nullfs29.c 77exit $s 78