Skip to content

Commit a6f63ff

Browse files
committed
Merge branch 'for-next-next-v6.12-20241009' into for-next-20241009
2 parents de5b27f + 9d65b5a commit a6f63ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1110
-815
lines changed

fs/btrfs/Kconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
# misc-next marker
23

34
config BTRFS_FS
45
tristate "Btrfs filesystem support"
@@ -78,6 +79,32 @@ config BTRFS_ASSERT
7879

7980
If unsure, say N.
8081

82+
config BTRFS_EXPERIMENTAL
83+
bool "Btrfs experimental features"
84+
depends on BTRFS_FS
85+
default n
86+
help
87+
Enable experimental features. These features may not be stable enough
88+
for end users. This is meant for btrfs developers or users who wish
89+
to test the functionality and report problems.
90+
91+
Current list:
92+
93+
- extent map shrinker - performance problems with too frequent shrinks
94+
95+
- send stream protocol v3 - fs-verity support
96+
97+
- checksum offload mode - sysfs knob to affect when checksums are
98+
calculated (at IO time, or in a thread)
99+
100+
- raid-stripe-tree - additional mapping of extents to devices to
101+
support RAID1* profiles on zoned devices,
102+
RAID56 not yet supported
103+
104+
- extent tree v2 - complex rework of extent tracking
105+
106+
If unsure, say N.
107+
81108
config BTRFS_FS_REF_VERIFY
82109
bool "Btrfs with the ref verify tool compiled in"
83110
depends on BTRFS_FS

fs/btrfs/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ btrfs-$(CONFIG_FS_VERITY) += verity.o
4343
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
4444
tests/extent-buffer-tests.o tests/btrfs-tests.o \
4545
tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o \
46-
tests/free-space-tree-tests.o tests/extent-map-tests.o
46+
tests/free-space-tree-tests.o tests/extent-map-tests.o \
47+
tests/raid-stripe-tree-tests.o

fs/btrfs/backref.c

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,9 +3021,6 @@ void btrfs_backref_init_cache(struct btrfs_fs_info *fs_info,
30213021
cache->rb_root = RB_ROOT;
30223022
for (i = 0; i < BTRFS_MAX_LEVEL; i++)
30233023
INIT_LIST_HEAD(&cache->pending[i]);
3024-
INIT_LIST_HEAD(&cache->changed);
3025-
INIT_LIST_HEAD(&cache->detached);
3026-
INIT_LIST_HEAD(&cache->leaves);
30273024
INIT_LIST_HEAD(&cache->pending_edge);
30283025
INIT_LIST_HEAD(&cache->useless_node);
30293026
cache->fs_info = fs_info;
@@ -3131,29 +3128,17 @@ void btrfs_backref_drop_node(struct btrfs_backref_cache *tree,
31313128
void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache,
31323129
struct btrfs_backref_node *node)
31333130
{
3134-
struct btrfs_backref_node *upper;
31353131
struct btrfs_backref_edge *edge;
31363132

31373133
if (!node)
31383134
return;
31393135

3140-
BUG_ON(!node->lowest && !node->detached);
31413136
while (!list_empty(&node->upper)) {
31423137
edge = list_entry(node->upper.next, struct btrfs_backref_edge,
31433138
list[LOWER]);
3144-
upper = edge->node[UPPER];
31453139
list_del(&edge->list[LOWER]);
31463140
list_del(&edge->list[UPPER]);
31473141
btrfs_backref_free_edge(cache, edge);
3148-
3149-
/*
3150-
* Add the node to leaf node list if no other child block
3151-
* cached.
3152-
*/
3153-
if (list_empty(&upper->lower)) {
3154-
list_add_tail(&upper->lower, &cache->leaves);
3155-
upper->lowest = 1;
3156-
}
31573142
}
31583143

31593144
btrfs_backref_drop_node(cache, node);
@@ -3165,33 +3150,13 @@ void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache,
31653150
void btrfs_backref_release_cache(struct btrfs_backref_cache *cache)
31663151
{
31673152
struct btrfs_backref_node *node;
3168-
int i;
3169-
3170-
while (!list_empty(&cache->detached)) {
3171-
node = list_entry(cache->detached.next,
3172-
struct btrfs_backref_node, list);
3173-
btrfs_backref_cleanup_node(cache, node);
3174-
}
31753153

3176-
while (!list_empty(&cache->leaves)) {
3177-
node = list_entry(cache->leaves.next,
3178-
struct btrfs_backref_node, lower);
3154+
while ((node = rb_entry_safe(rb_first(&cache->rb_root),
3155+
struct btrfs_backref_node, rb_node)))
31793156
btrfs_backref_cleanup_node(cache, node);
3180-
}
31813157

3182-
for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
3183-
while (!list_empty(&cache->pending[i])) {
3184-
node = list_first_entry(&cache->pending[i],
3185-
struct btrfs_backref_node,
3186-
list);
3187-
btrfs_backref_cleanup_node(cache, node);
3188-
}
3189-
}
31903158
ASSERT(list_empty(&cache->pending_edge));
31913159
ASSERT(list_empty(&cache->useless_node));
3192-
ASSERT(list_empty(&cache->changed));
3193-
ASSERT(list_empty(&cache->detached));
3194-
ASSERT(RB_EMPTY_ROOT(&cache->rb_root));
31953160
ASSERT(!cache->nr_nodes);
31963161
ASSERT(!cache->nr_edges);
31973162
}
@@ -3315,8 +3280,16 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
33153280
root = btrfs_get_fs_root(fs_info, ref_key->offset, false);
33163281
if (IS_ERR(root))
33173282
return PTR_ERR(root);
3318-
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
3319-
cur->cowonly = 1;
3283+
3284+
/*
3285+
* We shouldn't be using backref cache for non shareable roots, ASSERT
3286+
* for developers, return -EUCLEAN for users.
3287+
*/
3288+
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
3289+
btrfs_put_root(root);
3290+
ASSERT(0);
3291+
return -EUCLEAN;
3292+
}
33203293

33213294
if (btrfs_root_level(&root->root_item) == cur->level) {
33223295
/* Tree root */
@@ -3402,8 +3375,20 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
34023375
goto out;
34033376
}
34043377
upper->owner = btrfs_header_owner(eb);
3405-
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
3406-
upper->cowonly = 1;
3378+
3379+
/*
3380+
* We shouldn't be using backref cache for non shareable
3381+
* roots, ASSERT for developers, return -EUCLEAN for
3382+
* users.
3383+
*/
3384+
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
3385+
btrfs_put_root(root);
3386+
btrfs_backref_free_edge(cache, edge);
3387+
btrfs_backref_free_node(cache, upper);
3388+
ASSERT(0);
3389+
ret = -EUCLEAN;
3390+
goto out;
3391+
}
34073392

34083393
/*
34093394
* If we know the block isn't shared we can avoid
@@ -3594,15 +3579,11 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
35943579

35953580
ASSERT(start->checked);
35963581

3597-
/* Insert this node to cache if it's not COW-only */
3598-
if (!start->cowonly) {
3599-
rb_node = rb_simple_insert(&cache->rb_root, start->bytenr,
3600-
&start->rb_node);
3601-
if (rb_node)
3602-
btrfs_backref_panic(cache->fs_info, start->bytenr,
3603-
-EEXIST);
3604-
list_add_tail(&start->lower, &cache->leaves);
3605-
}
3582+
rb_node = rb_simple_insert(&cache->rb_root, start->bytenr,
3583+
&start->rb_node);
3584+
if (rb_node)
3585+
btrfs_backref_panic(cache->fs_info, start->bytenr,
3586+
-EEXIST);
36063587

36073588
/*
36083589
* Use breadth first search to iterate all related edges.
@@ -3641,11 +3622,6 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
36413622
* parents have already been linked.
36423623
*/
36433624
if (!RB_EMPTY_NODE(&upper->rb_node)) {
3644-
if (upper->lowest) {
3645-
list_del_init(&upper->lower);
3646-
upper->lowest = 0;
3647-
}
3648-
36493625
list_add_tail(&edge->list[UPPER], &upper->lower);
36503626
continue;
36513627
}
@@ -3656,23 +3632,14 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
36563632
return -EUCLEAN;
36573633
}
36583634

3659-
/* Sanity check, COW-only node has non-COW-only parent */
3660-
if (start->cowonly != upper->cowonly) {
3661-
ASSERT(0);
3635+
rb_node = rb_simple_insert(&cache->rb_root, upper->bytenr,
3636+
&upper->rb_node);
3637+
if (rb_node) {
3638+
btrfs_backref_panic(cache->fs_info,
3639+
upper->bytenr, -EEXIST);
36623640
return -EUCLEAN;
36633641
}
36643642

3665-
/* Only cache non-COW-only (subvolume trees) tree blocks */
3666-
if (!upper->cowonly) {
3667-
rb_node = rb_simple_insert(&cache->rb_root, upper->bytenr,
3668-
&upper->rb_node);
3669-
if (rb_node) {
3670-
btrfs_backref_panic(cache->fs_info,
3671-
upper->bytenr, -EEXIST);
3672-
return -EUCLEAN;
3673-
}
3674-
}
3675-
36763643
list_add_tail(&edge->list[UPPER], &upper->lower);
36773644

36783645
/*

fs/btrfs/backref.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ struct btrfs_backref_node {
318318
u64 bytenr;
319319
}; /* Use rb_simple_node for search/insert */
320320

321+
/*
322+
* This is a sanity check, whenever we cow a block we will update
323+
* new_bytenr with it's current location, and we will check this in
324+
* various places to validate that the cache makes sense, it shouldn't
325+
* be used for anything else.
326+
*/
321327
u64 new_bytenr;
322328
/* Objectid of tree block owner, can be not uptodate */
323329
u64 owner;
@@ -335,10 +341,6 @@ struct btrfs_backref_node {
335341
struct extent_buffer *eb;
336342
/* Level of the tree block */
337343
unsigned int level:8;
338-
/* Is the block in a non-shareable tree */
339-
unsigned int cowonly:1;
340-
/* 1 if no child node is in the cache */
341-
unsigned int lowest:1;
342344
/* Is the extent buffer locked */
343345
unsigned int locked:1;
344346
/* Has the block been processed */
@@ -391,12 +393,6 @@ struct btrfs_backref_cache {
391393
* level blocks may not reflect the new location
392394
*/
393395
struct list_head pending[BTRFS_MAX_LEVEL];
394-
/* List of backref nodes with no child node */
395-
struct list_head leaves;
396-
/* List of blocks that have been COWed in current transaction */
397-
struct list_head changed;
398-
/* List of detached backref node. */
399-
struct list_head detached;
400396

401397
u64 last_trans;
402398

fs/btrfs/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static bool should_async_write(struct btrfs_bio *bbio)
598598
{
599599
bool auto_csum_mode = true;
600600

601-
#ifdef CONFIG_BTRFS_DEBUG
601+
#ifdef CONFIG_BTRFS_EXPERIMENTAL
602602
struct btrfs_fs_devices *fs_devices = bbio->fs_info->fs_devices;
603603
enum btrfs_offload_csum_mode csum_mode = READ_ONCE(fs_devices->offload_csum_mode);
604604

fs/btrfs/block-group.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans)
27972797
* uncompressed data size, because the compression is only done
27982798
* when writeback triggered and we don't know how much space we
27992799
* are actually going to need, so we reserve the uncompressed
2800-
* size because the data may be uncompressible in the worst case.
2800+
* size because the data may be incompressible in the worst case.
28012801
*/
28022802
if (ret == 0) {
28032803
bool used;

fs/btrfs/btrfs_inode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ void btrfs_merge_delalloc_extent(struct btrfs_inode *inode, struct extent_state
577577
struct extent_state *other);
578578
void btrfs_split_delalloc_extent(struct btrfs_inode *inode,
579579
struct extent_state *orig, u64 split);
580-
void btrfs_set_range_writeback(struct btrfs_inode *inode, u64 start, u64 end);
581580
void btrfs_evict_inode(struct inode *inode);
582581
struct inode *btrfs_alloc_inode(struct super_block *sb);
583582
void btrfs_destroy_inode(struct inode *inode);

fs/btrfs/compression.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,16 @@ int btrfs_compress_folios(unsigned int type_level, struct address_space *mapping
10301030
{
10311031
int type = btrfs_compress_type(type_level);
10321032
int level = btrfs_compress_level(type_level);
1033+
const unsigned long orig_len = *total_out;
10331034
struct list_head *workspace;
10341035
int ret;
10351036

10361037
level = btrfs_compress_set_level(type, level);
10371038
workspace = get_workspace(type, level);
10381039
ret = compression_compress_pages(type, workspace, mapping, start, folios,
10391040
out_folios, total_in, total_out);
1041+
/* The total read-in bytes should be no larger than the input. */
1042+
ASSERT(*total_in <= orig_len);
10401043
put_workspace(type, workspace);
10411044
return ret;
10421045
}

fs/btrfs/delayed-ref.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref,
830830
qrecord->data_rsv = reserved;
831831
qrecord->data_rsv_refroot = generic_ref->ref_root;
832832
}
833-
qrecord->bytenr = generic_ref->bytenr;
834833
qrecord->num_bytes = generic_ref->num_bytes;
835834
qrecord->old_roots = NULL;
836835
}
@@ -849,6 +848,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans,
849848
struct btrfs_qgroup_extent_record *qrecord,
850849
int action, bool *qrecord_inserted_ret)
851850
{
851+
struct btrfs_fs_info *fs_info = trans->fs_info;
852852
struct btrfs_delayed_ref_head *existing;
853853
struct btrfs_delayed_ref_root *delayed_refs;
854854
bool qrecord_inserted = false;
@@ -859,11 +859,12 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans,
859859
if (qrecord) {
860860
int ret;
861861

862-
ret = btrfs_qgroup_trace_extent_nolock(trans->fs_info,
863-
delayed_refs, qrecord);
862+
ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, qrecord,
863+
head_ref->bytenr);
864864
if (ret) {
865865
/* Clean up if insertion fails or item exists. */
866-
xa_release(&delayed_refs->dirty_extents, qrecord->bytenr);
866+
xa_release(&delayed_refs->dirty_extents,
867+
head_ref->bytenr >> fs_info->sectorsize_bits);
867868
/* Caller responsible for freeing qrecord on error. */
868869
if (ret < 0)
869870
return ERR_PTR(ret);
@@ -873,7 +874,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans,
873874
}
874875
}
875876

876-
trace_add_delayed_ref_head(trans->fs_info, head_ref, action);
877+
trace_add_delayed_ref_head(fs_info, head_ref, action);
877878

878879
existing = htree_insert(&delayed_refs->href_root,
879880
&head_ref->href_node);
@@ -895,8 +896,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans,
895896
if (head_ref->is_data && head_ref->ref_mod < 0) {
896897
delayed_refs->pending_csums += head_ref->num_bytes;
897898
trans->delayed_ref_csum_deletions +=
898-
btrfs_csum_bytes_to_leaves(trans->fs_info,
899-
head_ref->num_bytes);
899+
btrfs_csum_bytes_to_leaves(fs_info, head_ref->num_bytes);
900900
}
901901
delayed_refs->num_heads++;
902902
delayed_refs->num_heads_ready++;
@@ -1030,7 +1030,8 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans,
10301030
goto free_head_ref;
10311031
}
10321032
if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents,
1033-
generic_ref->bytenr, GFP_NOFS)) {
1033+
generic_ref->bytenr >> fs_info->sectorsize_bits,
1034+
GFP_NOFS)) {
10341035
ret = -ENOMEM;
10351036
goto free_record;
10361037
}
@@ -1073,7 +1074,7 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans,
10731074
kmem_cache_free(btrfs_delayed_ref_node_cachep, node);
10741075

10751076
if (qrecord_inserted)
1076-
return btrfs_qgroup_trace_extent_post(trans, record);
1077+
return btrfs_qgroup_trace_extent_post(trans, record, head_ref->bytenr);
10771078
return 0;
10781079

10791080
free_record:

fs/btrfs/delayed-ref.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,15 @@ struct btrfs_delayed_ref_root {
202202
/* head ref rbtree */
203203
struct rb_root_cached href_root;
204204

205-
/* Track dirty extent records. */
205+
/*
206+
* Track dirty extent records.
207+
* The keys correspond to the logical address of the extent ("bytenr")
208+
* right shifted by fs_info->sectorsize_bits. This is both to get a more
209+
* dense index space (optimizes xarray structure) and because indexes in
210+
* xarrays are of "unsigned long" type, meaning they are 32 bits wide on
211+
* 32 bits platforms, limiting the extent range to 4G which is too low
212+
* and makes it unusable (truncated index values) on 32 bits platforms.
213+
*/
206214
struct xarray dirty_extents;
207215

208216
/* this spin lock protects the rbtree and the entries inside */

0 commit comments

Comments
 (0)