summaryrefslogtreecommitdiff
path: root/tests/generic/081
blob: c3cd41bef963a84fe1f01401b07f2db833d29a9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
#
# FS QA Test No. 081
#
# Test I/O error path by fully filling an dm snapshot.
#
. ./common/preamble
_begin_fstest auto quick

# Override the default cleanup function.
_cleanup()
{
	local pv_ret
	cd /
	rm -f $tmp.*

	# Tear down the lvm vg and snapshot.
	#
	# NOTE: We do the unmount and {vg,pv}remove in a loop here because
	# dmeventd could be configured to unmount the filesystem automatically
	# after the IO errors.  That is racy with the umount we're trying to do
	# here because there's a window in which the directory tree has been
	# removed from the mount namespaces (so the umount call here sees no
	# mount and exits) but the filesystem hasn't yet released the block
	# device, which causes the vgremove here to fail.
	#
	# We "solve" the race by repeating the umount/lvm teardown until the
	# block device goes away, because we cannot exit this test without
	# removing the lvm devices from the scratch device -- this will cause
	# other tests to fail.
	while test -e /dev/mapper/$vgname-$snapname || \
	      test -e /dev/mapper/$vgname-$lvname; do
		$UMOUNT_PROG $mnt >> $seqres.full 2>&1
		$LVM_PROG lvremove -f $vgname/$snapname >>$seqres.full 2>&1
		$LVM_PROG lvremove -f $vgname/$lvname >>$seqres.full 2>&1
		$LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
		$LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
		pv_ret=$?
		$UDEV_SETTLE_PROG
		test $pv_ret -eq 0 && break
		sleep 2
	done
}

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs generic
_require_test
_require_scratch_nolvm
_require_dm_target snapshot
_require_command $LVM_PROG lvm

echo "Silence is golden"

vgname=vg_$seq
lvname=base_$seq
snapname=snap_$seq
mnt=$TEST_DIR/mnt_$seq
mkdir -p $mnt

size=$(_small_fs_size_mb 300)
lvsize=$((size * 85 / 100))	 # ~256M

# make sure there's enough disk space for 256M lv, test for 300M here in case
# lvm uses some space for metadata
_scratch_mkfs_sized $((size * 1024 * 1024)) >>$seqres.full 2>&1
$LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
# We use yes pipe instead of 'lvcreate --yes' because old version of lvm
# (like 2.02.95 in RHEL6) don't support --yes option
yes | $LVM_PROG lvcreate -L ${lvsize}M -n $lvname $vgname >>$seqres.full 2>&1
# wait for lvcreation to fully complete
$UDEV_SETTLE_PROG >>$seqres.full 2>&1

# _mkfs_dev exits the test on failure, this can make sure lv is created in
# above vgcreate/lvcreate steps
_mkfs_dev /dev/mapper/$vgname-$lvname

# create a 4M snapshot
$LVM_PROG lvcreate -s -L 4M -n $snapname $vgname/$lvname >>$seqres.full 2>&1 || \
	_fail "Failed to create snapshot"

_mount -t $FSTYP /dev/mapper/$vgname-$snapname $mnt

# write 5M data to the snapshot
$XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1

# _check_dmesg will check for WARNINGs/BUGs in dmesg
status=0
exit