Btrfs: correctly flush data on defrag when compression is enabled
authorFilipe Manana <fdmanana@gmail.com>
Sat, 1 Mar 2014 10:55:54 +0000 (10:55 +0000)
committerJosef Bacik <jbacik@fb.com>
Mon, 10 Mar 2014 19:17:16 +0000 (15:17 -0400)
When the defrag flag BTRFS_DEFRAG_RANGE_START_IO is set and compression
enabled, we weren't flushing completely, as writing compressed extents
is a 2 steps process, one to compress the data and another one to write
the compressed data to disk.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
fs/btrfs/ioctl.c

index d4c17950277595eb353cd7169d91414bf859ef62..f914b5db7ff16d33d7a75cb40db1278718e22053 100644 (file)
@@ -1382,8 +1382,12 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                }
        }
 
-       if ((range->flags & BTRFS_DEFRAG_RANGE_START_IO))
+       if ((range->flags & BTRFS_DEFRAG_RANGE_START_IO)) {
                filemap_flush(inode->i_mapping);
+               if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
+                            &BTRFS_I(inode)->runtime_flags))
+                       filemap_flush(inode->i_mapping);
+       }
 
        if ((range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) {
                /* the filemap_flush will queue IO into the worker threads, but