2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
7 # Test constant inode numbers
9 # This simple test demonstrates a known issue with overlayfs:
10 # - stat file A shows inode number X
11 # - modify A to trigger copy up
12 # - stat file A shows inode number Y != X
14 # Also test if d_ino of readdir entries changes after copy up
15 # and if inode numbers persist after rename, drop caches and
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
24 status=1 # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
37 # real QA test starts here
41 _require_test_program "af_unix"
42 _require_test_program "t_dir_type"
43 # Require redirect_dir for renaming a merge directory
44 _require_scratch_feature redirect_dir
48 _scratch_mkfs >>$seqres.full 2>&1
50 # Create our test files.
51 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
55 ln -s $lowerdir/file $lowerdir/symlink
56 mknod $lowerdir/chrdev c 1 1
57 mknod $lowerdir/blkdev b 1 1
58 mknod $lowerdir/fifo p
59 $here/src/af_unix $lowerdir/socket
61 FILES="dir file symlink chrdev blkdev fifo socket"
63 # Record inode numbers in format <ino> <basename>
64 function record_inode_numbers()
72 while read ino file; do
73 echo $ino `basename $file` >> $outfile
77 # Check inode numbers match recorder inode numbers
78 function check_inode_numbers()
84 record_inode_numbers $dir $after
86 # Test constant stat(2) st_ino -
87 # Compare before..after - expect silence
88 # We use diff -u so out.bad will tell us which stage failed
89 diff -u $before $after
91 # Test constant readdir(3)/getdents(2) d_ino -
92 # Expect to find file by inode number
93 cat $before | while read ino f; do
94 $here/src/t_dir_type $dir $ino | grep -q $f || \
95 echo "$f not found by ino $ino (from $before)"
99 # Enable redirect_dir for renaming a merge directory
100 _scratch_mount "-o redirect_dir=on"
103 testdir=$SCRATCH_MNT/test
106 # Record inode numbers before copy up
107 record_inode_numbers $SCRATCH_MNT $tmp.before
110 # chown -h modifies all those file types
111 chown -h 100 $SCRATCH_MNT/$f
114 # Compare inode numbers before/after copy up
115 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
118 # move to another dir
119 mv $SCRATCH_MNT/$f $testdir/
122 echo 3 > /proc/sys/vm/drop_caches
124 # Compare inode numbers before/after rename and drop caches
125 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
127 # Verify that the inode numbers survive a mount cycle
128 _scratch_cycle_mount "redirect_dir=on"
130 # Compare inode numbers before/after mount cycle
131 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
133 echo "Silence is golden"