]> git.hungrycats.org Git - btrfs-progs/log
btrfs-progs
4 weeks agobtrfs-progs: replace: add --abort-on-uncorrectable topics/replace-abort-uncorrectable
Zygo Blaxell [Fri, 16 Oct 2026 17:03:37 +0000 (13:03 -0400)]
btrfs-progs: replace: add --abort-on-uncorrectable

Device replace counts blocks that cannot be read from any copy and goes
on without them.  That suits rescuing data from a failing device, but
not replacing a healthy one, where an unreadable block should stop the
replace before the source device is removed.

Add "btrfs replace start --abort-on-uncorrectable", which sets
BTRFS_IOCTL_DEV_REPLACE_ABORT_ON_UNCORRECTABLE in the high bits of
cont_reading_from_srcdev_mode.  Kernels that do not support it reject
the start with EINVAL (or EOPNOTSUPP for a flag they do not know), and
say so when the replace runs in the foreground; an aborted replace fails
with EIO.  dump-tree prints the flag in the dev_replace item's mode.

The kernel side is the patch "btrfs: dev-replace: optionally abort on
uncorrectable read errors" (kernel replace-fixes series), which defines
the flag and keeps it in the dev_replace item.

Assisted-by: Claude:claude-opus-5-5
3 weeks agobtrfs-progs: gitignore: add GNUmakefile
Qu Wenruo [Tue, 27 Oct 2026 09:34:51 +0000 (20:04 +1030)]
btrfs-progs: gitignore: add GNUmakefile

I use GNUmakefile to add extra compiling flags without modifying the
existing Makefile:

 MAKEFLAGS += -j12
 include Makefile

So the GNUmakefile is more or less reflecting personal tastes, better to
add it to gitignore.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: remove set but unused variables
Qu Wenruo [Tue, 27 Oct 2026 09:34:50 +0000 (20:04 +1030)]
btrfs-progs: remove set but unused variables

If using clang to compile btrfs-progs, two warnings will be reported:

 cmds/rescue-fix-data-checksum.c:73:12: warning: variable 'global_repair_mode' set but not used [-Wunused-but-set-global]
    73 | static int global_repair_mode;
       |            ^
 1 warning generated.
 cmds/inspect-tree-stats.c:43:12: warning: variable 'verbose' set but not used [-Wunused-but-set-global]
    43 | static int verbose = 0;
       |            ^
 1 warning generated.

Both are correct reports, so just remove them.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: properly error out when fseek() failed
Qu Wenruo [Sun, 25 Oct 2026 08:41:46 +0000 (19:11 +1030)]
btrfs-progs: image: properly error out when fseek() failed

When fseek() inside restore_metadump() failed, @ret is still 0, and no
error is returned.

Fix it by using the errno on the error path.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: reject incorrect super block size
Qu Wenruo [Sun, 25 Oct 2026 08:41:45 +0000 (19:11 +1030)]
btrfs-progs: image: reject incorrect super block size

For an uncompressed image, if the super block size is smaller than
BTRFS_SUPER_INFO_SIZE, we know it's definitely corrupted, reject it or
later code can read beyond the allocated buffer.

This covers the following cases:

- build_chunk_tree()
  * Validate the compression level
  * Check the uncompressed super block size
  * Handle short decompression

- add_cluster()
  * Validate the compression level

- fill_mdres_info()
  if build_chunk_tree() is skipped, we read super block here.

  * Check the uncompressed super block size
  * Call btrfs_check_super() to validate the super block
  * Handle short decompression

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: validate the nritems before reading the content
Qu Wenruo [Sun, 25 Oct 2026 08:41:44 +0000 (19:11 +1030)]
btrfs-progs: image: validate the nritems before reading the content

When iterating a header, we read out one 1KiB buffer, then grab the
cluster->header->nritems to grab the number of items stored in the 1K
block.

However if a corrupted or maliciously crafted header is passed in, we
can easily grab a huge number as @nritems, and easily go beyond the 1KiB
buffer.

Fix it by rejecting obviously incorrect nritems before iterating, this
involves 3 call sites:

- build_chunk_tree()
- search_for_chunk_blocks()
- add_cluster()

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: fix overwritten ret in restore_metadump()
Qu Wenruo [Sun, 25 Oct 2026 08:41:43 +0000 (19:11 +1030)]
btrfs-progs: image: fix overwritten ret in restore_metadump()

In the "while(!mdrestore.error) {}" loop if we got a bad header or
add_cluster() failed, we break the loop.

But immediately after breaking out the loop, we call wait_for_worker(),
which overwrites @ret, and also continue to open_ctree().

Fix the problem by directly jumping to out label.
Also for bad header case, update the error code to -EUCLEAN.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: fix memory leak on async_work for restore
Qu Wenruo [Sun, 25 Oct 2026 08:41:42 +0000 (19:11 +1030)]
btrfs-progs: image: fix memory leak on async_work for restore

There are two paths to leak the async_work memory, fix them by:

- restore_one_work() failure inside restore_worker()
  Manually release memory before jumping to out label.

- all restore_worker() failed to process any async_work
  Those async_work will stay inside mdres->list until the end of the
  program.

  Fix them by manually drain the mdres->list.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: fix the error handling of build_chunk_tree()
Qu Wenruo [Sun, 25 Oct 2026 08:41:41 +0000 (19:11 +1030)]
btrfs-progs: image: fix the error handling of build_chunk_tree()

When btrfs_check_super() or add_sys_array() failed, the buffer is not
released and the pthread mutex is still locked.

Fix it by adding a new out label, to release the buffer, unlock the
mutex and return the error code.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: avoid NULL-ptr-deref in build_chunk_tree()
Qu Wenruo [Sun, 25 Oct 2026 08:41:40 +0000 (19:11 +1030)]
btrfs-progs: image: avoid NULL-ptr-deref in build_chunk_tree()

Although very unlikely, if there is a header that has no item in it,
build_chunk_tree() left @item as NULL, then later during the error
message we still call "get_unaligned_le64(&item->bytenr)", which is
going to trigger a NULL-pointer dereference.

Fix it by removing the get_unaligned_le64() call.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: free the buffer if output allocation failed
Qu Wenruo [Sun, 25 Oct 2026 08:41:39 +0000 (19:11 +1030)]
btrfs-progs: image: free the buffer if output allocation failed

Inside dump_worker(), if the compression output buffer allocation
failed, since async->buffer is reused, no one can reach the old original
buffer.

This leads to leaked memory on the error path. Release the original
buffer in that case.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: do not cleanup the thread that failed to be created
Qu Wenruo [Sun, 25 Oct 2026 08:41:38 +0000 (19:11 +1030)]
btrfs-progs: image: do not cleanup the thread that failed to be created

Inside metadump_init(), we initialize every thread slot, but when one
failed, we need to cleanup the previously created one.

However the existing code tries to clean up the slot that failed the
pthread_create() call.
This means in metadump_destroy() we call pthread_join() on the slot where
it's still all zero.

Fix the error handling by only releasing the allocated slots.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: cleanup pending ordered works after an error
Qu Wenruo [Sun, 25 Oct 2026 08:41:37 +0000 (19:11 +1030)]
btrfs-progs: image: cleanup pending ordered works after an error

The function flush_pending() can queue at most ITEMS_PER_CLUSTER
async_works before submitting them to write_buffers().

But if we hit an critical error, e.g. read_tree_block() hit a bad tree
block, and there is already pending async_works, we rely on the last
flush_pending() call inside create_metadump() to do the cleanup.

However that final flush_pending() will hit the same corrupted tree
block and fail halfway, without really dispatch the existing async
works.

Fix the problem by:

- Avoid calling the final flush_pending() if we had already hit an error

- Manually cleanup any pending async works inside metadump_destroy()

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: only remove a chunk map from physical tree if non-empty
Qu Wenruo [Sun, 25 Oct 2026 08:41:36 +0000 (19:11 +1030)]
btrfs-progs: image: only remove a chunk map from physical tree if non-empty

During read_chunk_tree_block(), if a chunk is already in the physical
tree, then the fs_chunk is only added to overlapping_chunks list, but
not yet inserted into the physical_tree, since inserting it would
conflict with the existing chunk

Then remap_overlapping_chunks() remap the chunk into a new location, and
re-insert the updated fs_chunk into physical tree.

However if some error happened before remap_overlapping_chunks() is
called, one fs_chunk can be linked to overlapping_chunks list, but its
rbtree entry is not properly initialized (all zero), then
mdrestore_destroy() still calls rb_erase() on the uninitialized entry.

Fix the problem by always clearing the allocated fs_chunk->p.
Then at mdrestore_destroy() only call rb_erase() if the rb tree pointer
is not empty.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
3 weeks agobtrfs-progs: image: destroy chunk tree after all pthreads finished
Qu Wenruo [Sun, 25 Oct 2026 08:41:35 +0000 (19:11 +1030)]
btrfs-progs: image: destroy chunk tree after all pthreads finished

In the function mdrestore_destroy(), the chunk tree is destroyed before
all the pthreads finished.

This can lead to use-after-free problems for the chunk tree.

Fix it by waiting for all pthreads before destroy the chunk tree.

Since we're here, also fix the mdrestore_destroy() call inside
mdrestore_init() where if an error happened, we wait for a thread that
failed to be created.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
4 weeks agobtrfs-progs: receive: fix and enhance inlined lzo decompression
Qu Wenruo [Thu, 15 Oct 2026 00:25:02 +0000 (10:55 +1030)]
btrfs-progs: receive: fix and enhance inlined lzo decompression

[BUG]
There is a bug report of heap memory overflow during receive if
--force-decompress is utilized:

=================================================================
==557235==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x5020000000c0 at pc 0x5c38d895e8b9 bp 0x7ffdaefad510 sp 0x7ffdaefad500
WRITE of size 1 at 0x5020000000c0 thread T0
    #0 0x5c38d895e8b8 in lzo1x_decompress_safe /tmp/tmp.aIYhV2VAge/lzo-2.10/minilzo/minilzo.c:6313
    #1 0x5c38d88623cb in decompress_lzo cmds/receive.c:1165
    #2 0x5c38d886274f in decompress_and_write cmds/receive.c:1222
    #3 0x5c38d8863459 in process_encoded_write cmds/receive.c:1320
    #4 0x5c38d8785daf in read_and_process_cmd common/send-stream.c:505
    #5 0x5c38d878a16f in btrfs_read_and_process_send_stream common/send-stream.c:654
    #6 0x5c38d88650fc in do_receive cmds/receive.c:1589
    #7 0x5c38d88664ab in cmd_receive cmds/receive.c:1827
    #8 0x5c38d869729b in cmd_execute cmds/commands.h:126
    #9 0x5c38d8698a6b in main /home/kevinv/btrfs-progs/btrfs.c:474
    #10 0x72779f02a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #11 0x72779f02a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #12 0x5c38d8697184 in _start (/home/kevinv/btrfs-progs/btrfs+0x89184) (BuildId: a2ab208cbd7ebc744934a9ed7a8963a20b35fcf4)

0x5020000000c0 is located 0 bytes after 16-byte region [0x5020000000b0,0x5020000000c0)
allocated by thread T0 here:
    #0 0x72779f4fd340 in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x5c38d8862634 in decompress_and_write cmds/receive.c:1191
    #2 0x5c38d8863459 in process_encoded_write cmds/receive.c:1320
    #3 0x5c38d8785daf in read_and_process_cmd common/send-stream.c:505
    #4 0x5c38d878a16f in btrfs_read_and_process_send_stream common/send-stream.c:654
    #5 0x5c38d88650fc in do_receive cmds/receive.c:1589
    #6 0x5c38d88664ab in cmd_receive cmds/receive.c:1827
    #7 0x5c38d869729b in cmd_execute cmds/commands.h:126
    #8 0x5c38d8698a6b in main /home/kevinv/btrfs-progs/btrfs.c:474
    #9 0x72779f02a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #10 0x72779f02a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #11 0x5c38d8697184 in _start (/home/kevinv/btrfs-progs/btrfs+0x89184) (BuildId: a2ab208cbd7ebc744934a9ed7a8963a20b35fcf4)

SUMMARY: AddressSanitizer: heap-buffer-overflow /tmp/tmp.aIYhV2VAge/lz

[CAUSE]
During lzo decompression, btrfs-progs always assume that the output
buffer is block aligned, even for inlined extents.

However since kernel commit 3eaf5f082c4c ("btrfs: extract inlined
creation into a dedicated delalloc helper"), btrfs will create inlined
compressed extents with tailing zero included.

For zlib and zstd it's fine as they provide multi-shot APIs, if the
output is exhausted, zlib/zstd doesn't error out, allowing us to
gracefully end the decompression.

But LZO has no multi-shot API, thus we have to ensure the output is
large enough to contain one fs block.
For inlined case, the output buffer contains only i_size bytes, which
can be smaller than a block.

This makes inline lzo extents decompression to write the full block into
the output buffer, overflow the heap.

[FIX]
Follow the kernel by introducing a dedicated inline decompression path,
and do extra validation for inlined decompression.

There is also a similar bug in the regular path, that crafted stream can
intentionally create a segment that doesn't take a full block.
In that case we still advance output buffer by blocksize, which can
cause the last block to overflow the buffer.

Also fix that by always limiting the output buffer size comparing to
@unencoded_len.

Issue: #1184
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: slightly loosen the balance reject condition
Qu Wenruo [Mon, 12 Oct 2026 09:10:06 +0000 (19:40 +1030)]
btrfs-progs: slightly loosen the balance reject condition

Since commit dde71e2be9bd ("btrfs-progs: reject writes if the fs has
running replace/balance"), btrfs-progs will reject any writable
operation to the fs if there is a balance item in the root tree.

However there is a report that such rejection is too strict, as the user
had a corruption in the extent tree only, for which no reloc tree should
exist, and the corruption can be repaired.

Furthermore, the reloc tree in that image has refs 0, meaning it has
already been merged, thus it's safe to modify the fs.

Instead of the overly strict balance item checks, do a kernel-like reloc
tree search, and only reject the write if there is a valid reloc tree
whose refs are not 0.

If there is no such valid reloc tree, still allow writable operations.

Issue: #1182
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: add 7.0 tick on graphs
David Sterba [Mon, 19 Oct 2026 22:51:09 +0000 (00:51 +0200)]
btrfs-progs: docs: add 7.0 tick on graphs

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: add heading for 6.x on kernel/version
David Sterba [Mon, 19 Oct 2026 22:42:37 +0000 (00:42 +0200)]
btrfs-progs: docs: add heading for 6.x on kernel/version

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: minor fixups in kernel/version
David Sterba [Mon, 19 Oct 2026 22:37:20 +0000 (00:37 +0200)]
btrfs-progs: docs: minor fixups in kernel/version

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: add kernel changelog for 7.3
David Sterba [Tue, 16 Jun 2026 23:58:20 +0000 (01:58 +0200)]
btrfs-progs: docs: add kernel changelog for 7.3

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: add kernel changelog for 7.2
David Sterba [Tue, 16 Jun 2026 23:58:20 +0000 (01:58 +0200)]
btrfs-progs: docs: add kernel changelog for 7.2

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: update Status page
David Sterba [Mon, 13 Apr 2026 16:15:22 +0000 (18:15 +0200)]
btrfs-progs: docs: update Status page

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: add heading for 7.3
David Sterba [Mon, 15 Jul 2024 13:00:15 +0000 (15:00 +0200)]
btrfs-progs: docs: add heading for 7.3

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: update kernel features for 7.3
David Sterba [Mon, 9 Feb 2026 19:25:54 +0000 (20:25 +0100)]
btrfs-progs: docs: update kernel features for 7.3

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: update 7.3 contribution graphs
David Sterba [Thu, 20 Mar 2025 23:59:22 +0000 (00:59 +0100)]
btrfs-progs: docs: update 7.3 contribution graphs

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
4 weeks agobtrfs-progs: docs: add 7.3 kernel development statistics
David Sterba [Tue, 16 Jun 2026 23:24:08 +0000 (01:24 +0200)]
btrfs-progs: docs: add 7.3 kernel development statistics

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
5 weeks agobtrfs-progs: fsck-tests: add a new test case for qgroup tree check
Qu Wenruo [Mon, 5 Oct 2026 08:26:17 +0000 (18:56 +1030)]
btrfs-progs: fsck-tests: add a new test case for qgroup tree check

The workload is straight forward:

- Create a btrfs with qgroup full mode

- Create 512 subvolumes
  This should cause at least 2 leaves, even using 64K nodesize.

- Create qgroup 1/1 and assign 0/5 to it

- Run btrfs-check on the fs
  Unpatched progs will load the last leaf first, add the qgroup relation
  item without loading the qgroups in the previous leaf.

Signed-off-by: Qu Wenruo <wqu@suse.com>
5 weeks agobtrfs-progs: check: refactor load_quota_info()
Qu Wenruo [Mon, 5 Oct 2026 08:13:53 +0000 (18:43 +1030)]
btrfs-progs: check: refactor load_quota_info()

Modernize that function by:

- Use btrfs_key when possible
  The structure btrfs_disk_key is only for on-disk usage, every
  in-memory operation is based on btrfs_key.

  This includes the function alloc_count(), which now also accepts
  btrfs_key as a parameter.

- Enhance the error handling
  The path is not released when we hit an error.

- Use an dedicated helper to scan one leaf
  Instead of nested loops, which is bug-prone for continue/break calls.

- Remove the unnecessary double loop
  There is a local variable @search_relations, which has caused a long
  existing bug before.

  The idea is to skip all the QGROUP_LIMIT items, but we can skip them
  very quickly, and it's way better for one's mental health just to do a
  full tree iteration.

Signed-off-by: Qu Wenruo <wqu@suse.com>
5 weeks agobtrfs-progs: check: remove unused qgroup_count::key
Qu Wenruo [Mon, 5 Oct 2026 08:11:52 +0000 (18:41 +1030)]
btrfs-progs: check: remove unused qgroup_count::key

That member is only set during insert, but never read again.
And it's against the common practice to use btrfs_key structure for
in-memory structures.

Just remove the member to save some space for qgroup_count::key.

Signed-off-by: Qu Wenruo <wqu@suse.com>
5 weeks agobtrfs-progs: check: fix the inverted condition to load qgroups
Qu Wenruo [Mon, 5 Oct 2026 07:52:08 +0000 (18:22 +1030)]
btrfs-progs: check: fix the inverted condition to load qgroups

[BUG]
When a qgroup tree is higher than level 0 and has a qgroup relation
between the first subvolume and a higher level qgroup, the btrfs check
can failed to load qgroup tree.

A minimal reproducer looks like the following:

  mkfs.btrfs -f -K -n 4k $dev > /dev/null
  mount $dev $mnt
  btrfs quota enable "$mnt"
  btrfs quota rescan -w $mnt
  for i in $(seq 1 32); do
          btrfs subvolume create "$mnt/s$i" >/dev/null
  done
  id=$(btrfs subvolume list "$mnt" | awk 'NR==1 {print $2}')
  btrfs qgroup create 1/1 "$mnt"
  btrfs qgroup assign "0/$id" 1/1 "$mnt"
  umount $mnt
  btrfs check -Q $dev

The failure looks like:

 Opening filesystem to check...
 Checking filesystem on /dev/test/scratch1
 UUID: fbe3bc62-168a-4fec-8ef5-ba5f92d8c22c
 Print quota groups report for /dev/test/scratch1
 UUID: fbe3bc62-168a-4fec-8ef5-ba5f92d8c22c
 ERROR: failed to add qgroup relation, member=256 parent=281474976710657: No such file or directory
 ERROR: loading qgroups from disk: -2
 extent buffer leak: start 30789632 len 4096
 extent buffer leak: start 30793728 len 4096

[CAUSE]
With extra debug output, the following one line shows the problem pretty
well:

 load_quota_info: search_relations=0 search_key=(246 0 0)

That's for the first loop of load_quota_info(), which should start from
the first leaf and load all qgroups into memory.

However the search key is not (0 0 0), it's the inverted condition
initializing the search key cause btrfs-check to grab the leaf with
qgroup relation items, not the first leaf.

Thus btrfs-check failed to load the qgroups in earlier leaves, causing
the above failure.

[FIX]
The code is not that well written, but as a hot fix just revert the
condition to fix the bug.

Issues: #1180
Signed-off-by: Qu Wenruo <wqu@suse.com>
5 weeks agobtrfs-progs: CHANGES: release 7.2 skipped
David Sterba [Wed, 4 Feb 2026 06:36:30 +0000 (07:36 +0100)]
btrfs-progs: CHANGES: release 7.2 skipped

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
6 weeks agobtrfs-progs: docs: add a dedicated multi-device support chapter
Qu Wenruo [Mon, 14 Sep 2026 22:28:06 +0000 (07:58 +0930)]
btrfs-progs: docs: add a dedicated multi-device support chapter

Btrfs, like all other multi-device storage solutions, requires proper
device scan and registration to handle multi-device arrays.

However btrfs has some extra requirements and quirks related to
multi-device support.

Record those extra into into a new "MULTI-DEVICE SUPPORT" chapter in man
5 btrfs. For now it includes:

- Requirement for device scan registration

- Requirement for initramfs if the rootfs has multiple devices

- Quirk related to device path shown in mount point

Signed-off-by: Qu Wenruo <wqu@suse.com>
6 weeks agobtrfs-progs: scrub: only restore the old scrub limit after scrub is finished
Qu Wenruo [Tue, 1 Sep 2026 22:11:21 +0000 (07:41 +0930)]
btrfs-progs: scrub: only restore the old scrub limit after scrub is finished

[BUG]
There is a bug report that the --limit option of `btrfs scrub start`
doesn't properly apply for all devices.

[CAUSE]
It turns out that the timing we restore the scrub limit is too early:

 scrub_start()
 |- read_scrub_device_limit()
 |- write_scrub_device_limit()
 |  The old limit and new limit are written before we start scrub.
 |
 |- pthread_create()
 |  Now we start threads to do the real scrub ioctl for each device
 |
 |- write_scrub_device_limit()
 |  Now we already restore the old throughput for the first device.
 |
 |- pthread_join()
    We only wait for the scrub to finish after we have restored the old
    limit, which normally is no limit.

[FIX]
Move the old limit restore code after we have waited for all scrub
threads.

Issue: #1165
Fixes: 7c1c88e41668 ("btrfs-progs: scrub: add the new --limit option to set the throughput limit at runtime")
Signed-off-by: Qu Wenruo <wqu@suse.com>
6 weeks agobtrfs-progs: tests: fix typo in 044-rootdir-hardlink-size
Andrus Suvalau [Wed, 30 Sep 2026 10:58:20 +0000 (12:58 +0200)]
btrfs-progs: tests: fix typo in 044-rootdir-hardlink-size

Fix the error that occurs during mkfs test execution:
    [TEST/mkfs]   044-rootdir-hardlink-size
./test.sh: line 13: check_glolbal_prereq: command not found

Signed-off-by: Andrus Suvalau <andrus.suvalau@n-able.com>
6 weeks agobtrfs-progs: tests: add reproducibility check harness
Leo Martins [Thu, 28 May 2026 23:34:36 +0000 (16:34 -0700)]
btrfs-progs: tests: add reproducibility check harness

Add tests/reproducibility-check.sh, a standalone root-required test that
checks mkfs.btrfs produces byte-identical images from identical inputs.
For a matrix of environment variations it runs mkfs twice and cmp's the
raw images:

  - baseline, wall-clock time, TZ, locale, umask and working directory,
    for both empty and --rootdir images;
  - source uid, source filesystem (the same tree on loop-mounted ext4 vs
    xfs), and compression (lzo/zlib/zstd), for --rootdir only.

Each run uses the documented recipe: a fixed -U, SOURCE_DATE_EPOCH and
DETERMINISTIC_SEED=1, and no --device-uuid, so the matrix also confirms
mkfs derives the device UUID from the fs UUID on its own. The source
tree is chown'd to 0:0 first (the one piece left to the caller) and mkfs
normalizes timestamps itself. The ext4 mount's lost+found is stripped so
the ext4 and xfs trees match, and two locales are probed at startup so
the locale case compares two real locales or is skipped.

Root is required for the ownership and loop-mounted source-filesystem
variations. With the preceding patches, all variations pass.

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
6 weeks agobtrfs-progs: docs: document SOURCE_DATE_EPOCH and DETERMINISTIC_SEED
Leo Martins [Wed, 3 Jun 2026 03:58:01 +0000 (20:58 -0700)]
btrfs-progs: docs: document SOURCE_DATE_EPOCH and DETERMINISTIC_SEED

Add an ENVIRONMENT section to mkfs.btrfs(8) for the two environment
variables that make image creation reproducible: SOURCE_DATE_EPOCH
(timestamps) and DETERMINISTIC_SEED (UUID derivation, requires -U). It
covers the empty-is-unset and invalid-is-an-error handling, the minimal
recipe, and that normalizing ownership (chown -R 0:0) of a -r tree is
left to the caller.

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
6 weeks agobtrfs-progs: mkfs: add a sorted directory walker for reproducible -r
Leo Martins [Thu, 28 May 2026 21:44:48 +0000 (14:44 -0700)]
btrfs-progs: mkfs: add a sorted directory walker for reproducible -r

mkfs.btrfs -r walks the source tree with nftw(), which returns entries in
the source filesystem's readdir() order. That order comes from the
filesystem, not the tree: ext4 uses a name hash with a per-fs seed, xfs a
b+tree key order, tmpfs and btrfs insertion order. Discovery order then
decides inode numbers, dir_index values, extent bytenrs, and which
hardlink owns the data, so the same tree staged on two different
filesystems produces two different images.

Add path_sorted_walk() in common/path-utils, which sorts each directory's
entries by name (byte-wise strcmp, not the locale-dependent strcoll)
before recursing. It keeps nftw()'s callback signature and
preorder/FTW_PHYS semantics. ftw_add_inode() still needs a NULL-stat
guard: the walker reports a failed lstat() as FTW_NS with a NULL stat
where glibc nftw() passes a buffer, so the callback skips it instead of
dereferencing. The walker also matches
the two nftw() edges the callbacks depend on: an unreadable directory is
reported once as FTW_DNR, and errno is checked after the readdir() loop
since readdir() returns NULL for both end-of-stream and error. The child
path is heap-allocated so a deep tree doesn't overflow the stack.

A sorted traversal means reading a whole directory up front plus the qsort
and allocations that go with it. A regular mkfs doesn't need that, so keep
nftw() as the default and only sort when a reproducible image is actually
requested, i.e. when both SOURCE_DATE_EPOCH and DETERMINISTIC_SEED are set
(reproducible_is_enabled()). Setting just one can't produce a reproducible
image anyway, since the other source of nondeterminism (host time, or
random UUIDs) still leaks in. btrfs_mkfs_size_dir() stays on nftw()
regardless; it only sums sizes and counts inodes, so walk order doesn't
matter there.

The same reproducible mode sorts each inode's xattrs by name in
add_xattr_item(), the xattr counterpart of sorting directory entries. It
only matters when two names collide under btrfs_name_hash() and share a
dir_item stored in insertion order, but sorting removes the dependence.

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
6 weeks agobtrfs-progs: mkfs: honor SOURCE_DATE_EPOCH for -r source-file timestamps
Leo Martins [Thu, 28 May 2026 21:35:35 +0000 (14:35 -0700)]
btrfs-progs: mkfs: honor SOURCE_DATE_EPOCH for -r source-file timestamps

With `mkfs.btrfs -r`, stat_to_inode_item() copies each source inode's
atime, ctime and mtime from the host, so the image is not reproducible
even when the source tree is otherwise normalized. When
SOURCE_DATE_EPOCH is set, pin ctime and atime to it and clamp mtime to
it. When it is unset or empty, use the host timestamps as before.

The timestamps need different handling:

  - ctime cannot be set through the filesystem API; the kernel updates
    it after any inode change. mkfs writes the raw inode, so pin it to
    the epoch there.
  - atime is not stable source metadata. On a relatime filesystem, the
    first mkfs can record an old atime and advance it while reading the
    source, then a second mkfs records a different value. Pin it to the
    epoch so reads cannot change the image.
  - mtime remains meaningful source metadata. Preserve values older
    than the epoch and clamp newer values, so nothing in the image is
    newer than the source date.

Add a regression using a relatime source. The first build advances the
source atime. The test builds again, compares the raw images, and mounts
the result to verify that atime and ctime equal the epoch while
the older mtime is preserved.

Factor the "is SOURCE_DATE_EPOCH set" test into
reproducible_has_source_date() so it reads the same everywhere it is
needed.

uid/gid remain the caller's responsibility (chown -R 0:0): one line of
shell, where a --owner flag would be permanent CLI surface.

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
6 weeks agobtrfs-progs: mkfs: stop leaking host CPU count and page size
Leo Martins [Thu, 28 May 2026 20:01:33 +0000 (13:01 -0700)]
btrfs-progs: mkfs: stop leaking host CPU count and page size

Two host attributes leak into the on-disk image, so the same arguments
produce different output on different build machines.

  1. nr_global_roots defaulted to sysconf(_SC_NPROCESSORS_ONLN). With
     extent-tree-v2 this is written to the super block
     (btrfs_set_super_nr_global_roots) and sets how many global roots
     are created, so the host CPU count ends up in the image. Default
     to 1; --num-global-roots still overrides it. extent-tree-v2 is
     experimental, but the leak is real today.

  2. BTRFS_FEATURE_INCOMPAT_BIG_METADATA was set from
     sysconf(_SC_PAGE_SIZE): with the default 16K nodesize it was on for
     4K-page hosts and off for 16K-page hosts (aarch64). The flag is not
     a default feature and not -O-toggleable, so this is its only
     setter; the kernel sets it on any modern filesystem anyway, and
     only kernels older than Linux 3.4 (2012) lack it. Set it
     unconditionally, which drops the page-size dependency and also
     covers the 4K-nodesize case the old gate skipped.

Neither change is gated by DETERMINISTIC_SEED; both fix cross-host
consistency regardless of reproducibility intent.

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
6 weeks agobtrfs-progs: mkfs: derive UUIDs deterministically from the fs UUID
Leo Martins [Thu, 28 May 2026 23:33:11 +0000 (16:33 -0700)]
btrfs-progs: mkfs: derive UUIDs deterministically from the fs UUID

mkfs generates several internal UUIDs with uuid_generate(): every
device's dev_item.uuid, the chunk-tree UUID, the FS_TREE subvolume UUID,
and the per-subvolume UUIDs from the uuid-tree rebuild. All are random,
so even with -U and SOURCE_DATE_EPOCH pinned, two runs with identical
inputs differ. uuid_generate() reads the system CSPRNG and cannot be
seeded, so it cannot be made deterministic in place.

When DETERMINISTIC_SEED=1 is set and a fixed UUID is given with -U (the
xfsprogs convention), derive these UUIDs from the fs UUID. A plain copy
of the seed will not do: an image holds several UUIDs that must stay
distinct on disk, so each is derived from a (role, key) pair in the
fs-UUID namespace with libuuid's name-based (v5) generator:

    uuid_generate_sha1(out, fs_uuid, le32(role) || le64(key))

role is an enum (chunk tree, subvolume, device) and key distinguishes
instances within a role (subvolume objectid, devid; ignored for the
chunk-tree singleton). The name is serialized little-endian so the
result is the same on any host architecture.

uuid_generate_sha1() has been in libuuid since util-linux 2.31 (2017),
so configure.ac now requires uuid >= 2.31, like the version floors
already set for libzstd, libgcrypt and others.

Two helpers join reproducible_now() in common/reproducible.{c,h}:
reproducible_is_deterministic() checks DETERMINISTIC_SEED == "1", and
reproducible_uuid_generate() derives the UUID in deterministic mode and
otherwise falls back to uuid_generate(). mkfs errors out if
DETERMINISTIC_SEED=1 is set without -U, since there is no seed to derive
from.

Converted call sites:

  - mkfs/common.c btrfs_create_tree_root(): FS_TREE subvolume UUID.
  - mkfs/common.c make_btrfs(): chunk_tree_uuid and device 1's
    dev_item.uuid (used when --device-uuid is not given).
  - common/device-scan.c btrfs_add_to_fsid(): per-device UUID for
    devices 2..N.
  - common/root-tree-utils.c rescan_subvol_uuid(): per-subvolume UUID
    during the uuid-tree rebuild.

Only super.fsid is not derived; it is the seed, from -U (or random when
-U is absent). A user-supplied --device-uuid still overrides device 1
as before.

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
6 weeks agobtrfs-progs: mkfs: honor SOURCE_DATE_EPOCH for root-item timestamps
Leo Martins [Thu, 28 May 2026 23:32:20 +0000 (16:32 -0700)]
btrfs-progs: mkfs: honor SOURCE_DATE_EPOCH for root-item timestamps

mkfs stamps root-item timestamps with time(NULL), so every run embeds
the current wall clock and no two runs are bit-identical. Honor
SOURCE_DATE_EPOCH when it is set in the environment, the standard
reproducible-builds convention.

Add reproducible_now() in common/reproducible.{c,h}, which parses the
value with parse_u64(). An empty value means unset, per the spec. An
invalid value is rejected with an error and a non-zero exit instead of
falling back, so a typo does not silently produce a non-reproducible
image.

The helper goes in common/ because it is also called from
common/root-tree-utils.c, which is shared with other tools; later
patches add more reproducibility helpers next to it.

Convert the time(NULL) call sites:

  - mkfs/common.c btrfs_create_tree_root(): FS_TREE root_item ctime and
    otime.
  - common/root-tree-utils.c btrfs_make_root_dir(): atime/ctime/mtime/
    otime of the top inode of every root it creates (root_tree_dir,
    fs_tree, each -u subvolume, the data-reloc tree).

Signed-off-by: Leo Martins <loemra.dev@gmail.com>
7 weeks agobtrfs-progs: misc-tests: add a test case for btrfs-restore devel
Qu Wenruo [Wed, 16 Sep 2026 03:51:33 +0000 (13:21 +0930)]
btrfs-progs: misc-tests: add a test case for btrfs-restore

The new test case will:

- Create an inlined compressed file extent
- Generate checksum for that file
- Use btrfs-restore to extract that file
- Compare the extracted file with the generated checksum

The checksum should match.

This is a regression test for a behavior change in kernel, which results
older btrfs-restore unable to handle newerly created inlined compressed
file extents.

Signed-off-by: Qu Wenruo <wqu@suse.com>
7 weeks agobtrfs-progs: restore: handle inlined extent larger than 4K
Qu Wenruo [Wed, 16 Sep 2026 04:00:50 +0000 (13:30 +0930)]
btrfs-progs: restore: handle inlined extent larger than 4K

Most btrfs are already using 4K sectorsize, but for systems with 64K
page size, it's possible to create large inlined extent that is larger
than 4K:

item 6 key (257 EXTENT_DATA 0) itemoff 56802 itemsize 8213
generation 9 type 0 (inline)
inline extent data size 8192 ram_bytes 8192 compression 0 (none)

In that case, btrfs-restore will crash as its input buffer is only 4K
sized.

Enhance btrfs-restore to handle larger block size correctly, by allocate
a block-sized buffer at input buffer.

Signed-off-by: Qu Wenruo <wqu@suse.com>
7 weeks agobtrfs-progs: restore: handle full block compressed inline extent
Qu Wenruo [Wed, 16 Sep 2026 03:36:02 +0000 (13:06 +0930)]
btrfs-progs: restore: handle full block compressed inline extent

Since kernel commit 3eaf5f082c4c ("btrfs: extract inlined creation into a
dedicated delalloc helper"), the creation of compressed inlined extent
has changed to compress the whole block, then truncate the ram_bytes to
isize.

This means the compressed data needs to have a full block as the output
buffer.
This is fine for kernel, as the inlined extent is alwasy decompressed to
a folio which is at least one block sized.

But for progs, if the output buffer is smaller than a block, the
decompression will fail early (not enough output buffer), causing
btrfs-restore to completely skip the content of the inlined extent.

Fix it by always allocating a full block for copy_one_inline().

Issue: #1171
Signed-off-by: Qu Wenruo <wqu@suse.com>
7 weeks agobtrfs-progs: mkfs: make -O mixed-bg behave identically to --mixed
Andrus Suvalau [Mon, 28 Sep 2026 15:10:04 +0000 (17:10 +0200)]
btrfs-progs: mkfs: make -O mixed-bg behave identically to --mixed

Mixed block groups can be requested either with the -M/--mixed flag or
with the -O mixed-bg filesystem feature.

However using "mkfs.btrfs -O mixed-bg" results non-mixed block groups:

 Label:              (null)
 UUID:               8b6b2eaf-d399-4190-8b64-fcbed24f20fe
 Node size:          4096
 Sector size:        4096        (CPU page size: 4096)
 Filesystem size:    2.00GiB
 Block group profiles:
   Data:             single            8.00MiB <<<
   Metadata:         DUP             102.38MiB <<<
   Data+Metadata:    single            8.00MiB
   System:           DUP               8.00MiB

As "-O mixed-bg" option didn't properly set @mixed variable, thus
regular non-mixed block groups are still created.

Fix it by setting @mixed if BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS feature
is also set.

Signed-off-by: Andrus Suvalau <andrus.suvalau@n-able.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Update the commit message to show the problem more clearly ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Andrus Suvalau <andrus.suvalau@n-able.com>
7 weeks agobtrfs-progs: receive: fix unused variable warning without LZO
liuh0329 [Wed, 30 Sep 2026 06:43:28 +0000 (14:43 +0800)]
btrfs-progs: receive: fix unused variable warning without LZO

When btrfs-progs is built without LZO support, sector_shift is still
declared in decompress_and_write(), while all its uses are guarded by
COMPRESSION_LZO. This results in an unused variable warning.

Move the sector_shift calculation into the only user, which is already
under the "#if COMPRESSION_LZO" branch.

Fixes: 345731fff32d ("btrfs-progs: receive: optional build for lzo, zstd")
Signed-off-by: liuh0329 <liuhuan01@kylinos.cn>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Remove the sector_shift declaration completely, as older toolchains
  have older C-standard, which doesn't allow declaring a variable
  inside a case branch. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2 months agobtrfs-progs: check: detect leaked active zones on zoned devices
Johannes Thumshirn [Fri, 4 Sep 2026 06:24:44 +0000 (08:24 +0200)]
btrfs-progs: check: detect leaked active zones on zoned devices

On a zoned filesystem a sequential zone can end up open (and written) on
the device while it is not referenced by any dev extent and is not in a
sb-log zone. Such a zone is unreferenced - its space is free according to
the device tree - yet it stays active on the device, permanently consuming
one of the device's limited active zones. On a device with few active
zones this can lead to premature ENOSPC and/or allocation hangs.

One way to end up in this state is a mkfs that failed to reset a
temporary chunk's zone before finishing (fixed in a preceding commit).
Existing filesystems created by such a mkfs need a way to detect and
repair the condition.

Add a zoned device specific check that cross-checks the on-disk metadata
against the physical zone state of the device. It flags any written,
sequential zone that is not backed by a dev extent, and in
--repair mode resets it. The check is a no-op on non-zoned filesystems and
runs as part of the extent/device checking rather than as a separate
numbered check phase.

Introduce check_zoned() as a entry point for future zoned device checks.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: zoned: refresh stale cached zone state in btrfs_reset_dev_zone()
Johannes Thumshirn [Fri, 4 Sep 2026 06:24:43 +0000 (08:24 +0200)]
btrfs-progs: zoned: refresh stale cached zone state in btrfs_reset_dev_zone()

btrfs-progs reads the device zone layout once, in btrfs_get_zone_info() ->
report_zones() when the device is opened, and caches it in 'zinfo->zones[]'
without ever refreshing it afterwards. btrfs_reset_dev_zone() skips
resetting a zone whose cached condition is EMPTY, but that condition can be
stale: a zone written after open, for example a temporary chunk that mkfs
writes and then removes, can still be cached as EMPTY. Its reset is then
skipped and the zone is left open on the device, referenced by no chunk nor
dev extent, permanently consuming one of the device's limited active zones.
On a device with few active zones this results in premature ENOSPC or an
allocation hang.

Before skipping the reset of a supposedly empty zone, re-read its real
condition from the device and only skip if it is really empty.

Fixes: bfdb3ae23713 ("btrfs-progs: zoned: reset zone of freed block group")
Reported-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: sb-mod: use per-type digest size for superblock csum
Tom Hale [Wed, 26 Aug 2026 00:06:06 +0000 (07:06 +0700)]
btrfs-progs: sb-mod: use per-type digest size for superblock csum

The global csum_size was hardcoded to the CRC32C digest size (4),
while the actual checksum type is read from each superblock. For
xxhash64 (8), sha256 (32) and blake2b (32), check_csum_superblock()
compared only the first 4 bytes and update_block_csum() wrote a
truncated digest into the zeroed csum field, producing superblocks
that dump-super reports as [DON'T MATCH].

Replace both uses with btrfs_csum_type_size(csum_type) and drop the
now-unused global.

Verified against an xxhash64 filesystem: before the fix dump-super
shows csum 0x7cbc602b00000000 [DON'T MATCH], after the fix it shows
0x7cbc602bf714f3a8 [match]; the kernel accepts the repaired
superblock. See #1160.

Pull-request: #1161
Signed-off-by: Tom Hale <tom@hale.ee>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: sb-mod: add checksum type validation
David Sterba [Tue, 8 Sep 2026 20:03:19 +0000 (22:03 +0200)]
btrfs-progs: sb-mod: add checksum type validation

Check that value stored in super block checksum type is supported
before. As we allow to set csum_type it is possible to force an invalid
value, as does the fuzz/010 test case.

Preparatory work for pull request #1161 which removes the hardcoded
CRC32C checksum type.

Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: tests: remove csum_type from fuzz/010 case
David Sterba [Tue, 8 Sep 2026 20:22:54 +0000 (22:22 +0200)]
btrfs-progs: tests: remove csum_type from fuzz/010 case

As the checksum is the used for primary verification, fuzzing it with
the whole set of operations will eventually hit an invalid value and
prevent updating the superblock.

The only valid case is to set it to a different supported value, this
will recalculate the checksum and set it for the whole filesystem, but
all metadata will mismatch. Related issue #1160.

Signed-off-by: David Sterba <dsterba@suse.com>
2 months agolibbtrfsutil: don't leave subvolume iterator pointing at unfilled search buffer
Wehrwolfmann [Sat, 22 Aug 2026 07:43:54 +0000 (09:43 +0200)]
libbtrfsutil: don't leave subvolume iterator pointing at unfilled search buffer

subvolume_iterator_next_tree_search() sets nr_items to 4096 before
BTRFS_IOC_TREE_SEARCH and returns BTRFS_UTIL_ERROR_SEARCH_FAILED without
restoring it when the ioctl fails. items_pos and buf_off stay at 0, so the
next call to btrfs_util_subvolume_iterator_next() takes the 'items_pos <
nr_items' branch and parses btrfs_ioctl_search_header structures out of a
buffer the failed ioctl never filled.

Each phantom item advances buf_off by the header size plus the length read
from the uninitialized memory, so the walk quickly leaves the 3992 byte
buffer; with 4096 items it ends about 128 KB past its start. Depending on
what follows the buffer this either segfaults or spins on an unbounded
number of bogus items.

An unprivileged caller reaches this easily: use_tree_search is true whenever
top != 0, so BTRFS_UTIL_SUBVOLUME_ITERATOR_* users that pass a subvolume id
take the TREE_SEARCH path, the iterator is created successfully, and the
first ioctl then fails with EPERM.

Reset the entry on the error path so the search buffer is never parsed
before an ioctl has filled it.

Pull-request: #1159
Issue: #1158
Assisted-by: LLM
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: docs: add a note about RW degraded mount
Qu Wenruo [Wed, 12 Aug 2026 00:53:17 +0000 (10:23 +0930)]
btrfs-progs: docs: add a note about RW degraded mount

When a new chunk is allocated during a RW degraded mount, btrfs can
allocate new chunks with other profiles, like SINGLE, if the current
devices can no longer support the original profile.

This can cause unexpected chunk profiles, and the end user is
recommended to balance them out if they want to maintain the current
allocation profile.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: tests: add case for unexpected file extent items
Qu Wenruo [Tue, 18 Aug 2026 06:04:07 +0000 (15:34 +0930)]
btrfs-progs: tests: add case for unexpected file extent items

The image is created using btrfs-corrupt-block, the fs tree leaf looks
like this:

item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
generation 3 transid 9 size 12 nbytes 16384
block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
sequence 1 flags 0x0(none)
item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
index 0 namelen 2 name: ..
item 2 key (256 DIR_ITEM 496027801) itemoff 16075 itemsize 36
location key (257 INODE_ITEM 0) type BLKDEV <<<
transid 9 data_len 0 name_len 6
name: foobar
item 3 key (256 DIR_INDEX 2) itemoff 16039 itemsize 36
location key (257 INODE_ITEM 0) type BLKDEV <<<
transid 9 data_len 0 name_len 6
name: foobar
item 4 key (257 INODE_ITEM 0) itemoff 15879 itemsize 160
generation 9 transid 9 size 8192 nbytes 8192
block group 0 mode 60660 links 1 uid 0 gid 0 rdev 0 <<<
sequence 2 flags 0x0(none)
item 5 key (257 INODE_REF 256) itemoff 15863 itemsize 16
index 2 namelen 6 name: foobar
item 6 key (257 EXTENT_DATA 0) itemoff 15810 itemsize 53
generation 9 type 1 (regular)
extent data disk byte 13631488 nr 8192
extent data offset 0 nr 8192 ram 8192
extent compression 0 (none)

The image is generated by the following steps:

  # mkfs.btrfs -f $dev
  # mount $dev $mnt
  # xfs_io -f -c "pwrite 0 4k" $mnt/foobar
  # umount $mnt

  ## Change the inode's mode from REG to BLK
  # btrfs-corrupt-block -i 257 -f mode --value 25008 $dev

  ## Change the dir item's flag from REG to BLK
  # btrfs-corrupt-block -D 256,84,496027801 -f flags --value 4 $dev

  ## Change the dir index's flag from REG to BLK
  # btrfs-corrupt-block -D 256,96,2 -f flags --value 4 $dev

The inode's mode and dir flags all match, but there is one unexpected
file extent item there.

Both lowmem and original mode should detect such problem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: check: detect invalid file extent items
Qu Wenruo [Tue, 18 Aug 2026 05:49:05 +0000 (15:19 +0930)]
btrfs-progs: check: detect invalid file extent items

File extent items should only exist for regular and symlink inodes.
And for symlink inodes, the file extent must be inlined.

Add such check for lowmem mode to detect those invalid file extents.

Now for a corrupted image with the following fs tree layout:

item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
generation 3 transid 9 size 12 nbytes 16384
block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
sequence 1 flags 0x0(none)
item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
index 0 namelen 2 name: ..
item 2 key (256 DIR_ITEM 496027801) itemoff 16075 itemsize 36
location key (257 INODE_ITEM 0) type BLKDEV
transid 9 data_len 0 name_len 6
name: foobar
item 3 key (256 DIR_INDEX 2) itemoff 16039 itemsize 36
location key (257 INODE_ITEM 0) type BLKDEV
transid 9 data_len 0 name_len 6
name: foobar
item 4 key (257 INODE_ITEM 0) itemoff 15879 itemsize 160
generation 9 transid 9 size 8192 nbytes 8192
block group 0 mode 60660 links 1 uid 0 gid 0 rdev 0
sequence 2 flags 0x0(none)
item 5 key (257 INODE_REF 256) itemoff 15863 itemsize 16
index 2 namelen 6 name: foobar
item 6 key (257 EXTENT_DATA 0) itemoff 15810 itemsize 53
generation 9 type 1 (regular)
extent data disk byte 13631488 nr 8192
extent data offset 0 nr 8192 ram 8192
extent compression 0 (none)

Lowmem mode will detect the error like the following:

  [5/8] checking fs roots
  ERROR: root 5 ino 257 should not have file extent
  ERROR: root 5 INODE[257] nbytes 8192 not equal to extent_size 0
  ERROR: errors found in fs roots
  found 172032 bytes used, error(s) found

For the original mode, it's less strict than the lowmem mode, and it
only rejects the obvious cases, without the extra verification on
inlined extent for symlinks:

  [5/8] checking fs roots
  root 5 inode 257 errors 40, bad file extent
  ERROR: errors found in fs roots
  found 172032 bytes used, error(s) found

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: corrupt-block: allow corrupting dir item flags
Qu Wenruo [Tue, 18 Aug 2026 05:35:10 +0000 (15:05 +0930)]
btrfs-progs: corrupt-block: allow corrupting dir item flags

With this feature and the previous inode corruption, we can change the
type in inode item, dir item, dir index to be consistent with each
other.

Assisted-by: LLM (coding)
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: corrupt-block: allow dir item corruption to use --value option
Qu Wenruo [Tue, 18 Aug 2026 05:30:15 +0000 (15:00 +0930)]
btrfs-progs: corrupt-block: allow dir item corruption to use --value option

For now this only affects DIR_ITEM location objectid corruption, but
later this will be utilized for more dir item member corruption.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: corrupt-block: allow inode corruption to use --value option
Qu Wenruo [Tue, 18 Aug 2026 05:21:56 +0000 (14:51 +0930)]
btrfs-progs: corrupt-block: allow inode corruption to use --value option

This allows us to do more accurate inode item corruption, not only to
inject random number, but more targeted values.

This feature will be later utilized to change inode's mode from REG to
BLK.

Assisted-by: LLM (coding)
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: set creation/change time (otime/ctime) of offline-created subvolumes
koraynilay [Thu, 20 Aug 2026 22:08:30 +0000 (00:08 +0200)]
btrfs-progs: set creation/change time (otime/ctime) of offline-created subvolumes

Update common/root-tree-utils.c's btrfs_make_subvolume() to also
generate a UUID and set otime and ctime of subvolumes created offline
(if it's a normal subvolume).

This is essentially the same change as commit ("btrfs-progs: convert:
set creation/change time (otime/ctime) of root subvol") but that applies to:

* mkfs.btrfs' --rootdir and --subvol options
* btrfs-convert's ext2_saved subvolume

Pull-request: #1157
Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Remove the duplicated <string.h> header inclusion ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: convert: set creation/change time (otime/ctime) of root subvol
koraynilay [Thu, 20 Aug 2026 17:33:44 +0000 (19:33 +0200)]
btrfs-progs: convert: set creation/change time (otime/ctime) of root subvol

Before this, btrfs-convert would leave the root subvol of the converted
fs with 0 as both otime and ctime, showing "-" when using
btrfs subvolume show /path.

This patch uses the code from mkfs.btrfs's btrfs_create_tree_root() to
set the otime/ctime to the root subvol and generate its UUID right away
(instead of having to wait for btrfs_rebuild_uuid_tree(), not
necessarily needed but cleaner).

This way the timestamp of the filesystem conversion will be available in
the "Creation time" field of btrfs subvolume show /path output, while
the original ext* "Filesystem created" timestamp is available with stat
as the mountpoint's birth time.

Pull-request: #1157
Assisted-by: Claude:opus-4.6 antigravity-cli-1.1.7
Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Remove the duplicated <time.h> header inclusion ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2 months agobtrfs-progs: subvolume show: fix "Creation time" value being shown for "Send time...
koraynilay [Thu, 20 Aug 2026 16:50:01 +0000 (18:50 +0200)]
btrfs-progs: subvolume show: fix "Creation time" value being shown for "Send time" too

The send time would be printed before updating tstr, which is previously used
to store the string for the subvol creation time, thus showing an incorrect
send time.

Signed-off-by: koraynilay <koray.fra@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: drop stable 5.4 heading from feature overview
David Sterba [Tue, 18 Aug 2026 08:55:34 +0000 (10:55 +0200)]
btrfs-progs: docs: drop stable 5.4 heading from feature overview

The stable version headings are anchors for currently active stable
versions, 5.4 is not anymore. As the entries are short it's easy to look
up a particular version if needed.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: ci: update image administration steps
David Sterba [Tue, 18 Aug 2026 08:43:27 +0000 (10:43 +0200)]
btrfs-progs: ci: update image administration steps

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: clarify Deduplication
David Sterba [Tue, 18 Aug 2026 08:15:15 +0000 (10:15 +0200)]
btrfs-progs: docs: clarify Deduplication

Based on question and answer in the issue, udpate the initial paragraph.
Mention that we now have access to raw checksums too.

[ci skip]

Issue: #1137
Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: add heading for 7.2
David Sterba [Mon, 15 Jul 2024 13:00:15 +0000 (15:00 +0200)]
btrfs-progs: docs: add heading for 7.2

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: update list of experimental features
David Sterba [Mon, 17 Aug 2026 17:46:51 +0000 (19:46 +0200)]
btrfs-progs: docs: update list of experimental features

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: update kernel features for 7.2
David Sterba [Mon, 9 Feb 2026 19:25:54 +0000 (20:25 +0100)]
btrfs-progs: docs: update kernel features for 7.2

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: update Status page
David Sterba [Tue, 16 Jun 2026 23:17:09 +0000 (01:17 +0200)]
btrfs-progs: docs: update Status page

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: update 7.2 contribution graphs
David Sterba [Thu, 20 Mar 2025 23:59:22 +0000 (00:59 +0100)]
btrfs-progs: docs: update 7.2 contribution graphs

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: add 7.2 kernel development statistics
David Sterba [Tue, 16 Jun 2026 23:24:08 +0000 (01:24 +0200)]
btrfs-progs: docs: add 7.2 kernel development statistics

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: fix typos or spelling
David Sterba [Mon, 17 Aug 2026 13:29:06 +0000 (15:29 +0200)]
btrfs-progs: fix typos or spelling

Manual pass over all sources to fix things not reported by codespell.
Raw spellcheck used.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: docs: update the stability on btrfs-quota
Qu Wenruo [Mon, 3 Aug 2026 00:35:22 +0000 (10:05 +0930)]
btrfs-progs: docs: update the stability on btrfs-quota

The core design of btrfs qgroup mode is to track the ownership of every
extent accurately, but that is conflicting with snapshots, which can
change the ownership of tons of extents in a very short time, during
snapshot creation and deletion.

Although qgroup mode has several workarounds, it is not fully resolved
and still introduces extra costs, e.g. requires frequent rescan,
breaking limits etc.

So make it more clear that qgroup mode is not recommended until the end
user has a rigid subvolume layout, e.g. no more new subvolume/snapshots,
nor deletion of any existing subvolume.

Signed-off-by: Qu Wenruo <wqu@suse.com>
3 months agobtrfs-progs: fix-data-checksum: fix an off-by-one error in the mirror bitmap
Sidong Yang [Tue, 4 Aug 2026 12:39:15 +0000 (12:39 +0000)]
btrfs-progs: fix-data-checksum: fix an off-by-one error in the mirror bitmap

[BUG]
With both mirrors of a DUP data block corrupted, only the first one shows
up in the report:

  # btrfs rescue fix-data-checksum dup.img

  logical=84082688 corrtuped mirrors=1 affected files:
    (subvolume 5)/file2

While both mirrors have a checksum mismatch, so the expected output is:

  logical=84082688 corrtuped mirrors=1,2 affected files:
    (subvolume 5)/file2

[CAUSE]
The error mirror bitmap uses bit 0 for mirror 1, as documented in struct
corrupted_block, and add_corrupted_block() does that conversion when it
allocates a new entry:

  set_bit(mirror - 1, last->error_mirror_bitmap);

But when an entry for the same logical bytenr already exists, the mirror
number is used as the bit number directly:

  set_bit(mirror, last->error_mirror_bitmap);

The first corrupted mirror of a block always goes through the allocation
path, so only the second and any following one are affected, and their bit
ends up one position too high.

For the last mirror this means bit @num_mirrors gets set, which is beyond
the range report_corrupted_blocks() walks, so the mirror is dropped from
the report. For the other mirrors the number reported is one larger than
the corrupted one, e.g. on a RAID1C3 block with mirrors 1 and 2 corrupted
the report claims mirrors 1 and 3, marking the only intact mirror as bad.

This is more than a cosmetic problem, as the report is what the user bases
the mirror choice on in the interactive mode. Picking a mirror that is
reported as intact but is in fact corrupted updates the checksum item to
match the corrupted data, making the corruption permanent.

[FIX]
Convert the mirror number to a bit number the same way the allocation path
does.

Fixes: 0e999c9bd3e7 ("btrfs-progs: introduce "btrfs rescue fix-data-checksum"")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Sidong Yang <sidong.yang@furiosa.ai>
Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: fix-data-checksum: fix the size of the error mirror bitmap
Sidong Yang [Tue, 4 Aug 2026 12:36:17 +0000 (12:36 +0000)]
btrfs-progs: fix-data-checksum: fix the size of the error mirror bitmap

[BUG]
Running "btrfs rescue fix-data-checksum" on a filesystem with a data
checksum mismatch triggers a heap buffer overflow:

  ==3692==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x502000000190
  READ of size 8 at 0x502000000190 thread T0
      #0 set_bit kernel-lib/bitops.h:32
      #1 add_corrupted_block cmds/rescue-fix-data-checksum.c:99
      #2 verify_one_data_block cmds/rescue-fix-data-checksum.c:143
      #3 iterate_one_csum_item cmds/rescue-fix-data-checksum.c:178
      #4 iterate_csum_root cmds/rescue-fix-data-checksum.c:252
      #5 btrfs_recover_fix_data_checksum cmds/rescue-fix-data-checksum.c:510
  0x502000000191 is located 0 bytes after 1-byte region [0x502000000190,0x502000000191)
  allocated by thread T0 here:
      #0 calloc
      #1 add_corrupted_block cmds/rescue-fix-data-checksum.c:94

[CAUSE]
BITS_TO_LONGS() returns the number of unsigned longs needed to hold the
given amount of bits, not the number of bytes. But the value is passed as
the byte size to calloc():

  last->error_mirror_bitmap = calloc(1, BITS_TO_LONGS(num_mirrors));

For any sane number of mirrors this allocates a single byte, while
set_bit() accesses the bitmap in unsigned long units, thus reading and
writing 8 bytes out of a 1 byte allocation.

[FIX]
Use bitmap_zalloc() from kernel-lib/bitmap.h, which does the size
calculation for the caller, and pair it with bitmap_free() when the
record is released.

Fixes: 0e999c9bd3e7 ("btrfs-progs: introduce "btrfs rescue fix-data-checksum"")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Sidong Yang <sidong.yang@furiosa.ai>
Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: remove unnecessary forced type casting in print-tree.c
Qu Wenruo [Thu, 6 Aug 2026 09:13:09 +0000 (18:43 +0930)]
btrfs-progs: remove unnecessary forced type casting in print-tree.c

In kernel-shared/print-tree.c, we have a lot of forced type casting to
"(unsigned long long)" for the format "%llu", no matter if the original
value is really u64.

Change all those forced type casting used in printing functions, to use
the correct native type instead.

Assisted-by: LLM (coding)
Signed-off-by: Qu Wenruo <wqu@suse.com>
[ reformat short lines ]
Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: tests: update bash style guide
David Sterba [Mon, 3 Aug 2026 11:04:11 +0000 (13:04 +0200)]
btrfs-progs: tests: update bash style guide

[ ci skip ]

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: tests: cleanup bash style in ./common
David Sterba [Fri, 31 Jul 2026 16:42:39 +0000 (18:42 +0200)]
btrfs-progs: tests: cleanup bash style in ./common

- use [[ ]]
- use $* or [*] inside string
- add missing quotes
- visual style fixups
- arithmetic expression simplifications

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: tests: cleanup bash style in common scripts
David Sterba [Fri, 31 Jul 2026 16:00:10 +0000 (18:00 +0200)]
btrfs-progs: tests: cleanup bash style in common scripts

- use [[ ]]
- use $* inside string
- visual style fixups

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: tests: cleanup bash style in driver scripts
David Sterba [Fri, 31 Jul 2026 15:32:57 +0000 (17:32 +0200)]
btrfs-progs: tests: cleanup bash style in driver scripts

- use [[ ]]
- use $* inside string
- use "=" for simple comparisons
- add missing quotes
- change && || to if-else

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: drop type casts from set/get_label calls
David Sterba [Thu, 23 Jul 2026 10:31:49 +0000 (12:31 +0200)]
btrfs-progs: drop type casts from set/get_label calls

The helpers set_label() and get_label() take const parameters and the
arguments are also const so it's not necessary to cast them, probably
some leftover from the past.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: receive: use correct type for pwrite in process_write()
David Sterba [Thu, 23 Jul 2026 10:14:08 +0000 (12:14 +0200)]
btrfs-progs: receive: use correct type for pwrite in process_write()

pwrite() return value will fit 'int' most of the time, but we should use
the correct type for consistency.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: receive: handle writes of 0 bytes
David Sterba [Thu, 23 Jul 2026 10:11:23 +0000 (12:11 +0200)]
btrfs-progs: receive: handle writes of 0 bytes

If pwrite() writes 0 bytes for some reason the loop will become
infinite. While this is unlikely to happen, this is a condition hard to
detect so we better handle it.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: fix assigning negative errno
David Sterba [Thu, 23 Jul 2026 09:52:47 +0000 (11:52 +0200)]
btrfs-progs: fix assigning negative errno

As we use negative errno in many places, there were two conversion that
assigned a negative value there, which is wrong.

Note that in many other places we do 'errno = ret' but that's for
pthread_* or posix_memalign() functions that return errno directly.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: use full size path buffer in cmd_subvolume_delete()
David Sterba [Thu, 23 Jul 2026 08:38:06 +0000 (10:38 +0200)]
btrfs-progs: use full size path buffer in cmd_subvolume_delete()

Commit d544db2078fd43 ("btrfs-progs: unify naming of return values in
cmd_subvolume_create()") converted the unchecked sprintf to path API but
the full_subvolpath is actually shorter than PATH_MAX. This could lead
to stack overflow for a really long path.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: use path API to build subvolume paths
David Sterba [Wed, 22 Jul 2026 16:32:53 +0000 (18:32 +0200)]
btrfs-progs: use path API to build subvolume paths

There's open coded path concatenation using raw str* functions, we have
the path API for that.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: use parse_u64() in cmd_subvolume_sync()
David Sterba [Wed, 22 Jul 2026 11:44:52 +0000 (13:44 +0200)]
btrfs-progs: use parse_u64() in cmd_subvolume_sync()

Use our helper to avoid intricacies of strtoull().

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: reset errno before strtoull() when parsing numbers
David Sterba [Wed, 22 Jul 2026 11:37:43 +0000 (13:37 +0200)]
btrfs-progs: reset errno before strtoull() when parsing numbers

On success strtoull() does not change the errno, so we have to reset it
not to read any stale value.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: don't reuse filesystem fd for sysfs files
David Sterba [Wed, 22 Jul 2026 11:32:01 +0000 (13:32 +0200)]
btrfs-progs: don't reuse filesystem fd for sysfs files

Sysfs helpers reuse the input file descriptor of the filesystem for the
sysfs files, as this is one time read. For clarity use two variables for
that.

Signed-off-by: David Sterba <dsterba@suse.com>
3 months agobtrfs-progs: handle strdup() failures
David Sterba [Wed, 22 Jul 2026 11:13:02 +0000 (13:13 +0200)]
btrfs-progs: handle strdup() failures

There are many unhandled calls to strdup(), while this almost never
fails we still want to handle all runtime errors.

Signed-off-by: David Sterba <dsterba@suse.com>
4 months agobtrfs-progs: misc-tests: replace deprecated standalone "usebackuproot" option
Qu Wenruo [Wed, 8 Jul 2026 06:26:04 +0000 (15:56 +0930)]
btrfs-progs: misc-tests: replace deprecated standalone "usebackuproot" option

That option is already marked deprecated a long time ago, and is going to
be completely removed in v7.3.

Update the test case to auto-detect if the running kernel has support
for "rescue=usebackuproot", and if not skip the test case.

Furthermore, since v7.3 all "rescue=" mount options, including
"rescue=usebackuproot" will require full RO mount, also add "ro" mount
option to the test run.

Signed-off-by: Qu Wenruo <wqu@suse.com>
4 months agobtrfs-progs: docs: mark "usebackuproot" mount option as removed
Qu Wenruo [Sat, 4 Jul 2026 09:05:30 +0000 (18:35 +0930)]
btrfs-progs: docs: mark "usebackuproot" mount option as removed

Since the kernel patch is going to land in v7.3, update the man page to
reflect that change.

Also, just in case end users are using the latest progs but on a much
older kernel, keep the "usebackuproot" mount option entry, but
explicitly mark it as "removed", along with the history of deprecation.

Reviewed-by: Johannes Thumshirn <joahnnes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
4 months agobtrfs-progs: update the direct IO behavior notes for version 7.3
Qu Wenruo [Tue, 30 Jun 2026 23:50:39 +0000 (09:20 +0930)]
btrfs-progs: update the direct IO behavior notes for version 7.3

Since v7.3 will use IOMAP_DIO_BOUNCE flag to address the performance
drop of falling back to buffer IO, update the direct IO behavior notes
to avoid confusion.

Signed-off-by: Qu Wenruo <wqu@suse.com>
4 months agobtrfs-progs: sync BTRFS_FEATURE_INCOMPAT_SUPP_STABLE from the kernel
Qu Wenruo [Sat, 27 Jun 2026 04:30:49 +0000 (14:00 +0930)]
btrfs-progs: sync BTRFS_FEATURE_INCOMPAT_SUPP_STABLE from the kernel

Unlike kernel, btrfs-progs was using explicit definitions for
experimental and regular builds.

This makes maintaining them much harder, since there are already 14
different features just for non-experimental builds.

Simplify the definition by pulling BTRFS_FEATURE_INCOMPAT_SUPP_STABLE
from kernel, and only add new features into experimental builds based on
that BTRFS_FEATURE_INCOMPAT_SUPP_STABLE macro.

This also addresses a small feature mismatch, the feature
raid-stripe-tree is still experimental in the kernel, and all involved
feature flags are also only defined for experimental progs builds, but
it's still defined as supported feature.

Now progs will share the same feature as kernels, for both experimental
and regular builds.

Signed-off-by: Qu Wenruo <wqu@suse.com>
4 months agobtrfs-progs: remove out-of-data comments on free space tree
Qu Wenruo [Sat, 27 Jun 2026 04:21:53 +0000 (13:51 +0930)]
btrfs-progs: remove out-of-data comments on free space tree

Btrfs-progs has read-write support for free-space-tree since commit
f46b08f3ab69 ("btrfs-progs: Add freespace tree as compat_ro supported
feature").

The out-of-date comment no longer makes any sense, just remove it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
4 months agobtrfs-progs: tests: don't use eval in mkfs/014 for file filler
David Sterba [Mon, 20 Jul 2026 10:21:10 +0000 (12:21 +0200)]
btrfs-progs: tests: don't use eval in mkfs/014 for file filler

While the 'eval printf' is safe here, let's avoid it and use a different
way based on zero prefix of decimal values.

The other use of 'eval' is in the interactive test console which is not
ran during the testsuite and only meant for local prototyping.

Signed-off-by: David Sterba <dsterba@suse.com>
4 months agobtrfs-progs: tests: fix simple shellcheck warnings in test cases
David Sterba [Mon, 20 Jul 2026 10:01:23 +0000 (12:01 +0200)]
btrfs-progs: tests: fix simple shellcheck warnings in test cases

- add quotes where missing (variables, arrays, ...)
- use $(...) instead of `....`
- use {..} ranges instead of seq or ((...))
- add command prerequisites
- minor style fixups

Signed-off-by: David Sterba <dsterba@suse.com>
4 months agobtrfs-progs: tests: fix ctime check in convert/019
David Sterba [Mon, 20 Jul 2026 08:29:04 +0000 (10:29 +0200)]
btrfs-progs: tests: fix ctime check in convert/019

This seems to be a copy&paste error, stat format %z is ctime and this is
also reported in the failure. Use the correct variable.

Signed-off-by: David Sterba <dsterba@suse.com>
4 months agobtrfs-progs: tests: remove unused variables from test cases
David Sterba [Mon, 20 Jul 2026 08:28:23 +0000 (10:28 +0200)]
btrfs-progs: tests: remove unused variables from test cases

Signed-off-by: David Sterba <dsterba@suse.com>
4 months agobtrfs-progs: tests: assign default size value directly in prepare_test_dev()
David Sterba [Mon, 20 Jul 2026 08:25:26 +0000 (10:25 +0200)]
btrfs-progs: tests: assign default size value directly in prepare_test_dev()

Shellcheck is slightly confused by the way the size is assigned the
default value, in a separate statement. Do it directly in the local
declaration.

Signed-off-by: David Sterba <dsterba@suse.com>