2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
7 # This test excercises the problem with unwritten and delayed extents
8 # in ext4 extent status tree where we might in some cases lose a block
9 # worth of data. Even though this was a ext4 specific problem the
10 # reproducer can be easily tun on any file system so let's do that just
13 # This tests excercises the problem fixed in kernel with commit
14 # "ext4: Fix data corruption caused by unwritten and delayed extents"
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
31 # get standard environment, filters and checks
35 # real QA test starts here
37 # Modify as appropriate.
40 _require_xfs_io_command "falloc"
42 test_file=${TEST_DIR}/testfile-$seq
46 # The first write creates a delayed extent, fallocate creates
47 # unwritten extent which will be marked as delayed in ext4
48 # extent status tree. Second write will convert unwritten/delayed
49 # block into written/delayed.
50 $XFS_IO_PROG -f -c "pwrite -S 0xaa 4096 2048" \
51 -c "falloc 0 131072" \
52 -c "pwrite -S 0xbb 65536 2048" \
53 -c "fsync" $test_file > $seqres.full 2>&1
55 # Drop the caches to evict dirty buffers from memory
56 echo 3 > /proc/sys/vm/drop_caches
58 # Write into the second part of the block with 0xbb write from before
59 # will create new empty! buffer because the block is still marked as
60 # delayed even though it's already written - resulting in
61 # overwriting previous data.
62 $XFS_IO_PROG -c "pwrite -S 0xdd 67584 2048" $test_file >> $seqres.full 2>&1
64 # On a faulty ext4 oxbb data will be missing, overwritten by zeroes.