Skip to content

Commit

Permalink
btrfs: defrag: cleanup checking for compression status
Browse files Browse the repository at this point in the history
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
David Sterba committed Aug 16, 2017
1 parent eec63c6 commit 1e2ef46
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,15 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
unsigned long cluster = max_cluster;
u64 new_align = ~((u64)SZ_128K - 1);
struct page **pages = NULL;
bool do_compress = range->flags & BTRFS_DEFRAG_RANGE_COMPRESS;

if (isize == 0)
return 0;

if (range->start >= isize)
return -EINVAL;

if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) {
if (do_compress) {
if (range->compress_type > BTRFS_COMPRESS_TYPES)
return -EINVAL;
if (range->compress_type)
Expand Down Expand Up @@ -1341,8 +1342,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,

if (!should_defrag_range(inode, (u64)i << PAGE_SHIFT,
extent_thresh, &last_len, &skip,
&defrag_end, range->flags &
BTRFS_DEFRAG_RANGE_COMPRESS)) {
&defrag_end, do_compress)){
unsigned long next;
/*
* the should_defrag function tells us how much to skip
Expand Down Expand Up @@ -1370,7 +1370,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
}

inode_lock(inode);
if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)
if (do_compress)
BTRFS_I(inode)->defrag_compress = compress_type;
ret = cluster_pages_for_defrag(inode, pages, i, cluster);
if (ret < 0) {
Expand Down Expand Up @@ -1418,7 +1418,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
filemap_flush(inode->i_mapping);
}

if ((range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) {
if (do_compress) {
/* the filemap_flush will queue IO into the worker threads, but
* we have to make sure the IO is actually started and that
* ordered extents get created before we return
Expand All @@ -1440,7 +1440,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
ret = defrag_count;

out_ra:
if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) {
if (do_compress) {
inode_lock(inode);
BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
inode_unlock(inode);
Expand Down

0 comments on commit 1e2ef46

Please sign in to comment.