mbox series

[00/12] btrfs-progs: zoned: support zone capacity and

Message ID cover.1739756953.git.naohiro.aota@wdc.com (mailing list archive)
Headers show
Series btrfs-progs: zoned: support zone capacity and | expand

Message

Naohiro Aota Feb. 17, 2025, 2:37 a.m. UTC
Running mkfs.btrfs on a null_blk device with the following setup fails
as below.

- zone size: 64MB
- zone capacity: 64MB
- number of conventional zones: 6
- storage size: 2048MB

    + /home/naota/src/btrfs-progs/mkfs.btrfs -d single -m dup -f /dev/nullb0
    btrfs-progs v6.10
    See https://btrfs.readthedocs.io for more information.

    zoned: /dev/nullb0: host-managed device detected, setting zoned feature
    Resetting device zones /dev/nullb0 (32 zones) ...
    NOTE: several default settings have changed in version 5.15, please make sure
          this does not affect your deployments:
          - DUP for metadata (-m dup)
          - enabled no-holes (-O no-holes)
          - enabled free-space-tree (-R free-space-tree)

    bad tree block 268435456, bytenr mismatch, want=268435456, have=0
    kernel-shared/disk-io.c:485: write_tree_block: BUG_ON `1` triggered, value 1
    /home/naota/src/btrfs-progs/mkfs.btrfs(+0x290ca) [0x55603cf7e0ca]
    /home/naota/src/btrfs-progs/mkfs.btrfs(write_tree_block+0xa7) [0x55603cf80417]
    /home/naota/src/btrfs-progs/mkfs.btrfs(__commit_transaction+0xe8) [0x55603cf9b7d8]
    /home/naota/src/btrfs-progs/mkfs.btrfs(btrfs_commit_transaction+0x176) [0x55603cf9ba66]
    /home/naota/src/btrfs-progs/mkfs.btrfs(main+0x2831) [0x55603cf67291]
    /usr/lib64/libc.so.6(+0x271ee) [0x7f5ab706f1ee]
    /usr/lib64/libc.so.6(__libc_start_main+0x89) [0x7f5ab706f2a9]
    /home/naota/src/btrfs-progs/mkfs.btrfs(_start+0x25) [0x55603cf6a135]
    /home/naota/tmp/test-mkfs.sh: line 13: 821886 Aborted                 (core dumped)

The crash happens because btrfs-progs failed to set proper allocation
pointer when a DUP block group is created over a conventional zone and a
sequential write required zone. In that case, the write pointer is
recovered from the last allocated extent in the block group. That
functionality is not well implemented in btrfs-progs side.

Implementing that functionality is relatively trivial because we can
copy the code from the kernel side. However, the code is quite out of
sync between the kernel side and user space side. So, this series first
refactors btrfs_load_block_group_zone_info() to make it easy to
integrate the code from the kernel side.

The main part is the last patch, which fixes allocation pointer
calculation for all the profiles.

While at it, this series also adds support for zone capacity and zone
activeness. But, zone activeness support is currently limited. It does
not attempt to check the zone active limit on the extent allocation,
because mkfs.btrfs should work without hitting the limit.

Naohiro Aota (12):
  btrfs-progs: introduce min_not_zero()
  btrfs-progs: zoned: introduce a zone_info struct in
    btrfs_load_block_group_zone_info
  btrfs-progs: zoned: support zone capacity
  btrfs-progs: zoned: load zone activeness
  btrfs-progs: zoned: activate block group on loading
  btrfs-progs: factor out btrfs_load_zone_info()
  btrfs-progs: zoned: factor out SINGLE zone info loading
  btrfs-progs: zoned: implement DUP zone info loading
  btrfs-progs: zoned: implement RAID1 zone info loading
  btrfs-progs: zoned: implement RAID0 zone info loading
  btrfs-progs: implement RAID10 zone info loading
  btrfs-progs: zoned: fix alloc_offset calculation for partly
    conventional block groups

 include/kerncompat.h        |  10 +
 kernel-shared/ctree.h       |   3 +
 kernel-shared/extent-tree.c |   2 +-
 kernel-shared/zoned.c       | 458 +++++++++++++++++++++++++++++++-----
 kernel-shared/zoned.h       |   3 +
 5 files changed, 414 insertions(+), 62 deletions(-)

--
2.48.1