~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/cp/sparse-fiemap

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# Test cp --sparse=always through fiemap copy
3
 
 
4
 
# Copyright (C) 2010-2011 Free Software Foundation, Inc.
5
 
 
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.
10
 
 
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.
15
 
 
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/>.
18
 
 
19
 
. "${srcdir=.}/init.sh"; path_prepend_ ../src
20
 
print_ver_ cp
21
 
$PERL -e 1 || skip_ 'you lack perl'
22
 
 
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)
25
 
touch fiemap_chk
26
 
if fiemap_capable_ fiemap_chk && ! df -t ext3 . >/dev/null; then
27
 
  : # Current partition has working extents.  Good!
28
 
else
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"
32
 
 
33
 
  # It's not;  we need to create one, hence we need root access.
34
 
  require_root_
35
 
  require_mkfs_PATH_
36
 
 
37
 
  cwd=$PWD
38
 
  cleanup_() { cd /; umount "$cwd/mnt"; }
39
 
 
40
 
  skip=0
41
 
  # Create an ext4 loopback file system
42
 
  dd if=/dev/zero of=blob bs=32k count=1000 || skip=1
43
 
  mkdir mnt
44
 
  mkfs -t ext4 -F blob ||
45
 
    skip_ "failed to create ext4 file system"
46
 
  mount -oloop blob mnt   || skip=1
47
 
  cd mnt                  || skip=1
48
 
  echo test > f           || skip=1
49
 
  test -s f               || skip=1
50
 
 
51
 
  test $skip = 1 &&
52
 
    skip_ "insufficient mount/ext4 support"
53
 
fi
54
 
 
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.
60
 
 
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.
65
 
f()
66
 
{
67
 
  sed 's/ [a-z,][a-z,]*$//' $@ \
68
 
    | awk '/^ *[0-9]/ {printf "%d %d ", $2, (NF<5 ? $NF : $5) } END {print ""}'
69
 
}
70
 
 
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
76
 
 
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
82
 
 
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'
86
 
      skip=1
87
 
    else
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
92
 
      #   $ filefrag -v 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
96
 
      #      0       4  6258884               4
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
101
 
      #   j: 6 extents found
102
 
 
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 \
107
 
        || {
108
 
             warn_ ignoring filefrag-reported extent map differences
109
 
             # Show the differing extent maps.
110
 
             head -n99 ff1 ff2
111
 
           }
112
 
    fi
113
 
    test $fail = 1 && break 2
114
 
  done
115
 
done
116
 
 
117
 
Exit $fail