[PATCH] e4defrag: fallocate donor file only once

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we allocate the donor file once for all, it will have a better chance
to be continuous.

Signed-off-by: "Peng Tao" <bergwolf@xxxxxxxxx>
---
 misc/e4defrag.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index c25514a..c1e9213 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -1603,6 +1603,7 @@ static int file_defrag(const char *file, const struct stat64 *buf,
 	struct fiemap_extent_list	*donor_list_logical = NULL;
 	struct fiemap_extent_group	*orig_group_head = NULL;
 	struct fiemap_extent_group	*orig_group_tmp = NULL;
+	ext4_fsblk_t	orig_block_count;
 
 	defraged_file_count++;
 
@@ -1742,19 +1743,17 @@ static int file_defrag(const char *file, const struct stat64 *buf,
 	/* Allocate space for donor inode */
 	orig_group_tmp = orig_group_head;
 	do {
-		ret = fallocate(donor_fd, 0,
-		  (loff_t)orig_group_tmp->start->data.logical * block_size,
-		  (loff_t)orig_group_tmp->len * block_size);
-		if (ret < 0) {
-			if (mode_flag & DETAIL) {
-				PRINT_FILE_NAME(file);
-				PRINT_ERR_MSG_WITH_ERRNO("Failed to fallocate");
-			}
-			goto out;
-		}
-
+		orig_block_count += orig_group_tmp->len;
 		orig_group_tmp = orig_group_tmp->next;
 	} while (orig_group_tmp != orig_group_head);
+	ret = fallocate(donor_fd, 0, 0, (loff_t)orig_block_count * block_size);
+	if (ret < 0) {
+		if (mode_flag & DETAIL) {
+			PRINT_FILE_NAME(file);
+			PRINT_ERR_MSG_WITH_ERRNO("Failed to fallocate");
+		}
+		goto out;
+	}
 
 	/* Get donor inode's extents */
 	ret = get_file_extents(donor_fd, &donor_list_physical);
-- 
1.6.2-rc2.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux