generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 393
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Jaegeuk Kim.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/393
6 #
7 # Test some small truncations to check inline_data and its cached data are
8 # truncated correctly at the same time.
9 #
10 # The inline_data feature was introduced in ext4 and f2fs as follows.
11 #  ext4 : http://lwn.net/Articles/468678/
12 #  f2fs : http://lwn.net/Articles/573408/
13 #
14 # The basic idea is embedding small-sized file's data into relatively large
15 # inode space.
16 # In ext4, up to 132 bytes of data can be stored in 256 bytes-sized inode.
17 # In f2fs, up to 3.4KB of data can be embedded into 4KB-sized inode block.
18 #
19 . ./common/preamble
20 _begin_fstest auto quick rw
21
22 # Import common functions.
23 . ./common/filter
24
25 _supported_fs generic
26 _require_scratch
27
28 testfile=$SCRATCH_MNT/testfile
29 OD_CMD="od -A x -t x1z"
30
31 _scratch_mkfs > /dev/null 2>&1
32 _scratch_mount
33
34 # 1. make a file containing inline_data.
35 # 2. "truncated 0"  is to check cached page #0 was truncated entirely.
36 # 3. "truncated 50" is to check inline_data was truncated within its inode.
37 $XFS_IO_PROG -t -f \
38         -c "pwrite -S 0x58 0 40" `# write    |XXXXXXXXXXXXXXXXXXXXXXXX|` \
39         -c "fsync"                                                       \
40         -c "truncate 0"          `# truncate |                        |` \
41         -c "truncate 50"         `# truncate |                        |` \
42 $testfile | _filter_xfs_io
43
44 echo "= truncate inline_data after #0 page was truncated entirely ="
45 $OD_CMD $testfile
46 _scratch_cycle_mount
47 $OD_CMD $testfile
48 rm $testfile
49
50 # 1. make a file containing inline_data.
51 # 2. "truncated 0"     is to check cached page #0 was truncated entirely.
52 # 3. "truncated 4096"  is to check inline_data was dismissed and truncated.
53 $XFS_IO_PROG -t -f \
54         -c "pwrite -S 0x58 0 40" `# write    |XXXXXXXXXXXXXXXXXXXXXXXX|` \
55         -c "fsync"                                                       \
56         -c "truncate 0"          `# truncate |                        |` \
57         -c "truncate 4096"       `# truncate |                        |` \
58 $testfile | _filter_xfs_io
59
60 echo "= truncate dismissed inline_data after #0 page was truncated entirely ="
61 $OD_CMD $testfile
62 _scratch_cycle_mount
63 $OD_CMD $testfile
64 rm $testfile
65
66 # 1. make a file containing inline_data.
67 # 2. "truncated 4"   is to check cached page #0 was truncated partially.
68 # 3. "truncated 50"  is to check inline_data was truncated within its inode.
69 $XFS_IO_PROG -t -f \
70         -c "pwrite -S 0x58 0 40" `# write    |XXXXXXXXXXXXXXXXXXXXXXXX|` \
71         -c "fsync"                                                       \
72         -c "truncate 4"          `# truncate |XXXX                    |` \
73         -c "truncate 50"         `# truncate |XXXX                    |` \
74 $testfile | _filter_xfs_io
75
76 echo "= truncate inline_data after #0 page was truncated partially ="
77 $OD_CMD $testfile
78 _scratch_cycle_mount
79 $OD_CMD $testfile
80 rm $testfile
81
82 # 1. make a file containing inline_data.
83 # 2. "truncated 4"     is to check cached page #0 was truncated partially.
84 # 3. "truncated 4096"  is to check inline_data was dismissed and truncated.
85 $XFS_IO_PROG -t -f \
86         -c "pwrite -S 0x58 0 40" `# write    |XXXXXXXXXXXXXXXXXXXXXXXX|` \
87         -c "fsync"                                                       \
88         -c "truncate 4"          `# truncate |XXXX                    |` \
89         -c "truncate 4096"       `# truncate |XXXX                    |` \
90 $testfile | _filter_xfs_io
91
92 echo "= truncate dismissed inline_data after #0 page was truncated partially ="
93 $OD_CMD $testfile
94 _scratch_cycle_mount
95 $OD_CMD $testfile
96 rm $testfile
97
98 status=0
99 exit