Skip to content

Commit c44db6c

Browse files
committed
Merge tag 'for-7.0-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "One-liner or short fixes for minor/moderate problems reported recently: - fixes or level adjustments of error messages - fix leaked transaction handles after aborted transactions, when using the remap tree feature - fix a few leaked chunk maps after errors - fix leaked page array in io_uring encoded read if an error occurs and the 'finished' is not called - fix double release of reserved extents when doing a range COW - don't commit super block when the filesystem is in shutdown state - fix squota accounting condition when checking members vs parent usage - other error handling fixes" * tag 'for-7.0-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: check block group lookup in remove_range_from_remap_tree() btrfs: fix transaction handle leaks in btrfs_last_identity_remap_gone() btrfs: fix chunk map leak in btrfs_map_block() after btrfs_translate_remap() btrfs: fix chunk map leak in btrfs_map_block() after btrfs_chunk_map_num_copies() btrfs: fix compat mask in error messages in btrfs_check_features() btrfs: print correct subvol num if active swapfile prevents deletion btrfs: fix warning in scrub_verify_one_metadata() btrfs: fix objectid value in error message in check_extent_data_ref() btrfs: fix incorrect key offset in error message in check_dev_extent_item() btrfs: fix error message order of parameters in btrfs_delete_delayed_dir_index() btrfs: don't commit the super block when unmounting a shutdown filesystem btrfs: free pages on error in btrfs_uring_read_extent() btrfs: fix referenced/exclusive check in squota_check_parent_usage() btrfs: remove pointless WARN_ON() in cache_save_setup() btrfs: convert log messages to error level in btrfs_replay_log() btrfs: remove btrfs_handle_fs_error() after failure to recover log trees btrfs: remove redundant warning message in btrfs_check_uuid_tree() btrfs: change warning messages to error level in open_ctree() btrfs: fix a double release on reserved extents in cow_one_range() btrfs: handle discard errors in in btrfs_finish_extent_commit()
2 parents af4e9ef + f8db800 commit c44db6c

File tree

11 files changed

+67
-28
lines changed

11 files changed

+67
-28
lines changed

fs/btrfs/block-group.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3340,7 +3340,6 @@ static int cache_save_setup(struct btrfs_block_group *block_group,
33403340
btrfs_abort_transaction(trans, ret);
33413341
goto out_put;
33423342
}
3343-
WARN_ON(ret);
33443343

33453344
/* We've already setup this transaction, go ahead and exit */
33463345
if (block_group->cache_generation == trans->transid &&

fs/btrfs/delayed-inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
16571657
if (unlikely(ret)) {
16581658
btrfs_err(trans->fs_info,
16591659
"failed to add delayed dir index item, root: %llu, inode: %llu, index: %llu, error: %d",
1660-
index, btrfs_root_id(node->root), node->inode_id, ret);
1660+
btrfs_root_id(node->root), node->inode_id, index, ret);
16611661
btrfs_delayed_item_release_metadata(dir->root, item);
16621662
btrfs_release_delayed_item(item);
16631663
}

fs/btrfs/disk-io.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
19941994
int level = btrfs_super_log_root_level(disk_super);
19951995

19961996
if (unlikely(fs_devices->rw_devices == 0)) {
1997-
btrfs_warn(fs_info, "log replay required on RO media");
1997+
btrfs_err(fs_info, "log replay required on RO media");
19981998
return -EIO;
19991999
}
20002000

@@ -2008,9 +2008,9 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
20082008
check.owner_root = BTRFS_TREE_LOG_OBJECTID;
20092009
log_tree_root->node = read_tree_block(fs_info, bytenr, &check);
20102010
if (IS_ERR(log_tree_root->node)) {
2011-
btrfs_warn(fs_info, "failed to read log tree");
20122011
ret = PTR_ERR(log_tree_root->node);
20132012
log_tree_root->node = NULL;
2013+
btrfs_err(fs_info, "failed to read log tree with error: %d", ret);
20142014
btrfs_put_root(log_tree_root);
20152015
return ret;
20162016
}
@@ -2023,9 +2023,9 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
20232023
/* returns with log_tree_root freed on success */
20242024
ret = btrfs_recover_log_trees(log_tree_root);
20252025
btrfs_put_root(log_tree_root);
2026-
if (ret) {
2027-
btrfs_handle_fs_error(fs_info, ret,
2028-
"Failed to recover log tree");
2026+
if (unlikely(ret)) {
2027+
ASSERT(BTRFS_FS_ERROR(fs_info) != 0);
2028+
btrfs_err(fs_info, "failed to recover log trees with error: %d", ret);
20292029
return ret;
20302030
}
20312031

@@ -2972,7 +2972,6 @@ static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info)
29722972
task = kthread_run(btrfs_uuid_rescan_kthread, fs_info, "btrfs-uuid");
29732973
if (IS_ERR(task)) {
29742974
/* fs_info->update_uuid_tree_gen remains 0 in all error case */
2975-
btrfs_warn(fs_info, "failed to start uuid_rescan task");
29762975
up(&fs_info->uuid_tree_rescan_sem);
29772976
return PTR_ERR(task);
29782977
}
@@ -3188,7 +3187,7 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
31883187
if (incompat & ~BTRFS_FEATURE_INCOMPAT_SUPP) {
31893188
btrfs_err(fs_info,
31903189
"cannot mount because of unknown incompat features (0x%llx)",
3191-
incompat);
3190+
incompat & ~BTRFS_FEATURE_INCOMPAT_SUPP);
31923191
return -EINVAL;
31933192
}
31943193

@@ -3220,7 +3219,7 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
32203219
if (compat_ro_unsupp && is_rw_mount) {
32213220
btrfs_err(fs_info,
32223221
"cannot mount read-write because of unknown compat_ro features (0x%llx)",
3223-
compat_ro);
3222+
compat_ro_unsupp);
32243223
return -EINVAL;
32253224
}
32263225

@@ -3233,7 +3232,7 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
32333232
!btrfs_test_opt(fs_info, NOLOGREPLAY)) {
32343233
btrfs_err(fs_info,
32353234
"cannot replay dirty log with unsupported compat_ro features (0x%llx), try rescue=nologreplay",
3236-
compat_ro);
3235+
compat_ro_unsupp);
32373236
return -EINVAL;
32383237
}
32393238

@@ -3642,7 +3641,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
36423641
fs_info->fs_root = btrfs_get_fs_root(fs_info, BTRFS_FS_TREE_OBJECTID, true);
36433642
if (IS_ERR(fs_info->fs_root)) {
36443643
ret = PTR_ERR(fs_info->fs_root);
3645-
btrfs_warn(fs_info, "failed to read fs tree: %d", ret);
3644+
btrfs_err(fs_info, "failed to read fs tree: %d", ret);
36463645
fs_info->fs_root = NULL;
36473646
goto fail_qgroup;
36483647
}
@@ -3663,8 +3662,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
36633662
btrfs_info(fs_info, "checking UUID tree");
36643663
ret = btrfs_check_uuid_tree(fs_info);
36653664
if (ret) {
3666-
btrfs_warn(fs_info,
3667-
"failed to check the UUID tree: %d", ret);
3665+
btrfs_err(fs_info, "failed to check the UUID tree: %d", ret);
36683666
close_ctree(fs_info);
36693667
return ret;
36703668
}
@@ -4399,9 +4397,17 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
43994397
*/
44004398
btrfs_flush_workqueue(fs_info->delayed_workers);
44014399

4402-
ret = btrfs_commit_super(fs_info);
4403-
if (ret)
4404-
btrfs_err(fs_info, "commit super ret %d", ret);
4400+
/*
4401+
* If the filesystem is shutdown, then an attempt to commit the
4402+
* super block (or any write) will just fail. Since we freeze
4403+
* the filesystem before shutting it down, the filesystem is in
4404+
* a consistent state and we don't need to commit super blocks.
4405+
*/
4406+
if (!btrfs_is_shutdown(fs_info)) {
4407+
ret = btrfs_commit_super(fs_info);
4408+
if (ret)
4409+
btrfs_err(fs_info, "commit super block returned %d", ret);
4410+
}
44054411
}
44064412

44074413
kthread_stop(fs_info->transaction_kthread);

fs/btrfs/extent-tree.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2933,9 +2933,15 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
29332933
while (!TRANS_ABORTED(trans) && cached_state) {
29342934
struct extent_state *next_state;
29352935

2936-
if (btrfs_test_opt(fs_info, DISCARD_SYNC))
2936+
if (btrfs_test_opt(fs_info, DISCARD_SYNC)) {
29372937
ret = btrfs_discard_extent(fs_info, start,
29382938
end + 1 - start, NULL, true);
2939+
if (ret) {
2940+
btrfs_warn(fs_info,
2941+
"discard failed for extent [%llu, %llu]: errno=%d %s",
2942+
start, end, ret, btrfs_decode_error(ret));
2943+
}
2944+
}
29392945

29402946
next_state = btrfs_next_extent_state(unpin, cached_state);
29412947
btrfs_clear_extent_dirty(unpin, start, end, &cached_state);

fs/btrfs/inode.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,25 @@ static int cow_one_range(struct btrfs_inode *inode, struct folio *locked_folio,
13921392
return ret;
13931393

13941394
free_reserved:
1395+
/*
1396+
* If we have reserved an extent for the current range and failed to
1397+
* create the respective extent map or ordered extent, it means that
1398+
* when we reserved the extent we decremented the extent's size from
1399+
* the data space_info's bytes_may_use counter and
1400+
* incremented the space_info's bytes_reserved counter by the same
1401+
* amount.
1402+
*
1403+
* We must make sure extent_clear_unlock_delalloc() does not try
1404+
* to decrement again the data space_info's bytes_may_use counter, which
1405+
* will be handled by btrfs_free_reserved_extent().
1406+
*
1407+
* Therefore we do not pass it the flag EXTENT_CLEAR_DATA_RESV, but only
1408+
* EXTENT_CLEAR_META_RESV.
1409+
*/
13951410
extent_clear_unlock_delalloc(inode, file_offset, cur_end, locked_folio, cached,
13961411
EXTENT_LOCKED | EXTENT_DELALLOC |
13971412
EXTENT_DELALLOC_NEW |
1398-
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
1413+
EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV,
13991414
PAGE_UNLOCK | PAGE_START_WRITEBACK |
14001415
PAGE_END_WRITEBACK);
14011416
btrfs_qgroup_free_data(inode, NULL, file_offset, cur_len, NULL);
@@ -4764,7 +4779,7 @@ int btrfs_delete_subvolume(struct btrfs_inode *dir, struct dentry *dentry)
47644779
spin_unlock(&dest->root_item_lock);
47654780
btrfs_warn(fs_info,
47664781
"attempt to delete subvolume %llu with active swapfile",
4767-
btrfs_root_id(root));
4782+
btrfs_root_id(dest));
47684783
ret = -EPERM;
47694784
goto out_up_write;
47704785
}

fs/btrfs/ioctl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4581,7 +4581,7 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
45814581
{
45824582
struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp));
45834583
struct extent_io_tree *io_tree = &inode->io_tree;
4584-
struct page **pages;
4584+
struct page **pages = NULL;
45854585
struct btrfs_uring_priv *priv = NULL;
45864586
unsigned long nr_pages;
45874587
int ret;
@@ -4639,6 +4639,11 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
46394639
btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
46404640
btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
46414641
kfree(priv);
4642+
for (int i = 0; i < nr_pages; i++) {
4643+
if (pages[i])
4644+
__free_page(pages[i]);
4645+
}
4646+
kfree(pages);
46424647
return ret;
46434648
}
46444649

fs/btrfs/qgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static bool squota_check_parent_usage(struct btrfs_fs_info *fs_info, struct btrf
370370
nr_members++;
371371
}
372372
mismatch = (parent->excl != excl_sum || parent->rfer != rfer_sum ||
373-
parent->excl_cmpr != excl_cmpr_sum || parent->rfer_cmpr != excl_cmpr_sum);
373+
parent->excl_cmpr != excl_cmpr_sum || parent->rfer_cmpr != rfer_cmpr_sum);
374374

375375
WARN(mismatch,
376376
"parent squota qgroup %hu/%llu has mismatched usage from its %d members. "

fs/btrfs/relocation.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,6 +4723,7 @@ int btrfs_last_identity_remap_gone(struct btrfs_chunk_map *chunk_map,
47234723
ret = btrfs_remove_dev_extents(trans, chunk_map);
47244724
if (unlikely(ret)) {
47254725
btrfs_abort_transaction(trans, ret);
4726+
btrfs_end_transaction(trans);
47264727
return ret;
47274728
}
47284729

@@ -4732,6 +4733,7 @@ int btrfs_last_identity_remap_gone(struct btrfs_chunk_map *chunk_map,
47324733
if (unlikely(ret)) {
47334734
mutex_unlock(&trans->fs_info->chunk_mutex);
47344735
btrfs_abort_transaction(trans, ret);
4736+
btrfs_end_transaction(trans);
47354737
return ret;
47364738
}
47374739
}
@@ -4750,6 +4752,7 @@ int btrfs_last_identity_remap_gone(struct btrfs_chunk_map *chunk_map,
47504752
ret = remove_chunk_stripes(trans, chunk_map, path);
47514753
if (unlikely(ret)) {
47524754
btrfs_abort_transaction(trans, ret);
4755+
btrfs_end_transaction(trans);
47534756
return ret;
47544757
}
47554758

@@ -5982,6 +5985,9 @@ static int remove_range_from_remap_tree(struct btrfs_trans_handle *trans,
59825985
struct btrfs_block_group *dest_bg;
59835986

59845987
dest_bg = btrfs_lookup_block_group(fs_info, new_addr);
5988+
if (unlikely(!dest_bg))
5989+
return -EUCLEAN;
5990+
59855991
adjust_block_group_remap_bytes(trans, dest_bg, -overlap_length);
59865992
btrfs_put_block_group(dest_bg);
59875993
ret = btrfs_add_to_free_space_tree(trans,

fs/btrfs/scrub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ static void scrub_verify_one_metadata(struct scrub_stripe *stripe, int sector_nr
743743
btrfs_warn_rl(fs_info,
744744
"scrub: tree block %llu mirror %u has bad fsid, has %pU want %pU",
745745
logical, stripe->mirror_num,
746-
header->fsid, fs_info->fs_devices->fsid);
746+
header->fsid, fs_info->fs_devices->metadata_uuid);
747747
return;
748748
}
749749
if (memcmp(header->chunk_tree_uuid, fs_info->chunk_tree_uuid,

fs/btrfs/tree-checker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ static int check_extent_data_ref(struct extent_buffer *leaf,
17401740
objectid > BTRFS_LAST_FREE_OBJECTID)) {
17411741
extent_err(leaf, slot,
17421742
"invalid extent data backref objectid value %llu",
1743-
root);
1743+
objectid);
17441744
return -EUCLEAN;
17451745
}
17461746
if (unlikely(!IS_ALIGNED(offset, leaf->fs_info->sectorsize))) {
@@ -1921,7 +1921,7 @@ static int check_dev_extent_item(const struct extent_buffer *leaf,
19211921
if (unlikely(prev_key->offset + prev_len > key->offset)) {
19221922
generic_err(leaf, slot,
19231923
"dev extent overlap, prev offset %llu len %llu current offset %llu",
1924-
prev_key->objectid, prev_len, key->offset);
1924+
prev_key->offset, prev_len, key->offset);
19251925
return -EUCLEAN;
19261926
}
19271927
}

0 commit comments

Comments
 (0)