Commit Graph

1352385 Commits

Author SHA1 Message Date
Kent Overstreet
1c8dfd7ba5 bcachefs: sb_validate() no longer requires members_v1
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:19 -04:00
Kent Overstreet
d12bd41018 bcachefs: Add a recovery pass for making sure root inode is readable
If the root inode/subvolume is unreadable we can repair automatically -
but only if we're still in recovery, so that we can rewind to the
appropriate recovery pass.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:19 -04:00
Kent Overstreet
bdad8962c9 bcachefs: Flag for repair on missing subvolume
Instead of going emegency read only with a bch2_fs_inconsistent() call,
log the error and recovery pass appropriately.

If we're still in recovery it'll be repaired immediately, otherwise
it'll be repaired on the next mount.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:18 -04:00
Kent Overstreet
ebf561b208 bcachefs: print_str_as_lines() -> print_str()
bch2_print_string_as_lines() is a low level helper that allows messages
longer than 1k to be printed without truncation.

But we should always be printing with the helpers that take a filesystem
object, if we're in fsck they direct output to the userspace process
controlling fsck instead of the dmesg log.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:18 -04:00
Kent Overstreet
040c762152 bcachefs: bch2_dev_missing_bkey()
Part of the ongoing project to kill off bch2_(fs|trans)_inconsistent
calls - they generally need to be replaced with either

- a fsck_err() call that can repair the error, or

- logging an error of the appropriate type in the superblock, and
  flagging the appropriate recovery pass to repair the error

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:17 -04:00
Kent Overstreet
2085325171 bcachefs: Simplify bch2_count_fsck_err()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:17 -04:00
Kent Overstreet
bb36a12921 bcachefs: bch2_run_explicit_recovery_pass_printbuf()
We prefer helpers that emit log messages to printbufs rather than
printing them directly; that way, we can ensure that different log
messages from the same event are grouped together and formatted
appropriately in the dmesg log.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:16 -04:00
Kent Overstreet
5022d0e183 bcachefs: Incompatible features may now be enabled at runtime
version_upgrade is now a runtime option.

In the future we'll want to add compatible upgrades at runtime, and call
the full check_version_upgrade() when the option changes, but we don't
have compatible optional upgrades just yet.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:16 -04:00
Kent Overstreet
c79eb06da4 bcachefs: Clean up option pre/post hooks, small fixes
The helpers are now:
- bch2_opt_hook_pre_set()
- bch2_opts_hooks_pre_set()
- bch2_opt_hook_post_set

Fix a bug where the filesystem discard option would incorrectly be
changed when setting the device option, and don't trigger rebalance
scans unnecessarily (when options aren't changing).

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:16 -04:00
Kent Overstreet
83ecd1b122 bcachefs: Use drop_locks_do() in bch2_inode_hash_find()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:16 -04:00
Kent Overstreet
c02e5b5728 bcachefs: Single device mode
Single device filesystems are now identified by the block device name,
not the UUID - and single device filesystems with the same UUID can be
mounted simultaneously, without any special options.

This allocates a new bit in the superblock, BCH_SB_MULTI_DEVICE, which
indicates whether a filesystem has ever been multi device.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:15 -04:00
Kent Overstreet
58c36e6710 bcachefs: Initialize c->name earlier on single dev filesystems
On single device filesystems, c->name contains the block device name,
not the UUID.

Initialize this earlier, so that single device mode can use it for
initializing sysfs/debugfs.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:15 -04:00
Alan Huang
0e43bf5a6a bcachefs: Simplify logic
Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:14 -04:00
Alan Huang
152bae193c bcachefs: Remove spurious +1/-1 operation
Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:14 -04:00
Alan Huang
f013b4ca35 bcachefs: Kill bch2_trans_unlock_noassert
Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:14 -04:00
Kent Overstreet
6f03e30e7c bcachefs: Clean up duplicated code in bch2_journal_halt()
It's now a wrapper around bch2_journal_halt_locked().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:13 -04:00
Kent Overstreet
03f8f9a129 bcachefs: bch2_dev_allocator_set_rw()
Add a helper that lets us change bch_member.data_allowed at runtime.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:13 -04:00
Kent Overstreet
2e0d51d00e bcachefs: bch2_dev_journal_alloc() now respects data_allowed
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:13 -04:00
Kent Overstreet
93ac4d5f92 bcachefs: Improve bch2_btree_cache_to_text()
Make the output slightly clearer, and include a counter for "nodes we
couldn't free because we would have gone under our reserve".

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:13 -04:00
Kent Overstreet
e50fe14c54 bcachefs: __btree_node_reclaim_checks()
Factor out a helper so we're not duplicating checks after locking the
btree node.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:13 -04:00
Kent Overstreet
68aaeb7c8b bcachefs: kill BTREE_CACHE_NOT_FREED_INCREMENT()
Small cleanup, just always increment the counters.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:12 -04:00
Kent Overstreet
ef8dd631f7 bcachefs: Improve opts.degraded
Kill 'opts.very_degraded', and make 'opts.degraded' a persistent option,
stored in the superblock.

It's now an enum, with available choices ask/yes/very/no.

"ask" mode will be handled by the mount helper, for prompting the user
(on a machine used interactively) for whether to do a degraded mount.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:12 -04:00
Kent Overstreet
2758c28aca bcachefs: export bch2_chacha20
Needed for userspcae.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:11 -04:00
Integral
dd1b99f706 bcachefs: indent error messages of invalid compression
This patch uses printbuf_indent_add_nextline() to set a consistent
indentation level for error messages of invalid compression.

In my previous patch [1], the newline is added by using '\n' in
the argument of prt_str(). This patch replaces prt_str() with
prt_printf() to make indentation level work correctly.

[1] Link: https://lore.kernel.org/20250406152659.205997-2-integral@archlinuxcn.org

Signed-off-by: Integral <integral@archlinuxcn.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:10 -04:00
Integral
84ccd47d26 bcachefs: split error messages of invalid compression into two lines
When an invalid compression type or level is passed as an argument
to `--compression`, two error messages are squashed into one line:

    > bcachefs format --compression=lzo bcachefs-comp.img
    invalid option: invalid compression typecompression: parse error

    > bcachefs format --compression=lz4:16 bcachefs-comp.img
    invalid option: invalid compression levelcompression: parse error

To resolve this issue, add a newline character at the end of the
first error message to separate them into two lines.

Signed-off-by: Integral <integral@archlinuxcn.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:08 -04:00
Integral
0e790469bf bcachefs: early return for negative values when parsing BCH_OPT_UINT
Currently, when passing a negative integer as argument, the error
message is "too big" due to casting to an unsigned integer:

    > bcachefs format --block_size=-1 bcachefs.img
    invalid option: block_size: too big (max 65536)

When negative value in argument detected, return early before
calling bch2_opt_validate().

A new error code `BCH_ERR_option_negative` is added.

Signed-off-by: Integral <integral@archlinuxcn.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:07 -04:00
Kent Overstreet
3a2a0d08b2 bcachefs: move_data_phys: stats are not required
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:05 -04:00
Kent Overstreet
d4d71b58e5 bcachefs: RO mounts now use less memory
Defer memory allocations only needed in RW mode until we actually go RW.

This is part of improved support for RO images.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:04 -04:00
Kent Overstreet
a17e985be9 bcachefs: Move various init code to _init_early()
_init_early() is for initialization that cannot fail, and often must
happen for teardown partway through initialization to work.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:02 -04:00
Kent Overstreet
31813dcf37 bcachefs: alphabetize init function calls
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:00 -04:00
Kent Overstreet
25ee021c7f bcachefs: simplify journal pin initialization
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:59 -04:00
Kent Overstreet
2767f4f258 bcachefs: btree_io_complete_wq -> btree_write_complete_wq
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:56 -04:00
Kent Overstreet
c9b5d9cd26 bcachefs: bch2_kvmalloc() mem alloc profiling
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:56 -04:00
Kent Overstreet
bcaea61adc bcachefs: add missing include
Hygeine, and fix build in userspace.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:52 -04:00
Kent Overstreet
b974357c63 bcachefs: bch2_snapshot_table_make_room()
Add a better helper for check_snapshot_exists().

create_snapids() can't be changed to use this, unfortunately, because
the transaction that creates new snapshot will also be inserting other
keys (e.g. root inode) that reference that snapshot ID, and they expect
the snapshot table to already be updated.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:50 -04:00
Kent Overstreet
ea27e8ca5d bcachefs: darray: provide typedefs for primitive types
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:47 -04:00
Kent Overstreet
2a81bd454c bcachefs: reduce new_stripe_alloc_buckets() stack usage
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:44 -04:00
Kent Overstreet
a0b0b9bb9e bcachefs: alloc_request no longer on stack
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:43 -04:00
Kent Overstreet
95f2315af7 bcachefs: alloc_request.ptrs2
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:40 -04:00
Kent Overstreet
e038213658 bcachefs: alloc_request.ca
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:39 -04:00
Kent Overstreet
7f65d1cf5c bcachefs: alloc_request.counters
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:37 -04:00
Kent Overstreet
4d00e88d21 bcachefs: alloc_request.usage
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:36 -04:00
Kent Overstreet
a0312f4251 bcachefs: alloc_request: deallocate_extra_replicas()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:35 -04:00
Kent Overstreet
ac0952b0e5 bcachefs: new_stripe_alloc_buckets() takes alloc_request
More stack usage improvements: instead of creating a new alloc_request
(currently on the stack), save/restore just the fields we need to reuse.

This is a bit tricky, because we're doing a normal alloc_foreground.c
allocation, which calls into ec.c to get a stripe, which then does more
normal allocations - some of the fields get reused, and used
differently.

So we have to save and restore them - but the stack usage improvements
will be well worth it.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:33 -04:00
Kent Overstreet
7100344301 bcachefs: bch2_ec_stripe_head_get() takes alloc_request
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:32 -04:00
Kent Overstreet
9259883b79 bcachefs: bch2_bucket_alloc_trans() takes alloc_request
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:31 -04:00
Kent Overstreet
799c418303 bcachefs: alloc_request.data_type
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:30 -04:00
Kent Overstreet
ad63f9f1e9 bcachefs: struct alloc_request
Add a struct for common state for satisfying an on disk allocation,
instead of passing the same long list of items to every function.

This will help with stack usage, performance, and perhaps enable some
code cleanups.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:27 -04:00
Kent Overstreet
d02755b8c5 bcachefs: trace bch2_trans_kmalloc()
We're occasionally seeing the WARN_ON() for bump allocator usage
exceeding BTREE_TRANS_MEM_MAX; add some tracing so we can see what's
going on.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:27 -04:00
Roxana Nicolescu
caa6baa45f bcachefs: replace memcpy with memcpy_and_pad for jset_entry_log->d buff
This was achieved before by zero-ing out the source buffer and then
copying the bytes into the destination buffer. This can also be done with
memcpy_and_pad which will zero out only the destination buffer if its
size is bigger than the size of the source buffer. This is already used in
the same way in journal_transaction_name().

Moreover, zero-ing the source buffer was done twice, first in
__bch2_fs_log_msg() and then in bch2_trans_log_msg(). And this method
may also require allocating some extra memory for the source buffer.

In conclusion, using memcpy_and_pad is better even tough the result is
the same because it brings uniformity with what's already used in
journal_transaction_name, it avoids code duplication and reallocating
extra memory.

Signed-off-by: Roxana Nicolescu <nicolescu.roxana@protonmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:13:25 -04:00