generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 121
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 121
6 #
7 # Ensure that we can dedupe parts of two files:
8 #   - Dedupe identical parts of two identical files
9 #   - Check that still have identical contents
10 #
11 . ./common/preamble
12 _begin_fstest auto quick clone dedupe
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17     cd /
18     rm -rf $tmp.* $testdir
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/reflink
24
25 # real QA test starts here
26 _require_test_dedupe
27
28 testdir=$TEST_DIR/test-$seq
29 rm -rf $testdir
30 mkdir $testdir
31
32 echo "Create the original files"
33 blksz=65536
34 _pwrite_byte 0x61 $((blksz * 2)) $((blksz * 6)) $testdir/file1 >> $seqres.full
35 _pwrite_byte 0x61 $((blksz * 2)) $((blksz * 6)) $testdir/file2 >> $seqres.full
36 _test_cycle_mount
37
38 md5sum $testdir/file1 | _filter_test_dir
39 md5sum $testdir/file2 | _filter_test_dir
40
41 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 8)) \
42        || echo "Files 1-2 do not match (intentional)"
43
44 echo "Dedupe the middle blocks together"
45 free_before=$(stat -f -c '%a' $testdir)
46 _dedupe_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
47                 $((blksz * 4)) $((blksz * 2)) >> $seqres.full
48 _test_cycle_mount
49 free_after=$(stat -f -c '%a' $testdir)
50 echo "freesp changed by $free_before -> $free_after" >> $seqres.full
51
52 echo "Compare sections"
53 md5sum $testdir/file1 | _filter_test_dir
54 md5sum $testdir/file2 | _filter_test_dir
55
56 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 4)) \
57        || echo "Start sections do not match"
58
59 _compare_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
60                 $((blksz * 4)) $((blksz * 2)) \
61        || echo "Middle sections do not match"
62
63 _compare_range $testdir/file1 $((blksz * 6)) $testdir/file2 \
64                 $((blksz * 6)) $((blksz * 2)) \
65        || echo "End sections do not match"
66
67 # success, all done
68 status=0
69 exit