1# $OpenBSD: Makefile,v 1.10 2023/10/12 16:59:24 anton 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# The unmount-nested test uses a disk template to create 15 partitions 41# on a vnd device. All are initialized with a ffs file system. 42# Then they are mounted nestedly in /mnt, see disktemplate for the 43# tree layout. The unmount-nested test uses umount -f to unmount 44# /mnt, without -f it does not work. It is checked that the kernel 45# does the unmount recursively. There must be no dangling mount 46# points. 47 48REGRESS_TARGETS+= run-unmount-nested 49run-unmount-nested: mount-nested 50 ! umount /mnt/regress-mount 51 umount -f /mnt/regress-mount 52 mount 53 [ `mount | grep -c "/dev/$$(<vnd). on /mnt/regress-mount\>"` -eq 0 ] 54 55# Create a 1 GB vnd partition and fill the ffs file system it with 56# cp -r. After 15 seconds clean it with rm -rf. While this is 57# running, unmount with -f. Run fsck -f to see that everything is 58# clean. 59 60REGRESS_TARGETS+= run-unmount-busy 61run-unmount-busy: mount 62 cp -r /usr /mnt/regress-mount & 63 sleep 5 64 sync 65 sleep 10 66 rm -rf /mnt/regress-mount/usr & 67 sleep .1 68 umount -f /mnt/regress-mount 69 fsck -y /dev/r$$(<vnd)a 2>&1 | tee fsck-clean.log 70 fsck -f -y /dev/r$$(<vnd)a 2>&1 | tee fsck-force.log 71 egrep -q 'File system is clean' \ 72 fsck-clean.log 73 ! egrep -q 'yes|FILE SYSTEM WAS MODIFIED|MARKING FILE SYSTEM CLEAN' \ 74 fsck-force.log 75 76run-readonly-busy run-readonly-dangling: 77 # Remounting a file system read-only that has dangling vnodes fails 78 # currently. It is marked as clean but has unreferenced files. 79 @echo DISABLED 80 81# Create a 1 GB vnd partition and fill the ffs file system it with 82# cp -r. After 15 seconds clean it with rm -rf. While this is 83# running, remount read-only with -ur. Unmount the partition and 84# run fsck -f to see that a file system marked as clean is really 85# clean. 86 87REGRESS_TARGETS+= run-readonly-busy 88run-readonly-busy: mount 89 cp -r /usr /mnt/regress-mount & 90 sleep 5 91 sync 92 sleep 10 93 rm -rf /mnt/regress-mount/usr & 94 sleep .1 95 mount -f -ur /mnt/regress-mount 96 # XXX mount -ur should not return before it is done 97 for i in `jot 20`; do \ 98 pgrep -xf 'cp -r /usr' || \ 99 pgrep -xf 'rm -rf /mnt/regress-mount/usr' || \ 100 break; sleep 1; done 101 umount /mnt/regress-mount 102 fsck -y /dev/r$$(<vnd)a 2>&1 | tee fsck-clean.log 103 fsck -f -y /dev/r$$(<vnd)a 2>&1 | tee fsck-force.log 104 ! egrep -q 'File system is clean' fsck-clean.log || \ 105 ! egrep -q 'yes|FILE SYSTEM WAS MODIFIED|MARKING FILE SYSTEM CLEAN' \ 106 fsck-force.log 107 108# Open a file, unlink it, and remount the file system read-only. 109# Then the file system cannot be clean after unmounting it. 110# Check that clean flag is not set and repair it with fsck -y. 111 112REGRESS_TARGETS+= run-readonly-dangling 113run-readonly-dangling: mount 114 touch /mnt/regress-mount/file 115 sleep 73 </mnt/regress-mount/file & 116 sleep .1 117 rm /mnt/regress-mount/file 118 mount -ur /mnt/regress-mount 119 pkill -xf 'sleep 73' 120 sleep .1 121 umount /mnt/regress-mount 122 fsck -y /dev/r$$(<vnd)a 2>&1 | tee fsck-clean.log 123 fsck -f -y /dev/r$$(<vnd)a 2>&1 | tee fsck-force.log 124 ! egrep -q 'File system is clean' fsck-clean.log 125 egrep -q 'yes|FILE SYSTEM WAS MODIFIED|MARKING FILE SYSTEM CLEAN' \ 126 fsck-clean.log fsck-force.log 127 128.include <bsd.regress.mk> 129