xref: /freebsd/tools/test/stress2/misc/symlink4.sh (revision c1d255d3)
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
52bsdlabel -w md$mdstart auto
53newfs $newfs_flags md${mdstart}$part > /dev/null
54mount /dev/md${mdstart}$part $mntpoint
55set +e
56
57cd $mntpoint
58i=`df -ik $mntpoint | tail -1 | awk '{printf "%d\n", ($7 - 500)/2}'`
59/tmp/symlink4 $i
60s=$?
61[ -f symlink4.core -a $s -eq 0 ] &&
62    { ls -l symlink4.core; mv symlink4.core /tmp; s=1; }
63cd $odir
64
65for i in `jot 6`; do
66	mount | grep -q "on $mntpoint " || break
67	umount $mntpoint && break || sleep 10
68done
69[ $i -eq 6 ] && exit 1
70mdconfig -d -u $mdstart
71rm -rf $dir/symlink4
72exit $s
73
74EOF
75#include <sys/types.h>
76#include <sys/mount.h>
77#include <sys/param.h>
78#include <sys/stat.h>
79#include <sys/sysctl.h>
80
81#include <unistd.h>
82#include <err.h>
83#include <errno.h>
84#include <fcntl.h>
85#include <stdio.h>
86#include <stdlib.h>
87#include <string.h>
88
89int
90main(int argc, char **argv)
91{
92	int64_t size;
93	pid_t pid;
94	int i, j;
95	char file[128], link[256];
96
97	if (argc != 2)
98		errx(1, "Usage: %s <links>", argv[0]);
99	size = atol(argv[1]);
100	strcpy(link, "/mnt/not/there/");
101	for (i = 15; i < 200; i++)
102		link[i] = '1';
103	link[++i] = 0;
104
105	pid = getpid();
106	for (j = 0; j < size; j++) {
107		sprintf(file,"p%05d.%05d", pid, j);
108		if (symlink(link, file) == -1) {
109			if (errno != EINTR) {
110				warn("symlink(%s, %s)", link, file);
111				printf("break out at %d, errno %d\n", j,
112				    errno);
113				break;
114			}
115		}
116	}
117
118	for (i = --j; i >= 0; i--) {
119		sprintf(file,"p%05d.%05d", pid, i);
120		if (unlink(file) == -1)
121			err(3, "unlink(%s)", file);
122
123	}
124	return (0);
125}
126