2 # Test cp reads unwritten extents efficiently
4 # Copyright (C) 2011 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/init.sh"; path_prepend_ ..
/src
23 fiemap_capable_ fiemap_chk ||
24 skip_test_
'this file system lacks FIEMAP support'
27 # TODO: rather than requiring `fallocate`, possible add
28 # this functionality to truncate --alloc
29 fallocate
--help >/dev
/null || skip_test_
'The fallocate utility is required'
30 fallocate
-l 1 -n falloc.
test ||
31 skip_test_
'this file system lacks FALLOCATE support'
34 # Require more space than we'll actually use, so that
35 # tests run in parallel do not run out of space.
36 # Otherwise, with inadequate space, simply running the following
37 # fallocate command would induce a temporary disk-full condition,
38 # which would cause failure of unrelated tests run in parallel.
39 require_file_system_bytes_free_
800000000
41 fallocate
-l 600000000 space.
test ||
42 skip_test_
'this test needs at least 600MB free space'
44 # Disable this test on old BTRFS (e.g. Fedora 14)
45 # which reports ordinary extents for unwritten ones.
46 filefrag space.
test || skip_test_
'the `filefrag` utility is missing'
47 filefrag
-v space.
test |
grep -F 'unwritten' > /dev
/null ||
48 skip_test_
'this file system does not report empty extents as "unwritten"'
52 # Ensure we read a large empty file quickly
53 fallocate
-l 300000000 empty.big || framework_failure
54 timeout
3 cp --sparse=always empty.big
cp.
test || fail
=1
55 test $
(stat
-c %s empty.big
) = $
(stat
-c %s
cp.
test) || fail
=1
58 # Ensure we handle extents beyond file size correctly.
59 # Note until we support fallocate, we will not maintain
60 # the file allocation. FIXME: amend this test when fallocate is supported.
61 fallocate
-l 10000000 -n unwritten.withdata || framework_failure
62 dd count
=10 if=/dev
/urandom conv
=notrunc iflag
=fullblock of
=unwritten.withdata
63 cp unwritten.withdata
cp.
test || fail
=1
64 test $
(stat
-c %s unwritten.withdata
) = $
(stat
-c %s
cp.
test) || fail
=1
65 cmp unwritten.withdata
cp.
test || fail
=1
66 rm unwritten.withdata
cp.
test
68 # The following to generate unaccounted extents followed by a hole, is not
69 # supported by ext4 at least. The ftruncate discards all extents not
70 # accounted for in the size.
71 # fallocate -l 10000000 -n unacc.withholes
72 # dd count=10 if=/dev/urandom conv=notrunc iflag=fullblock of=unacc.withholes
73 # truncate -s20000000 unacc.withholes
75 # Ensure we handle a hole after empty extents correctly.
76 # Since all extents are accounted for in the size,
77 # we can maintain the allocation independently from
78 # fallocate() support.
79 fallocate
-l 10000000 empty.withholes
80 truncate
-s 20000000 empty.withholes
81 sectors_per_block
=$
(expr $
(stat
-c %o .
) / 512)
82 cp empty.withholes
cp.
test || fail
=1
83 test $
(stat
-c %s empty.withholes
) = $
(stat
-c %s
cp.
test) || fail
=1
84 # These are usually equal but can vary by an IO block due to alignment
85 alloc_diff
=$
(expr $
(stat
-c %b empty.withholes
) - $
(stat
-c %b
cp.
test))
86 alloc_diff
=$
(echo $alloc_diff |
tr -d -- -) # abs()
87 test $alloc_diff -le $sectors_per_block || fail
=1
88 # Again with SPARSE_ALWAYS
89 cp --sparse=always empty.withholes
cp.
test || fail
=1
90 test $
(stat
-c %s empty.withholes
) = $
(stat
-c %s
cp.
test) || fail
=1
91 # cp.test should take 0 space, but allowing for some systems
92 # that store default extended attributes in data blocks
93 test $
(stat
-c %b
cp.
test) -le $sectors_per_block || fail
=1
94 rm empty.withholes
cp.
test