Thread (4 messages) 4 messages, 2 authors, 2012-06-20
STALE5143d

[PATCH] btrfs: ignore unfragmented file checks in defrag when compression enabled

From: Andrew Mahone <hidden>
Date: 2012-06-18 17:35:06
Subsystem: btrfs file system, filesystems (vfs and infrastructure), the rest · Maintainers: Chris Mason, David Sterba, Alexander Viro, Christian Brauner, Linus Torvalds

Inform should_defrag_range if BTRFS_DEFRAG_RANGE_COMPRESS is set. If so, skip
checks for adjacent extents and extent size when deciding whether to defrag,
as these can prevent an uncompressed and unfragmented file from being
compressed as requested.

Signed-off-by: Andrew Mahone <redacted>
---
 fs/btrfs/ioctl.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 24b776c..ac48d7f 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -812,7 +812,7 @@ static int check_adjacent_extents(struct inode *inode, struct extent_map *em)
 
 static int should_defrag_range(struct inode *inode, u64 start, u64 len,
 			       int thresh, u64 *last_len, u64 *skip,
-			       u64 *defrag_end)
+			       u64 *defrag_end, int compress)
 {
 	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
 	struct extent_map *em = NULL;
@@ -853,7 +853,7 @@ static int should_defrag_range(struct inode *inode, u64 start, u64 len,
 	}
 
 	/* If we have nothing to merge with us, just skip. */
-	if (check_adjacent_extents(inode, em)) {
+	if (!compress && check_adjacent_extents(inode, em)) {
 		ret = 0;
 		goto out;
 	}
@@ -861,7 +861,8 @@ static int should_defrag_range(struct inode *inode, u64 start, u64 len,
 	/*
 	 * we hit a real extent, if it is big don't bother defragging it again
 	 */
-	if ((*last_len == 0 || *last_len >= thresh) && em->len >= thresh)
+	if (!compress &&
+	    (*last_len == 0 || *last_len >= thresh) && em->len >= thresh)
 		ret = 0;
 
 out:
@@ -1143,7 +1144,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 
 		if (!should_defrag_range(inode, (u64)i << PAGE_CACHE_SHIFT,
 					 PAGE_CACHE_SIZE, extent_thresh,
-					 &last_len, &skip, &defrag_end)) {
+					 &last_len, &skip, &defrag_end,
+					 range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) {
 			unsigned long next;
 			/*
 			 * the should_defrag function tells us how much to skip
-- 
1.7.10.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help