common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / generic / 508
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test 508
6 #
7 # This testcase is trying to test recovery flow of generic filesystem, it needs
8 # creation time support on specified filesystem.
9 # With below steps, once the file is created, creation time attribute should be
10 # valid on the file, after we fsync that file, it expects creation time can be
11 # recovered after sudden power-cuts.
12 # 1. touch testfile;
13 # 1.1 sync (optional)
14 # 2. xfs_io -f testfile -c "fsync";
15 # 3. godown;
16 # 4. umount;
17 # 5. mount;
18 # 6. check creation time
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # remove previous $seqres.full before test
40 rm -f $seqres.full
41
42 # real QA test starts here
43 _supported_fs generic
44
45 _require_test_lsattr
46 _require_statx
47 _require_xfs_io_command "statx" "-v"
48
49 _require_scratch
50 _require_scratch_shutdown
51 _require_scratch_btime
52
53 _scratch_mkfs >/dev/null 2>&1
54 _require_metadata_journaling $SCRATCH_DEV
55
56 testfile=$SCRATCH_MNT/testfile
57
58 do_check()
59 {
60         _scratch_mount
61
62         touch $testfile
63
64         if [ "$1" == "sync" ]; then
65                 sync
66         fi
67
68         before=`$XFS_IO_PROG -f $testfile -c "statx -v" | grep btime`
69
70         $XFS_IO_PROG -f $testfile -c "fsync" | _filter_xfs_io
71
72         _scratch_shutdown | tee -a $seqres.full
73         _scratch_cycle_mount
74
75         after=`$XFS_IO_PROG -f $testfile -c "statx -v" | grep btime`
76
77         # check inode's creation time
78         if [ "$before" != "$after" ]; then
79                 echo "Before: $before"
80                 echo "After : $after"
81         fi
82         echo "Before: $before" >> $seqres.full
83         echo "After : $after" >> $seqres.full
84
85         rm -f $testfile
86         _scratch_unmount
87 }
88
89 echo "Silence is golden"
90
91 do_check
92 do_check sync
93
94 status=0
95 exit