Skip to content

Commit 9907ab3

Browse files
committed
Merge tag 'for-5.9-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - fix swapfile activation on subvolumes with deleted snapshots - error value mixup when removing directory entries from tree log - fix lzo compression level reset after previous level setting - fix space cache memory leak after transaction abort - fix const function attribute - more error handling improvements * tag 'for-5.9-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: detect nocow for swap after snapshot delete btrfs: check the right error variable in btrfs_del_dir_entries_in_log btrfs: fix space cache memory leak after transaction abort btrfs: use the correct const function attribute for btrfs_get_num_csums btrfs: reset compression level for lzo on remount btrfs: handle errors from async submission
2 parents c41c3ec + a84d5d4 commit 9907ab3

9 files changed

Lines changed: 39 additions & 31 deletions

File tree

‎fs/btrfs/ctree.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const char *btrfs_super_csum_driver(u16 csum_type)
6868
btrfs_csums[csum_type].name;
6969
}
7070

71-
size_t __const btrfs_get_num_csums(void)
71+
size_t __attribute_const__ btrfs_get_num_csums(void)
7272
{
7373
return ARRAY_SIZE(btrfs_csums);
7474
}

‎fs/btrfs/ctree.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
22622262
int btrfs_super_csum_size(const struct btrfs_super_block *s);
22632263
const char *btrfs_super_csum_name(u16 csum_type);
22642264
const char *btrfs_super_csum_driver(u16 csum_type);
2265-
size_t __const btrfs_get_num_csums(void);
2265+
size_t __attribute_const__ btrfs_get_num_csums(void);
22662266

22672267

22682268
/*
@@ -2518,7 +2518,7 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
25182518
u64 bytenr, u64 num_bytes);
25192519
int btrfs_exclude_logged_extents(struct extent_buffer *eb);
25202520
int btrfs_cross_ref_exist(struct btrfs_root *root,
2521-
u64 objectid, u64 offset, u64 bytenr);
2521+
u64 objectid, u64 offset, u64 bytenr, bool strict);
25222522
struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
25232523
struct btrfs_root *root,
25242524
u64 parent, u64 root_objectid,
@@ -2934,7 +2934,7 @@ struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
29342934
u64 start, u64 len);
29352935
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
29362936
u64 *orig_start, u64 *orig_block_len,
2937-
u64 *ram_bytes);
2937+
u64 *ram_bytes, bool strict);
29382938

29392939
void __btrfs_del_delalloc_inode(struct btrfs_root *root,
29402940
struct btrfs_inode *inode);

‎fs/btrfs/disk-io.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,6 +4551,7 @@ static void btrfs_cleanup_bg_io(struct btrfs_block_group *cache)
45514551
cache->io_ctl.inode = NULL;
45524552
iput(inode);
45534553
}
4554+
ASSERT(cache->io_ctl.pages == NULL);
45544555
btrfs_put_block_group(cache);
45554556
}
45564557

‎fs/btrfs/extent-tree.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,8 @@ static noinline int check_delayed_ref(struct btrfs_root *root,
23062306

23072307
static noinline int check_committed_ref(struct btrfs_root *root,
23082308
struct btrfs_path *path,
2309-
u64 objectid, u64 offset, u64 bytenr)
2309+
u64 objectid, u64 offset, u64 bytenr,
2310+
bool strict)
23102311
{
23112312
struct btrfs_fs_info *fs_info = root->fs_info;
23122313
struct btrfs_root *extent_root = fs_info->extent_root;
@@ -2348,9 +2349,13 @@ static noinline int check_committed_ref(struct btrfs_root *root,
23482349
btrfs_extent_inline_ref_size(BTRFS_EXTENT_DATA_REF_KEY))
23492350
goto out;
23502351

2351-
/* If extent created before last snapshot => it's definitely shared */
2352-
if (btrfs_extent_generation(leaf, ei) <=
2353-
btrfs_root_last_snapshot(&root->root_item))
2352+
/*
2353+
* If extent created before last snapshot => it's shared unless the
2354+
* snapshot has been deleted. Use the heuristic if strict is false.
2355+
*/
2356+
if (!strict &&
2357+
(btrfs_extent_generation(leaf, ei) <=
2358+
btrfs_root_last_snapshot(&root->root_item)))
23542359
goto out;
23552360

23562361
iref = (struct btrfs_extent_inline_ref *)(ei + 1);
@@ -2375,7 +2380,7 @@ static noinline int check_committed_ref(struct btrfs_root *root,
23752380
}
23762381

23772382
int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
2378-
u64 bytenr)
2383+
u64 bytenr, bool strict)
23792384
{
23802385
struct btrfs_path *path;
23812386
int ret;
@@ -2386,7 +2391,7 @@ int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
23862391

23872392
do {
23882393
ret = check_committed_ref(root, path, objectid,
2389-
offset, bytenr);
2394+
offset, bytenr, strict);
23902395
if (ret && ret != -ENOENT)
23912396
goto out;
23922397

‎fs/btrfs/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ static int check_can_nocow(struct btrfs_inode *inode, loff_t pos,
15711571
}
15721572

15731573
ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
1574-
NULL, NULL, NULL);
1574+
NULL, NULL, NULL, false);
15751575
if (ret <= 0) {
15761576
ret = 0;
15771577
if (!nowait)

‎fs/btrfs/free-space-cache.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,6 @@ static int __btrfs_wait_cache_io(struct btrfs_root *root,
11861186
ret = update_cache_item(trans, root, inode, path, offset,
11871187
io_ctl->entries, io_ctl->bitmaps);
11881188
out:
1189-
io_ctl_free(io_ctl);
11901189
if (ret) {
11911190
invalidate_inode_pages2(inode->i_mapping);
11921191
BTRFS_I(inode)->generation = 0;
@@ -1347,6 +1346,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
13471346
* them out later
13481347
*/
13491348
io_ctl_drop_pages(io_ctl);
1349+
io_ctl_free(io_ctl);
13501350

13511351
unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
13521352
i_size_read(inode) - 1, &cached_state);

‎fs/btrfs/inode.c‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
16101610
goto out_check;
16111611
ret = btrfs_cross_ref_exist(root, ino,
16121612
found_key.offset -
1613-
extent_offset, disk_bytenr);
1613+
extent_offset, disk_bytenr, false);
16141614
if (ret) {
16151615
/*
16161616
* ret could be -EIO if the above fails to read
@@ -2161,11 +2161,8 @@ static blk_status_t btrfs_submit_bio_start(void *private_data, struct bio *bio,
21612161
u64 bio_offset)
21622162
{
21632163
struct inode *inode = private_data;
2164-
blk_status_t ret = 0;
21652164

2166-
ret = btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0);
2167-
BUG_ON(ret); /* -ENOMEM */
2168-
return 0;
2165+
return btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0);
21692166
}
21702167

21712168
/*
@@ -6953,6 +6950,8 @@ static struct extent_map *btrfs_new_extent_direct(struct btrfs_inode *inode,
69536950
* @orig_start: (optional) Return the original file offset of the file extent
69546951
* @orig_len: (optional) Return the original on-disk length of the file extent
69556952
* @ram_bytes: (optional) Return the ram_bytes of the file extent
6953+
* @strict: if true, omit optimizations that might force us into unnecessary
6954+
* cow. e.g., don't trust generation number.
69566955
*
69576956
* This function will flush ordered extents in the range to ensure proper
69586957
* nocow checks for (nowait == false) case.
@@ -6967,7 +6966,7 @@ static struct extent_map *btrfs_new_extent_direct(struct btrfs_inode *inode,
69676966
*/
69686967
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
69696968
u64 *orig_start, u64 *orig_block_len,
6970-
u64 *ram_bytes)
6969+
u64 *ram_bytes, bool strict)
69716970
{
69726971
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
69736972
struct btrfs_path *path;
@@ -7045,8 +7044,9 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
70457044
* Do the same check as in btrfs_cross_ref_exist but without the
70467045
* unnecessary search.
70477046
*/
7048-
if (btrfs_file_extent_generation(leaf, fi) <=
7049-
btrfs_root_last_snapshot(&root->root_item))
7047+
if (!strict &&
7048+
(btrfs_file_extent_generation(leaf, fi) <=
7049+
btrfs_root_last_snapshot(&root->root_item)))
70507050
goto out;
70517051

70527052
backref_offset = btrfs_file_extent_offset(leaf, fi);
@@ -7082,7 +7082,8 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
70827082
*/
70837083

70847084
ret = btrfs_cross_ref_exist(root, btrfs_ino(BTRFS_I(inode)),
7085-
key.offset - backref_offset, disk_bytenr);
7085+
key.offset - backref_offset, disk_bytenr,
7086+
strict);
70867087
if (ret) {
70877088
ret = 0;
70887089
goto out;
@@ -7303,7 +7304,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
73037304
block_start = em->block_start + (start - em->start);
73047305

73057306
if (can_nocow_extent(inode, start, &len, &orig_start,
7306-
&orig_block_len, &ram_bytes) == 1 &&
7307+
&orig_block_len, &ram_bytes, false) == 1 &&
73077308
btrfs_inc_nocow_writers(fs_info, block_start)) {
73087309
struct extent_map *em2;
73097310

@@ -7619,10 +7620,8 @@ static blk_status_t btrfs_submit_bio_start_direct_io(void *private_data,
76197620
struct bio *bio, u64 offset)
76207621
{
76217622
struct inode *inode = private_data;
7622-
blk_status_t ret;
7623-
ret = btrfs_csum_one_bio(BTRFS_I(inode), bio, offset, 1);
7624-
BUG_ON(ret); /* -ENOMEM */
7625-
return 0;
7623+
7624+
return btrfs_csum_one_bio(BTRFS_I(inode), bio, offset, 1);
76267625
}
76277626

76287627
static void btrfs_end_dio_bio(struct bio *bio)
@@ -10136,7 +10135,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
1013610135
free_extent_map(em);
1013710136
em = NULL;
1013810137

10139-
ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL);
10138+
ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL, true);
1014010139
if (ret < 0) {
1014110140
goto out;
1014210141
} else if (ret) {

‎fs/btrfs/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
625625
} else if (strncmp(args[0].from, "lzo", 3) == 0) {
626626
compress_type = "lzo";
627627
info->compress_type = BTRFS_COMPRESS_LZO;
628+
info->compress_level = 0;
628629
btrfs_set_opt(info->mount_opt, COMPRESS);
629630
btrfs_clear_opt(info->mount_opt, NODATACOW);
630631
btrfs_clear_opt(info->mount_opt, NODATASUM);

‎fs/btrfs/tree-log.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,11 +3449,13 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
34493449
btrfs_free_path(path);
34503450
out_unlock:
34513451
mutex_unlock(&dir->log_mutex);
3452-
if (ret == -ENOSPC) {
3452+
if (err == -ENOSPC) {
34533453
btrfs_set_log_full_commit(trans);
3454-
ret = 0;
3455-
} else if (ret < 0)
3456-
btrfs_abort_transaction(trans, ret);
3454+
err = 0;
3455+
} else if (err < 0 && err != -ENOENT) {
3456+
/* ENOENT can be returned if the entry hasn't been fsynced yet */
3457+
btrfs_abort_transaction(trans, err);
3458+
}
34573459

34583460
btrfs_end_log_trans(root);
34593461

0 commit comments

Comments
 (0)