btrfs/012: check free size of scratch device before copying files
[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 _require_scratch
36 _require_dm_target flakey
37
38 rm -f $seqres.full
39
40 _scratch_mkfs >> $seqres.full 2>&1
41
42 SAVE_MOUNT_OPTIONS="$MOUNT_OPTIONS"
43 MOUNT_OPTIONS="$MOUNT_OPTIONS -o inode_cache,commit=100"
44
45 # create a basic flakey device that will never error out
46 _init_flakey
47 _mount_flakey
48
49 _get_inode_id()
50 {
51         local inode_id
52         inode_id=`stat $1 | grep Inode: | $AWK_PROG '{print $4}'`
53         echo $inode_id
54 }
55
56 $XFS_IO_PROG -f -c "pwrite 0 10M" -c "fsync" \
57         $SCRATCH_MNT/data >& /dev/null
58
59 inode_id=`_get_inode_id "$SCRATCH_MNT/data"`
60 rm -f $SCRATCH_MNT/data
61
62 for i in `seq 1 5`;
63 do
64         mkdir $SCRATCH_MNT/dir_$i
65         new_inode_id=`_get_inode_id $SCRATCH_MNT/dir_$i`
66         if [ $new_inode_id -eq $inode_id ]
67         then
68                 $XFS_IO_PROG -f -c "pwrite 0 1M" -c "fsync" \
69                         $SCRATCH_MNT/dir_$i/data1 >& /dev/null
70                 _load_flakey_table 1
71                 _unmount_flakey
72                 need_umount=1
73                 break
74         fi
75         sleep 1
76 done
77
78 # restore previous mount options
79 export MOUNT_OPTIONS="$SAVE_MOUNT_OPTIONS"
80
81 # ok mount so that any recovery that needs to happen is done
82 if [ $new_inode_id -eq $inode_id ];then
83         _load_flakey_table $FLAKEY_ALLOW_WRITES
84         _mount_flakey
85         _unmount_flakey
86 fi
87
88 # make sure we got a valid fs after replay
89 _check_scratch_fs $FLAKEY_DEV
90
91 status=0
92 exit