2
# Test cp --sparse=always through fiemap copy
4
# Copyright (C) 2010-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
21
$PERL -e 1 || skip_ 'you lack perl'
23
# The test was seen to fail on ext3 so exclude that type
24
# (or any file system where the type can't be determined)
26
if fiemap_capable_ fiemap_chk && ! df -t ext3 . >/dev/null; then
27
: # Current partition has working extents. Good!
29
# FIXME: temporarily(?) skip this variant, at least until after this bug
30
# is fixed: http://thread.gmane.org/gmane.comp.file-systems.ext4/24495
31
skip_ "current file system has insufficient FIEMAP support"
33
# It's not; we need to create one, hence we need root access.
38
cleanup_() { cd /; umount "$cwd/mnt"; }
41
# Create an ext4 loopback file system
42
dd if=/dev/zero of=blob bs=32k count=1000 || skip=1
44
mkfs -t ext4 -F blob ||
45
skip_ "failed to create ext4 file system"
46
mount -oloop blob mnt || skip=1
48
echo test > f || skip=1
52
skip_ "insufficient mount/ext4 support"
55
# =================================================
56
# Ensure that we exercise the FIEMAP-copying code enough
57
# to provoke at least two iterations of the do...while loop
58
# in which it calls ioctl (fd, FS_IOC_FIEMAP,...
59
# This also verifies that non-trivial extents are preserved.
61
# Extract logical block number and length pairs from filefrag -v output.
62
# The initial sed is to remove the "eof" from the normally-empty "flags" field.
63
# Similarly, remove flags values like "unknown,delalloc,eof".
64
# That is required when that final extent has no number in the "expected" field.
67
sed 's/ [a-z,][a-z,]*$//' $@ \
68
| awk '/^ *[0-9]/ {printf "%d %d ", $2, (NF<5 ? $NF : $5) } END {print ""}'
71
for i in $(seq 1 2 21); do
72
for j in 1 2 31 100; do
73
$PERL -e '$n = '$i' * 1024; *F = *STDOUT;' \
74
-e 'for (1..'$j') { sysseek (*F, $n, 1)' \
75
-e '&& syswrite (*F, chr($_)x$n) or die "$!"}' > j1 || fail=1
77
# Note there is an implicit sync performed by cp on Linux kernels
78
# before 2.6.39 to work around bugs in EXT4 and BTRFS.
79
# Note also the -s parameter to the filefrag commands below
80
# for the same reasons.
81
cp --sparse=always j1 j2 || fail=1
83
cmp j1 j2 || fail_ "data loss i=$i j=$j"
84
if ! filefrag -vs j1 | grep -F extent >/dev/null; then
85
test $skip != 1 && warn_ 'skipping part; you lack filefrag'
88
# Here is sample filefrag output:
89
# $ perl -e 'BEGIN{$n=16*1024; *F=*STDOUT}' \
90
# -e 'for (1..5) { sysseek(*F,$n,1)' \
91
# -e '&& syswrite *F,"."x$n or die "$!"}' > j
93
# File system type is: ef53
94
# File size of j is 163840 (40 blocks, blocksize 4096)
95
# ext logical physical expected length flags
97
# 1 12 6258892 6258887 4
98
# 2 20 6258900 6258895 4
99
# 3 28 6258908 6258903 4
100
# 4 36 6258916 6258911 4 eof
103
# exclude the physical block numbers; they always differ
104
filefrag -v j1 > ff1 || framework_failure_
105
filefrag -vs j2 > ff2 || framework_failure_
106
{ f ff1; f ff2; } | $PERL $abs_top_srcdir/tests/filefrag-extent-compare \
108
warn_ ignoring filefrag-reported extent map differences
109
# Show the differing extent maps.
113
test $fail = 1 && break 2