common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / ext4 / 034
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Liu Bo, Alibaba.  All Rights Reserved.
4 #
5 # FS QA Test 034
6 #
7 # Regression test for a ENOSPC warning when both quota and
8 # "-o dioread_nolock,nodelalloc" is used.
9 #
10 # The bug was fixed by commit
11 # "ext4: make sure enough credits are reserved for dioread_nolock writes"
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/quota
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37
38 # Modify as appropriate.
39 _supported_fs ext4
40 _require_scratch
41 _require_quota
42 _require_nobody
43 _require_xfs_io_command "falloc"
44 _require_xfs_io_command "fiemap"
45 _require_xfs_io_command "syncfs"
46
47 echo "Format and mount"
48 _scratch_mkfs "-O quota" > $seqres.full 2>&1
49 _scratch_mount "-o dioread_nolock,nodelalloc" > $seqres.full 2>&1
50
51 echo "Create the original file"
52 touch $SCRATCH_MNT/foobar >> $seqres.full
53 chown nobody $SCRATCH_MNT/foobar >> $seqres.full
54
55 echo "Set hard quota"
56 setquota -u nobody 0 10M 0 0 $SCRATCH_MNT
57 _report_quota_blocks $SCRATCH_MNT >> $seqres.full
58
59 echo "Create 2 level extent tree (btree) for foobar with a unwritten extent"
60 $XFS_IO_PROG -f -c "pwrite 0 4k" -c "falloc 4k 4k" -c "pwrite 8k 4k" \
61              -c "pwrite 20k 4k"  -c "pwrite 28k 4k" -c "pwrite 36k 4k" \
62              -c "fsync" $SCRATCH_MNT/foobar >> $seqres.full
63
64 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar >> $seqres.full
65
66 echo "Convert unwritten extent to written and collapse extent tree to inode"
67 $XFS_IO_PROG -c "pwrite 4k 4k" $SCRATCH_MNT/foobar >> $seqres.full
68
69 echo "Create a new file and do fsync to force a jbd2 commit"
70 $XFS_IO_PROG -f -c "pwrite 0 4k" -c "fsync" $SCRATCH_MNT/dummy >> $seqres.full
71
72 # Use 'syncfs' instead of 'sync' here as 'sync' could have dirtied quota files
73 # ahead of writeback and could not reproduce the bug.
74 echo "sync $SCRATCH_MNT to writeback" | _filter_scratch
75 $XFS_IO_PROG -c "syncfs" $SCRATCH_MNT >> $seqres.full
76
77 # success, all done
78 status=0
79 exit