Skip to content

Commit fe3f566

Browse files
Li Zefanchrismason-xx
authored andcommitted
Btrfs: Fix oops for defrag with compression turned on
When we defrag a file, whose size can be fit into an inline extent, with compression enabled, the compress type is set to be fs_info->compress_type, which is 0 if the btrfs filesystem is mounted without compress option. This leads to oops. Reported-by: Daniel Blueman <daniel.blueman@gmail.com> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 200da64 commit fe3f566

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

fs/btrfs/inode.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static int btrfs_init_inode_security(struct btrfs_trans_handle *trans,
111111
static noinline int insert_inline_extent(struct btrfs_trans_handle *trans,
112112
struct btrfs_root *root, struct inode *inode,
113113
u64 start, size_t size, size_t compressed_size,
114+
int compress_type,
114115
struct page **compressed_pages)
115116
{
116117
struct btrfs_key key;
@@ -125,12 +126,9 @@ static noinline int insert_inline_extent(struct btrfs_trans_handle *trans,
125126
size_t cur_size = size;
126127
size_t datasize;
127128
unsigned long offset;
128-
int compress_type = BTRFS_COMPRESS_NONE;
129129

130-
if (compressed_size && compressed_pages) {
131-
compress_type = root->fs_info->compress_type;
130+
if (compressed_size && compressed_pages)
132131
cur_size = compressed_size;
133-
}
134132

135133
path = btrfs_alloc_path();
136134
if (!path)
@@ -220,7 +218,7 @@ static noinline int insert_inline_extent(struct btrfs_trans_handle *trans,
220218
static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,
221219
struct btrfs_root *root,
222220
struct inode *inode, u64 start, u64 end,
223-
size_t compressed_size,
221+
size_t compressed_size, int compress_type,
224222
struct page **compressed_pages)
225223
{
226224
u64 isize = i_size_read(inode);
@@ -253,7 +251,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,
253251
inline_len = min_t(u64, isize, actual_end);
254252
ret = insert_inline_extent(trans, root, inode, start,
255253
inline_len, compressed_size,
256-
compressed_pages);
254+
compress_type, compressed_pages);
257255
BUG_ON(ret);
258256
btrfs_delalloc_release_metadata(inode, end + 1 - start);
259257
btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0);
@@ -432,12 +430,13 @@ static noinline int compress_file_range(struct inode *inode,
432430
* to make an uncompressed inline extent.
433431
*/
434432
ret = cow_file_range_inline(trans, root, inode,
435-
start, end, 0, NULL);
433+
start, end, 0, 0, NULL);
436434
} else {
437435
/* try making a compressed inline extent */
438436
ret = cow_file_range_inline(trans, root, inode,
439437
start, end,
440-
total_compressed, pages);
438+
total_compressed,
439+
compress_type, pages);
441440
}
442441
if (ret == 0) {
443442
/*
@@ -791,7 +790,7 @@ static noinline int cow_file_range(struct inode *inode,
791790
if (start == 0) {
792791
/* lets try to make an inline extent */
793792
ret = cow_file_range_inline(trans, root, inode,
794-
start, end, 0, NULL);
793+
start, end, 0, 0, NULL);
795794
if (ret == 0) {
796795
extent_clear_unlock_delalloc(inode,
797796
&BTRFS_I(inode)->io_tree,

0 commit comments

Comments
 (0)