btrfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / btrfs / 049
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/049
6 #
7 # Regression test for btrfs inode caching vs tree log which was
8 # addressed by the following kernel patch.
9 #
10 # Btrfs: fix inode caching vs tree log
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         _cleanup_flakey
25         rm -rf $tmp
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/dmflakey
32
33 # real QA test starts here
34 _supported_fs btrfs
35 _supported_os Linux
36 _require_scratch
37 _require_dm_target flakey
38
39 rm -f $seqres.full
40
41 _scratch_mkfs >> $seqres.full 2>&1
42
43 SAVE_MOUNT_OPTIONS="$MOUNT_OPTIONS"
44 MOUNT_OPTIONS="$MOUNT_OPTIONS -o inode_cache,commit=100"
45
46 # create a basic flakey device that will never error out
47 _init_flakey
48 _mount_flakey
49
50 _get_inode_id()
51 {
52         local inode_id
53         inode_id=`stat $1 | grep Inode: | $AWK_PROG '{print $4}'`
54         echo $inode_id
55 }
56
57 $XFS_IO_PROG -f -c "pwrite 0 10M" -c "fsync" \
58         $SCRATCH_MNT/data >& /dev/null
59
60 inode_id=`_get_inode_id "$SCRATCH_MNT/data"`
61 rm -f $SCRATCH_MNT/data
62
63 for i in `seq 1 5`;
64 do
65         mkdir $SCRATCH_MNT/dir_$i
66         new_inode_id=`_get_inode_id $SCRATCH_MNT/dir_$i`
67         if [ $new_inode_id -eq $inode_id ]
68         then
69                 $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" \
70                         $SCRATCH_MNT/dir_$i/data1 >& /dev/null
71                 _load_flakey_table 1
72                 _unmount_flakey
73                 need_umount=1
74                 break
75         fi
76         sleep 1
77 done
78
79 # restore previous mount options
80 export MOUNT_OPTIONS="$SAVE_MOUNT_OPTIONS"
81
82 # ok mount so that any recovery that needs to happen is done
83 if [ $new_inode_id -eq $inode_id ];then
84         _load_flakey_table $FLAKEY_ALLOW_WRITES
85         _mount_flakey
86         _unmount_flakey
87 fi
88
89 # make sure we got a valid fs after replay
90 _check_scratch_fs $FLAKEY_DEV
91
92 status=0
93 exit