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 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
39 # real QA test starts here
41 # Use non-default scratch underlying overlay dirs, we need to check
42 # them explicity after test.
43 _require_scratch_nocheck
45 _require_test_program "af_unix"
46 _require_test_program "t_dir_type"
47 # Require redirect_dir for renaming a merge directory
48 _require_scratch_feature redirect_dir
52 lowerdir=$OVL_BASE_TEST_DIR/$seq-ovl-lower
56 # Create our test files.
59 ln -s $lowerdir/file $lowerdir/symlink
60 mknod $lowerdir/chrdev c 1 1
61 mknod $lowerdir/blkdev b 1 1
62 mknod $lowerdir/fifo p
63 $here/src/af_unix $lowerdir/socket
65 _scratch_mkfs >>$seqres.full 2>&1
67 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
68 workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK
70 # Enable redirect_dir for renaming a merge directory.
71 # Enabling xino in this test requires that base filesystem inode numbers will
72 # not use bit 63 in inode number of the test files, because bit 63 is used by
73 # overlayfs to indicate the layer. Let's just assume that this is true for all
74 # tested filesystems and if we are wrong, the test may fail.
75 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on || \
76 _notrun "cannot mount overlay with xino=on option"
77 _fs_options $SCRATCH_DEV | grep -q "xino=on" || \
78 _notrun "cannot enable xino feature"
80 FILES="dir file symlink chrdev blkdev fifo socket"
82 # Record inode numbers in format <ino> <basename>
83 function record_inode_numbers()
91 while read ino file; do
92 echo $ino `basename $file` >> $outfile
96 # Check inode numbers match recorder inode numbers
97 function check_inode_numbers()
103 record_inode_numbers $dir $after
105 # Test constant stat(2) st_ino -
106 # Compare before..after - expect silence
107 # We use diff -u so out.bad will tell us which stage failed
108 diff -u $before $after
110 # Test constant readdir(3)/getdents(2) d_ino -
111 # Expect to find file by inode number
112 cat $before | while read ino f; do
113 $here/src/t_dir_type $dir $ino | grep -q $f || \
114 echo "$f not found by ino $ino (from $before)"
119 testdir=$SCRATCH_MNT/test
122 # Record inode numbers before copy up
123 record_inode_numbers $SCRATCH_MNT $tmp.before
126 # chown -h modifies all those file types
127 chown -h 100 $SCRATCH_MNT/$f
130 # Compare inode numbers before/after copy up
131 check_inode_numbers $SCRATCH_MNT $tmp.before $tmp.after_copyup
134 # move to another dir
135 mv $SCRATCH_MNT/$f $testdir/
138 echo 3 > /proc/sys/vm/drop_caches
140 # Compare inode numbers before/after rename and drop caches
141 check_inode_numbers $testdir $tmp.after_copyup $tmp.after_move
143 # Verify that the inode numbers survive a mount cycle
144 $UMOUNT_PROG $SCRATCH_MNT
145 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on
147 # Compare inode numbers before/after mount cycle
148 check_inode_numbers $testdir $tmp.after_move $tmp.after_cycle
151 _overlay_check_scratch_dirs $lowerdir $upperdir $workdir -o redirect_dir=on,xino=on
153 echo "Silence is golden"