From: Darrick J. Wong Date: Tue, 22 Jul 2014 16:40:56 +0000 (-0400) Subject: e4defrag: backwards-allocated files should be defragmented too X-Git-Tag: v1.42.12~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7c539e8fd86de691475eea00409c6c030f312cd;p=thirdparty%2Fe2fsprogs.git e4defrag: backwards-allocated files should be defragmented too 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 Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/misc/e4defrag.c b/misc/e4defrag.c index a2047935d..d0eac605b 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -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++; }