-e 'for (1..'$j') { sysseek (*F, $n, 1)' \
-e '&& syswrite (*F, chr($_)x$n) or die "$!"}' > j1 || fail=1
- # Note the explicit fdatasync is used here as
- # it was seen that `filefrag -s` (FIEMAP_FLAG_SYNC) was
- # ineffective on ext4 loopback on Linux 2.6.35.10-72.fc14.i686
- dd if=/dev/null of=j1 conv=notrunc,fdatasync
+ # Note there is an implicit sync performed by cp to
+ # work around bugs in EXT4 and BTRFS before Linux 2.6.38
+ # Note also the -s parameter to the filefrag commands below
+ # for the same reasons.
cp --sparse=always j1 j2 || fail=1
- dd if=/dev/null of=j2 conv=notrunc,fdatasync
cmp j1 j2 || fail=1
- if ! filefrag -v j1 | grep -F extent >/dev/null; then
+ if ! filefrag -vs j1 | grep -F extent >/dev/null; then
test $skip != 1 && warn_ 'skipping part; you lack filefrag'
skip=1
else
# exclude the physical block numbers; they always differ
filefrag -v j1 > ff1 || framework_failure
- filefrag -v j2 > ff2 || framework_failure
+ filefrag -vs j2 > ff2 || framework_failure
{ f ff1; f ff2; } | $PERL $abs_top_srcdir/tests/filefrag-extent-compare ||
fail=1
fi
foreach my $i (0..@A/2-1) { $a[$i] = { L_BLK => $A[2*$i], LEN => $A[2*$i+1] } };
foreach my $i (0..@B/2-1) { $b[$i] = { L_BLK => $B[2*$i], LEN => $B[2*$i+1] } };
+# Merge adjacent extents in array E.
+sub merge_extents($)
+{
+ my ($e) = @_;
+
+ my $i = 0;
+ while (1)
+ {
+ !defined $e->[$i+1]
+ and last;
+ $e->[$i]->{L_BLK} + $e->[$i]->{LEN} != $e->[$i+1]->{L_BLK}
+ and ++$i, next;
+
+ $e->[$i]->{LEN} += $e->[$i+1]->{LEN};
+ # Remove $e->[$i+1]
+ splice @$e, $i+1, 1;
+ }
+}
+
+merge_extents \@a;
+merge_extents \@b;
+
+@a == @b
+ or die "$ME: extent counts differ, even after adjustment\n";
+
my $i = 0;
-my $j = 0;
-while (1)
- {
- !defined $a[$i] && !defined $b[$j]
- and exit 0;
- defined $a[$i] && defined $b[$j]
- or die "\@a and \@b have different lengths, even after adjustment\n";
- ($a[$i]->{L_BLK} == $b[$j]->{L_BLK}
- && $a[$i]->{LEN} == $b[$j]->{LEN})
- and next;
- ($a[$i]->{LEN} < $b[$j]->{LEN}
- && exists $a[$i+1] && $a[$i]->{LEN} + $a[$i+1]->{LEN} == $b[$j]->{LEN})
- and ++$i, next;
- exists $b[$j+1] && $a[$i]->{LEN} == $b[$i]->{LEN} + $b[$i+1]->{LEN}
- and ++$j, next;
- die "differing extent:\n"
- . " [$i]=$a[$i]->{L_BLK} $a[$i]->{LEN}\n"
- . " [$j]=$b[$j]->{L_BLK} $b[$j]->{LEN}\n"
- }
-continue
+while (defined $a[$i])
{
- ++$i;
- ++$j;
+ $a[$i]->{L_BLK} == $b[$i]->{L_BLK} && $a[$i]->{LEN} == $b[$i]->{LEN}
+ or die "$ME: differing extent:\n"
+ . " [$i]=$a[$i]->{L_BLK} $a[$i]->{LEN}\n"
+ . " [$i]=$b[$i]->{L_BLK} $b[$i]->{LEN}\n";
+ $i++;
}
### Setup "GNU" style for perl-mode and cperl-mode.