Commit Graph

1352461 Commits

Author SHA1 Message Date
Kent Overstreet
970dde8271 bcachefs: Add missing include
fix debug build in userspace

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:50 -04:00
Kent Overstreet
8c69e2b52e bcachefs: Knob for manual snapshot deletion
Add 'opts.snapshot_deletion_enabled', enabled by default.

This may be turned off so that the new sysfs knob,
'internal/trigger_delete_dead_snapshots', may be used instead - this
will allow snapshot deletion to be profiled more easily.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:49 -04:00
Kent Overstreet
a8539ad8fa bcachefs: bcachefs_metadata_version_fast_device_removal
Fast device removal, that uses backpointers to find pointers to the
device being removed instead of a full metadata scan.

This requires BCH_SB_MEMBER_DELETED_UUID, which is an incompatible
change - hence the version number bump. We don't fully trust
backpointers, so we don't want to reuse device indexes until after a
fsck has verified that there aren't any pointers to removed devices.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:49 -04:00
Kent Overstreet
09fa6c3039 bcachefs: bch2_dev_data_drop_by_backpointers()
Currently, device removal has to scan all metadata for pointers to the
device being removed.

Add a new method, with the same interface as bch2_dev_data_drop(), that
scans by backpointers instead - this will drastically speed up device
removal.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:49 -04:00
Kent Overstreet
b3f80d0923 bcachefs: BCH_SB_MEMBER_DELETED_UUID
Add a sentinal value for devices that have been removed, but don't want
to reuse their index until a fsck has completed.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:49 -04:00
Kent Overstreet
66e9a7f139 bcachefs: bch2_dev_remove_stripes() respects degraded flags
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:48 -04:00
Kent Overstreet
96fc7d8adb bcachefs: opts.rebalance_on_ac_only
Add an option for setting rebalance to only run when connected to mains
power.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:48 -04:00
Kent Overstreet
502222041c bcachefs: __bch2_fs_free() cleanup
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:47 -04:00
Kent Overstreet
39430cfd27 bcachefs: Improve bch2_extent_ptr_set_cached()
Preferentially keep existing cached pointers instead of adding new ones.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:47 -04:00
Kent Overstreet
fbe728f956 bcachefs: improve check_inode_hash_info_matches_root() error message
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:47 -04:00
Kent Overstreet
84bd6afee1 bcachefs: inline bch2_ob_ptr()
This was an oversight, we want bch2_alloc_sectors_append_ptrs_inlined()
fully inlined.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:46 -04:00
Kent Overstreet
e02888faab bcachefs: bch2_dev_in_target() no longer takes rcu_read_lock()
Minor optimization, the caller generally has it already.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:45 -04:00
Kent Overstreet
7d4f2687ef bcachefs: bch2_journal_write() refactoring
Make the locking easier to follow; also take io_refs earlier, in
__journal_write_alloc().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:45 -04:00
Kent Overstreet
88f62ed60c bcachefs: delete_dead_snapshot_keys_v2()
Since extents, dirents and xattrs require an inode with the
corresponding snapshot ID to exists, we can avoid a lot of scanning by
only scanning those trees for keys to process if the correspending inode
exists.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:45 -04:00
Kent Overstreet
e9756dd29f bcachefs: bcachefs_metadata_version_snapshot_deletion_v2
We're going to be speeding up snapshot deletion, by only having it
process the extents/dirents/xattrs btrees if an inode of a given
snapshot ID was present.

This raises the possibility of 'bkey_in_missing_snapshot' errors popping
up, if we ever accidentally don't do the corresponding inode update, or
if the new algorithm has bugs.

So instead of deleting snapshot IDs, add a new deleted flag, so that
'key in missing snapshot' errors can more definitively tell what
happened and automatically repair.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:45 -04:00
Kent Overstreet
08d14d90a4 bcachefs: BCH_SNAPSHOT_DELETED -> BCH_SNAPSHOT_WILL_DELETE
We're going to be speeding up snapshot deletion, by only having it
process the extents/dirents/xattrs btrees if an inode of a given
snapshot ID was present.

This raises the possibility of 'bkey_in_missing_snapshot' errors popping
up, if we ever accidentally don't do the corresponding inode update, or
if the new algorithm has bugs.

So we'll want to be able to differentiate more definitively between
'snapshot went missing' (and perhaps needs to be reconstructed), and
'key in snapshot that was deleted'.

So instead of deleting snapshot IDs, we'll be adding a new deleted flag
and leaving them permanently.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:44 -04:00
Kent Overstreet
3f8e977265 bcachefs: Skip unrelated snapshot trees in snapshot deletion
Don't scan keys in inodes for which the snapshot tree doesn't match any
we're deleting from.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:43 -04:00
Kent Overstreet
0afdf4969e bcachefs: BCH_FSCK_ERR_snapshot_key_missing_inode_snapshot
We're going to be doing some snapshot deletion performance improvements,
and those will strictly require that if an extent/dirent/xattr is
present, an inode is present in that snapshot ID.

We already check for this, but we don't repair it on disk: this patch
adds that repair and turns it into a real fsck_err().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:43 -04:00
Kent Overstreet
855070dc0b bcachefs: get_inodes_all_snapshots() now includes whiteouts
The next patch is going to change lookup_inode_for_snapshot to
rigorously require that a extent/dirent/xattr keys have a corresponding
inode key present - whiteouts included, so this simplifies the checks
lookup_inode_for_snapshot() will have to do.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:43 -04:00
Kent Overstreet
a9421140fc bcachefs: bch2_inode_unpack() cleanup
bi_snapshot is now handled like other fields

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:43 -04:00
Kent Overstreet
00757984d5 bcachefs: Improve bch2_request_incompat_feature() message
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:42 -04:00
Alan Huang
3c97ebea61 bcachefs: Fix inconsistent req->ec
There is req->ec = erasure_code above.

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:42 -04:00
Kent Overstreet
6f2bbd5747 bcachefs: kill inode_walker_entry.snapshot
redundant

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:41 -04:00
Kent Overstreet
7b8c41c178 bcachefs: Add comments for inode snapshot requirements
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:41 -04:00
Kent Overstreet
15dbd0d814 bcachefs: snapshot delete progress indicator
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:40 -04:00
Kent Overstreet
e3006cb010 bcachefs: Don't emit bch_sb_field_members_v1 if not required
In 'bcachefs_metadata_extent_flags', we stopped requireding members_v1
to be present - only that either v1 or v2 is present.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:40 -04:00
Alan Huang
9180c5f918 bcachefs: Rename x_name to x_name_and_value
The flexible array contains name and value, the x_name is misleading.

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:39 -04:00
Kent Overstreet
a42f709f9a bcachefs: Improve bch2_disk_groups_to_text()
Print out the actual name of each path/label, instead of just the
integer indexes.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:39 -04:00
Kent Overstreet
c53e5c0c19 docs: bcachefs: add casefolding reference
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:39 -04:00
Kent Overstreet
8a6b883e78 bcachefs: Fix setting ca->name in device add
Device add doesn't get the devide index and attach to the filesystem
until after attaching the block device, and setting the device name from
the block device name - these needs some minor tweaks.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:39 -04:00
Kent Overstreet
5ce11d9d1b bcachefs: sysfs trigger_recalc_capacity
For bug diagnosis

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:38 -04:00
Gustavo A. R. Silva
ae0386e111 bcachefs: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

Refactor a couple of structs that contain flexible arrays in the
middle by replacing them with unions.

So, with these changes, fix the following warnings:

fs/bcachefs/disk_accounting.c:429:51: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
fs/bcachefs/ec_types.h:8:41: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:38 -04:00
Kent Overstreet
98e5e36d8c bcachefs: bch2_dev_add() can run on a non-started fs
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:37 -04:00
Kent Overstreet
a349868b5e bcachefs: bch2_fs_open() now takes a darray
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:37 -04:00
Kent Overstreet
cf95296295 bcachefs: bch2_trans_update_ip()
Allow btree_insert_entry.ip_allocated to be passed in, so we get better
info on where alloc updates are coming from.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:37 -04:00
Kent Overstreet
7677859a47 bcachefs: Run most explicit recovery passes persistent
If we detect an error that requires running a recovery pass, and we're
not in recovery, we won't be able to fix it until the next mount - make
sure we're noting in the superblock that it needs to run.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:37 -04:00
Kent Overstreet
aff2b6a7fc bcachefs: provide unlocked version of run_explicit_recovery_pass_persistent
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:36 -04:00
Kent Overstreet
c21f41f690 bcachefs: bch2_dirent_to_text() shows casefolded dirents
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:36 -04:00
Kent Overstreet
cd3cdb1ef7 bcachefs: Single err message for btree node reads
Like we just did with the data read path, emit a single error message
per btree node reads, nicely formatted, with all the actions we took
grouped together.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:35 -04:00
Kent Overstreet
9c2472658b bcachefs: bch2_mark_btree_validate_failure()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:35 -04:00
Kent Overstreet
d31f155964 bcachefs: bch2_fsck_err_opt()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:34 -04:00
Kent Overstreet
600a9207c8 bcachefs: Plumb printbuf through bch2_btree_lost_data()
Part of the ongoing project to improve error messages by building them
up in printbufs and emitting them all at once, so that we can easily see
what events are related in the log.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:34 -04:00
Kent Overstreet
300904700f bcachefs: kill bch2_run_explicit_recovery_pass_persistent()
No longer has users, so we can kill it and rename
bch2_run_explicit_recovery_pass_persistent_locked().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:33 -04:00
Kent Overstreet
3aecbb01a1 bcachefs: Remove redundant calls to btree_lost_data()
The btree node read path calls this before returning the read error.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:33 -04:00
Kent Overstreet
3be132f93c bcachefs: bch2_btree_lost_data() now handles snapshots tree
We have a consolidated places for "this btree lost data, run this
repair", so use it.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:33 -04:00
Kent Overstreet
b3bbd47f83 bcachefs: Kill redundant error message in topology repair
The btree node read path already logs btree node read errors, this isn't
needed.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:32 -04:00
Kent Overstreet
156d9e8341 bcachefs: Emit a single log message on data read error
Instead of emitting a message immediately when we get an error in the
read path, and then another at the end if we successfully retry - emit
one single log message before returning from bch2_rbio_retry().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:32 -04:00
Kent Overstreet
353b89c6e6 bcachefs: bch2_io_failures_to_text()
Pretty printer for bch_io_failures, to be used for better read error
messages.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:31 -04:00
Kent Overstreet
dbc18c97f1 bcachefs: print_string_as_lines: avoid printing empty line
If the final line in in the message to be printed is blang, don't print
it.

This happens with indented printbufs - after a newline we emit spaces up
to the indent level.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:31 -04:00
Kent Overstreet
41e51769b8 bcachefs: Make various async objs visible in debugfs
Add async objs list for
- promote_op
- bch_read_bio
- btree_read_bio
- btree_write_bio

This gets us introspection on in-flight async ops, and because under the
hood it uses fast_lists (percpu slot buffer on top of a radix tree),
it'll be fast enough to enable in production.

This will be very helpful for debugging "something got stuck" issues,
which have been cropping up from time to time (in the CI, especially
with folio writeback).

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-21 20:14:30 -04:00