summaryrefslogtreecommitdiff
path: root/tests/generic/730
blob: 988c47e18e9fac064f8e25b65566a8eebe92f616 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
# Copyright (c) 2023 Christoph Hellwig
#
# Test proper file system shut down when the block device is removed underneath
# and there is dirty data.
#
. ./common/preamble
_begin_fstest auto quick

_cleanup()
{
	cd /
	$UMOUNT_PROG $SCSI_DEBUG_MNT >>$seqres.full 2>&1
	_put_scsi_debug_dev
	rm -f $tmp.*
}

. ./common/filter
. ./common/scsi_debug

_supported_fs generic

# We don't actually use the test device, but we need a block based fs
_require_test
_require_block_device $TEST_DEV
_require_scsi_debug

size=$(_small_fs_size_mb 256)
SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size`
test -b "$SCSI_DEBUG_DEV" || _notrun "Failed to initialize scsi debug device"
echo "SCSI debug device $SCSI_DEBUG_DEV" >>$seqres.full

run_check _mkfs_dev $SCSI_DEBUG_DEV

SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
rm -rf $SCSI_DEBUG_MNT
mkdir $SCSI_DEBUG_MNT
run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT

# create a test file
$XFS_IO_PROG -f -c "pwrite 0 1M" $SCSI_DEBUG_MNT/testfile >>$seqres.full

# open a file descriptor for reading the file
exec 3< $SCSI_DEBUG_MNT/testfile

# delete the scsi debug device while it still has dirty data
echo 1 > /sys/block/$(_short_dev $SCSI_DEBUG_DEV)/device/delete

# try to read from the file, which should give us -EIO
cat <&3 > /dev/null

# close the file descriptor to not block unmount
exec 3<&-

status=0
exit