generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 361
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test 361
6 #
7 # Test remount on I/O errors.
8 #
9 # XFS had a bug to hang on remount in this case, this kernel commit fix
10 # the issue.
11 # 5cb13dc cancel the setfilesize transation when io error happen
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         $UMOUNT_PROG $fs_mnt
25         _destroy_loop_device $loop_dev
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 rm -f $seqres.full
35
36 # real QA test starts here
37 _supported_fs generic
38 _require_scratch
39 _require_block_device $SCRATCH_DEV
40 _require_loop
41
42 # create a small filesystem to hold another filesystem image
43 _scratch_mkfs_sized $((512 * 1024 * 1024)) >>$seqres.full 2>&1
44 _scratch_mount
45
46 # create the sparse fs image and mount point
47 fs_img=$SCRATCH_MNT/fs.img
48 fs_mnt=$SCRATCH_MNT/mnt
49 $XFS_IO_PROG -fc "truncate 1g" $fs_img >>$seqres.full 2>&1
50 mkdir -p $fs_mnt
51
52 # mount loop device and create a larger file to hit I/O errors on loop device
53 loop_dev=$(_create_loop_device $fs_img)
54 _mkfs_dev $loop_dev
55 _mount $loop_dev $fs_mnt
56 if [ "$FSTYP" = "xfs" ]; then
57         # Turn off all XFS metadata IO error retries
58         dname=$(_short_dev $loop_dev)
59         echo 0 | tee /sys/fs/xfs/$dname/error/*/*/* > /dev/null
60 fi
61 $XFS_IO_PROG -fc "pwrite 0 520m" $fs_mnt/testfile >>$seqres.full 2>&1
62
63 # remount should not hang
64 $MOUNT_PROG -o remount,ro $fs_mnt >>$seqres.full 2>&1
65
66 # success, all done
67 echo "Silence is golden"
68 status=0
69 exit