xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 329
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 329
6 #
7 # Ensure that xfs_fsr handles errors correctly while defragging files.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick clone fsr
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/attr
15 . ./common/reflink
16 . ./common/inject
17
18 # real QA test starts here
19 _supported_fs xfs
20 _require_scratch_reflink
21 _require_cp_reflink
22 _require_command "$XFS_FSR_PROG" "xfs_fsr"
23 _require_xfs_io_error_injection "bmap_finish_one"
24 _require_xfs_scratch_rmapbt
25
26 rm -f "$seqres.full"
27
28 echo "Format and mount"
29 _scratch_mkfs > "$seqres.full" 2>&1
30 _scratch_mount >> "$seqres.full" 2>&1
31
32 testdir="$SCRATCH_MNT/test-$seq"
33 blksz=65536
34 blks=3
35 mkdir "$testdir"
36
37 echo "Create a many-block file"
38 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
39 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
40 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
41 _scratch_cycle_mount
42 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full
43
44 echo "Inject error"
45 _scratch_inject_error "bmap_finish_one"
46
47 echo "Defrag the file"
48 old_nextents=$(_count_extents $testdir/file1)
49 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full 2>&1
50
51 echo "FS should be shut down, touch will fail"
52 touch $SCRATCH_MNT/badfs 2>&1 | _filter_scratch
53
54 echo "Remount to replay log" | tee /dev/ttyprintk
55 _scratch_inject_logprint >> $seqres.full
56 new_nextents=$(_count_extents $testdir/file1)
57
58 echo "Check extent count" | tee /dev/ttyprintk
59 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
60 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
61 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
62
63 echo "FS should be online, touch should succeed"
64 touch $SCRATCH_MNT/goodfs
65 $XFS_IO_PROG -c 'bmap -v' $testdir/file1 >> $seqres.full
66
67 # success, all done
68 status=0
69 exit