Kent Overstreet [Sun, 20 Feb 2022 09:52:44 +0000 (04:52 -0500)]
bcachefs: Kill bch_scnmemcpy()
bch_scnmemcpy was for printing length-limited strings that might not
have a terminating null - turns out sprintf & pr_buf can do this with
%.*s.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 21 Feb 2022 10:05:29 +0000 (05:05 -0500)]
bcachefs: Don't issue discards when in nochanges mode
When the nochanges option is selected, we're supposed to never issue
writes. Unfortunately, it seems discards were missed when implemnting
this, leading to some painful filesystem corruption.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 19 Feb 2022 10:15:53 +0000 (05:15 -0500)]
bcachefs: opts.read_journal_only
Add an option that tells recovery to only read the journal, to be used
by the list_journal command.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 19 Feb 2022 07:40:45 +0000 (02:40 -0500)]
bcachefs: Change __bch2_trans_commit() to run triggers then get RW
This is prep work for the next patch, which is going to change
__bch2_trans_commit() to use bch2_journal_key_insert() when very early
in the recovery process, so that we have a unified interface for doing
btree updates.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 19 Feb 2022 07:39:56 +0000 (02:39 -0500)]
bcachefs: Delete some flag bits that are no longer used
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 19 Feb 2022 06:18:18 +0000 (01:18 -0500)]
bcachefs: Store logical location of journal entries
When viewing what's in the journal, it's more useful to have the logical
location - journal bucket and offset within that bucket - than just the
offset on that device.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 19 Feb 2022 05:42:12 +0000 (00:42 -0500)]
bcachefs: Check for errors from crypto_skcipher_encrypt()
Apparently it actually is possible for crypto_skcipher_encrypt() to
return an error - not sure why that would be - but we need to replace
our assertion with actual error handling.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 18 Feb 2022 05:47:45 +0000 (00:47 -0500)]
bcachefs: Fix failure to allocate btree node in cache
The error code when we fail to allocate a node in the btree node cache
doesn't make it to bch2_btree_path_traverse_all(). Instead, we need to
stash a flag in btree_trans so we know we have to take the cannibalize
lock.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 11:23:06 +0000 (06:23 -0500)]
bcachefs: Change bch2_dev_lookup() to not use lookup_bdev()
bch2_dev_lookup() is used from the extended attribute set methods, for
setting the target options, where we're already holding an inode lock -
it turns out pathname lookups also take inode locks, so that was
susceptible to deadlocks.
Fortunately we already stash the device name in ca->name. This does
change user-visible behaviour though: instead of specifying e.g.
/dev/sda1, user must now specify sda1.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 14 Feb 2022 06:42:31 +0000 (01:42 -0500)]
bcachefs: Only allocate buckets_nouse when requested
It's only needed by the migrate tool - this patch adds an option to
enable allocating it.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 13 Feb 2022 06:58:12 +0000 (01:58 -0500)]
bcachefs: Stale ptr cleanup is now done by gc_gens
Before we had dedicated gc code for bucket->oldest_gen this was
btree_gc's responsibility, but now that we have that we can rip it out,
simplifying the already overcomplicated btree_gc.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 07:50:39 +0000 (02:50 -0500)]
bcachefs: Improve journal_entry_btree_keys_to_text()
This improves the formatting of journal_entry_btree_keys_to_text() by
putting each key on its own line.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 08:13:36 +0000 (03:13 -0500)]
bcachefs: Fix __btree_path_traverse_all
The loop that traverses paths in traverse_all() needs to be a little bit
tricky, because traversing a path can cause other paths to be added (or
perhaps removed) at about the same position.
The old logic was buggy, replace it with simpler logic.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 05:42:34 +0000 (00:42 -0500)]
bcachefs: Fix slow tracepoints
Some of our tracepoints were calling snprintf("pS") - which does symbol
table lookups - in TP_fast_assign(), which turns out to be a really bad
idea.
This was done because perf trace wasn't correctly printing tracepoints
that use %pS anymore - but it turns out trace-cmd does handle it
correctly.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 15 Feb 2022 05:06:59 +0000 (00:06 -0500)]
bcachefs: Check for stale dirty pointer before reads
Since we retry reads when we discover we read from a pointer that went
stale, if a dirty pointer is erroniously stale it would cause us to loop
retrying that read forever - unless we check before issuing the read,
while the btree is still locked, when we know that a dirty pointer
should never be stale.
This patch adds that check, along with printing some helpful debug info.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 14 Feb 2022 09:20:39 +0000 (04:20 -0500)]
bcachefs: Kill verify_not_stale()
This is ancient code that's more effectively checked in other places
now.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 03:01:33 +0000 (22:01 -0500)]
bcachefs: Fix __bch2_btree_node_lock
__bch2_btree_node_lock() was implementing the wrong lock ordering for
cached vs. non cached paths - this fixes it to match the btree path sort
order as defined by __btree_path_cmp(), and also simplifies the code
some.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 03:28:37 +0000 (22:28 -0500)]
bcachefs: Also show when blocked on write locks
This consolidates some of the btree node lock path, so that when we're
blocked taking a write lock on a node it shows up in
bch2_btree_trans_to_text(), along with intent and read locks.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 02:45:04 +0000 (21:45 -0500)]
bcachefs: Delete redundant tracepoint
We were emitting two trace events on transaction restart in this code
path - delete the redundant one.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 16 Feb 2022 04:40:30 +0000 (23:40 -0500)]
bcachefs: Fix locking in data move path
We need to ensure we don't have any btree locks held when calling
do_pending_writes() - besides issuing IOs, upcoming allocator changes
will have allocations doing btree lookups directly.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 14 Feb 2022 03:16:45 +0000 (22:16 -0500)]
bcachefs: Kill bch2_bkey_debugcheck
The old .debugcheck methods are no more and this just calls the .invalid
method, which doesn't add much since we already check that when doing
btree updates and when reading metadata in.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 14 Feb 2022 01:47:05 +0000 (20:47 -0500)]
bcachefs: Print a better message for mark and sweep pass
Btree gc, aka mark and sweep, checks allocations - so let's just print
that.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 14 Feb 2022 01:42:12 +0000 (20:42 -0500)]
bcachefs: Small fsck fix
The check_dirents pass handles transaction restarts at the toplevel -
check_subdir_count() was incorrectly handling transaction restarts
without returning -EINTR, meaning that the iterator pointing to the
dirent being checked was left invalid.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 10 Feb 2022 08:40:44 +0000 (03:40 -0500)]
bcachefs: Fix reflink repair code
The reflink repair code was incorrectly inserting a nonzero deleted key
via journal replay - this is due to bch2_journal_key_insert() being
somewhat hacky, and so this fix is also hacky for now.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 24 Dec 2021 09:51:10 +0000 (04:51 -0500)]
bcachefs: bch2_gc_gens() no longer uses bucket array
Like the previous patches, this converts bch2_gc_gens() to use the alloc
btree directly, and private arrays of generation numbers for its own
recalculation of oldest_gen.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 25 Dec 2021 08:37:52 +0000 (03:37 -0500)]
bcachefs: Copygc no longer uses bucket array
This converts the copygc code to use the alloc btree directly to find
buckets that need to be evacuated instead of the in-memory bucket array,
which is finally going away soon.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Dec 2021 01:39:19 +0000 (20:39 -0500)]
bcachefs: btree_gc no longer uses main in-memory bucket array
This changes the btree_gc code to only use the second bucket array, the
one dedicated to GC. On completion, it compares what's in its in memory
bucket array to the allocation information in the btree and writes it
directly, instead of updating the main in-memory bucket array and
writing that.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 9 Jan 2023 07:25:08 +0000 (02:25 -0500)]
bcachefs: Inode create no longer needs to probe key cache
Now that we have full key cache coherency, we can simplify
bch2_inode_create().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Wed, 12 Jan 2022 06:14:47 +0000 (01:14 -0500)]
bcachefs: Btree key cache coherency
- Updates to non key cache iterators will now be transparently
redirected to the key cache for cached btrees.
- Except when creating new keys: then the update goes to underlying
btree
For for iterating over a cached btree to work, we need to ensure that if
a key exists in the key cache, it also exists in the btree - otherwise
the iterator code will skip past it and not check the key cache.
Otherwise, for consistency, all updates should go to the same place -
the key cache.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Mon, 7 Feb 2022 04:15:12 +0000 (23:15 -0500)]
bcachefs: BTREE_ITER_WITH_KEY_CACHE
This is the start of cache coherency with the btree key cache - this
adds a btree iterator flag that causes lookups to also check the key
cache when we're iterating over the btree (not iterating over the key
cache).
Note that we could still race with another thread creating at item in
the key cache and updating it, since we aren't holding the key cache
locked if it wasn't found. The next patch for the update path will
address this by causing the transaction to restart if the key cache is
found to be dirty.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Thu, 24 Feb 2022 13:08:53 +0000 (08:08 -0500)]
bcachefs: run_one_trigger() now checks journal keys
Previously, when doing updates and running triggers before journal
replay completes, triggers would see the incorrect key for the old key
being overwritten - this patch updates the trigger code to check the
journal keys when necessary, needed for the upcoming allocator rewrite.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 24 Feb 2022 16:02:58 +0000 (11:02 -0500)]
bcachefs: Stash a copy of key being overwritten in btree_insert_entry
We currently need to call bch2_btree_path_peek_slot() multiple times in
the transaction commit path - and some of those need to be updated to
also check the keys from journal replay, too. Let's consolidate this and
stash the key being overwritten in btree_insert_entry.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 7 Feb 2022 03:21:44 +0000 (22:21 -0500)]
bcachefs: bch2_btree_path_set_pos()
bch2_btree_path_set_pos() is now available outside of btree_iter.c
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Wed, 12 Jan 2022 07:13:21 +0000 (02:13 -0500)]
bcachefs: btree_id_cached()
Add a new helper that returns true if the given btree ID uses the btree
key cache. This enables some new cleanups, since the helper can check
the options for whether caching is enabled on a given btree.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 12 Jan 2022 05:49:23 +0000 (00:49 -0500)]
bcachefs: Improve btree_key_cache_flush_pos()
btree_key_cache_flush_pos() uses BTREE_ITER_CACHED_NOFILL - but it
wasn't checking for !ck->valid. It does check for the entry being dirty,
so it shouldn't matter, but this refactor it a bit and adds and
assertion.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 7 Feb 2022 00:20:36 +0000 (19:20 -0500)]
bcachefs: Fix freeing in bch2_dev_buckets_resize()
We were double-freeing old_buckets and not freeing old_buckets_gens:
also, the code was supposed to free buckets, not old_buckets;
old_buckets is only needed because we have to use rcu_assign_pointer()
instead of swap(), and won't be set if we hit the error path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 7 Feb 2022 06:19:39 +0000 (01:19 -0500)]
bcachefs: Don't keep nodes in btree_reserve locked
These nodes aren't reachable by other threads, so there's no need to
keep it locked - and this fixes a bug with the assertion in
bch2_trans_unlock() firing on transaction restart.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 12 Jan 2022 03:08:44 +0000 (22:08 -0500)]
bcachefs: Log message improvements
Change the error messages in bch2_inconsistent_error() and
bch2_fatal_error() so we can distinguish them.
Also, prefer bch2_fs_fatal_error() (which also logs an error message) to
bch2_fatal_error(), and change a call to bch2_inconsistent_error() to
bch2_fatal_error() when we can't continue.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 11 Jan 2022 05:19:52 +0000 (00:19 -0500)]
bcachefs: Delete some dead code
__bch2_mark_replicas() is now only used in one place, so inline it into
the caller.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 11 Jan 2022 00:46:39 +0000 (19:46 -0500)]
bcachefs: Ignore cached data when calculating fragmentation
Previously, bucket fragmentation was considered to be bucket size -
total amount of live data, both dirty and cached.
This meant that if a bucket was full but only a small amount of data in
it was dirty - the rest cached, we'd get stuck: copygc wouldn't move the
dirty data out of the bucket and the allocator wouldn't be able to
invalidate and drop the cached data.
This changes fragmentation to exclude cached data, so that copygc will
evacuate these buckets and copygc/the allocator will always be able to
make forward progress.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Dec 2021 01:36:47 +0000 (20:36 -0500)]
bcachefs: Don't use in-memory bucket array for alloc updates
More prep work for getting rid of the in-memory bucket array: now that
we have BTREE_ITER_WITH_JOURNAL, the allocator code can do ntree lookups
before journal replay is finished, and there's no longer any need for it
to get allocation information from the in-memory bucket array.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 24 Dec 2021 05:34:48 +0000 (00:34 -0500)]
bcachefs: Kill allocator short-circuit invalidate
The allocator thread invalidates buckets (increments their generation
number) prior to discarding them and putting them on freelists. We've
had a short circuit path for some time to only update the in-memory
bucket mark when doing the invalidate if we're not invalidating cached
data, but that short-circuit path hasn't really been needed for quite
some time (likely since the btree key cache code was added).
We're deleting it now as part of deleting/converting code that uses the
in memory bucket array.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 10 Jan 2022 01:55:58 +0000 (20:55 -0500)]
bcachefs: BTREE_INSERT_LAZY_RW is only for recovery path
BTREE_INSERT_LAZY_RW shouldn't do anything after the filesystem has
finished starting up - otherwise, it might interfere with going
read-only as part of shutting down.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 10 Jan 2022 01:52:10 +0000 (20:52 -0500)]
bcachefs: Handle transaction restarts in __bch2_move_data()
We weren't checking for -EINTR in the main loop in __bch2_move_data -
this code predates modern transaction restarts.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 27 Dec 2021 23:25:23 +0000 (18:25 -0500)]
bcachefs: Simplify bch2_inode_delete_keys()
Had a bug report that implies bch2_inode_delete_keys() returned -EINTR
before it completed, so this patch simplifies it and makes the flow
control a little more conventional.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 9 Jan 2022 02:22:31 +0000 (21:22 -0500)]
bcachefs: iter->update_path
With BTREE_ITER_FILTER_SNAPSHOTS, we have to distinguish between the
path where the key was found, and the path for inserting into the
current snapshot. This adds a new field to struct btree_iter for saving
a path for the current snapshot, and plumbs it through
bch2_trans_update().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Sun, 9 Jan 2022 06:07:29 +0000 (01:07 -0500)]
bcachefs: Refactor bch2_btree_iter()
This splits bch2_btree_iter() up into two functions: an inner function
that handles BTREE_ITER_WITH_JOURNAL, BTREE_ITER_WITH_UPDATES, and
iterating acrcoss leaf nodes, and an outer one that implements
BTREE_ITER_FILTER_SNAPHSOTS.
This is prep work for remember a btree_path at our update position in
BTREE_ITER_FILTER_SNAPSHOTS mode.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Sun, 9 Jan 2022 03:59:58 +0000 (22:59 -0500)]
bcachefs: Tracepoint improvements
This improves the transaction restart tracepoints - adding distinct
tracepoints for all the locations and reasons a transaction might have
been restarted, and ensures that there's a tracepoint for every
transaction restart.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 29 Dec 2021 18:50:50 +0000 (13:50 -0500)]
bcachefs: New snapshot unit test
This still needs to be expanded more, but this adds a basic test for
BTREE_ITER_FILTER_SNAPSHOTS.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 9 Jan 2022 00:07:32 +0000 (19:07 -0500)]
bcachefs: Fix an error path in bch2_snapshot_node_create()
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 8 Jan 2022 08:39:54 +0000 (03:39 -0500)]
bcachefs: Use BTREE_INSERT_USE_RESERVE in btree_update_key()
bch2_btree_update_key() is used in the btree node write path - before
delivering the completion we have to update the parent pointer with the
number of sectors written.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 6 Jan 2022 06:20:12 +0000 (01:20 -0500)]
bcachefs: Refactor trigger code
This breaks bch2_trans_commit_run_triggers() up into multiple functions,
and deletes a bit of duplication - prep work for triggers on alloc keys,
which will need to run last.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 7 Jan 2022 02:38:08 +0000 (21:38 -0500)]
bcachefs: Rename data_op_data_progress -> data_jobs
Mild refactoring.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 6 Jan 2022 05:04:56 +0000 (00:04 -0500)]
bcachefs: Fix check_pos_snapshot_overwritten for !snapshots
It shouldn't run if the btree being checked doesn't have snapshots.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 5 Jan 2022 03:32:09 +0000 (22:32 -0500)]
bcachefs: New data structure for buckets waiting on journal commit
Implement a hash table, using cuckoo hashing, for empty buckets that are
waiting on a journal commit before they can be reused.
This replaces the journal_seq field of bucket_mark, and is part of
eventually getting rid of the in memory bucket array.
We may need to make bch2_bucket_needs_journal_commit() lockless, pending
profiling and testing.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 13 Feb 2022 23:15:35 +0000 (18:15 -0500)]
bcachefs: Also print out in-memory gen on stale dirty pointer
We're trying to track down a bug that shows itself as newly-created
extents having stale dirty pointers - possibly due to the in memory gen
and the btree gen being inconsistent. This patch changes the error
message to also print out the in memory bucket gen when this happens.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 2 Jan 2022 04:16:15 +0000 (23:16 -0500)]
bcachefs: Improve path for when btree_gc needs another pass
btree_gc sometimes needs another pass when it corrects bucket generation
numbers or data types - when it finds multiple pointers of different
data types to the same bucket, it may want to keep the second one it
found.
When this happens, we now clear out bucket sector counts _without_
resetting the bucket generation/data types that we already found,
instead of resetting them to what we have in the alloc btree.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 4 Jan 2022 23:35:00 +0000 (18:35 -0500)]
bcachefs: Fix bch2_check_fix_ptrs()
The repair for for btree_ptrs was saying one thing and doing another -
fortunately, that code can just be deleted.
Also, when we update a btree node pointer, we also have to update node
in memery, if it exists in the btree node cache - this fixes
bch2_check_fix_ptrs() to do that.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 5 Jan 2022 00:45:39 +0000 (19:45 -0500)]
bcachefs: Fix an uninitialized variable
Only userspace builds were complaining about it, oddly enough.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 5 Jan 2022 00:41:23 +0000 (19:41 -0500)]
Revert "bcachefs: Delete some obsolete journal_seq_blacklist code"
This reverts commit
f95b61228efd04c9c158123da5827c96e9773b29.
It turns out, we're seeing filesystems in the wild end up with
blacklisted btree node bsets - this should not be happening, and until
we understand why and fix it we need to keep this code around.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 5 Jan 2022 00:05:08 +0000 (19:05 -0500)]
bcachefs: Log & error message improvements
- Add a shim uuid_unparse_lower() in the kernel, since %pU doesn't work
in userspace
- We don't need to print the bcachefs: or the filesystem name prefix in
userspace
- Improve a few error messages
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 4 Jan 2022 23:24:55 +0000 (18:24 -0500)]
bcachefs: BTREE_ITER_FILTER_SNAPSHOTS is selected automatically
It doesn't have to be specified - this patch deletes the two instances
where it was.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 4 Jan 2022 05:33:52 +0000 (00:33 -0500)]
bcachefs: Switch to __func__for recording where btree_trans was initialized
Symbol decoding, via %ps, isn't supported in userspace - this will also
be faster when we're using trans->fn in the fast path, as with the new
BCH_JSET_ENTRY_log journal messages.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 4 Jan 2022 05:07:23 +0000 (00:07 -0500)]
bcachefs: Fix bch2_journal_seq_blacklist_add()
The old code correctly handled the case where we were blacklisting a
range that exactly matched an existing entry, but not the case where the
new range partially overlaps an existing entry.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 4 Jan 2022 05:06:49 +0000 (00:06 -0500)]
bcachefs: Add verbose log messages for journal read
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 4 Jan 2022 04:38:50 +0000 (23:38 -0500)]
bcachefs: Improved superblock-related error messages
This patch converts bch2_sb_validate() and the .validate methods for the
various superblock sections to take printbuf, to which they can print
detailed error messages, including printing the entire section that was
invalid.
This is a great improvement over the previous situation, where we could
only return static strings that didn't have precise information about
what was wrong.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 3 Jan 2022 09:17:02 +0000 (04:17 -0500)]
bcachefs: Use kvmalloc() for array of sorted keys in journal replay
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 3 Jan 2022 05:22:29 +0000 (00:22 -0500)]
bcachefs: Make eytzinger size parameter more conventional
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 3 Jan 2022 05:14:39 +0000 (00:14 -0500)]
bcachefs: Kill bch2_bset_fix_invalidated_key()
Was dead code, so delete it.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 3 Jan 2022 03:24:43 +0000 (22:24 -0500)]
bcachefs: Fix an assertion
bch2_trans_commit() can legitimately return -ENOSPC with
BTREE_INSERT_NOFAIL set if BTREE_INSERT_NOWAIT was also set.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 3 Jan 2022 02:45:35 +0000 (21:45 -0500)]
bcachefs: bch_dev->dev
Add a field to bch_dev for the dev_t of the underlying block device -
this fixes a null ptr deref in tracepoints.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 04:10:06 +0000 (23:10 -0500)]
bcachefs: Simplify journal replay
With BTREE_ITER_WITH_JOURNAL, there's no longer any restrictions on the
order we have to replay keys from the journal in, and we can also start
up journal reclaim right away - and delete a bunch of code.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 11 Sep 2023 03:35:25 +0000 (23:35 -0400)]
fixup! bcachefs: Factor out __bch2_btree_iter_set_pos()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Sun, 26 Dec 2021 01:07:00 +0000 (20:07 -0500)]
bcachefs: BTREE_ITER_WITH_JOURNAL
This adds a new btree iterator flag, BTREE_ITER_WITH_JOURNAL, that is
automatically enabled when initializing a btree iterator before journal
replay has completed - it overlays the contents of the journal with the
btree.
This lets us delete bch2_btree_and_journal_walk() and just use the
normal btree iterator interface instead - which also lets us delete a
significant amount of duplicated code.
Note that BTREE_ITER_WITH_JOURNAL is still unoptimized in this patch -
we're redoing the binary search over keys in the journal every time we
call bch2_btree_iter_peek().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Sun, 2 Jan 2022 01:45:30 +0000 (20:45 -0500)]
bcachefs: Tweak journal reclaim order
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 2 Jan 2022 00:46:12 +0000 (19:46 -0500)]
bcachefs: Make sure BCH_FS_FSCK_DONE gets set
If we're not running fsck we still want to set BCH_FS_FSCK_DONE, so that
bch2_fsck_err() calls are interpreted as bch2_inconsistent_error()
calls().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 2 Jan 2022 00:04:33 +0000 (19:04 -0500)]
bcachefs: Improve error messages in superblock write path
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 1 Jan 2022 23:27:50 +0000 (18:27 -0500)]
bcachefs: Log what we're doing when repairing
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 31 Dec 2021 22:54:13 +0000 (17:54 -0500)]
bcachefs: Fix race between btree updates & journal replay
Add a flag to indicate whether a journal replay key has been
overwritten, and set/test it with appropriate btree locks held.
This fixes a race between the allocator - invalidating buckets, and
doing btree updates - and journal replay, which before this patch could
clobber the allocator thread's update with an older version of the key
from the journal.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 31 Dec 2021 22:06:29 +0000 (17:06 -0500)]
bcachefs: bch2_journal_entry_to_text()
This adds a _to_text() pretty printer for journal entries - including
every subtype - which will shortly be used by the 'bcachefs
list_journal' subcommand.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 31 Dec 2021 21:12:54 +0000 (16:12 -0500)]
bcachefs: BCH_JSET_ENTRY_log
Add a journal entry type for logging messages, and add an option to use
it to log the transaction name - this makes for a very handy debugging
tool, as with it we can use the 'bcachefs list_journal' command to see
not only what updates were done, but what was doing them.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 31 Dec 2021 01:14:52 +0000 (20:14 -0500)]
bcachefs: Add error messages for memory allocation failures
This adds some missing diagnostics from rare but annoying to debug
runtime allocation failure paths.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 29 Dec 2021 20:55:25 +0000 (15:55 -0500)]
bcachefs: Journal replay does't resort main list of keys
The upcoming BTREE_ITER_WITH_JOURNAL patch will require journal keys to
stay in sorted order, so the btree iterator code can overlay them over
btree keys.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 29 Dec 2021 18:49:34 +0000 (13:49 -0500)]
bcachefs: Add iter_flags arg to bch2_btree_delete_range()
Will be used by the new snapshot tests, to pass in
BTREE_ITER_ALL_SNAPSHOTS.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 02:28:50 +0000 (21:28 -0500)]
bcachefs: Add an error message for copygc spinning
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 29 Dec 2021 16:27:47 +0000 (11:27 -0500)]
bcachefs: Fix keylist size in btree_update
This fixes a buffer overrun, fortunately caught by a BUG_ON().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 21:31:57 +0000 (16:31 -0500)]
bcachefs: Improve error messages in device add path
This converts the error messages in the device add to a better style,
and adds some missing ones.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 21:01:25 +0000 (16:01 -0500)]
bcachefs: bch2_hprint(): don't print decimal if conversion was exact
There's places where we parse these numbers, and our parsing doesn't
cope with decimals currently - this is a hack to get the device_add path
working again where for the device blocksize there doesn't ever need to
be a decimal.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 04:56:13 +0000 (23:56 -0500)]
bcachefs: Optimize bucket reuse
If the btree updates pointing to a bucket were never flushed by the
journal before the bucket became empty again, we can reuse the bucket
without a journal flush.
This tweaks the tracking of journal sequence numbers in alloc keys to
implement this optimization: now, we only update the journal sequence
number in alloc keys on transitions to and from empty. When a bucket
becomes empty, we check if we can tell the journal not to flush entries
starting from when the bucket was used.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 12 Feb 2022 07:32:11 +0000 (02:32 -0500)]
bcachefs: Always check for bucket reuse after read
Since dirty extents can be moved or overwritten, it's not just cached
data that we need the ptr_stale() check in bc2h_read_endio for - this
fixes data checksum errors seen in the tiering ktest tests.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 04:51:48 +0000 (23:51 -0500)]
bcachefs: bch2_journal_noflush_seq()
Add bch2_journal_noflush_seq(), for telling the journal that entries
before a given sequence number should not be flushes - to be used by an
upcoming allocator optimization.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 01:45:07 +0000 (20:45 -0500)]
bcachefs: Add a tracepoint for the btree cache shrinker
This is to help with diagnosing why the btree node can doesn't seem to
be shrinking - we've had issues in the past with granularity/batch size,
since btree nodes are so big.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 01:05:07 +0000 (20:05 -0500)]
bcachefs: Run scan_old_btree_nodes after version upgrade
In the recovery path, we scan for old btree nodes if we don't have
certain compat bits set. If we do this, we should be doing it after we
upgraded to the newest on disk format.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 28 Dec 2021 00:58:12 +0000 (19:58 -0500)]
bcachefs: Update sysfs compression_stats for snapshots
- BTREE_ITER_ALL_SNAPSHOTS flag is required here
- change it to also walk the reflink btree
- change it to accumulate stats for all pointers in an extent
- change it to account for incompressible data
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 27 Dec 2021 03:27:10 +0000 (22:27 -0500)]
bcachefs: Kill bch2_ec_mem_alloc()
bch2_ec_mem_alloc() was only used by GC, and there's no real need to
preallocate the stripes radix tree since we can cope fine with memory
allocation failure when we use the radix tree. This deletes a fair bit
of code, and it's also needed for the upcoming patch because
bch2_btree_iter_peek_prev() won't be working before journal replay
completes (and using it was incorrect previously, as well).
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 27 Dec 2021 02:41:09 +0000 (21:41 -0500)]
bcachefs: Fix allocator + journal interaction
The allocator needs to wait until the last update touching a bucket has
been commited before writing to it again. However, the code was checking
against the last dirty journal sequence number, not the last flushed
journal sequence number.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Dec 2021 00:55:34 +0000 (19:55 -0500)]
bcachefs: New in-memory array for bucket gens
The main in-memory bucket array is going away, but we'll still need to
keep bucket generations in memory, at least for now - ptr_stale() needs
to be an efficient operation.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Dec 2021 03:37:19 +0000 (22:37 -0500)]
bcachefs: Separate out gc_bucket()
Since the main in memory bucket array is going away, we don't want to be
calling bucket() or __bucket() when what we want is the GC in-memory
bucket.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Dec 2021 02:43:29 +0000 (21:43 -0500)]
bcachefs: Put open_buckets in a hashtable
This is so that the copygc code doesn't have to refer to
bucket_mark.owned_by_allocator - assisting in getting rid of the in
memory bucket array.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Dec 2021 02:21:46 +0000 (21:21 -0500)]
bcachefs: Refactor open_bucket code
Prep work for adding a hash table of open buckets - instead of embedding
a bch_extent_ptr, we need to refer to the bucket directly so that we're
not calling sector_to_bucket() in the hash table lookup code, which has
an expensive divide.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>