fstests: print symbolic names for fiemap flags
[xfstests-dev.git] / tests / generic / 108
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
4 #
5 # FS QA Test 108
6 #
7 # Test partial block device failure. Calls like fsync() should report failure
8 # on partial I/O failure, e.g. a single failed disk in a raid 0 stripe.
9 #
10 # Test motivated by an XFS bug, and this commit fixed the issue
11 # xfs: return errors from partial I/O failures to files
12 #
13 . ./common/preamble
14 _begin_fstest auto quick rw
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19         cd /
20         echo running > /sys/block/`_short_dev $SCSI_DEBUG_DEV`/device/state
21         $UMOUNT_PROG $SCRATCH_MNT >>$seqres.full 2>&1
22         $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
23         $LVM_PROG pvremove -f $SCRATCH_DEV $SCSI_DEBUG_DEV >>$seqres.full 2>&1
24         $UDEV_SETTLE_PROG
25         _put_scsi_debug_dev
26         rm -f $tmp.*
27 }
28
29 # Import common functions.
30 . ./common/filter
31 . ./common/scsi_debug
32
33 # real QA test starts here
34 _supported_fs generic
35 _require_scratch_nocheck
36 _require_block_device $SCRATCH_DEV
37 _require_scsi_debug
38 _require_command "$LVM_PROG" lvm
39 # We cannot ensure the Logical Volume is aligned to the zone boundary
40 _require_non_zoned_device $SCRATCH_DEV
41
42 lvname=lv_$seq
43 vgname=vg_$seq
44
45 # _get_scsi_debug_dev returns a scsi debug device with 128M in size by default
46 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 300`
47 test -b "$SCSI_DEBUG_DEV" || _notrun "Failed to initialize scsi debug device"
48 echo "SCSI debug device $SCSI_DEBUG_DEV" >>$seqres.full
49
50 # create striped volume with 4MB stripe size
51 $LVM_PROG pvcreate -f $SCSI_DEBUG_DEV $SCRATCH_DEV >>$seqres.full 2>&1
52 $LVM_PROG vgcreate -f $vgname $SCSI_DEBUG_DEV $SCRATCH_DEV >>$seqres.full 2>&1
53 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
54 # (like 2.02.95 in RHEL6) don't support --yes option
55 yes | $LVM_PROG lvcreate -i 2 -I 4m -L 275m -n $lvname $vgname \
56         >>$seqres.full 2>&1
57 # wait for lv creation to fully complete
58 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
59
60 # _mkfs_dev exits the test on failure, this makes sure test lv is created by
61 # above vgcreate/lvcreate operations
62 _mkfs_dev /dev/mapper/$vgname-$lvname
63
64 _mount /dev/mapper/$vgname-$lvname $SCRATCH_MNT
65
66 # create a test file with contiguous blocks which will span across the 2 disks
67 $XFS_IO_PROG -f -c "pwrite 0 16M" -c fsync $SCRATCH_MNT/testfile >>$seqres.full
68
69 # offline the scsi debug device
70 echo offline > /sys/block/`_short_dev $SCSI_DEBUG_DEV`/device/state
71
72 # write to an allocated area of the test file with writes which spans both disks
73 # and call fsync, the fsync should report failure
74 $XFS_IO_PROG -c "pwrite -b 1M 0 6M" -c fsync $SCRATCH_MNT/testfile \
75         >>$seqres.full
76
77 status=0
78 exit