overlay/061: enhance mmap ro/rw inconsistencies test
authorAmir Goldstein <amir73il@gmail.com>
Sun, 27 Jan 2019 08:38:50 +0000 (10:38 +0200)
committerEryu Guan <guaneryu@gmail.com>
Sun, 3 Feb 2019 07:26:47 +0000 (15:26 +0800)
overlay/061 is currently the only overlay test that is expected to
fail on upstream kernel.

It is a flavor of test overlay/016 with mread in stead of pread.
The ro/rw inconsistencies related to file read()/write() API were
fixed with stacked file operations in v4.19, but the ro/rw
inconsistencies related to shared mmap read/write remain to be
fixed.

The test currently checks cache coherency between mmap read and file
write(), but this sort of cache coherency is a Linux implementation
detail not a requirement of the API.

Instead of mread vs. pwrite, check consistency of mread vs. mwrite
to shared mmap, which is required by the MMAP_SHARED API.

Because we can, perform the test on shared memory that maps files
that are already close and check also that mwrite after file is
closed is persistent. This adds test coverage for future overlayfs
writeback code.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/overlay/061
tests/overlay/061.out

index aea72eb9456409d4051640a97b20a58acee20f41..47be2cc342f08c5b1281682ee9361562078d169e 100755 (executable)
@@ -4,14 +4,15 @@
 #
 # FSQA Test No. 061
 #
-# Test ro/rw fd data inconsistecies
+# Test memory mapped data inconsistencies
 #
 # This is a variant of test overlay/016 with mread instead of pread.
 #
 # This simple test demonstrates a known issue with overlayfs:
-# - process A opens file F for read + mmap
-# - process B writes new data to file F
-# - process A reads old data from mapped memory
+# - process A created shared ro mmap on file F
+# - process B created shared rw mmap on file F
+# - process B writes new data to shared mmap
+# - process A reads old data from shared mmap
 #
 seq=`basename $0`
 seqres=$RESULT_DIR/$seq
@@ -49,15 +50,36 @@ echo "This is old news" > $lowerdir/foo
 _scratch_mount
 
 
+filter_xfs_io_mmap()
+{
+       # filter out these lines:
+       # [000] 0x7f3d9aece000 - 0x7f3d9aece010 r--  SCRATCH_MNT/foo (0 : 16)
+       grep -Fv '[00'
+}
+
 #
 # mmap MAP_SHARED|PROT_READ of rofd
-# write to rwfd
-# read from mapped memory
+# mmap MAP_SHARED|PROT_WRITE of rwfd
+# write to rw mmap
+# read from ro mmap
 #
 $XFS_IO_PROG -r $SCRATCH_MNT/foo \
        -C "mmap -r 0 16" \
+       -C "close" \
        -C "open $SCRATCH_MNT/foo" \
-       -C "pwrite -S 0x61 0 16" \
+       -C "mmap -w 0 16" \
+       -C "close" \
+       -C "mwrite -S 0x61 0 16" \
+       -C "munmap" \
+       -C "mread -v 0 16" \
+| _filter_xfs_io | _filter_scratch | filter_xfs_io_mmap
+
+_scratch_cycle_mount
+
+# Verify mmap write after close has persisted through mount cycle
+echo "After mount cycle:"
+$XFS_IO_PROG -r $SCRATCH_MNT/foo \
+       -C "mmap -r 0 16" \
        -C "mread -v 0 16" \
 | _filter_xfs_io | _filter_scratch
 
index 0662721c27c61d8ca4abdd2c589b97bb78027116..d0e8b86e0de8496107fef92a28cfa167c1ed8227 100644 (file)
@@ -1,4 +1,4 @@
 QA output created by 061
-wrote 16/16 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+00000000:  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  aaaaaaaaaaaaaaaa
+After mount cycle:
 00000000:  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  aaaaaaaaaaaaaaaa