generic: test full dm snapshot devices
[xfstests-dev.git] / tests / generic / 081
1 #! /bin/bash
2 # FS QA Test No. 081
3 #
4 # Test I/O error path by fully filling an dm snapshot.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35         cd /
36         rm -f $tmp.*
37         # lvm may have umounted it on I/O error, but in case it does not
38         $UMOUNT_PROG $mnt >/dev/null 2>&1
39         $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
40         $LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # real QA test starts here
48 _supported_fs generic
49 _supported_os Linux
50 _require_test
51 _require_scratch_nocheck
52 _require_dm_snapshot
53 _require_block_device $SCRATCH_DEV
54 _require_command $LVM_PROG lvm
55
56 echo "Silence is golden"
57 rm -f $seqres.full
58
59 vgname=vg_$seq
60 lvname=base_$seq
61 snapname=snap_$seq
62 mnt=$TEST_DIR/mnt_$seq
63 mkdir -p $mnt
64
65 # make sure there's enough disk space for 256M lv, test for 300M here in case
66 # lvm uses some space for metadata
67 _scratch_mkfs_sized $((300 * 1024 * 1024)) >>$seqres.full 2>&1
68 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
69 $LVM_PROG lvcreate --yes -L 256M -n $lvname $vgname >>$seqres.full 2>&1
70
71 # _mkfs_dev exits the test on failure, this can make sure lv is created in
72 # above vgcreate/lvcreate steps
73 _mkfs_dev /dev/mapper/$vgname-$lvname
74
75 # create a 4M snapshot
76 $LVM_PROG lvcreate -s -L 4M -n $snapname $vgname/$lvname >>$seqres.full 2>&1 || \
77         _fail "Failed to create snapshot"
78
79 _mount /dev/mapper/$vgname-$snapname $mnt
80
81 # write 5M data to the snapshot
82 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
83
84 # _check_dmesg will check for WARNINGs/BUGs in dmesg
85 status=0
86 exit