]> git.hungrycats.org Git - linux/commitdiff
btrfs: load the on-disk btrfs_chunk::stripe_len
authorQu Wenruo <wqu@suse.com>
Wed, 21 Oct 2026 03:39:36 +0000 (14:09 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:18 +0000 (21:36 +0100)
Currently btrfs doesn't load btrfs_chunk::stripe_len into
btrfs_chunk_map, as tree-checker will reject any chunk whose stripe_len
is not 64K.

But for the future we will want stripe length other than 64K.

As a preparation for the variable stripe length in the future, load
btrfs_chunk::stripe_len into btrfs_chunk_map::stripe_len and
stripe_shift.

For now stripe_len is still 64K, no matter if it's loaded from the
on-disk metadata or newly allocated chunk.
As tree-checker still rejects any chunk whose stripe_len is not 64K.

The two new members fit into the existing hole of btrfs_chunk_map, so
the size of btrfs_chunk_map stay the same.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index 6574939e1295b561c5bcfd900c8d2b15dec619b9..a30b212ef0f1deed72e6662a21b5da6d05ad4ad6 100644 (file)
@@ -6166,6 +6166,12 @@ struct btrfs_chunk_map *btrfs_alloc_chunk_map(int num_stripes, gfp_t gfp)
        refcount_set(&map->refs, 1);
        RB_CLEAR_NODE(&map->rb_node);
 
+       /*
+        * Initialize the default stripe len, selftests will utilize them
+        * without an on-disk chunk item.
+        */
+       map->stripe_len = BTRFS_STRIPE_LEN;
+       map->stripe_shift = ilog2(map->stripe_len);
        return map;
 }
 
@@ -6203,6 +6209,8 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
        map->on_disk_type = type;
        map->sub_stripes = ctl->sub_stripes;
        map->num_stripes = ctl->num_stripes;
+       map->stripe_len = BTRFS_STRIPE_LEN;
+       map->stripe_shift = ilog2(BTRFS_STRIPE_LEN);
        set_real_chunk_type(map);
 
        for (int i = 0; i < ctl->ndevs; i++) {
@@ -6381,7 +6389,7 @@ int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,
 
        btrfs_set_stack_chunk_length(chunk, bg->length);
        btrfs_set_stack_chunk_owner(chunk, BTRFS_EXTENT_TREE_OBJECTID);
-       btrfs_set_stack_chunk_stripe_len(chunk, BTRFS_STRIPE_LEN);
+       btrfs_set_stack_chunk_stripe_len(chunk, map->stripe_len);
        btrfs_set_stack_chunk_type(chunk, map->on_disk_type);
        btrfs_set_stack_chunk_num_stripes(chunk, map->num_stripes);
        btrfs_set_stack_chunk_io_align(chunk, BTRFS_STRIPE_LEN);
@@ -7781,6 +7789,8 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
        map->chunk_len = length;
        map->num_stripes = num_stripes;
        map->on_disk_type = type;
+       map->stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
+       map->stripe_shift = ilog2(map->stripe_len);
        /*
         * We can't use the sub_stripes value, as for profiles other than
         * RAID10, they may have 0 as sub_stripes for filesystems created by
index d97ca875c596671ecc6b071e96e8216b5f260e0a..9dcc14cd61e2f2b00f17cec169a60213e03bb64e 100644 (file)
@@ -640,6 +640,8 @@ struct btrfs_chunk_map {
        u64 on_disk_type;
        /* For mount time dev extent verification. */
        u16 verified_stripes;
+       u8 stripe_shift;
+       u32 stripe_len;
        struct btrfs_io_stripe stripes[];
 };