generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 506
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 506
6 #
7 # This testcase is trying to test recovery flow of generic filesystem, w/ below
8 # steps, once project id changes, after we fsync that file, we can expect that
9 # project id can be recovered after sudden power-cuts.
10 # 1. touch testfile;
11 # 1.1 sync (optional)
12 # 2. chattr -p 100 testfile;
13 # 3. xfs_io -f testfile -c "fsync";
14 # 4. godown;
15 # 5. umount;
16 # 6. mount;
17 # 7. check project id
18 #
19 . ./common/preamble
20 _begin_fstest shutdown auto quick metadata quota
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/quota
25
26 # real QA test starts here
27 _supported_fs generic
28
29 _require_scratch
30 _require_scratch_shutdown
31
32 _scratch_mkfs >/dev/null 2>&1
33 _require_metadata_journaling $SCRATCH_DEV
34 _qmount_option "prjquota"
35 _qmount
36 _require_prjquota $SCRATCH_DEV
37 _scratch_unmount
38
39 testfile=$SCRATCH_MNT/testfile
40
41 do_check()
42 {
43         _scratch_mount
44
45         touch $testfile
46
47         if [ "$1" == "sync" ]; then
48                 sync
49         fi
50
51         $XFS_IO_PROG -x -c "chproj 100" $testfile
52
53         before=`$XFS_IO_PROG -x -c "lsproj" $testfile`
54
55         $XFS_IO_PROG -f $testfile -c "fsync" | _filter_xfs_io
56
57         _scratch_shutdown | tee -a $seqres.full
58         _scratch_cycle_mount
59
60         after=`$XFS_IO_PROG -x -c "lsproj" $testfile`
61
62         # check inode's project quota id
63         if [ "$before" != "$after" ]; then
64                 echo "Before: $before"
65                 echo "After : $after"
66         fi
67         echo "Before: $before" >> $seqres.full
68         echo "After : $after" >> $seqres.full
69
70         rm -f $testfile
71         _scratch_unmount
72 }
73
74 echo "Silence is golden"
75
76 do_check
77 do_check sync
78
79 status=0
80 exit