Skip to content

Commit 21c730d

Browse files
committed
Merge tag 'for-5.3-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - fixes for leaks caused by recently merged patches - one build fix - a fix to prevent mixing of incompatible features * tag 'for-5.3-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: don't leak extent_map in btrfs_get_io_geometry() btrfs: free checksum hash on in close_ctree btrfs: Fix build error while LIBCRC32C is module btrfs: inode: Don't compress if NODATASUM or NODATACOW set
2 parents c92f038 + 373c3b8 commit 21c730d

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

fs/btrfs/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config BTRFS_FS
44
tristate "Btrfs filesystem support"
55
select CRYPTO
66
select CRYPTO_CRC32C
7+
select LIBCRC32C
78
select ZLIB_INFLATE
89
select ZLIB_DEFLATE
910
select LZO_COMPRESS

fs/btrfs/disk-io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
41064106
percpu_counter_destroy(&fs_info->dev_replace.bio_counter);
41074107
cleanup_srcu_struct(&fs_info->subvol_srcu);
41084108

4109+
btrfs_free_csum_hash(fs_info);
41094110
btrfs_free_stripe_hash_table(fs_info);
41104111
btrfs_free_ref_cache(fs_info);
41114112
}

fs/btrfs/inode.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,31 @@ static noinline int add_async_extent(struct async_chunk *cow,
395395
return 0;
396396
}
397397

398+
/*
399+
* Check if the inode has flags compatible with compression
400+
*/
401+
static inline bool inode_can_compress(struct inode *inode)
402+
{
403+
if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW ||
404+
BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
405+
return false;
406+
return true;
407+
}
408+
409+
/*
410+
* Check if the inode needs to be submitted to compression, based on mount
411+
* options, defragmentation, properties or heuristics.
412+
*/
398413
static inline int inode_need_compress(struct inode *inode, u64 start, u64 end)
399414
{
400415
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
401416

417+
if (!inode_can_compress(inode)) {
418+
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
419+
KERN_ERR "BTRFS: unexpected compression for ino %llu\n",
420+
btrfs_ino(BTRFS_I(inode)));
421+
return 0;
422+
}
402423
/* force compress */
403424
if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
404425
return 1;
@@ -1631,7 +1652,8 @@ int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page,
16311652
} else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) {
16321653
ret = run_delalloc_nocow(inode, locked_page, start, end,
16331654
page_started, 0, nr_written);
1634-
} else if (!inode_need_compress(inode, start, end)) {
1655+
} else if (!inode_can_compress(inode) ||
1656+
!inode_need_compress(inode, start, end)) {
16351657
ret = cow_file_range(inode, locked_page, start, end, end,
16361658
page_started, nr_written, 1, NULL);
16371659
} else {

fs/btrfs/volumes.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5941,6 +5941,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
59415941
u64 stripe_len;
59425942
u64 raid56_full_stripe_start = (u64)-1;
59435943
int data_stripes;
5944+
int ret = 0;
59445945

59455946
ASSERT(op != BTRFS_MAP_DISCARD);
59465947

@@ -5961,8 +5962,8 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
59615962
btrfs_crit(fs_info,
59625963
"stripe math has gone wrong, stripe_offset=%llu offset=%llu start=%llu logical=%llu stripe_len=%llu",
59635964
stripe_offset, offset, em->start, logical, stripe_len);
5964-
free_extent_map(em);
5965-
return -EINVAL;
5965+
ret = -EINVAL;
5966+
goto out;
59665967
}
59675968

59685969
/* stripe_offset is the offset of this block in its stripe */
@@ -6009,7 +6010,10 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
60096010
io_geom->stripe_offset = stripe_offset;
60106011
io_geom->raid56_stripe_offset = raid56_full_stripe_start;
60116012

6012-
return 0;
6013+
out:
6014+
/* once for us */
6015+
free_extent_map(em);
6016+
return ret;
60136017
}
60146018

60156019
static int __btrfs_map_block(struct btrfs_fs_info *fs_info,

0 commit comments

Comments
 (0)