]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e4defrag: backwards-allocated files should be defragmented too
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 22 Jul 2014 16:40:56 +0000 (12:40 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 22 Jul 2014 16:40:56 +0000 (12:40 -0400)
Currently, e4defrag avoids increasing file fragmentation by comparing
the number of runs of physical extents of both the original and the
donor files.  Unfortunately, there is a bug in the routine that counts
physical extents, since it doesn't look at the logical block offsets
of the extents.  Therefore, a file whose blocks were allocated in
reverse order will be seen as only having one big physical extent, and
therefore will not be defragmented.

Fix the counting routine to consider logical extent offset so that we
defragment backwards-allocated files.  This could be problematic if we
ever gain the ability to lay out logically sparse extents in a
physically contiguous manner, but presumably one wouldn't call defrag
on such a file.

Reported-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/e4defrag.c

index a2047935dd91a9ffb8445d7d10d0cdf3a1f87b96..d0eac605bebc5084278aac5af951470ba0cda46e 100644 (file)
@@ -888,7 +888,9 @@ static int get_physical_count(struct fiemap_extent_list *physical_list_head)
 
        do {
                if ((ext_list_tmp->data.physical + ext_list_tmp->data.len)
-                               != ext_list_tmp->next->data.physical) {
+                               != ext_list_tmp->next->data.physical ||
+                   (ext_list_tmp->data.logical + ext_list_tmp->data.len)
+                               != ext_list_tmp->next->data.logical) {
                        /* This extent and next extent are not continuous. */
                        ret++;
                }