xref: /freebsd/tools/test/stress2/misc/symlink4.sh (revision 608c97bff921c8936eb71f4b1a177625cfa60250)
1#!/bin/sh
2
3#
4# Copyright (c) 2018 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# Testing with links longer than 120 characters, which is not stored in the
30# inode but will be placed in its own data fragment.
31
32# "panic: softdep_deallocate_dependencies: dangling deps" seen with SU:
33# https://people.freebsd.org/~pho/stress/log/symlink4.txt
34# Fixed by r327821
35
36[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37
38. ../default.cfg
39
40dir=/tmp
41odir=`pwd`
42cd $dir
43sed '1,/^EOF/d' < $odir/$0 > $dir/symlink4.c
44mycc -o symlink4 -Wall -Wextra -O0 -g symlink4.c || exit 1
45rm -f symlink4.c
46cd $odir
47
48set -e
49mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
50[ -c /dev/md$mdstart ] &&  mdconfig -d -u $mdstart
51mdconfig -a -t swap -s 1g -u $mdstart
52newfs $newfs_flags md$mdstart > /dev/null
53mount /dev/md$mdstart $mntpoint
54set +e
55
56cd $mntpoint
57i=`df -ik $mntpoint | tail -1 | awk '{printf "%d\n", ($7 - 500)/2}'`
58/tmp/symlink4 $i
59s=$?
60[ -f symlink4.core -a $s -eq 0 ] &&
61    { ls -l symlink4.core; mv symlink4.core /tmp; s=1; }
62cd $odir
63
64for i in `jot 6`; do
65	mount | grep -q "on $mntpoint " || break
66	umount $mntpoint && break || sleep 10
67done
68[ $i -eq 6 ] && exit 1
69mdconfig -d -u $mdstart
70rm -rf $dir/symlink4
71exit $s
72
73EOF
74#include <sys/types.h>
75#include <sys/mount.h>
76#include <sys/param.h>
77#include <sys/stat.h>
78#include <sys/sysctl.h>
79
80#include <unistd.h>
81#include <err.h>
82#include <errno.h>
83#include <fcntl.h>
84#include <stdio.h>
85#include <stdlib.h>
86#include <string.h>
87
88int
89main(int argc, char **argv)
90{
91	int64_t size;
92	pid_t pid;
93	int i, j;
94	char file[128], link[256];
95
96	if (argc != 2)
97		errx(1, "Usage: %s <links>", argv[0]);
98	size = atol(argv[1]);
99	strcpy(link, "/mnt/not/there/");
100	for (i = 15; i < 200; i++)
101		link[i] = '1';
102	link[++i] = 0;
103
104	pid = getpid();
105	for (j = 0; j < size; j++) {
106		sprintf(file,"p%05d.%05d", pid, j);
107		if (symlink(link, file) == -1) {
108			if (errno != EINTR) {
109				warn("symlink(%s, %s)", link, file);
110				printf("break out at %d, errno %d\n", j,
111				    errno);
112				break;
113			}
114		}
115	}
116
117	for (i = --j; i >= 0; i--) {
118		sprintf(file,"p%05d.%05d", pid, i);
119		if (unlink(file) == -1)
120			err(3, "unlink(%s)", file);
121
122	}
123	return (0);
124}
125