linux-block.git
8 months agobcachefs: trans_commit() path can now insert to interior nodes
Kent Overstreet [Mon, 16 Mar 2020 03:29:43 +0000 (23:29 -0400)]
bcachefs: trans_commit() path can now insert to interior nodes

This will be needed for the upcoming patches to journal updates to
interior btree nodes.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Disable extent merging
Kent Overstreet [Tue, 24 Mar 2020 21:00:48 +0000 (17:00 -0400)]
bcachefs: Disable extent merging

Extent merging is currently broken, and will be reimplemented
differently soon - right now it only happens when btree nodes are being
compacted, which makes it difficult to test.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix a locking bug in fsck
Kent Overstreet [Sat, 21 Mar 2020 18:47:00 +0000 (14:47 -0400)]
bcachefs: Fix a locking bug in fsck

This works around a btree locking issue - we can't be holding read locks
while taking write locks, which currently means we can't have live
iterators holding read locks at commit time.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix count_iters_for_insert()
Kent Overstreet [Sat, 21 Mar 2020 18:08:01 +0000 (14:08 -0400)]
bcachefs: Fix count_iters_for_insert()

This fixes a transaction iterator overflow.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix an iterator bug
Kent Overstreet [Wed, 18 Mar 2020 17:40:28 +0000 (13:40 -0400)]
bcachefs: Fix an iterator bug

We were incorrectly not restarting the transaction when re-traversing
iterators.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Shut down quicker
Kent Overstreet [Wed, 18 Mar 2020 15:46:46 +0000 (11:46 -0400)]
bcachefs: Shut down quicker

Internal writes (i.e. copygc/rebalance operations) shouldn't be blocking
on the allocator when we're going RO.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: BCH_FEATURE_new_extent_overwrite is now required
Kent Overstreet [Wed, 18 Mar 2020 15:40:07 +0000 (11:40 -0400)]
bcachefs: BCH_FEATURE_new_extent_overwrite is now required

The patch "bcachefs: Move extent overwrite handling out of core btree
code" should have been flipping on this feature bit; extent btree nodes
in the old format have to be rewritten before we can insert into them
with the new extent update path. Not turning on this feature bit was
causing us to go into an infinite loop where we keep rewriting btree
nodes over and over.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Clear BCH_FEATURE_extents_above_btree_updates on clean shutdown
Kent Overstreet [Mon, 16 Mar 2020 21:23:37 +0000 (17:23 -0400)]
bcachefs: Clear BCH_FEATURE_extents_above_btree_updates on clean shutdown

This is needed so that users can roll back to before "d9bb516b2d
bcachefs: Move extent overwrite handling out of core btree code", which
it appears may still be buggy.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix another iterator leak
Kent Overstreet [Mon, 16 Mar 2020 19:48:58 +0000 (15:48 -0400)]
bcachefs: Fix another iterator leak

This updates bch2_rbio_narrow_crcs() to the current style for
transactional btree code, and fixes a rare panic on iterator overflow.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't use peek_filter() unnecessarily
Kent Overstreet [Mon, 16 Mar 2020 19:49:23 +0000 (15:49 -0400)]
bcachefs: Don't use peek_filter() unnecessarily

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix a use after free in dio write path
Kent Overstreet [Mon, 16 Mar 2020 18:49:52 +0000 (14:49 -0400)]
bcachefs: Fix a use after free in dio write path

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Drop unused export
Kent Overstreet [Mon, 16 Mar 2020 02:41:10 +0000 (22:41 -0400)]
bcachefs: Drop unused export

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Move extent overwrite handling out of core btree code
Kent Overstreet [Mon, 30 Dec 2019 19:37:25 +0000 (14:37 -0500)]
bcachefs: Move extent overwrite handling out of core btree code

Ever since the btree code was first written, handling of overwriting
existing extents - including partially overwriting and splittin existing
extents - was handled as part of the core btree insert path. The modern
transaction and iterator infrastructure didn't exist then, so that was
the only way for it to be done.

This patch moves that outside of the core btree code to a pass that runs
at transaction commit time.

This is a significant simplification to the btree code and overall
reduction in code size, but more importantly it gets us much closer to
the core btree code being completely independent of extents and is
important prep work for snapshots.

This introduces a new feature bit; the old and new extent update models
are incompatible when the filesystem needs journal replay.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: btree_iter_peek_with_updates()
Kent Overstreet [Thu, 5 Mar 2020 23:44:59 +0000 (18:44 -0500)]
bcachefs: btree_iter_peek_with_updates()

Introduce a new iterator method that provides a consistent view of the
btree plus uncommitted updates.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix build when CONFIG_BCACHEFS_DEBUG=n
Kent Overstreet [Sun, 15 Mar 2020 20:15:08 +0000 (16:15 -0400)]
bcachefs: Fix build when CONFIG_BCACHEFS_DEBUG=n

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: More btree iter invariants
Kent Overstreet [Tue, 18 Feb 2020 21:17:55 +0000 (16:17 -0500)]
bcachefs: More btree iter invariants

Ensure that iter->pos always lies between the start and end of iter->k
(the last key returned). Also, bch2_btree_iter_set_pos() now invalidates
the key that peek() or next() returned.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Simplify bch2_btree_iter_peek_slot()
Kent Overstreet [Sat, 14 Mar 2020 01:41:22 +0000 (21:41 -0400)]
bcachefs: Simplify bch2_btree_iter_peek_slot()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Iterator debug code improvements
Kent Overstreet [Tue, 18 Feb 2020 21:17:55 +0000 (16:17 -0500)]
bcachefs: Iterator debug code improvements

More aggressively checking iterator invariants, and fixing the resulting
bugs. Also greatly simplifying iter_next() and iter_next_slot() - they
were hyper optimized before, but the optimizations were getting too
brittle.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Skip 0 size deleted extents in journal replay
Kent Overstreet [Thu, 5 Mar 2020 23:43:31 +0000 (18:43 -0500)]
bcachefs: Skip 0 size deleted extents in journal replay

These are created by the new extent update path, but not used yet by the
recovery code and they break the existing recovery code, so we can just
skip them.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Traverse iterator in journal replay
Kent Overstreet [Mon, 9 Mar 2020 20:15:54 +0000 (16:15 -0400)]
bcachefs: Traverse iterator in journal replay

This fixes a bug where we end up spinning in journal replay - in theory
this shouldn't be necessary though, transaction reset should be
re-traversing all iterators.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't log errors that are expected during shutdown
Kent Overstreet [Mon, 9 Mar 2020 18:19:58 +0000 (14:19 -0400)]
bcachefs: Don't log errors that are expected during shutdown

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix bch2_dump_bset()
Kent Overstreet [Sat, 7 Mar 2020 22:20:39 +0000 (17:20 -0500)]
bcachefs: Fix bch2_dump_bset()

It's used in the write path when the bset isn't in the btree node
buffer.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix another iterator leak
Kent Overstreet [Sat, 7 Mar 2020 18:30:55 +0000 (13:30 -0500)]
bcachefs: Fix another iterator leak

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix off by one error in bch2_extent_crc_append()
Kent Overstreet [Thu, 5 Mar 2020 22:06:15 +0000 (17:06 -0500)]
bcachefs: Fix off by one error in bch2_extent_crc_append()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix extent_sort_fix_overlapping()
Kent Overstreet [Mon, 2 Mar 2020 22:08:19 +0000 (17:08 -0500)]
bcachefs: Fix extent_sort_fix_overlapping()

Recently the extent update path started emmiting 0 size whiteouts on
extent overwrite, as part of transitioning to moving extent handling
out of the core btree code.

Unfortunately, this broke the old code path that handles overlapping
extents when reading in btree nodes - it relies on sorting incomming
extents by start position, but the 0 size whiteouts broke that ordering.
Skipping over them before the main algorithm sees them fixes this.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Some btree iterator improvements
Kent Overstreet [Mon, 2 Mar 2020 18:38:19 +0000 (13:38 -0500)]
bcachefs: Some btree iterator improvements

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Journal pin cleanups
Kent Overstreet [Thu, 27 Feb 2020 20:03:44 +0000 (15:03 -0500)]
bcachefs: Journal pin cleanups

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Dont't del sysfs dir until after we go RO
Kent Overstreet [Thu, 27 Feb 2020 20:03:53 +0000 (15:03 -0500)]
bcachefs: Dont't del sysfs dir until after we go RO

This will help for debugging hangs during unmount

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix error message on bucket sector count overflow
Kent Overstreet [Thu, 27 Feb 2020 03:29:52 +0000 (22:29 -0500)]
bcachefs: Fix error message on bucket sector count overflow

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Improve an error message
Kent Overstreet [Thu, 27 Feb 2020 01:39:06 +0000 (20:39 -0500)]
bcachefs: Improve an error message

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: BCH_SB_FEATURES_ALL
Kent Overstreet [Wed, 26 Feb 2020 22:34:27 +0000 (17:34 -0500)]
bcachefs: BCH_SB_FEATURES_ALL

BCH_FEATURE_btree_ptr_v2 wasn't getting set on new filesystems, oops

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: fix setting btree_node_accessed()
Kent Overstreet [Wed, 26 Feb 2020 22:25:13 +0000 (17:25 -0500)]
bcachefs: fix setting btree_node_accessed()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Use btree_ptr_v2.mem_ptr to avoid hash table lookup
Kent Overstreet [Mon, 24 Feb 2020 20:25:00 +0000 (15:25 -0500)]
bcachefs: Use btree_ptr_v2.mem_ptr to avoid hash table lookup

Nice performance optimization

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix incorrect initialization of btree_node_old_extent_overwrite()
Kent Overstreet [Wed, 26 Feb 2020 22:11:00 +0000 (17:11 -0500)]
bcachefs: Fix incorrect initialization of btree_node_old_extent_overwrite()

b->level and b->btree_id weren't set when the code was checking
btree_node_is_extents()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Issue discards when needed to allocate journal write
Kent Overstreet [Wed, 26 Feb 2020 20:58:36 +0000 (15:58 -0500)]
bcachefs: Issue discards when needed to allocate journal write

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Kill TRANS_RESET_MEM|TRANS_RESET_ITERS
Kent Overstreet [Wed, 26 Feb 2020 20:39:46 +0000 (15:39 -0500)]
bcachefs: Kill TRANS_RESET_MEM|TRANS_RESET_ITERS

All iterators should be released now with bch2_trans_iter_put(), so
TRANS_RESET_ITERS shouldn't be needed anymore, and TRANS_RESET_MEM is
always used.

Also convert more code to __bch2_trans_do().

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Seralize btree_update operations at btree_update_nodes_written()
Kent Overstreet [Sat, 8 Feb 2020 21:39:37 +0000 (16:39 -0500)]
bcachefs: Seralize btree_update operations at btree_update_nodes_written()

Prep work for journalling updates to interior nodes - enforcing ordering
will greatly simplify those changes.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: btree_ptr_v2
Kent Overstreet [Fri, 7 Feb 2020 18:38:02 +0000 (13:38 -0500)]
bcachefs: btree_ptr_v2

Add a new btree ptr type which contains the sequence number (random 64
bit cookie, actually) for that btree node - this lets us verify that
when we read in a btree node it really is the btree node we wanted.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: introduce b->hash_val
Kent Overstreet [Tue, 18 Feb 2020 22:15:32 +0000 (17:15 -0500)]
bcachefs: introduce b->hash_val

This is partly prep work for introducing bch_btree_ptr_v2, but it'll
also be a bit of a performance boost by moving the full key out of the
hot part of struct btree.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix traversing to interior nodes
Kent Overstreet [Wed, 19 Feb 2020 00:29:33 +0000 (19:29 -0500)]
bcachefs: Fix traversing to interior nodes

NULL is used to mean "reach end of traversal" - we were only
initializing the leaf node in the iterator to the right sentinal value.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Check for bad key version number
Kent Overstreet [Wed, 19 Feb 2020 01:02:41 +0000 (20:02 -0500)]
bcachefs: Check for bad key version number

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix bch2_ptr_swab for indirect extents
Kent Overstreet [Fri, 7 Feb 2020 01:15:15 +0000 (20:15 -0500)]
bcachefs: Fix bch2_ptr_swab for indirect extents

bch2_ptr_swab was never updated when the code for generic keys with
pointers was added - it assumed the entire val was only used for
pointers.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Make BTREE_ITER_IS_EXTENTS private to iter code
Kent Overstreet [Fri, 31 Jan 2020 18:26:05 +0000 (13:26 -0500)]
bcachefs: Make BTREE_ITER_IS_EXTENTS private to iter code

Prep work for changing the core btree update path to handle extents like
regular keys; we need to reduce the scope of what BTREE_ITER_IS_EXTENTS
means

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: __bch2_btree_iter_set_pos()
Kent Overstreet [Fri, 31 Jan 2020 18:23:18 +0000 (13:23 -0500)]
bcachefs: __bch2_btree_iter_set_pos()

This one takes an additional argument for whether we're searching for >=
or > the search key.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: btree_and_journal_iter
Kent Overstreet [Sat, 28 Dec 2019 01:51:35 +0000 (20:51 -0500)]
bcachefs: btree_and_journal_iter

Introduce a new iterator that iterates over keys in the btree with keys
from the journal overlaid on top. This factors out what the erasure
coding init code was doing manually.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Make sure we're releasing btree iterators
Kent Overstreet [Tue, 18 Feb 2020 19:27:10 +0000 (14:27 -0500)]
bcachefs: Make sure we're releasing btree iterators

This wasn't originally required, but this is the model we're moving
towards.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Improve an insert path optimization
Kent Overstreet [Fri, 31 Jan 2020 01:26:08 +0000 (20:26 -0500)]
bcachefs: Improve an insert path optimization

The insert path had an optimization to short circuit lookup
table/iterator fixups when overwriting an existing key with the same
size value - but it was incorrect when other key fields
(size/version) were changing. This is important for the upcoming rework
to have extent updates use the same insert path as regular keys.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix an uninitialized field in bch_write_op
Kent Overstreet [Wed, 29 Jan 2020 18:05:04 +0000 (13:05 -0500)]
bcachefs: Fix an uninitialized field in bch_write_op

Regression from "bcachefs: Track incompressible data"

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix an in iterator leak
Kent Overstreet [Mon, 27 Jan 2020 22:47:07 +0000 (17:47 -0500)]
bcachefs: Fix an in iterator leak

This should fix a transaction iterator overflow bug during fsck.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Track incompressible data
Kent Overstreet [Fri, 23 Feb 2018 21:26:10 +0000 (16:26 -0500)]
bcachefs: Track incompressible data

This fixes the background_compression option: wihout some way of marking
data as incompressible, rebalance will keep rewriting incompressible
data over and over.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Refactor rebalance_pred function
Kent Overstreet [Tue, 21 Jan 2020 00:42:38 +0000 (19:42 -0500)]
bcachefs: Refactor rebalance_pred function

Before, the logic for if we should move an extent was duplicated
somewhat, in both rebalance_add_key() and rebalance_pred(); this
centralizes that in __rebalance_pred()

This is prep work for a patch that enables marking data as
incompressible.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Improve tracepoints slightly in commit path
Kent Overstreet [Thu, 9 Jan 2020 23:30:05 +0000 (18:30 -0500)]
bcachefs: Improve tracepoints slightly in commit path

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Add a cond_resched() to rebalance loop
Kent Overstreet [Thu, 16 Jan 2020 21:20:53 +0000 (16:20 -0500)]
bcachefs: Add a cond_resched() to rebalance loop

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't modify existing key in place in sort_repack_merge()
Kent Overstreet [Thu, 16 Jan 2020 21:14:56 +0000 (16:14 -0500)]
bcachefs: Don't modify existing key in place in sort_repack_merge()

This fixes a nasty memory corruption with other threads that are still
reading the btree node being compacted.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix bch2_sort_keys() to not modify src keys
Kent Overstreet [Thu, 16 Jan 2020 03:53:49 +0000 (22:53 -0500)]
bcachefs: Fix bch2_sort_keys() to not modify src keys

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Change btree split threshold to be in u64s
Kent Overstreet [Wed, 15 Jan 2020 20:11:22 +0000 (15:11 -0500)]
bcachefs: Change btree split threshold to be in u64s

This fixes a bug with very small btree nodes where splitting would end
up with one of the new nodes empty.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Add some comments for btree iterator flags
Kent Overstreet [Fri, 10 Jan 2020 01:43:58 +0000 (20:43 -0500)]
bcachefs: Add some comments for btree iterator flags

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Refactor bch2_btree_bset_insert_key()
Kent Overstreet [Tue, 7 Jan 2020 04:43:04 +0000 (23:43 -0500)]
bcachefs: Refactor bch2_btree_bset_insert_key()

The main thing going on is to separate out the different cases deletion,
overwriting, and inserting a new key.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Rework iter->pos handling
Kent Overstreet [Tue, 7 Jan 2020 03:25:09 +0000 (22:25 -0500)]
bcachefs: Rework iter->pos handling

- Rework some of the helper comparison functions for consistency

- Currently trying to refactor all the logic that's different for
extents in the btree iterator code. The main difference is that for non
extents we search for a key greater than or equal to the search key,
while for extents we search for a key strictly greater than the search
key (iter->pos).

So that logic is now handled by btree_iter_search_key(), which computes
the real search key based on iter->pos and whether or not we're
searching for a key >= or > iter->pos.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't lose needs_whiteout in overwrite path
Kent Overstreet [Sun, 5 Jan 2020 23:20:23 +0000 (18:20 -0500)]
bcachefs: Don't lose needs_whiteout in overwrite path

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't call trans_iter_put() on error pointer
Kent Overstreet [Sun, 5 Jan 2020 00:04:47 +0000 (19:04 -0500)]
bcachefs: Don't call trans_iter_put() on error pointer

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Ensure iterators are valid before calling trans_mark_key()
Kent Overstreet [Sat, 4 Jan 2020 21:46:23 +0000 (16:46 -0500)]
bcachefs: Ensure iterators are valid before calling trans_mark_key()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix extent_to_replicas()
Kent Overstreet [Sat, 4 Jan 2020 21:33:32 +0000 (16:33 -0500)]
bcachefs: Fix extent_to_replicas()

This needs to match bch2_mark_extent()/bch2_trans_mark_extent() in
buckets.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Kill bch2_fs_bug()
Kent Overstreet [Sat, 4 Jan 2020 21:09:52 +0000 (16:09 -0500)]
bcachefs: Kill bch2_fs_bug()

These have all been converted to fsck/inconsistent errors

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Hacky fixes for device removal
Kent Overstreet [Sat, 4 Jan 2020 03:38:14 +0000 (22:38 -0500)]
bcachefs: Hacky fixes for device removal

The device remove test was sporadically failing, because we hadn't
finished dropping btree sector counts for the device when
bch2_replicas_gc2() was called - mainly due to in flight journal writes.
We don't yet have a good mechanism for flushing the counts that
correspend to open journal entries yet.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't print anything when device doesn't have a label
Kent Overstreet [Fri, 3 Jan 2020 23:57:32 +0000 (18:57 -0500)]
bcachefs: Don't print anything when device doesn't have a label

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix an iterator error path
Kent Overstreet [Fri, 3 Jan 2020 23:04:19 +0000 (18:04 -0500)]
bcachefs: Fix an iterator error path

On transaction restart (-EINTR), we need to traverse all iterators.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Make sure bch2_read_extent obeys BCH_READ_MUST_CLONE
Kent Overstreet [Fri, 3 Jan 2020 21:03:10 +0000 (16:03 -0500)]
bcachefs: Make sure bch2_read_extent obeys BCH_READ_MUST_CLONE

This fixes the bch2_read_retry_nodecode() path, we were resubmitting a
bio without properly reinitializing it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Sort & deduplicate updates in bch2_trans_update()
Kent Overstreet [Wed, 1 Jan 2020 00:37:10 +0000 (19:37 -0500)]
bcachefs: Sort & deduplicate updates in bch2_trans_update()

Previously, when doing multiple update in the same transaction commit
that overwrote each other, we relied on doing the updates in the same
order as the bch2_trans_update() calls in order to get the correct
result. But that wasn't correct for triggers; bch2_trans_mark_update()
when marking overwrites would do the wrong thing because it hadn't seen
the update that was being overwritten.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Split out btree_trigger_flags
Kent Overstreet [Tue, 31 Dec 2019 21:17:42 +0000 (16:17 -0500)]
bcachefs: Split out btree_trigger_flags

The trigger flags really belong with individual btree_insert_entries,
not the transaction commit flags - this splits out those  flags and
unifies them with the BCH_BUCKET_MARK flags. Todo - split out
btree_trigger.c from buckets.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Make btree_insert_entry more private to update path
Kent Overstreet [Mon, 30 Dec 2019 18:08:26 +0000 (13:08 -0500)]
bcachefs: Make btree_insert_entry more private to update path

This should be private to btree_update_leaf.c, and we might end up
removing it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Use bch2_trans_reset in bch2_trans_commit()
Kent Overstreet [Mon, 30 Dec 2019 17:43:19 +0000 (12:43 -0500)]
bcachefs: Use bch2_trans_reset in bch2_trans_commit()

Clean up a bit of duplicated code.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Use KEY_TYPE_deleted whitouts for extents
Kent Overstreet [Tue, 26 Nov 2019 22:26:04 +0000 (17:26 -0500)]
bcachefs: Use KEY_TYPE_deleted whitouts for extents

Previously, partial overwrites of existing extents were handled
implicitly by the btree code; when reading in a btree node, we'd do a
mergesort of the different bsets and detect and fix partially
overlapping extents during that mergesort.

That approach won't work with snapshots: this changes extents to work
like regular keys as far as the btree code is concerned, where a 0 size
KEY_TYPE_deleted whiteout will completely overwrite an existing extent.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Convert some enums to x-macros
Kent Overstreet [Sun, 29 Dec 2019 01:17:06 +0000 (20:17 -0500)]
bcachefs: Convert some enums to x-macros

Helps for preventing things from getting out of sync.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Add an assertion to track down a heisenbug
Kent Overstreet [Sat, 28 Dec 2019 01:42:06 +0000 (20:42 -0500)]
bcachefs: Add an assertion to track down a heisenbug

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix a use after free
Kent Overstreet [Fri, 27 Dec 2019 18:44:03 +0000 (13:44 -0500)]
bcachefs: Fix a use after free

op->end_io may free the op struct

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't export __bch2_fs_read_write
Kent Overstreet [Thu, 26 Dec 2019 19:54:43 +0000 (14:54 -0500)]
bcachefs: Don't export __bch2_fs_read_write

BTREE_INSERT_LAZY_RW was added for this since this code was written; use
it instead.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Don't reexecute triggers when retrying transaction commit
Kent Overstreet [Tue, 24 Dec 2019 23:03:53 +0000 (18:03 -0500)]
bcachefs: Don't reexecute triggers when retrying transaction commit

This was causing a bug with transaction iterators overflowing; now, if
triggers have to be reexecuted we always return -EINTR and retry from
the start of the transaction.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Kill BTREE_INSERT_ATOMIC
Kent Overstreet [Mon, 23 Dec 2019 04:39:28 +0000 (23:39 -0500)]
bcachefs: Kill BTREE_INSERT_ATOMIC

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Convert all bch2_trans_commit() users to BTREE_INSERT_ATOMIC
Kent Overstreet [Mon, 23 Dec 2019 04:04:30 +0000 (23:04 -0500)]
bcachefs: Convert all bch2_trans_commit() users to BTREE_INSERT_ATOMIC

BTREE_INSERT_ATOMIC should really be the default mode, and there's not
that much code that doesn't need it - so this is prep work for getting
rid of the flag.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: bch2_trans_reset() calls should be at the tops of loops
Kent Overstreet [Fri, 20 Dec 2019 21:35:24 +0000 (16:35 -0500)]
bcachefs: bch2_trans_reset() calls should be at the tops of loops

It needs to be called when we get -EINTR due to e.g. lock restart - this
fixes a transaction iterators overflow bug.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Drop a faulty assertion
Kent Overstreet [Fri, 20 Dec 2019 21:26:27 +0000 (16:26 -0500)]
bcachefs: Drop a faulty assertion

This assertion was wrong for interior nodes (and wasn't terribly useful
to begin with)

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Redo copygc throttling
Kent Overstreet [Fri, 20 Dec 2019 21:19:46 +0000 (16:19 -0500)]
bcachefs: Redo copygc throttling

The code that checked the current free space and waited if it was too
big was causing issues - btree node allocations do not increment the
write IO clock (perhaps they should); but more broadly the check
wouldn't run copygc at all until the device was mostly full, at which
point it might have to do a bunch of work.

This redoes that logic so that copygc starts to run earlier, smoothly
running more and more often as the device becomes closer to full.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Make io timers less buggy
Kent Overstreet [Thu, 19 Dec 2019 20:07:51 +0000 (15:07 -0500)]
bcachefs: Make io timers less buggy

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix a memory splat
Kent Overstreet [Wed, 18 Dec 2019 22:34:36 +0000 (17:34 -0500)]
bcachefs: Fix a memory splat

In __bch2_sb_field_resize, when a field's old a new size was 0, we were
doing an invalid write just past the end of the superblock.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Redo filesystem usage ioctls
Kent Overstreet [Mon, 16 Dec 2019 22:53:59 +0000 (17:53 -0500)]
bcachefs: Redo filesystem usage ioctls

When disk space accounting was changed to be tracked by replicas entry,
the ioctl interface was never update: this patch finally does that.

Aditionally, the BCH_IOCTL_USAGE ioctl is now broken out into separate
ioctls for filesystem and device usage.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Update directory timestamps during link
Justin Husted [Tue, 12 Nov 2019 04:14:30 +0000 (20:14 -0800)]
bcachefs: Update directory timestamps during link

Timestamp updates on the directory during a link operation were cached.
This is inconsistent with other metadata operations such as rename, as
well as being less efficient.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix for an assertion on filesystem error
Kent Overstreet [Wed, 18 Dec 2019 18:18:33 +0000 (13:18 -0500)]
bcachefs: Fix for an assertion on filesystem error

Normally the in memory i_size is always greater than or equal to i_size
on disk; this doesn't hold on filesystem error.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix a null ptr deref in btree_iter_traverse_one()
Kent Overstreet [Mon, 16 Dec 2019 20:37:47 +0000 (15:37 -0500)]
bcachefs: Fix a null ptr deref in btree_iter_traverse_one()

When traversing nodes and we've reached the end of the btree, the
current btree node will be NULL.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Kill btree_node_iter_large
Kent Overstreet [Sat, 14 Dec 2019 21:20:33 +0000 (16:20 -0500)]
bcachefs: Kill btree_node_iter_large

Long overdue cleanup - this converts btree_node_iter_large uses to
sort_iter.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Use one buffer for sorting whiteouts
Kent Overstreet [Sat, 14 Dec 2019 20:55:29 +0000 (15:55 -0500)]
bcachefs: Use one buffer for sorting whiteouts

We're not really supposed to allocate from the same mempool more than
once.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Refactor whiteouts compaction
Kent Overstreet [Fri, 13 Dec 2019 18:08:37 +0000 (13:08 -0500)]
bcachefs: Refactor whiteouts compaction

The whiteout compaction path - as opposed to just dropping whiteouts -
is now only needed for extents, and soon will only be needed for extent
btree nodes in the old format.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Whiteout changes
Kent Overstreet [Fri, 29 Nov 2019 19:08:51 +0000 (14:08 -0500)]
bcachefs: Whiteout changes

More prep work for snapshots: extents will soon be using
KEY_TYPE_deleted for whiteouts, with 0 size. But we wen't be able to
keep these whiteouts with the rest of the extents in the btree node, due
to sorting invariants breaking.

We can deal with this by immediately moving the new whiteouts to the
unwritten whiteouts area - this just means those whiteouts won't be
sorted, so we need new code to sort them prior to merging them with the
rest of the keys to be written.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Always emit new extents on partial overwrite
Kent Overstreet [Wed, 20 Nov 2019 21:22:49 +0000 (16:22 -0500)]
bcachefs: Always emit new extents on partial overwrite

This is prep work for snapshots: the algorithm in
bch2_extent_sort_fix_overlapping() will break when we have multiple
overlapping extents in unrelated snapshots - but, we'll be able to make
extents work like regular keys and use bch2_key_sort_fix_overlapping()
for extent btree nodes if we make a couple changes - the main one being
to always emit new extents when we partially overwrite an existing
(written) extent.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Fix bch2_verify_insert_pos()
Kent Overstreet [Tue, 26 Nov 2019 22:18:23 +0000 (17:18 -0500)]
bcachefs: Fix bch2_verify_insert_pos()

We were calling __btree_node_key_to_offset() on a key that wasn't in the
btree node.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Put inline data behind a mount option for now
Kent Overstreet [Fri, 29 Nov 2019 18:48:09 +0000 (13:48 -0500)]
bcachefs: Put inline data behind a mount option for now

Inline data extents + reflink is still broken

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: bch2_check_set_feature()
Kent Overstreet [Fri, 29 Nov 2019 18:47:42 +0000 (13:47 -0500)]
bcachefs: bch2_check_set_feature()

New helper function for setting incompatible feature bits

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: Switch to macro for bkey_ops
Kent Overstreet [Tue, 26 Nov 2019 22:09:32 +0000 (17:09 -0500)]
bcachefs: Switch to macro for bkey_ops

Older versions of gcc refuse to compile it the other way

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: bkey_on_stack_reassemble()
Kent Overstreet [Wed, 20 Nov 2019 19:51:30 +0000 (14:51 -0500)]
bcachefs: bkey_on_stack_reassemble()

Small helper function.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
8 months agobcachefs: kill ca->freelist_lock
Kent Overstreet [Wed, 20 Nov 2019 21:16:57 +0000 (16:16 -0500)]
bcachefs: kill ca->freelist_lock

All uses were supposed to be switched over to c->freelist_lock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>