Skip to content

Commit fc7b76c

Browse files
committed
Merge tag 'for-6.2-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "A few more regression and regular fixes: - regressions: - fix assertion condition using = instead of == - fix false alert on bad tree level check - fix off-by-one error in delalloc search during lseek - fix compat ro feature check at read-write remount - handle case when read-repair happens with ongoing device replace - updated error messages" * tag 'for-6.2-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: fix compat_ro checks against remount btrfs: always report error in run_one_delayed_ref() btrfs: handle case when repair happens with dev-replace btrfs: fix off-by-one in delalloc search during lseek btrfs: fix false alert on bad tree level check btrfs: add error message for metadata level mismatch btrfs: fix ASSERT em->len condition in btrfs_get_extent
2 parents a389e54 + 2ba48b2 commit fc7b76c

File tree

9 files changed

+53
-16
lines changed

9 files changed

+53
-16
lines changed

fs/btrfs/bio.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,16 @@ int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
329329
&map_length, &bioc, mirror_num);
330330
if (ret)
331331
goto out_counter_dec;
332-
BUG_ON(mirror_num != bioc->mirror_num);
332+
/*
333+
* This happens when dev-replace is also running, and the
334+
* mirror_num indicates the dev-replace target.
335+
*
336+
* In this case, we don't need to do anything, as the read
337+
* error just means the replace progress hasn't reached our
338+
* read range, and later replace routine would handle it well.
339+
*/
340+
if (mirror_num != bioc->mirror_num)
341+
goto out_counter_dec;
333342
}
334343

335344
sector = bioc->stripes[bioc->mirror_num - 1].physical >> 9;

fs/btrfs/disk-io.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ static int validate_extent_buffer(struct extent_buffer *eb,
530530
}
531531

532532
if (found_level != check->level) {
533+
btrfs_err(fs_info,
534+
"level verify failed on logical %llu mirror %u wanted %u found %u",
535+
eb->start, eb->read_mirror, check->level, found_level);
533536
ret = -EIO;
534537
goto out;
535538
}
@@ -3381,6 +3384,8 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
33813384
/*
33823385
* Do various sanity and dependency checks of different features.
33833386
*
3387+
* @is_rw_mount: If the mount is read-write.
3388+
*
33843389
* This is the place for less strict checks (like for subpage or artificial
33853390
* feature dependencies).
33863391
*
@@ -3391,7 +3396,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
33913396
* (space cache related) can modify on-disk format like free space tree and
33923397
* screw up certain feature dependencies.
33933398
*/
3394-
int btrfs_check_features(struct btrfs_fs_info *fs_info, struct super_block *sb)
3399+
int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
33953400
{
33963401
struct btrfs_super_block *disk_super = fs_info->super_copy;
33973402
u64 incompat = btrfs_super_incompat_flags(disk_super);
@@ -3430,7 +3435,7 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, struct super_block *sb)
34303435
if (btrfs_super_nodesize(disk_super) > PAGE_SIZE)
34313436
incompat |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA;
34323437

3433-
if (compat_ro_unsupp && !sb_rdonly(sb)) {
3438+
if (compat_ro_unsupp && is_rw_mount) {
34343439
btrfs_err(fs_info,
34353440
"cannot mount read-write because of unknown compat_ro features (0x%llx)",
34363441
compat_ro);
@@ -3633,7 +3638,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
36333638
goto fail_alloc;
36343639
}
36353640

3636-
ret = btrfs_check_features(fs_info, sb);
3641+
ret = btrfs_check_features(fs_info, !sb_rdonly(sb));
36373642
if (ret < 0) {
36383643
err = ret;
36393644
goto fail_alloc;

fs/btrfs/disk-io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int __cold open_ctree(struct super_block *sb,
5050
void __cold close_ctree(struct btrfs_fs_info *fs_info);
5151
int btrfs_validate_super(struct btrfs_fs_info *fs_info,
5252
struct btrfs_super_block *sb, int mirror_num);
53-
int btrfs_check_features(struct btrfs_fs_info *fs_info, struct super_block *sb);
53+
int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount);
5454
int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
5555
struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
5656
struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,

fs/btrfs/extent-io-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ u64 count_range_bits(struct extent_io_tree *tree,
15511551
u64 last = 0;
15521552
int found = 0;
15531553

1554-
if (WARN_ON(search_end <= cur_start))
1554+
if (WARN_ON(search_end < cur_start))
15551555
return 0;
15561556

15571557
spin_lock(&tree->lock);

fs/btrfs/extent-tree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,11 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
17131713
BUG();
17141714
if (ret && insert_reserved)
17151715
btrfs_pin_extent(trans, node->bytenr, node->num_bytes, 1);
1716+
if (ret < 0)
1717+
btrfs_err(trans->fs_info,
1718+
"failed to run delayed ref for logical %llu num_bytes %llu type %u action %u ref_mod %d: %d",
1719+
node->bytenr, node->num_bytes, node->type,
1720+
node->action, node->ref_mod, ret);
17161721
return ret;
17171722
}
17181723

@@ -1954,8 +1959,6 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans,
19541959
if (ret) {
19551960
unselect_delayed_ref_head(delayed_refs, locked_ref);
19561961
btrfs_put_delayed_ref(ref);
1957-
btrfs_debug(fs_info, "run_one_delayed_ref returned %d",
1958-
ret);
19591962
return ret;
19601963
}
19611964

fs/btrfs/extent_io.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ struct btrfs_bio_ctrl {
103103
u32 len_to_oe_boundary;
104104
btrfs_bio_end_io_t end_io_func;
105105

106+
/*
107+
* This is for metadata read, to provide the extra needed verification
108+
* info. This has to be provided for submit_one_bio(), as
109+
* submit_one_bio() can submit a bio if it ends at stripe boundary. If
110+
* no such parent_check is provided, the metadata can hit false alert at
111+
* endio time.
112+
*/
113+
struct btrfs_tree_parent_check *parent_check;
114+
106115
/*
107116
* Tell writepage not to lock the state bits for this range, it still
108117
* does the unlocking.
@@ -133,13 +142,24 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
133142

134143
btrfs_bio(bio)->file_offset = page_offset(bv->bv_page) + bv->bv_offset;
135144

136-
if (!is_data_inode(&inode->vfs_inode))
145+
if (!is_data_inode(&inode->vfs_inode)) {
146+
if (btrfs_op(bio) != BTRFS_MAP_WRITE) {
147+
/*
148+
* For metadata read, we should have the parent_check,
149+
* and copy it to bbio for metadata verification.
150+
*/
151+
ASSERT(bio_ctrl->parent_check);
152+
memcpy(&btrfs_bio(bio)->parent_check,
153+
bio_ctrl->parent_check,
154+
sizeof(struct btrfs_tree_parent_check));
155+
}
137156
btrfs_submit_metadata_bio(inode, bio, mirror_num);
138-
else if (btrfs_op(bio) == BTRFS_MAP_WRITE)
157+
} else if (btrfs_op(bio) == BTRFS_MAP_WRITE) {
139158
btrfs_submit_data_write_bio(inode, bio, mirror_num);
140-
else
159+
} else {
141160
btrfs_submit_data_read_bio(inode, bio, mirror_num,
142161
bio_ctrl->compress_type);
162+
}
143163

144164
/* The bio is owned by the end_io handler now */
145165
bio_ctrl->bio = NULL;
@@ -4829,6 +4849,7 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
48294849
struct extent_state *cached_state = NULL;
48304850
struct btrfs_bio_ctrl bio_ctrl = {
48314851
.mirror_num = mirror_num,
4852+
.parent_check = check,
48324853
};
48334854
int ret = 0;
48344855

@@ -4878,7 +4899,6 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
48784899
*/
48794900
atomic_dec(&eb->io_pages);
48804901
}
4881-
memcpy(&btrfs_bio(bio_ctrl.bio)->parent_check, check, sizeof(*check));
48824902
submit_one_bio(&bio_ctrl);
48834903
if (ret || wait != WAIT_COMPLETE) {
48844904
free_extent_state(cached_state);
@@ -4905,6 +4925,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num,
49054925
unsigned long num_reads = 0;
49064926
struct btrfs_bio_ctrl bio_ctrl = {
49074927
.mirror_num = mirror_num,
4928+
.parent_check = check,
49084929
};
49094930

49104931
if (test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags))
@@ -4996,7 +5017,6 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num,
49965017
}
49975018
}
49985019

4999-
memcpy(&btrfs_bio(bio_ctrl.bio)->parent_check, check, sizeof(*check));
50005020
submit_one_bio(&bio_ctrl);
50015021

50025022
if (ret || wait != WAIT_COMPLETE)

fs/btrfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,7 @@ bool btrfs_find_delalloc_in_range(struct btrfs_inode *inode, u64 start, u64 end,
33543354
bool search_io_tree = true;
33553355
bool ret = false;
33563356

3357-
while (cur_offset < end) {
3357+
while (cur_offset <= end) {
33583358
u64 delalloc_start;
33593359
u64 delalloc_end;
33603360
bool delalloc;

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7092,7 +7092,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
70927092
* Other members are not utilized for inline extents.
70937093
*/
70947094
ASSERT(em->block_start == EXTENT_MAP_INLINE);
7095-
ASSERT(em->len = fs_info->sectorsize);
7095+
ASSERT(em->len == fs_info->sectorsize);
70967096

70977097
ret = read_inline_extent(inode, path, page);
70987098
if (ret < 0)

fs/btrfs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
17051705
if (ret)
17061706
goto restore;
17071707

1708-
ret = btrfs_check_features(fs_info, sb);
1708+
ret = btrfs_check_features(fs_info, !(*flags & SB_RDONLY));
17091709
if (ret < 0)
17101710
goto restore;
17111711

0 commit comments

Comments
 (0)