generic: test adding filesystem-level fscrypt key via key_id
[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 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         echo running > /sys/block/`_short_dev $SCSI_DEBUG_DEV`/device/state
26         $UMOUNT_PROG $SCRATCH_MNT >>$seqres.full 2>&1
27         $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
28         $LVM_PROG pvremove -f $SCRATCH_DEV $SCSI_DEBUG_DEV >>$seqres.full 2>&1
29         _put_scsi_debug_dev
30         rm -f $tmp.*
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/scsi_debug
37
38 # real QA test starts here
39 _supported_fs generic
40 _supported_os Linux
41 _require_scratch_nocheck
42 _require_block_device $SCRATCH_DEV
43 _require_scsi_debug
44 _require_command "$LVM_PROG" lvm
45
46 lvname=lv_$seq
47 vgname=vg_$seq
48 rm -f $seqres.full
49
50 # _get_scsi_debug_dev returns a scsi debug device with 128M in size by default
51 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 300`
52 test -b "$SCSI_DEBUG_DEV" || _notrun "Failed to initialize scsi debug device"
53 echo "SCSI debug device $SCSI_DEBUG_DEV" >>$seqres.full
54
55 # create striped volume with 4MB stripe size
56 $LVM_PROG pvcreate -f $SCSI_DEBUG_DEV $SCRATCH_DEV >>$seqres.full 2>&1
57 $LVM_PROG vgcreate -f $vgname $SCSI_DEBUG_DEV $SCRATCH_DEV >>$seqres.full 2>&1
58 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
59 # (like 2.02.95 in RHEL6) don't support --yes option
60 yes | $LVM_PROG lvcreate -i 2 -I 4m -L 275m -n $lvname $vgname \
61         >>$seqres.full 2>&1
62 # wait for lv creation to fully complete
63 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
64
65 # _mkfs_dev exits the test on failure, this makes sure test lv is created by
66 # above vgcreate/lvcreate operations
67 _mkfs_dev /dev/mapper/$vgname-$lvname
68
69 _mount /dev/mapper/$vgname-$lvname $SCRATCH_MNT
70
71 # create a test file with contiguous blocks which will span across the 2 disks
72 $XFS_IO_PROG -f -c "pwrite 0 16M" -c fsync $SCRATCH_MNT/testfile >>$seqres.full
73
74 # offline the scsi debug device
75 echo offline > /sys/block/`_short_dev $SCSI_DEBUG_DEV`/device/state
76
77 # write to an allocated area of the test file with writes which spans both disks
78 # and call fsync, the fsync should report failure
79 $XFS_IO_PROG -c "pwrite -b 1M 0 6M" -c fsync $SCRATCH_MNT/testfile \
80         >>$seqres.full
81
82 status=0
83 exit