Kent Overstreet [Fri, 29 Oct 2021 22:43:18 +0000 (18:43 -0400)]
bcachefs: Convert bch2_mark_key() to take a btree_trans *
This helps to unify the interface between bch2_mark_key() and
bch2_trans_mark_key() - and it also gives access to the journal
reservation and journal seq in the mark_key path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 29 Oct 2021 20:29:13 +0000 (16:29 -0400)]
bcachefs: Assorted ec fixes
- The backpointer that ec_stripe_update_ptrs() uses now needs to include
the snapshot ID, which means we have to change where we add the
backpointer to after getting the snapshot ID for the new extents
- ec_stripe_update_ptrs() needs to be calling bch2_trans_begin()
- improve error message in bch2_mark_stripe()
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 29 Oct 2021 22:21:05 +0000 (18:21 -0400)]
bcachefs: Fix bch2_mark_update()
When the old or new key doesn't exist, we should still pass in a deleted
key with the correct pos. This fixes a bug in the ec code, when
bch2_mark_stripe() was looking up the wrong in-memory stripe.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 28 Oct 2021 22:22:25 +0000 (18:22 -0400)]
bcachefs: Ensure journal doesn't get stuck in nochanges mode
This tweaks the journal code to always act as if there's space available
in nochanges mode, when we're not going to be doing any writes. This
helps in recovering filesystems that won't mount because they need
journal replay and the journal has gotten stuck.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 28 Oct 2021 20:16:55 +0000 (16:16 -0400)]
bcachefs: Improve transaction restart handling in fsck code
The fsck code has been handling transaction restarts locally, to avoid
calling fsck_err() multiple times (and asking the user/logging the error
multiple times) on transaction restart.
However, with our improving assertions about iterator validity, this
isn't working anymore - the code wasn't entirely correct, in ways that
are fine for now but are going to matter once we start wanting online
fsck.
This code converts much of the fsck code to handle transaction restarts
in a more rigorously correct way - moving restart handling up to the top
level of check_dirent, check_xattr and others - at the cost of logging
errors multiple times on transaction restart.
Fixing the issues with logging errors multiple times is probably going
to require memoizing calls to fsck_err() - we'll leave that for future
improvements.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 28 Oct 2021 20:34:17 +0000 (16:34 -0400)]
bcachefs: Fix bch2_btree_iter_advance()
Was popping an assertion on !BTREE_ITER_ALL_SNAPSHOTS iters when getting
to the end.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 28 Oct 2021 20:24:39 +0000 (16:24 -0400)]
bcachefs: Move bch2_evict_subvolume_inodes() to fs.c
This fixes building in userspace - code that's coupled to the kernel VFS
interface should live in fs.c
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 27 Oct 2021 21:53:20 +0000 (17:53 -0400)]
bcachefs: Don't do upgrades in nochanges mode
nochanges mode is often used for getting data off of otherwise
nonrecoverable filesystems, which is often because of errors hit during
fsck.
Don't force version upgrade & fsck in nochanges mode, so that it's more
likely to mount.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 26 Oct 2021 20:03:28 +0000 (16:03 -0400)]
bcachefs: Drop bch2_journal_meta() call when going RW
Back when we relied on the journal sequence number blacklist machinery
for consistency between btree and the journal, we needed to ensure a new
journal entry was written before any btree writes were done. But, this
had the side effect of consuming some space in the journal prior to
doing journal replay - which could lead to a very wedged filesystem,
since we don't yet have a way to grow the journal prior to going RW.
Fortunately, the journal sequence number blacklist machinery isn't
needed anymore, as btree node pointers now record the numer of sectors
currently written to that node - that code should all be ripped out.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 11 Oct 2021 16:03:19 +0000 (12:03 -0400)]
bcachefs: Add BCH_SUBVOLUME_UNLINKED
Snapshot deletion needs to become a multi step process, where we unlink,
then tear down the page cache, then delete the subvolume - the deleting
flag is equivalent to an inode with i_nlink = 0.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 26 Oct 2021 18:07:43 +0000 (14:07 -0400)]
bcachefs: Improve error messages in trans_mark_reflink_p()
We should always print out the key we were marking.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 25 Oct 2021 23:30:24 +0000 (19:30 -0400)]
bcachefs: Don't run triggers in fix_reflink_p_key()
It seems some users have reflink pointers which span many indirect
extents, from a short window in time when merging of reflink pointers
was allowed.
Now, we're seeing transaction path overflows in fix_reflink_p(), the
code path to clear out the reflink_p fields now used for front/back pad
- but, we don't actually need to be running triggers in that path, which
is an easy partial fix.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 25 Oct 2021 22:30:28 +0000 (18:30 -0400)]
bcachefs: More general fix for transaction paths overflow
for_each_btree_key() now calls bch2_trans_begin() as needed; that means,
we can also call it when we're in danger of overflowing transaction
paths.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 21 Oct 2021 19:48:05 +0000 (15:48 -0400)]
bcachefs: Fix fsck path for refink pointers
The way __bch2_mark_reflink_p returns errors was clashing with returning
the number of sectors processed - we weren't returning FSCK_ERR_EXIT
correctly.
Fix this by only using the return code for errors, which actually ends
up simplifying the overall logic.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 24 Oct 2021 21:00:33 +0000 (17:00 -0400)]
bcachefs: Ensure we flush btree updates in evacuate path
This fixes a possible race where we fail to remove a device because of
btree nodes still on it, that are being deleted by in flight btree
updates.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 24 Oct 2021 20:59:33 +0000 (16:59 -0400)]
bcachefs: bch2_btree_node_rewrite() now returns transaction restarts
We have been getting away from handling transaction restarts locally -
convert bch2_btree_node_rewrite() to the newer style.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 24 Oct 2021 20:55:17 +0000 (16:55 -0400)]
bcachefs: Fix bch2_btree_iter_next_node()
We were modifying state, then return -EINTR, causing us to skip nodes -
ouch.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 24 Oct 2021 20:40:05 +0000 (16:40 -0400)]
bcachefs: Must check for errors from bch2_trans_cond_resched()
But we don't need to call it from outside the btree iterator code
anymore, since it's called by bch2_trans_begin() and
bch2_btree_path_traverse().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 24 Oct 2021 15:57:47 +0000 (11:57 -0400)]
bcachefs: Fix dev accounting after device add
This is a hacky but effective fix to device usage stats for superblock
and journal being wrong on a newly added device (following the comment
that already told us how it needed to be done!)
Reported-by: Chris Webb <chris@arachsys.com>
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 22 Oct 2021 21:33:38 +0000 (17:33 -0400)]
bcachefs: Fix a transaction path overflow
readdir() in a directory with many subvolumes could overflow transaction
paths - this is a simple hack around the issue.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 21 Oct 2021 18:33:31 +0000 (14:33 -0400)]
bcachefs: Fix error handling in bch2_trans_extent_merging
The back merging case wasn't returning errors correctly.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 12 Oct 2021 16:06:02 +0000 (12:06 -0400)]
bcachefs: Subvol dirents are now only visible in parent subvol
This changes the on disk format for dirents that point to subvols so
that they also record the subvolid of the parent subvol, so that we can
filter them out in other subvolumes.
This also updates the dirent code to do that filtering, and in
particular tweaks the rename code - we need to ensure that there's only
ever one dirent (counting multiplicities in different snapshots) that
point to a subvolume.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 21 Oct 2021 16:05:21 +0000 (12:05 -0400)]
bcachefs: Fix restart handling in for_each_btree_key()
Code that uses for_each_btree_key often wants transaction restarts to be
handled locally and not returned. Originally, we wouldn't return
transaction restarts if there was a single iterator in the transaction -
the reasoning being if there weren't other iterators being invalidated,
and the current iterator was being advanced/retraversed, there weren't
any locks or iterators we were required to preserve.
But with the btree_path conversion that approach doesn't work anymore -
even when we're using for_each_btree_key() with a single iterator there
will still be two paths in the transaction, since we now always preserve
the path at the pos the iterator was initialized at - the reason being
that on restart we often restart from the same place.
And it turns out there's now a lot of for_each_btree_key() uses that _do
not_ want transaction restarts handled locally, and should be returning
them.
This patch splits out for_each_btree_key_norestart() and
for_each_btree_key_continue_norestart(), and converts existing users as
appropriate. for_each_btree_key(), for_each_btree_key_continue(), and
for_each_btree_node() now handle transaction restarts themselves by
calling bch2_trans_begin() when necessary - and the old hack to not
return transaction restarts when there's a single path in the
transaction has been deleted.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 21 Oct 2021 04:38:13 +0000 (00:38 -0400)]
bcachefs: cached data shouldn't prevent fs from mounting
It's not an error if we don't have cached data - skip BCH_DATA_cached in
bch2_have_enough_devs().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 21 Oct 2021 00:50:07 +0000 (20:50 -0400)]
bcachefs: Delete dentry when deleting snapshots
This fixes a bug where subsequently doing creates with the same name
fails.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 20 Oct 2021 21:59:38 +0000 (17:59 -0400)]
bcachefs: Fix check_path() for snapshots
check_path() wasn't checking the snapshot ID when checking for directory
structure loops - so, snapshots would cause us to detect a loop that
wasn't actually a loop.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 14 Oct 2021 13:54:47 +0000 (09:54 -0400)]
bcachefs: Fix for leaking of reflinked extents
When a reflink pointer points to only part of an indirect extent, and
then that indirect extent is fragmented (e.g. by copygc), if the reflink
pointer only points to one of the fragments we leak a reference.
Fix this by storing front/back pad values in reflink pointers - when
inserting reflink pointesr, we initialize them to cover the full range
of the indirect extents we reference.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 19 Oct 2021 21:30:16 +0000 (17:30 -0400)]
bcachefs: New on disk format to fix reflink_p pointers
We had a bug where reflink_p pointers weren't being initialized to 0,
and when we started using the second word, things broke badly.
This patch revs the on disk format version and adds cleanup code to zero
out the second word of reflink_p pointers before we start using it.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 19 Oct 2021 19:11:45 +0000 (15:11 -0400)]
bcachefs: Handle transaction restarts in bch2_blacklist_entries_gc()
It shouldn't be necessary when we're only using a single iterator and
not doing updates, but that's harder to debug at the moment.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 19 Oct 2021 19:08:00 +0000 (15:08 -0400)]
bcachefs: bch2_trans_exit() no longer returns errors
Now that peek_node()/next_node() are converted to return errors
directly, we don't need bch2_trans_exit() to return errors - it's
cleaner this way and wasn't used much anymore.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 19 Oct 2021 18:20:50 +0000 (14:20 -0400)]
bcachefs: for_each_btree_node() now returns errors directly
This changes for_each_btree_node() to work like for_each_btree_key(),
and to that end bch2_btree_iter_peek_node() and next_node() also return
error ptrs.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 19 Oct 2021 16:27:47 +0000 (12:27 -0400)]
bcachefs: Improve reflink repair code
When a reflink pointer points to an indirect extent that doesn't exist,
we need to replace it with a KEY_TYPE_error key.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 19 Oct 2021 05:08:05 +0000 (01:08 -0400)]
bcachefs: Fix check_path() across subvolumes
Checking of directory structure across subvolumes was broken - we need
to look up the snapshot ID of the parent subvolume when crossing subvol
boundaries.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 18 Oct 2021 18:46:57 +0000 (14:46 -0400)]
bcachefs: Fix a cache coherency bug in bch2_subvolume_create()
Subvolume deletion doesn't flush & evict the btree key cache - ideally
it would, but that's tricky, so instead bch2_subvolume_create() needs to
make sure the slot doesn't exist in the key cache to avoid triggering
assertions.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Brett Holman [Sun, 17 Oct 2021 01:13:53 +0000 (19:13 -0600)]
bcachefs: Fix compiler warnings
Type size_t is architecture-specific. Fix warnings for some non-amd64
arches.
Signed-off-by: Brett Holman <bholman.devel@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Mon, 18 Oct 2021 15:32:06 +0000 (11:32 -0400)]
bcachefs: Zero out reflink_p val in bch2_make_extent_indirect()
This bug was only discovered when we started using the 2nd word in the
val, which should have been zeroed out as those fields had never been
used before - ouch.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 14 Oct 2021 17:14:40 +0000 (13:14 -0400)]
bcachefs: Fix __bch2_dirent_read_target()
We were shadowing our exist status, oops
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 14 Oct 2021 15:47:52 +0000 (11:47 -0400)]
bcachefs: Improve bch2_dump_trans_paths_updates()
Also print the key beyng overwritten for each update.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 13 Oct 2021 17:45:46 +0000 (13:45 -0400)]
bcachefs: Don't allocate too-big bios
This fixes a null ptr deref in bio_alloc_bioset() -> biovec_slab()
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 13 Oct 2021 17:12:26 +0000 (13:12 -0400)]
bcachefs: Fix implementation of KEY_TYPE_error
When force-removing a device, we were silently dropping extents that we
no longer had pointers for - we should have been switching them to
KEY_TYPE_error, so that reads for data that was lost return errors.
This patch adds the logic for switching a key to KEY_TYPE_error to
bch2_bkey_drop_ptr(), and improves the logic somewhat.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 12 Oct 2021 18:25:13 +0000 (14:25 -0400)]
bcachefs: Fix deletion in __bch2_dev_usrdata_drop()
With snapshots, __bch2_dev_usr_data_drop() now uses an ALL_SNAPSHOTS
iterator, which isn't an extent iterator - meaning we shouldn't be
inserting whiteouts with nonzero size to delete. This fixes a bug where
we go RO because we tried to insert an invalid key in the device remove
path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Brett Holman [Wed, 13 Oct 2021 03:11:25 +0000 (21:11 -0600)]
bcachefs: Add a valgrind memcheck hint
Prevent false positives in bch2_varint_decode_fast()
Signed-off-by: Brett Holman <bholman.devel@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Tue, 12 Oct 2021 18:15:45 +0000 (14:15 -0400)]
bcachefs: Fix rereplicate_pred()
It was switching off of the key type incorrectly - this code must've
been quite old, and not rereplicating anything that wasn't a
btree_ptr_v1 or a plain old extent.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 1 Oct 2021 00:09:08 +0000 (20:09 -0400)]
bcachefs: Snapshot deletion fix
When we delete a snapshot, we unlink the inode but we don't want to run
the inode_rm path - the unlink path deletes the subvolume directly,
which does everything we need. Also allowing the inode_rm path to run
was getting us "missing subvolume" errors.
There's still another bug with snapshot deletion: we need to make
snapshot deletion a multi stage process, where we unlink the root
dentry, then tear down the page cache, then delete the snapshot.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 7 Oct 2021 22:18:01 +0000 (18:18 -0400)]
bcachefs: Fix a pcpu var splat
this_cpu_ptr() emits a warning when used without preemption disabled -
harmless in this case, as we have other locking where
bch2_acc_percpu_u64s() is used.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 7 Oct 2021 22:08:01 +0000 (18:08 -0400)]
bcachefs: Fix bch2_move_btree()
bch2_trans_begin() is now required for transaction restarts.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 7 Oct 2021 18:59:00 +0000 (14:59 -0400)]
bcachefs: Fixes for usrdata/metadata drop paths
These paths weren't updated for btree_path and snapshots - a couple of
minor fixes.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 7 Oct 2021 18:56:56 +0000 (14:56 -0400)]
bcachefs: More btree iterator fixes
- check for getting to the end of the btree in bch2_path_verify_locks
and __btree_path_traverse_all(), this fixes an infinite loop in
__btree_path_traverse_all().
- relax requirement in bch2_btree_node_upgrade() that we must want an
intent lock, this fixes bugs with paths that point to interior nodes
(nonzero level).
- bch2_btree_node_update_key(): fix it to upgrade the path to an intent
lock, if necessary
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 7 Oct 2021 18:54:50 +0000 (14:54 -0400)]
bcachefs: Ensure btree_path consistent with node iterators
Btree node iterators want the interior btree_path to point to the same
pos as the returned btree node - this fixes a regression from the
introduction of btree_path, where rewriting/updating keys of btree nodes
(e.g. in bch2_dev_metadata_drop()) via btree node iterators.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 7 Oct 2021 18:53:21 +0000 (14:53 -0400)]
bcachefs: Fix bch2_dev_remove_alloc()
It was missing a lockrestart_do(), to call bch2_trans_begin() and also
handle transaction restarts.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 30 Sep 2021 23:46:23 +0000 (19:46 -0400)]
bcachefs: bch2_subvolume_get()
Factor out a little helper.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 1 Oct 2021 14:08:13 +0000 (10:08 -0400)]
bcachefs: Fix allocator shutdown error message
We return 1 to indicate kthread_should_stop() returned true - we
shouldn't be printing an error.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 30 Sep 2021 21:51:18 +0000 (17:51 -0400)]
bcachefs: Fix a spurious fsck error
We were getting spurious "multiple types of data in same bucket" errors
in fsck, because the check was running for (cached) stale pointers -
oops.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 30 Sep 2021 15:09:26 +0000 (11:09 -0400)]
bcachefs: Fix check_inode_update_hardlinks()
We were incorrectly using bch2_inode_write(), which gets the snapshot ID
from the iterator, with a BTREE_ITER_ALL_SNAPSHOTS iterator -
fortunately caught by an assertion in the update path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 27 Sep 2021 17:25:18 +0000 (13:25 -0400)]
bcachefs: Rev the on disk format version for snapshots
This will cause the compat code to be run that creates entries in the
subvolumes and snapshots btrees.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 27 Sep 2021 05:56:31 +0000 (01:56 -0400)]
bcachefs: Fix an assertion
We can end up in a strange situation where a btree_path points to a node
being freed even after pointers to it should have been replaced by
pointers to the new node - if the btree node has been reused since the
pointer to it was created.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 17 Mar 2021 03:28:43 +0000 (23:28 -0400)]
bcachefs: Snapshot creation, deletion
This is the final patch in the patch series implementing snapshots.
This patch implements two new ioctls that work like creation and
deletion of directories, but fancier.
- BCH_IOCTL_SUBVOLUME_CREATE, for creating new subvolumes and snaphots
- BCH_IOCTL_SUBVOLUME_DESTROY, for deleting subvolumes and snapshots
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 16 Mar 2021 02:34:00 +0000 (22:34 -0400)]
bcachefs: Require snapshot id to be set
Now that all the existing code has been converted for snapshots, this
patch changes the code for initializing a btree iterator to require a
snapshot to be specified, and also change bkey_invalid() to allow for
non U32_MAX snapshot IDs.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 16 Dec 2021 01:38:56 +0000 (20:38 -0500)]
bcachefs: Fix unit & perf tests for snapshots
This finishes updating the unit & perf tests for snapshots - btrees that
use snapshots now always require the snapshot field of the start
position to be a valid snapshot ID.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 5 Aug 2021 04:41:41 +0000 (00:41 -0400)]
bcachefs: Update data move path for snapshots
The data move path operates on existing extents, and not within a
subvolume as the regular IO paths do. It needs to change because it may
cause existing extents to be split, and when splitting an existing
extent in an ancestor snapshot we need to make sure the new split has
the same visibility in child snapshots as the existing extent.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 2 Feb 2021 22:09:10 +0000 (17:09 -0500)]
bcachefs: Whiteouts for snapshots
This patch adds KEY_TYPE_whiteout, a new type of whiteout for snapshots,
when we're deleting and the key being deleted is in an ancestor
snapshot - and updates the transaction update/commit path to use it.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 13 Mar 2021 01:30:39 +0000 (20:30 -0500)]
bcachefs: Convert io paths for snapshots
This plumbs around the subvolume ID as was done previously for other
filesystem code, but now for the IO paths - the control flow in the IO
paths is trickier so the changes in this patch are more involved.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 20 Apr 2021 04:15:44 +0000 (00:15 -0400)]
bcachefs: Update fsck for snapshots
This updates the fsck algorithms to handle snapshots - meaning there
will be multiple versions of the same key (extents, inodes, dirents,
xattrs) in different snapshots, and we have to carefully consider which
keys are visible in which snapshot.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 16 Mar 2021 04:28:17 +0000 (00:28 -0400)]
bcachefs: Plumb through subvolume id
To implement snapshots, we need every filesystem btree operation (every
btree operation without a subvolume) to start by looking up the
subvolume and getting the current snapshot ID, with
bch2_subvolume_get_snapshot() - then, that snapshot ID is used for doing
btree lookups in BTREE_ITER_FILTER_SNAPSHOTS mode.
This patch adds those bch2_subvolume_get_snapshot() calls, and also
switches to passing around a subvol_inum instead of just an inode
number.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 5 Mar 2021 03:29:25 +0000 (22:29 -0500)]
bcachefs: BTREE_ITER_FILTER_SNAPSHOTS
For snapshots, we need to implement btree lookups that return the first
key that's an ancestor of the snapshot ID the lookup is being done in -
and filter out keys in unrelated snapshots. This patch adds the btree
iterator flag BTREE_ITER_FILTER_SNAPSHOTS which does that filtering.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 16 Mar 2021 05:33:39 +0000 (01:33 -0400)]
bcachefs: Add subvolume to ei_inode_info
Filesystem operations generally operate within a subvolume: at the start
of every btree transaction we'll be looking up (and locking) the
subvolume to get the current snapshot ID, which we then use for our
other btree lookups in BTREE_ITER_FILTER_SNAPSHOTS mode.
But inodes don't record what subvolume they're in - they can't, because
if they did we'd have to update every single inode within a subvolume
when taking a snapshot in order to keep that field up to date. So it
needs to be tracked in memory, based on how we got to that inode.
Hence this patch adds a subvolume field to ei_inode_info, and switches
to iget5() so we can index by it in the inode hash table.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 20 Apr 2021 03:31:40 +0000 (23:31 -0400)]
bcachefs: Per subvolume lost+found
On existing filesystems, we have a single global lost+found. Introducing
subvolumes means we need to introduce per subvolume lost+found
directories, because inodes are added to lost+found by their inode
number, and inode numbers are now only unique within a subvolume.
This patch adds support to fsck for per subvolume lost+found.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 16 Mar 2021 04:46:26 +0000 (00:46 -0400)]
bcachefs: Add support for dirents that point to subvolumes
Dirents currently always point to inodes. Subvolumes add a new type of
dirent, with d_type DT_SUBVOL, that instead points to an entry in the
subvolumes btree, and the subvolume has a pointer to the root inode.
This patch adds bch2_dirent_read_target() to get the inode (and
potentially subvolume) a dirent points to, and changes existing code to
use that instead of reading from d_inum directly.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 16 Mar 2021 04:42:25 +0000 (00:42 -0400)]
bcachefs: Subvolumes, snapshots
This patch adds subvolume.c - support for the subvolumes and snapshots
btrees and related data types and on disk data structures. The next
patches will start hooking up this new code to existing code.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 26 Sep 2021 17:54:14 +0000 (13:54 -0400)]
bcachefs: Disable quota support
Existing quota support breaks badly with snapshots. We're not deleting
the code because some of it will be needed when we reimplement quotas
along the lines of btrfs subvolume quotas.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 15 Sep 2021 15:15:18 +0000 (11:15 -0400)]
Revert "bcachefs: Add more assertions for locking btree iterators out of order"
Figured out the bug we were chasing, and it had nothing to do with
locking btree iterators/paths out of order.
This reverts commit
ff08733dd298c969aec7c7828095458f73fd5374.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 13 Sep 2021 20:04:49 +0000 (16:04 -0400)]
bcachefs: Improve btree_node_mem_ptr optimization
This patch checks b->hash_val before attempting to lock the node in the
btree, which makes it more equivalent to the "lookup in hash table"
path - and potentially avoids an unnecessary transaction restart if
btree_node_mem_ptr(k) no longer points to the node we want.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 13 Sep 2021 16:38:40 +0000 (12:38 -0400)]
bcachefs: Add a missing bch2_trans_relock() call
This was causing an assertion to pop in fsck, in one of the repair
paths.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Thu, 9 Sep 2021 23:05:34 +0000 (19:05 -0400)]
bcachefs: Fix some compiler warnings
gcc couldn't always deduce that written wasn't used uninitialized
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 8 Sep 2021 03:04:04 +0000 (23:04 -0400)]
bcachefs: Add missing BTREE_ITER_INTENT
No reason not to be using it here...
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 8 Sep 2021 01:25:32 +0000 (21:25 -0400)]
bcachefs: Better approach to write vs. read lock deadlocks
Instead of unconditionally upgrading read locks to intent locks in
do_bch2_trans_commit(), this patch changes the path that takes write
locks to first trylock, and then if trylock fails check if we have a
conflicting read lock, and restart the transaction if necessary.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 8 Sep 2021 01:24:05 +0000 (21:24 -0400)]
bcachefs: normalize_read_intent_locks
This is a new approach to avoiding the self deadlock we'd get if we
tried to take a write lock on a node while holding a read lock - we
simply upgrade the readers to intent.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 8 Sep 2021 00:23:30 +0000 (20:23 -0400)]
bcachefs: Consolidate intent lock code in btree_path_up_until_good_node
We need to take all needed intent locks when relocking an iterator:
bch2_btree_path_traverse() had a special cased, faster version of this,
but it really should be in up_until_good_node() so that set_pos() can
use it too.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 7 Sep 2021 19:34:16 +0000 (15:34 -0400)]
bcachefs: Optimize btree lookups in write path
This patch significantly reduces the number of btree lookups required in
the extent update path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 7 Sep 2021 17:55:33 +0000 (13:55 -0400)]
bcachefs: Add a missing btree_path_make_mut() call
Also add another small helper, btree_path_clone().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Tue, 7 Sep 2021 04:58:13 +0000 (00:58 -0400)]
bcachefs: Enabled shard_inode_numbers by default
We'd like performance increasing options to be on by default.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 6 Sep 2021 19:38:12 +0000 (15:38 -0400)]
bcachefs: No need to clone iterators for update
Since btree_path is now internally refcounted, we don't need to clone an
iterator before calling bch2_trans_update() if we'll be mutating it.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 5 Sep 2021 04:22:32 +0000 (00:22 -0400)]
bcachefs: Kill retry loop in btree merge path
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 5 Sep 2021 04:05:08 +0000 (00:05 -0400)]
bcachefs: Drop some fast path tracepoints
These haven't turned out to be useful
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 5 Sep 2021 01:23:11 +0000 (21:23 -0400)]
bcachefs: Tighten up btree locking invariants
New rule is: if a btree path holds any locks it should be holding
precisely the locks wanted (accoringing to path->level and
path->locks_want).
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 5 Sep 2021 01:19:48 +0000 (21:19 -0400)]
bcachefs: Extent btree iterators are no longer special
Since iter->real_pos was introduced, we no longer have to deal with
extent btree iterators that have skipped past deleted keys - this is a
real performance improvement on btree updates.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Fri, 3 Sep 2021 21:18:57 +0000 (17:18 -0400)]
bcachefs: Add more assertions for locking btree iterators out of order
btree_path_traverse_all() traverses btree iterators in sorted order, and
thus shouldn't see transaction restarts due to potential deadlocks - but
sometimes we do. This patch adds some more assertions and tracks some
more state to help track this down.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 19:18:31 +0000 (15:18 -0400)]
bcachefs: Kill bpos_diff() XXX check for perf regression
This improves the btree iterator lookup code by using
trans_for_each_iter_inorder().
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 19:18:31 +0000 (15:18 -0400)]
bcachefs: btree_path
This splits btree_iter into two components: btree_iter is now the
externally visible componont, and it points to a btree_path which is now
reference counted.
This means we no longer have to clone iterators up front if they might
be mutated - btree_path can be shared by multiple iterators, and cloned
if an iterator would mutate a shared btree_path. This will help us use
iterators more efficiently, as well as slimming down the main long lived
state in btree_trans, and significantly cleans up the logic for iterator
lifetimes.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Kent Overstreet [Fri, 3 Sep 2021 21:32:42 +0000 (17:32 -0400)]
bcachefs: Fix initialization of bch_write_op.nonce
If an extent ends up with a replica that is encrypted an a replica that
isn't encrypted (due the user changing options), and then
copygc/rebalance moves one of the replicas by reading from the
unencrypted replica, we had a bug where we wouldn't correctly initialize
op->nonce - for each crc field in an extent, crc.offset + crc.nonce must
be equal.
This patch fixes that by moving op.nonce initialization to
bch2_migrate_write_init.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 1 Sep 2021 22:06:01 +0000 (18:06 -0400)]
bcachefs: Improve an error message
When we detect an invalid key being inserted, we should print what code
was doing the update.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Wed, 1 Sep 2021 04:50:18 +0000 (00:50 -0400)]
bcachefs: Add an assertion for removing btree nodes from cache
Chasing a bug that has something to do with the btree node cache.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 19:54:41 +0000 (15:54 -0400)]
bcachefs: Kill BTREE_ITER_NODES
We really only need to distinguish between btree iterators and btree key
cache iterators - this is more prep work for btree_path.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 21:31:09 +0000 (17:31 -0400)]
bcachefs: Kill BTREE_ITER_NEED_PEEK
This was used for an optimization that hasn't existing in quite awhile
- iter->uptodate will probably be going away as well.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 20:08:34 +0000 (16:08 -0400)]
bcachefs: Prefer using btree_insert_entry to btree_iter
This moves some data dependencies forward, to improve pipelining.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 18:45:11 +0000 (14:45 -0400)]
bcachefs: More renaming
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 18:36:03 +0000 (14:36 -0400)]
bcachefs: Clean up/rename bch2_trans_node_* fns
These utility functions are for managing btree node state within a
btree_trans - rename them for consistency, and drop some unneeded
arguments.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Mon, 30 Aug 2021 18:22:43 +0000 (14:22 -0400)]
bcachefs: Further reduce iter->trans usage
This is prep work for splitting btree_path out from btree_iter -
btree_path will not have a pointer to btree_trans.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sat, 28 Aug 2021 00:55:44 +0000 (20:55 -0400)]
bcachefs: Better algorithm for btree node merging in write path
The existing algorithm was O(n^2) in the number of updates in the
commit.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Kent Overstreet [Sun, 29 Aug 2021 23:34:37 +0000 (19:34 -0400)]
bcachefs: Kill BTREE_ITER_SET_POS_AFTER_COMMIT
BTREE_ITER_SET_POS_AFTER_COMMIT is used internally to automagically
advance extent btree iterators on sucessful commit.
But with the upcomnig btree_path patch it's getting more awkward to
support, and it adds overhead to core data structures that's only used
in a few places, and can be easily done by the caller instead.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>