From c7c539e8fd86de691475eea00409c6c030f312cd Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 22 Jul 2014 12:40:56 -0400 Subject: [PATCH] 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 --- misc/e4defrag.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/e4defrag.c b/misc/e4defrag.c index a204793..d0eac60 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++; } -- 1.8.3.1