2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 IBM Corporation. All Rights Reserved.
7 # Test constant inode numbers on non-samefs setup
8 # This is a variant of overlay/017 to test constant st_ino numbers for
11 # This simple test demonstrates a known issue with overlayfs:
12 # - stat file A shows inode number X
13 # - modify A to trigger copy up
14 # - stat file A shows inode number Y != X
16 # Also test if d_ino of readdir entries changes after copy up
17 # and if inode numbers persist after rename, drop caches and
21 _begin_fstest auto quick copyup nonsamefs
23 # Import common functions.
26 # real QA test starts here
28 # Use non-default scratch underlying overlay dirs, we need to check
29 # them explicity after test.
30 _require_scratch_nocheck
32 _require_test_program "af_unix"
33 _require_test_program "t_dir_type"
34 # Require redirect_dir for renaming a merge directory
35 _require_scratch_feature redirect_dir
37 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
41 # Create our test files.
44 ln -s $lowerdir/file $lowerdir/symlink
45 mknod $lowerdir/chrdev c 1 1
46 mknod $lowerdir/blkdev b 1 1
47 mknod $lowerdir/fifo p
48 $here/src/af_unix $lowerdir/socket
50 _scratch_mkfs >>$seqres.full 2>&1
52 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
53 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
55 # Enable redirect_dir for renaming a merge directory.
56 # Enabling xino in this test requires that base filesystem inode numbers will
57 # not use bit 63 in inode number of the test files, because bit 63 is used by
58 # overlayfs to indicate the layer. Let's just assume that this is true for all
59 # tested filesystems and if we are wrong, the test may fail.
60 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on || \
61 _notrun "cannot mount overlay with xino=on option"
62 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
63 _notrun "cannot enable xino feature"
65 FILES="dir file symlink chrdev blkdev fifo socket"
67 # Record inode numbers in format <ino> <basename>
68 function record_inode_numbers()
76 while read ino file; do
77 echo $ino `basename $file` >> $outfile
81 # Check inode numbers match recorder inode numbers
82 function check_inode_numbers()
88 record_inode_numbers $dir $after
90 # Test constant stat(2) st_ino -
91 # Compare before..after - expect silence
92 # We use diff -u so out.bad will tell us which stage failed
93 diff -u $before $after
95 # Test constant readdir(3)/getdents(2) d_ino -
96 # Expect to find file by inode number
97 cat $before | while read ino f; do
98 $here/src/t_dir_type $dir $ino | grep -q $f || \
99 echo "$f not found by ino $ino (from $before)"
104 testdir=$SCRATCH_MNT/test
107 # Record inode numbers before copy up
108 record_inode_numbers $SCRATCH_MNT $tmp.before
111 # chown -h modifies all those file types
112 chown -h 100 $SCRATCH_MNT/$f
115 # Compare inode numbers before/after copy up
116 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
119 # move to another dir
120 mv $SCRATCH_MNT/$f $testdir/
123 echo 3 > /proc/sys/vm/drop_caches
125 # Compare inode numbers before/after rename and drop caches
126 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
128 # Verify that the inode numbers survive a mount cycle
129 $UMOUNT_PROG $SCRATCH_MNT
130 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on
132 # Compare inode numbers before/after mount cycle
133 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
136 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on
138 echo "Silence is golden"