2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
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.
10 # Test motivated by an XFS bug, and this commit fixed the issue
11 # xfs: return errors from partial I/O failures to files
14 _begin_fstest auto quick rw
16 # Override the default cleanup function.
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
29 # Import common functions.
33 # real QA test starts here
35 _require_scratch_nolvm
36 _require_block_device $SCRATCH_DEV
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
45 physical=`blockdev --getpbsz $SCRATCH_DEV`
46 logical=`blockdev --getss $SCRATCH_DEV`
48 # _get_scsi_debug_dev returns a scsi debug device with 128M in size by default
49 SCSI_DEBUG_DEV=`_get_scsi_debug_dev ${physical:-512} ${logical:-512} 0 300`
50 test -b "$SCSI_DEBUG_DEV" || _notrun "Failed to initialize scsi debug device"
51 echo "SCSI debug device $SCSI_DEBUG_DEV" >>$seqres.full
53 # create striped volume with 4MB stripe size
54 $LVM_PROG pvcreate -f $SCSI_DEBUG_DEV $SCRATCH_DEV >>$seqres.full 2>&1
55 $LVM_PROG vgcreate -f $vgname $SCSI_DEBUG_DEV $SCRATCH_DEV >>$seqres.full 2>&1
56 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
57 # (like 2.02.95 in RHEL6) don't support --yes option
58 yes | $LVM_PROG lvcreate -i 2 -I 4m -L 275m -n $lvname $vgname \
60 # wait for lv creation to fully complete
61 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
63 # _mkfs_dev exits the test on failure, this makes sure test lv is created by
64 # above vgcreate/lvcreate operations
65 _mkfs_dev /dev/mapper/$vgname-$lvname
67 _mount /dev/mapper/$vgname-$lvname $SCRATCH_MNT
69 # create a test file with contiguous blocks which will span across the 2 disks
70 $XFS_IO_PROG -f -c "pwrite 0 16M" -c fsync $SCRATCH_MNT/testfile >>$seqres.full
72 # offline the scsi debug device
73 echo offline > /sys/block/`_short_dev $SCSI_DEBUG_DEV`/device/state
75 # write to an allocated area of the test file with writes which spans both disks
76 # and call fsync, the fsync should report failure
77 $XFS_IO_PROG -c "pwrite -b 1M 0 6M" -c fsync $SCRATCH_MNT/testfile \