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
40 _require_test_program "af_unix"
41 _require_test_program "t_dir_type"
42 # Require redirect_dir for renaming a merge directory
43 _require_scratch_feature redirect_dir
47 _scratch_mkfs >>$seqres.full 2>&1
49 # Create our test files.
50 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
54 ln -s $lowerdir/file $lowerdir/symlink
55 mknod $lowerdir/chrdev c 1 1
56 mknod $lowerdir/blkdev b 1 1
57 mknod $lowerdir/fifo p
58 $here/src/af_unix $lowerdir/socket
60 FILES="dir file symlink chrdev blkdev fifo socket"
62 # Record inode numbers in format <ino> <basename>
63 function record_inode_numbers()
71 while read ino file; do
72 echo $ino `basename $file` >> $outfile
76 # Check inode numbers match recorder inode numbers
77 function check_inode_numbers()
83 record_inode_numbers $dir $after
85 # Test constant stat(2) st_ino -
86 # Compare before..after - expect silence
87 # We use diff -u so out.bad will tell us which stage failed
88 diff -u $before $after
90 # Test constant readdir(3)/getdents(2) d_ino -
91 # Expect to find file by inode number
92 cat $before | while read ino f; do
93 $here/src/t_dir_type $dir $ino | grep -q $f || \
94 echo "$f not found by ino $ino (from $before)"
98 # Enable redirect_dir for renaming a merge directory
99 _scratch_mount "-o redirect_dir=on"
102 testdir=$SCRATCH_MNT/test
105 # Record inode numbers before copy up
106 record_inode_numbers $SCRATCH_MNT $tmp.before
109 # chown -h modifies all those file types
110 chown -h 100 $SCRATCH_MNT/$f
113 # Compare inode numbers before/after copy up
114 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
117 # move to another dir
118 mv $SCRATCH_MNT/$f $testdir/
121 echo 3 > /proc/sys/vm/drop_caches
123 # Compare inode numbers before/after rename and drop caches
124 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
126 # Verify that the inode numbers survive a mount cycle
127 _scratch_cycle_mount "redirect_dir=on"
129 # Compare inode numbers before/after mount cycle
130 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
132 echo "Silence is golden"