xref: /openbsd/regress/sys/kern/mount/Makefile (revision 17284f7e)
1# $OpenBSD: Makefile,v 1.11 2024/11/06 18:42:54 bluhm Exp $
2
3# This regress test uses a vnd device to run mount and unmount.
4# All tests have to be run as root.
5
6CLEANFILES=	diskimage vnd *.log
7
8.PHONY: disk mount unconfig clean
9
10disk: unconfig
11	dd if=/dev/null of=diskimage bs=1m seek=1100
12	vnconfig diskimage >vnd
13	disklabel -wA -T ${.CURDIR}/disktemplate $$(<vnd)
14	disklabel $$(<vnd)
15	disklabel $$(<vnd) | grep -q '16 partitions:'
16	[ `disklabel $$(<vnd) | grep -c '\<4.2BSD\>'` -eq 15 ]
17
18mount: disk
19	newfs $$(<vnd)a
20	mkdir -p /mnt/regress-mount
21	mount /dev/$$(<vnd)a /mnt/regress-mount
22
23mount-nested: mount
24.for p in b d e f g h i j k l m n o p
25	newfs -O 1 $$(<vnd)${p}
26.endfor
27	mkdir /mnt/regress-mount/b
28	mount /dev/$$(<vnd)b /mnt/regress-mount/b
29	f=/mnt/regress-mount; for p in d e f g h i j k l m n o p;\
30	    do f=$$f/$$p; mkdir $$f; mount /dev/$$(<vnd)$$p $$f; done
31	mount
32	[ `mount | grep -c "/dev/$$(<vnd). on /mnt/regress-mount\>"` -eq 15 ]
33
34REGRESS_CLEANUP =	unconfig
35unconfig:
36	-umount -f /dev/$$(<vnd)a 2>/dev/null || true
37	-rmdir /mnt/regress-mount 2>/dev/null || true
38	-vnconfig -u $$(<vnd) 2>/dev/null || true
39
40# disk image takes up too much space in /usr/obj
41REGRESS_CLEANUP +=	remove-diskimage
42remove-diskimage:
43	rm -f diskimage
44
45# The unmount-nested test uses a disk template to create 15 partitions
46# on a vnd device.  All are initialized with a ffs file system.
47# Then they are mounted nestedly in /mnt, see disktemplate for the
48# tree layout.  The unmount-nested test uses umount -f to unmount
49# /mnt, without -f it does not work.  It is checked that the kernel
50# does the unmount recursively.  There must be no dangling mount
51# points.
52
53REGRESS_TARGETS+=	run-unmount-nested
54run-unmount-nested: mount-nested
55	! umount /mnt/regress-mount
56	umount -f /mnt/regress-mount
57	mount
58	[ `mount | grep -c "/dev/$$(<vnd). on /mnt/regress-mount\>"` -eq 0 ]
59
60# Create a 1 GB vnd partition and fill the ffs file system it with
61# cp -r.  After 15 seconds clean it with rm -rf.  While this is
62# running, unmount with -f.  Run fsck -f to see that everything is
63# clean.
64
65REGRESS_TARGETS+=	run-unmount-busy
66run-unmount-busy: mount
67	cp -r /usr /mnt/regress-mount &
68	sleep 5
69	sync
70	sleep 10
71	rm -rf /mnt/regress-mount/usr &
72	sleep .1
73	umount -f /mnt/regress-mount
74	fsck -y /dev/r$$(<vnd)a 2>&1 | tee fsck-clean.log
75	fsck -f -y /dev/r$$(<vnd)a 2>&1 | tee fsck-force.log
76	egrep -q 'File system is clean' \
77	    fsck-clean.log
78	! egrep -q 'yes|FILE SYSTEM WAS MODIFIED|MARKING FILE SYSTEM CLEAN' \
79	    fsck-force.log
80
81run-readonly-busy run-readonly-dangling:
82	# Remounting a file system read-only that has dangling vnodes fails
83	# currently.  It is marked as clean but has unreferenced files.
84	@echo DISABLED
85
86# Create a 1 GB vnd partition and fill the ffs file system it with
87# cp -r.  After 15 seconds clean it with rm -rf.  While this is
88# running, remount read-only with -ur.  Unmount the partition and
89# run fsck -f to see that a file system marked as clean is really
90# clean.
91
92REGRESS_TARGETS+=	run-readonly-busy
93run-readonly-busy: mount
94	cp -r /usr /mnt/regress-mount &
95	sleep 5
96	sync
97	sleep 10
98	rm -rf /mnt/regress-mount/usr &
99	sleep .1
100	mount -f -ur /mnt/regress-mount
101	# XXX mount -ur should not return before it is done
102	for i in `jot 20`; do \
103	    pgrep -xf 'cp -r /usr' || \
104	    pgrep -xf 'rm -rf /mnt/regress-mount/usr' || \
105	    break; sleep 1; done
106	umount /mnt/regress-mount
107	fsck -y /dev/r$$(<vnd)a 2>&1 | tee fsck-clean.log
108	fsck -f -y /dev/r$$(<vnd)a 2>&1 | tee fsck-force.log
109	! egrep -q 'File system is clean' fsck-clean.log || \
110	! egrep -q 'yes|FILE SYSTEM WAS MODIFIED|MARKING FILE SYSTEM CLEAN' \
111	    fsck-force.log
112
113# Open a file, unlink it, and remount the file system read-only.
114# Then the file system cannot be clean after unmounting it.
115# Check that clean flag is not set and repair it with fsck -y.
116
117REGRESS_TARGETS+=	run-readonly-dangling
118run-readonly-dangling: mount
119	touch /mnt/regress-mount/file
120	sleep 73 </mnt/regress-mount/file &
121	sleep .1
122	rm /mnt/regress-mount/file
123	mount -ur /mnt/regress-mount
124	pkill -xf 'sleep 73'
125	sleep .1
126	umount /mnt/regress-mount
127	fsck -y /dev/r$$(<vnd)a 2>&1 | tee fsck-clean.log
128	fsck -f -y /dev/r$$(<vnd)a 2>&1 | tee fsck-force.log
129	! egrep -q 'File system is clean' fsck-clean.log
130	egrep -q 'yes|FILE SYSTEM WAS MODIFIED|MARKING FILE SYSTEM CLEAN' \
131	    fsck-clean.log fsck-force.log
132
133.include <bsd.regress.mk>
134