Skip to content

Commit 76c7f88

Browse files
committed
Merge tag 'for-6.4-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull more btrfs fixes from David Sterba: - fix incorrect number of bitmap entries for space cache if loading is interrupted by some error - fix backref walking, this breaks a mode of LOGICAL_INO_V2 ioctl that is used in deduplication tools - zoned mode fixes: - properly finish zone reserved for relocation - correctly calculate super block zone end on ZNS - properly initialize new extent buffer for redirty - make mount option clear_cache work with block-group-tree, to rebuild free-space-tree instead of temporarily disabling it that would lead to a forced read-only mount - fix alignment check for offset when printing extent item * tag 'for-6.4-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: make clear_cache mount option to rebuild FST without disabling it btrfs: zero the buffer before marking it dirty in btrfs_redirty_list_add btrfs: zoned: fix full zone super block reading on ZNS btrfs: zoned: zone finish data relocation BG with last IO btrfs: fix backref walking not returning all inode refs btrfs: fix space cache inconsistency after error loading it from disk btrfs: print-tree: parent bytenr must be aligned to sector size
2 parents fd88f14 + 1d6a4fc commit 76c7f88

File tree

11 files changed

+102
-33
lines changed

11 files changed

+102
-33
lines changed

fs/btrfs/backref.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static int check_extent_in_eb(struct btrfs_backref_walk_ctx *ctx,
4545
int root_count;
4646
bool cached;
4747

48-
if (!btrfs_file_extent_compression(eb, fi) &&
48+
if (!ctx->ignore_extent_item_pos &&
49+
!btrfs_file_extent_compression(eb, fi) &&
4950
!btrfs_file_extent_encryption(eb, fi) &&
5051
!btrfs_file_extent_other_encoding(eb, fi)) {
5152
u64 data_offset;
@@ -552,7 +553,7 @@ static int add_all_parents(struct btrfs_backref_walk_ctx *ctx,
552553
count++;
553554
else
554555
goto next;
555-
if (!ctx->ignore_extent_item_pos) {
556+
if (!ctx->skip_inode_ref_list) {
556557
ret = check_extent_in_eb(ctx, &key, eb, fi, &eie);
557558
if (ret == BTRFS_ITERATE_EXTENT_INODES_STOP ||
558559
ret < 0)
@@ -564,7 +565,7 @@ static int add_all_parents(struct btrfs_backref_walk_ctx *ctx,
564565
eie, (void **)&old, GFP_NOFS);
565566
if (ret < 0)
566567
break;
567-
if (!ret && !ctx->ignore_extent_item_pos) {
568+
if (!ret && !ctx->skip_inode_ref_list) {
568569
while (old->next)
569570
old = old->next;
570571
old->next = eie;
@@ -1606,7 +1607,7 @@ static int find_parent_nodes(struct btrfs_backref_walk_ctx *ctx,
16061607
goto out;
16071608
}
16081609
if (ref->count && ref->parent) {
1609-
if (!ctx->ignore_extent_item_pos && !ref->inode_list &&
1610+
if (!ctx->skip_inode_ref_list && !ref->inode_list &&
16101611
ref->level == 0) {
16111612
struct btrfs_tree_parent_check check = { 0 };
16121613
struct extent_buffer *eb;
@@ -1647,7 +1648,7 @@ static int find_parent_nodes(struct btrfs_backref_walk_ctx *ctx,
16471648
(void **)&eie, GFP_NOFS);
16481649
if (ret < 0)
16491650
goto out;
1650-
if (!ret && !ctx->ignore_extent_item_pos) {
1651+
if (!ret && !ctx->skip_inode_ref_list) {
16511652
/*
16521653
* We've recorded that parent, so we must extend
16531654
* its inode list here.
@@ -1743,7 +1744,7 @@ int btrfs_find_all_leafs(struct btrfs_backref_walk_ctx *ctx)
17431744
static int btrfs_find_all_roots_safe(struct btrfs_backref_walk_ctx *ctx)
17441745
{
17451746
const u64 orig_bytenr = ctx->bytenr;
1746-
const bool orig_ignore_extent_item_pos = ctx->ignore_extent_item_pos;
1747+
const bool orig_skip_inode_ref_list = ctx->skip_inode_ref_list;
17471748
bool roots_ulist_allocated = false;
17481749
struct ulist_iterator uiter;
17491750
int ret = 0;
@@ -1764,7 +1765,7 @@ static int btrfs_find_all_roots_safe(struct btrfs_backref_walk_ctx *ctx)
17641765
roots_ulist_allocated = true;
17651766
}
17661767

1767-
ctx->ignore_extent_item_pos = true;
1768+
ctx->skip_inode_ref_list = true;
17681769

17691770
ULIST_ITER_INIT(&uiter);
17701771
while (1) {
@@ -1789,7 +1790,7 @@ static int btrfs_find_all_roots_safe(struct btrfs_backref_walk_ctx *ctx)
17891790
ulist_free(ctx->refs);
17901791
ctx->refs = NULL;
17911792
ctx->bytenr = orig_bytenr;
1792-
ctx->ignore_extent_item_pos = orig_ignore_extent_item_pos;
1793+
ctx->skip_inode_ref_list = orig_skip_inode_ref_list;
17931794

17941795
return ret;
17951796
}
@@ -1912,7 +1913,7 @@ int btrfs_is_data_extent_shared(struct btrfs_inode *inode, u64 bytenr,
19121913
goto out_trans;
19131914
}
19141915

1915-
walk_ctx.ignore_extent_item_pos = true;
1916+
walk_ctx.skip_inode_ref_list = true;
19161917
walk_ctx.trans = trans;
19171918
walk_ctx.fs_info = fs_info;
19181919
walk_ctx.refs = &ctx->refs;

fs/btrfs/backref.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ struct btrfs_backref_walk_ctx {
6060
* @extent_item_pos is ignored.
6161
*/
6262
bool ignore_extent_item_pos;
63+
/*
64+
* If true and bytenr corresponds to a data extent, then the inode list
65+
* (each member describing inode number, file offset and root) is not
66+
* added to each reference added to the @refs ulist.
67+
*/
68+
bool skip_inode_ref_list;
6369
/* A valid transaction handle or NULL. */
6470
struct btrfs_trans_handle *trans;
6571
/*

fs/btrfs/disk-io.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,23 +3121,34 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
31213121
{
31223122
int ret;
31233123
const bool cache_opt = btrfs_test_opt(fs_info, SPACE_CACHE);
3124-
bool clear_free_space_tree = false;
3124+
bool rebuild_free_space_tree = false;
31253125

31263126
if (btrfs_test_opt(fs_info, CLEAR_CACHE) &&
31273127
btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
3128-
clear_free_space_tree = true;
3128+
rebuild_free_space_tree = true;
31293129
} else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) &&
31303130
!btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) {
31313131
btrfs_warn(fs_info, "free space tree is invalid");
3132-
clear_free_space_tree = true;
3132+
rebuild_free_space_tree = true;
31333133
}
31343134

3135-
if (clear_free_space_tree) {
3136-
btrfs_info(fs_info, "clearing free space tree");
3137-
ret = btrfs_clear_free_space_tree(fs_info);
3135+
if (rebuild_free_space_tree) {
3136+
btrfs_info(fs_info, "rebuilding free space tree");
3137+
ret = btrfs_rebuild_free_space_tree(fs_info);
31383138
if (ret) {
31393139
btrfs_warn(fs_info,
3140-
"failed to clear free space tree: %d", ret);
3140+
"failed to rebuild free space tree: %d", ret);
3141+
goto out;
3142+
}
3143+
}
3144+
3145+
if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) &&
3146+
!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) {
3147+
btrfs_info(fs_info, "disabling free space tree");
3148+
ret = btrfs_delete_free_space_tree(fs_info);
3149+
if (ret) {
3150+
btrfs_warn(fs_info,
3151+
"failed to disable free space tree: %d", ret);
31413152
goto out;
31423153
}
31433154
}

fs/btrfs/free-space-cache.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,15 +870,16 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
870870
}
871871
spin_lock(&ctl->tree_lock);
872872
ret = link_free_space(ctl, e);
873-
ctl->total_bitmaps++;
874-
recalculate_thresholds(ctl);
875-
spin_unlock(&ctl->tree_lock);
876873
if (ret) {
874+
spin_unlock(&ctl->tree_lock);
877875
btrfs_err(fs_info,
878876
"Duplicate entries in free space cache, dumping");
879877
kmem_cache_free(btrfs_free_space_cachep, e);
880878
goto free_cache;
881879
}
880+
ctl->total_bitmaps++;
881+
recalculate_thresholds(ctl);
882+
spin_unlock(&ctl->tree_lock);
882883
list_add_tail(&e->list, &bitmaps);
883884
}
884885

fs/btrfs/free-space-tree.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ static int clear_free_space_tree(struct btrfs_trans_handle *trans,
12521252
return ret;
12531253
}
12541254

1255-
int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
1255+
int btrfs_delete_free_space_tree(struct btrfs_fs_info *fs_info)
12561256
{
12571257
struct btrfs_trans_handle *trans;
12581258
struct btrfs_root *tree_root = fs_info->tree_root;
@@ -1298,6 +1298,54 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
12981298
return ret;
12991299
}
13001300

1301+
int btrfs_rebuild_free_space_tree(struct btrfs_fs_info *fs_info)
1302+
{
1303+
struct btrfs_trans_handle *trans;
1304+
struct btrfs_key key = {
1305+
.objectid = BTRFS_FREE_SPACE_TREE_OBJECTID,
1306+
.type = BTRFS_ROOT_ITEM_KEY,
1307+
.offset = 0,
1308+
};
1309+
struct btrfs_root *free_space_root = btrfs_global_root(fs_info, &key);
1310+
struct rb_node *node;
1311+
int ret;
1312+
1313+
trans = btrfs_start_transaction(free_space_root, 1);
1314+
if (IS_ERR(trans))
1315+
return PTR_ERR(trans);
1316+
1317+
set_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
1318+
set_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags);
1319+
1320+
ret = clear_free_space_tree(trans, free_space_root);
1321+
if (ret)
1322+
goto abort;
1323+
1324+
node = rb_first_cached(&fs_info->block_group_cache_tree);
1325+
while (node) {
1326+
struct btrfs_block_group *block_group;
1327+
1328+
block_group = rb_entry(node, struct btrfs_block_group,
1329+
cache_node);
1330+
ret = populate_free_space_tree(trans, block_group);
1331+
if (ret)
1332+
goto abort;
1333+
node = rb_next(node);
1334+
}
1335+
1336+
btrfs_set_fs_compat_ro(fs_info, FREE_SPACE_TREE);
1337+
btrfs_set_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID);
1338+
clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
1339+
1340+
ret = btrfs_commit_transaction(trans);
1341+
clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags);
1342+
return ret;
1343+
abort:
1344+
btrfs_abort_transaction(trans, ret);
1345+
btrfs_end_transaction(trans);
1346+
return ret;
1347+
}
1348+
13011349
static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
13021350
struct btrfs_block_group *block_group,
13031351
struct btrfs_path *path)

fs/btrfs/free-space-tree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ struct btrfs_caching_control;
1818

1919
void set_free_space_tree_thresholds(struct btrfs_block_group *block_group);
2020
int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info);
21-
int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info);
21+
int btrfs_delete_free_space_tree(struct btrfs_fs_info *fs_info);
22+
int btrfs_rebuild_free_space_tree(struct btrfs_fs_info *fs_info);
2223
int load_free_space_tree(struct btrfs_caching_control *caching_ctl);
2324
int add_block_group_free_space(struct btrfs_trans_handle *trans,
2425
struct btrfs_block_group *block_group);

fs/btrfs/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,6 +3108,9 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
31083108
btrfs_rewrite_logical_zoned(ordered_extent);
31093109
btrfs_zone_finish_endio(fs_info, ordered_extent->disk_bytenr,
31103110
ordered_extent->disk_num_bytes);
3111+
} else if (btrfs_is_data_reloc_root(inode->root)) {
3112+
btrfs_zone_finish_endio(fs_info, ordered_extent->disk_bytenr,
3113+
ordered_extent->disk_num_bytes);
31113114
}
31123115

31133116
if (test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) {

fs/btrfs/print-tree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
151151
pr_cont("shared data backref parent %llu count %u\n",
152152
offset, btrfs_shared_data_ref_count(eb, sref));
153153
/*
154-
* offset is supposed to be a tree block which
155-
* must be aligned to nodesize.
154+
* Offset is supposed to be a tree block which must be
155+
* aligned to sectorsize.
156156
*/
157-
if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
157+
if (!IS_ALIGNED(offset, eb->fs_info->sectorsize))
158158
pr_info(
159159
"\t\t\t(parent %llu not aligned to sectorsize %u)\n",
160160
offset, eb->fs_info->sectorsize);

fs/btrfs/relocation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,7 @@ int add_data_references(struct reloc_control *rc,
34223422
btrfs_release_path(path);
34233423

34243424
ctx.bytenr = extent_key->objectid;
3425-
ctx.ignore_extent_item_pos = true;
3425+
ctx.skip_inode_ref_list = true;
34263426
ctx.fs_info = rc->extent_root->fs_info;
34273427

34283428
ret = btrfs_find_all_leafs(&ctx);

fs/btrfs/super.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
828828
ret = -EINVAL;
829829
}
830830
if (btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE) &&
831-
(btrfs_test_opt(info, CLEAR_CACHE) ||
832-
!btrfs_test_opt(info, FREE_SPACE_TREE))) {
831+
!btrfs_test_opt(info, FREE_SPACE_TREE)) {
833832
btrfs_err(info, "cannot disable free space tree with block-group-tree feature");
834833
ret = -EINVAL;
835834
}

0 commit comments

Comments
 (0)