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.
41 _require_xfs_io_command "falloc"
43 test_file=${TEST_DIR}/testfile-$seq
47 # The first write creates a delayed extent, fallocate creates
48 # unwritten extent which will be marked as delayed in ext4
49 # extent status tree. Second write will convert unwritten/delayed
50 # block into written/delayed.
51 $XFS_IO_PROG -f -c "pwrite -S 0xaa 4096 2048" \
52 -c "falloc 0 131072" \
53 -c "pwrite -S 0xbb 65536 2048" \
54 -c "fsync" $test_file > $seqres.full 2>&1
56 # Drop the caches to evict dirty buffers from memory
57 echo 3 > /proc/sys/vm/drop_caches
59 # Write into the second part of the block with 0xbb write from before
60 # will create new empty! buffer because the block is still marked as
61 # delayed even though it's already written - resulting in
62 # overwriting previous data.
63 $XFS_IO_PROG -c "pwrite -S 0xdd 67584 2048" $test_file >> $seqres.full 2>&1
65 # On a faulty ext4 oxbb data will be missing, overwritten by zeroes.