generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 462
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat.  All Rights Reserved.
4 #
5 # FS QA Test 462
6 #
7 # This is a regression test for kernel commit
8 #  ef947b2 x86, mm: fix gup_pte_range() vs DAX mappings
9 # created by Jeffrey Moyer <jmoyer@redhat.com>
10 #
11 # This is reproducible only when testing on pmem device
12 # which is configured in "memory mode", not in "raw mode".
13 #
14 . ./common/preamble
15 _begin_fstest auto quick dax
16
17 # Import common functions.
18 . ./common/filter
19
20 # Modify as appropriate.
21 _supported_fs generic
22 _require_test
23 _require_scratch_dax_mountopt "dax"
24 _require_test_program "t_mmap_write_ro"
25 # running by unpriviliged user is not necessary to reproduce
26 # this bug, just trying to test more.
27 _require_user
28
29 # real QA test starts here
30
31 _scratch_mkfs >>$seqres.full 2>&1
32 _scratch_mount "-o dax"
33
34 # remount TEST_DEV wo/ dax
35 export TEST_FS_MOUNT_OPTS=""
36 _test_cycle_mount
37
38 # prepare a 4k read-only DAX file, save its md5sum
39 $XFS_IO_PROG -f -c "pwrite -S 0xFF 0 4096" \
40         $SCRATCH_MNT/readonlyfile >> $seqres.full 2>&1
41 chmod 0644  $SCRATCH_MNT/readonlyfile
42 md5_1="$(_md5_checksum $SCRATCH_MNT/readonlyfile)"
43
44 # prepare another 4k non-DAX file
45 $XFS_IO_PROG -f -c "pwrite -S 0x00 0 4096" \
46         $TEST_DIR/${seq}.file >> $seqres.full 2>&1
47
48 # allow qa_user access
49 chown $qa_user $TEST_DIR/${seq}.file
50
51 # run test programme, read another file writing into
52 # the read-only file with mmap, which should fail.
53 #
54 # don't use $here/src/t_mmap_write_ro, as we're running it as a regular user,
55 # and $here may contain path component that a regular user doesn't have search
56 # permission
57 _user_do "src/t_mmap_write_ro $TEST_DIR/${seq}.file \
58         $SCRATCH_MNT/readonlyfile"
59
60 # read-only file should not get updated, md5sum again.
61 md5_2="$(_md5_checksum $SCRATCH_MNT/readonlyfile)"
62
63 [ "$md5_1" != "$md5_2" ] && echo "read only file changed"
64
65 # success, all done
66 status=0
67 exit