Skip to content

Commit b3f1da2

Browse files
committed
Merge tag 'for-7.0-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - multiple error handling fixes of unexpected conditions - reset block group size class once it becomes empty so that its class can be changed - error message level adjustments - fixes of returned error values - use correct block reserve for delayed refs * tag 'for-7.0-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: fix invalid leaf access in btrfs_quota_enable() if ref key not found btrfs: fix lost error return in btrfs_find_orphan_roots() btrfs: fix lost return value on error in finish_verity() btrfs: change unaligned root messages to error level in btrfs_validate_super() btrfs: use the correct type to initialize block reserve for delayed refs btrfs: do not ASSERT() when the fs flips RO inside btrfs_repair_io_failure() btrfs: reset block group size class when it becomes empty btrfs: replace BUG() with error handling in __btrfs_balance() btrfs: handle unexpected exact match in btrfs_set_inode_index_count()
2 parents 233a0c0 + ecb7c24 commit b3f1da2

10 files changed

Lines changed: 56 additions & 21 deletions

File tree

fs/btrfs/bio.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,6 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 fileoff,
934934
struct bio *bio = NULL;
935935
int ret = 0;
936936

937-
ASSERT(!(fs_info->sb->s_flags & SB_RDONLY));
938937
BUG_ON(!mirror_num);
939938

940939
/* Basic alignment checks. */
@@ -946,6 +945,13 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 fileoff,
946945
ASSERT(step <= length);
947946
ASSERT(is_power_of_2(step));
948947

948+
/*
949+
* The fs either mounted RO or hit critical errors, no need
950+
* to continue repairing.
951+
*/
952+
if (unlikely(sb_rdonly(fs_info->sb)))
953+
return 0;
954+
949955
if (btrfs_repair_one_zone(fs_info, logical))
950956
return 0;
951957

fs/btrfs/block-group.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,6 +3760,14 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
37603760
return ret;
37613761
}
37623762

3763+
static void btrfs_maybe_reset_size_class(struct btrfs_block_group *bg)
3764+
{
3765+
lockdep_assert_held(&bg->lock);
3766+
if (btrfs_block_group_should_use_size_class(bg) &&
3767+
bg->used == 0 && bg->reserved == 0)
3768+
bg->size_class = BTRFS_BG_SZ_NONE;
3769+
}
3770+
37633771
int btrfs_update_block_group(struct btrfs_trans_handle *trans,
37643772
u64 bytenr, u64 num_bytes, bool alloc)
37653773
{
@@ -3824,6 +3832,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
38243832
old_val -= num_bytes;
38253833
cache->used = old_val;
38263834
cache->pinned += num_bytes;
3835+
btrfs_maybe_reset_size_class(cache);
38273836
btrfs_space_info_update_bytes_pinned(space_info, num_bytes);
38283837
space_info->bytes_used -= num_bytes;
38293838
space_info->disk_used -= num_bytes * factor;
@@ -3952,6 +3961,7 @@ void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes,
39523961
spin_lock(&cache->lock);
39533962
bg_ro = cache->ro;
39543963
cache->reserved -= num_bytes;
3964+
btrfs_maybe_reset_size_class(cache);
39553965
if (is_delalloc)
39563966
cache->delalloc_bytes -= num_bytes;
39573967
spin_unlock(&cache->lock);

fs/btrfs/block-rsv.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ u64 btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
276276
struct btrfs_block_rsv *target = NULL;
277277

278278
/*
279-
* If we are a delayed block reserve then push to the global rsv,
280-
* otherwise dump into the global delayed reserve if it is not full.
279+
* If we are a delayed refs block reserve then push to the global
280+
* reserve, otherwise dump into the global delayed refs reserve if it is
281+
* not full.
281282
*/
282-
if (block_rsv->type == BTRFS_BLOCK_RSV_DELOPS)
283+
if (block_rsv->type == BTRFS_BLOCK_RSV_DELREFS)
283284
target = global_rsv;
284285
else if (block_rsv != global_rsv && !btrfs_block_rsv_full(delayed_rsv))
285286
target = delayed_rsv;

fs/btrfs/disk-io.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,18 +2416,18 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
24162416

24172417
/* Root alignment check */
24182418
if (!IS_ALIGNED(btrfs_super_root(sb), sectorsize)) {
2419-
btrfs_warn(fs_info, "tree_root block unaligned: %llu",
2420-
btrfs_super_root(sb));
2419+
btrfs_err(fs_info, "tree_root block unaligned: %llu",
2420+
btrfs_super_root(sb));
24212421
ret = -EINVAL;
24222422
}
24232423
if (!IS_ALIGNED(btrfs_super_chunk_root(sb), sectorsize)) {
2424-
btrfs_warn(fs_info, "chunk_root block unaligned: %llu",
2424+
btrfs_err(fs_info, "chunk_root block unaligned: %llu",
24252425
btrfs_super_chunk_root(sb));
24262426
ret = -EINVAL;
24272427
}
24282428
if (!IS_ALIGNED(btrfs_super_log_root(sb), sectorsize)) {
2429-
btrfs_warn(fs_info, "log_root block unaligned: %llu",
2430-
btrfs_super_log_root(sb));
2429+
btrfs_err(fs_info, "log_root block unaligned: %llu",
2430+
btrfs_super_log_root(sb));
24312431
ret = -EINVAL;
24322432
}
24332433

fs/btrfs/inode.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6146,9 +6146,18 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode)
61466146
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
61476147
if (ret < 0)
61486148
return ret;
6149-
/* FIXME: we should be able to handle this */
6150-
if (ret == 0)
6151-
return ret;
6149+
6150+
if (unlikely(ret == 0)) {
6151+
/*
6152+
* Key with offset -1 found, there would have to exist a dir
6153+
* index item with such offset, but this is out of the valid
6154+
* range.
6155+
*/
6156+
btrfs_err(root->fs_info,
6157+
"unexpected exact match for DIR_INDEX key, inode %llu",
6158+
btrfs_ino(inode));
6159+
return -EUCLEAN;
6160+
}
61526161

61536162
if (path->slots[0] == 0) {
61546163
inode->index_cnt = BTRFS_DIR_START_INDEX;

fs/btrfs/qgroup.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,14 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info,
11691169
}
11701170
if (ret > 0) {
11711171
/*
1172-
* Shouldn't happen, but in case it does we
1173-
* don't need to do the btrfs_next_item, just
1174-
* continue.
1172+
* Shouldn't happen because the key should still
1173+
* be there (return 0), but in case it does it
1174+
* means we have reached the end of the tree -
1175+
* there are no more leaves with items that have
1176+
* a key greater than or equals to @found_key,
1177+
* so just stop the search loop.
11751178
*/
1176-
continue;
1179+
break;
11771180
}
11781181
}
11791182
ret = btrfs_next_item(tree_root, path);

fs/btrfs/root-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
257257
root = btrfs_get_fs_root(fs_info, root_objectid, false);
258258
ret = PTR_ERR_OR_ZERO(root);
259259
if (ret && ret != -ENOENT) {
260-
break;
260+
return ret;
261261
} else if (ret == -ENOENT) {
262262
struct btrfs_trans_handle *trans;
263263

fs/btrfs/transaction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
726726

727727
h->type = type;
728728
INIT_LIST_HEAD(&h->new_bgs);
729-
btrfs_init_metadata_block_rsv(fs_info, &h->delayed_rsv, BTRFS_BLOCK_RSV_DELOPS);
729+
btrfs_init_metadata_block_rsv(fs_info, &h->delayed_rsv, BTRFS_BLOCK_RSV_DELREFS);
730730

731731
smp_mb();
732732
if (cur_trans->state >= TRANS_STATE_COMMIT_START &&

fs/btrfs/verity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc,
552552
btrfs_set_fs_compat_ro(root->fs_info, VERITY);
553553
end_trans:
554554
btrfs_end_transaction(trans);
555-
return 0;
555+
return ret;
556556

557557
}
558558

fs/btrfs/volumes.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,8 +4367,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
43674367
* this shouldn't happen, it means the last relocate
43684368
* failed
43694369
*/
4370-
if (ret == 0)
4371-
BUG(); /* FIXME break ? */
4370+
if (unlikely(ret == 0)) {
4371+
btrfs_err(fs_info,
4372+
"unexpected exact match of CHUNK_ITEM in chunk tree, offset 0x%llx",
4373+
key.offset);
4374+
mutex_unlock(&fs_info->reclaim_bgs_lock);
4375+
ret = -EUCLEAN;
4376+
goto error;
4377+
}
43724378

43734379
ret = btrfs_previous_item(chunk_root, path, 0,
43744380
BTRFS_CHUNK_ITEM_KEY);

0 commit comments

Comments
 (0)