summaryrefslogtreecommitdiff
path: root/tests/overlay/017
blob: 0bb248c25fcb43806c714842f8a8c7deedb21117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2016 CTERA Networks. All Rights Reserved.
#
# FSQA Test No. 017
#
# Test constant inode numbers
#
# This simple test demonstrates an issue with overlayfs on kernel < v4.14:
# - stat file A shows inode number X
# - modify A to trigger copy up
# - stat file A shows inode number Y != X
#
# Also test if d_ino of readdir entries changes after copy up
# and if inode numbers persist after rename, drop caches and
# mount cycle.
#
. ./common/preamble
_begin_fstest auto quick copyup redirect

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs overlay
_fixed_in_kernel_version "v4.14"

_require_scratch
_require_test_program "af_unix"
_require_test_program "t_dir_type"
# Require redirect_dir for renaming a merge directory
_require_scratch_feature redirect_dir

_scratch_mkfs >>$seqres.full 2>&1

# Create our test files.
lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
mkdir -p $lowerdir
mkdir $lowerdir/dir
touch $lowerdir/file
ln -s $lowerdir/file $lowerdir/symlink
mknod $lowerdir/chrdev c 1 1
mknod $lowerdir/blkdev b 1 1
mknod $lowerdir/fifo p
$here/src/af_unix $lowerdir/socket

FILES="dir file symlink chrdev blkdev fifo socket"

# Record inode numbers in format <ino> <basename>
function record_inode_numbers()
{
	dir=$1
	outfile=$2

	for f in $FILES; do
		ls -id $dir/$f
	done | \
	while read ino file; do
		echo $ino `basename $file` >> $outfile
	done
}

# Check inode numbers match recorder inode numbers
function check_inode_numbers()
{
	dir=$1
	before=$2
	after=$3

	record_inode_numbers $dir $after

	# Test constant stat(2) st_ino -
	#   Compare before..after - expect silence
	# We use diff -u so out.bad will tell us which stage failed
	diff -u $before $after

	# Test constant readdir(3)/getdents(2) d_ino -
	#   Expect to find file by inode number
	cat $before | while read ino f; do
		$here/src/t_dir_type $dir $ino | grep -q $f || \
			echo "$f not found by ino $ino (from $before)"
	done
}

# Enable redirect_dir for renaming a merge directory
_scratch_mount "-o redirect_dir=on"

rm -f $tmp.*
testdir=$SCRATCH_MNT/test
mkdir -p $testdir

# Record inode numbers before copy up
record_inode_numbers $SCRATCH_MNT $tmp.before

for f in $FILES; do
	# chown -h modifies all those file types
	chown -h 100 $SCRATCH_MNT/$f
done

# Compare inode numbers before/after copy up
check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup

for f in $FILES; do
	# move to another dir
	mv $SCRATCH_MNT/$f $testdir/
done

echo 3 > /proc/sys/vm/drop_caches

# Compare inode numbers before/after rename and drop caches
check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move

# Verify that the inode numbers survive a mount cycle
_scratch_cycle_mount "redirect_dir=on"

# Compare inode numbers before/after mount cycle
check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle

echo "Silence is golden"
status=0
exit