blob: f69836b50f8841f96a27ef388d07eafdbe2c2e5a (
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014 Filipe Manana. All Rights Reserved.
#
# FS QA Test No. btrfs/041
#
# Test that btrfs-progs' restore command is able to correctly recover files
# that have compressed extents, specially when the respective file extent
# items have a non-zero data offset field.
#
# This issue is fixed by the following btrfs-progs patch:
#
# Btrfs-progs: fix restore of files with compressed extents
#
. ./common/preamble
_begin_fstest auto quick compress
restore_dir=$TEST_DIR/btrfs-test-$seq
# Override the default cleanup function.
_cleanup()
{
rm -fr $tmp
rm -fr $restore_dir
}
. ./common/filter
_supported_fs btrfs
_require_test
_require_scratch
mkdir $restore_dir
test_btrfs_restore()
{
if [ -z $1 ]
then
OPTIONS=""
else
OPTIONS="-o compress-force=$1"
fi
_scratch_mkfs >/dev/null 2>&1
_scratch_mount $OPTIONS
# Create first file extent item, then fsync to make sure the next write
# won't end up in the same file extent item, so that we have 2 distinct
# file extent items.
$XFS_IO_PROG -f -c "pwrite -S 0xff -b 100000 0 100000" -c "fsync" \
$SCRATCH_MNT/foo | _filter_xfs_io
# This creates a second file extent item.
$XFS_IO_PROG -c "pwrite -S 0xaa -b 100000 100000 100000" -c "fsync" \
$SCRATCH_MNT/foo | _filter_xfs_io
# Now do a few writes that will cause the first extent item to be split,
# with some of the new smaller file extent items getting a data offset
# field different from 0.
$XFS_IO_PROG -c "pwrite -S 0x1e -b 2 10000 2" $SCRATCH_MNT/foo \
| _filter_xfs_io
$XFS_IO_PROG -c "pwrite -S 0xd0 -b 11 33000 11" $SCRATCH_MNT/foo \
| _filter_xfs_io
$XFS_IO_PROG -c "pwrite -S 0xbc -b 100 99000 100" $SCRATCH_MNT/foo \
| _filter_xfs_io
md5sum $SCRATCH_MNT/foo | _filter_scratch
_scratch_unmount
rm -f $restore_dir/foo
# Now that the fs is unmounted, call btrfs restore to read the file
# from disk and save it in the test directory. It used to incorrectly
# read compressed file extents that have a non-zero data offset field,
# resulting either in decompression failure or reading a wrong section
# of the extent.
_btrfs restore $SCRATCH_DEV $restore_dir
md5sum $restore_dir/foo | cut -d ' ' -f 1
}
echo "Testing restore of file compressed with lzo"
test_btrfs_restore "lzo"
echo "Testing restore of file compressed with zlib"
test_btrfs_restore "zlib"
echo "Testing restore of file without any compression"
test_btrfs_restore
status=0
exit
|