linux.git
18 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>
18 months agobcachefs: Reorganize extents.c
Kent Overstreet [Sat, 16 Nov 2019 21:25:58 +0000 (16:25 -0500)]
bcachefs: Reorganize extents.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Inline data extents
Kent Overstreet [Sat, 9 Nov 2019 21:43:16 +0000 (16:43 -0500)]
bcachefs: Inline data extents

This implements extents that have their data inline, in the value,
instead of the bkey value being pointers to the data - and the read and
write paths are updated to read from these new extent types and write
them out, when the write size is small enough.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Split out extent_update.c
Kent Overstreet [Fri, 15 Nov 2019 20:52:28 +0000 (15:52 -0500)]
bcachefs: Split out extent_update.c

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Rework of cut_front & cut_back
Kent Overstreet [Sun, 10 Nov 2019 00:02:48 +0000 (19:02 -0500)]
bcachefs: Rework of cut_front & cut_back

This changes bch2_cut_front and bch2_cut_back so that they're able to
shorten the size of the value, and it also changes the extent update
path to update the accounting in the btree node when this happens.

When the size of the value is shortened, they zero out the space that's
no longer used, so it's interpreted as noops (as implemented in the last
patch).

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: bkey noops
Kent Overstreet [Sun, 10 Nov 2019 04:50:52 +0000 (23:50 -0500)]
bcachefs: bkey noops

For upcoming inline data extents, we're going to need to be able to
shorten the value of existing bkeys in the btree - and to make that work
we're going to be able to need to pad out the space the value previously
took up with something.

This patch changes the various code that iterates over bkeys to handle
k->u64s == 0 as meaning "skip the next 8 bytes".

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: kill bch2_extent_has_device()
Kent Overstreet [Sat, 16 Nov 2019 01:40:15 +0000 (20:40 -0500)]
bcachefs: kill bch2_extent_has_device()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: bkey_on_stack
Kent Overstreet [Sat, 9 Nov 2019 21:01:15 +0000 (16:01 -0500)]
bcachefs: bkey_on_stack

This implements code for storing small bkeys on the stack and allocating
out of a mempool if they're too big.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Make memcpy_to_bio() param const
Kent Overstreet [Thu, 14 Nov 2019 00:46:11 +0000 (19:46 -0500)]
bcachefs: Make memcpy_to_bio() param const

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Use wbc_to_write_flags()
Kent Overstreet [Thu, 14 Nov 2019 00:45:48 +0000 (19:45 -0500)]
bcachefs: Use wbc_to_write_flags()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix erorr path in bch2_write()
Kent Overstreet [Mon, 11 Nov 2019 18:42:10 +0000 (13:42 -0500)]
bcachefs: Fix erorr path in bch2_write()

The error path in bch2_write wasn't updated when the end_io callback was
added to bch_write_op.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Set lost+found mode to 0700
Justin Husted [Sun, 10 Nov 2019 03:15:40 +0000 (19:15 -0800)]
bcachefs: Set lost+found mode to 0700

For security and conformance with other filesystems, the lost+found
directory should not be world or group accessible.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Be slightly less tricky with union usage
Kent Overstreet [Sat, 9 Nov 2019 19:58:09 +0000 (14:58 -0500)]
bcachefs: Be slightly less tricky with union usage

This is to fix a valgrind complaint - the code was correct, but too
tricky for valgrind to know that.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Remove some BKEY_PADDED uses
Kent Overstreet [Fri, 8 Nov 2019 20:09:36 +0000 (15:09 -0500)]
bcachefs: Remove some BKEY_PADDED uses

Prep work for extents with inline data

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Go back to 16 bit mantissa bkey floats
Kent Overstreet [Thu, 7 Nov 2019 00:40:09 +0000 (19:40 -0500)]
bcachefs: Go back to 16 bit mantissa bkey floats

The previous optimizations means using 32 bit mantissas are now a net
loss - having bkey_float be only 4 bytes is good for prefetching.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fall back to slowpath on exact comparison
Kent Overstreet [Wed, 23 Oct 2019 18:56:20 +0000 (14:56 -0400)]
bcachefs: Fall back to slowpath on exact comparison

This is basically equivalent to the original strategy of falling back to
checking against the original key when the original key and previous key
didn't differ in the required bits - except, now we only fall back when
the search key doesn't differ in the required bits, which ends up being
a bit faster.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: kill BFLOAT_FAILED_PREV
Kent Overstreet [Wed, 6 Nov 2019 21:37:29 +0000 (16:37 -0500)]
bcachefs: kill BFLOAT_FAILED_PREV

The assumption underlying BFLOAT_FAILED_PREV was wrong; the comparison
we're doing in bset_search_tree() doesn't have to tell the pivot apart
from the previous key, it just has to tell if search is definitely
greater than or equal to the pivot.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: bch2_read_extent() microoptimizations
Kent Overstreet [Thu, 7 Nov 2019 20:04:13 +0000 (15:04 -0500)]
bcachefs: bch2_read_extent() microoptimizations

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Pipeline binary searches and linear searches
Kent Overstreet [Thu, 7 Nov 2019 20:14:10 +0000 (15:14 -0500)]
bcachefs: Pipeline binary searches and linear searches

This makes prefetching for the linear search at the end of the lookup
much more effective, and is a couple percent speedup.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Make __bch2_bkey_cmp_packed() smaller
Kent Overstreet [Thu, 7 Nov 2019 20:03:09 +0000 (15:03 -0500)]
bcachefs: Make __bch2_bkey_cmp_packed() smaller

We can probably get rid of the version that dispatches based on type
checking too.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Inline fast path of bch2_increment_clock()
Kent Overstreet [Thu, 7 Nov 2019 20:00:08 +0000 (15:00 -0500)]
bcachefs: Inline fast path of bch2_increment_clock()

Shaving more cycles.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Avoid calling bch2_btree_iter_relock() in bch2_btree_iter_traverse()
Kent Overstreet [Mon, 4 Nov 2019 20:56:04 +0000 (15:56 -0500)]
bcachefs: Avoid calling bch2_btree_iter_relock() in bch2_btree_iter_traverse()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Add an option for fsck error ratelimiting
Kent Overstreet [Wed, 6 Nov 2019 20:32:11 +0000 (15:32 -0500)]
bcachefs: Add an option for fsck error ratelimiting

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't BUG_ON() sector count overflow
Kent Overstreet [Sat, 26 Oct 2019 18:58:36 +0000 (14:58 -0400)]
bcachefs: Don't BUG_ON() sector count overflow

Return an error instead (still work in progress...)

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Some reflink fixes
Kent Overstreet [Tue, 5 Nov 2019 03:22:13 +0000 (22:22 -0500)]
bcachefs: Some reflink fixes

len might fit into a loff_t when aligned_len does not - make sure we use
a u64 for aligned_len. Also, we weren't always extending the inode
correctly.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix setting of attributes mask in getattr
Kent Overstreet [Wed, 6 Nov 2019 19:29:30 +0000 (14:29 -0500)]
bcachefs: Fix setting of attributes mask in getattr

Discovered by xfstests generic/553

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Eliminate function calls in DIO fastpaths
Kent Overstreet [Wed, 2 Nov 2022 20:45:28 +0000 (16:45 -0400)]
bcachefs: Eliminate function calls in DIO fastpaths

We can assume that usually buffered and O_DIRECT IO won't be mixed, and
the calls to flush the page cache won't be needed.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: DIO write path only needs to shoot down pagecache once, not twice
Kent Overstreet [Mon, 4 Nov 2019 19:11:53 +0000 (14:11 -0500)]
bcachefs: DIO write path only needs to shoot down pagecache once, not twice

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Add pagecache_add lock to buffered IO path, fault path
Kent Overstreet [Fri, 18 Oct 2019 22:24:26 +0000 (18:24 -0400)]
bcachefs: Add pagecache_add lock to buffered IO path, fault path

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix uninitialized field in hash_check_init()
Justin Husted [Mon, 4 Nov 2019 05:50:32 +0000 (21:50 -0800)]
bcachefs: Fix uninitialized field in hash_check_init()

The chain_end field was not initialized before use in
hash_set_chain_start.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't hold inode lock longer than necessary in dio write path
Kent Overstreet [Sat, 2 Nov 2019 01:35:25 +0000 (21:35 -0400)]
bcachefs: Don't hold inode lock longer than necessary in dio write path

In theory we should be able to do (non appending/extending) dio writes
without taking the inode lock at all - but this gets us most of the way
there.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Avoid atomics in write fast path
Kent Overstreet [Sat, 2 Nov 2019 01:16:51 +0000 (21:16 -0400)]
bcachefs: Avoid atomics in write fast path

This adds some horrible hacks, but the atomic ops for closures were
getting to be a pretty expensive part of the write path. We don't want
to rip out closures entirely from the write path, because they're used
for e.g. waiting on the allocator, or waiting on the journal flush, and
that stuff would get really ugly without closures.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't use extent_ptr_decoded_append() in write path (fixup patch)
Kent Overstreet [Tue, 29 Oct 2019 07:57:58 +0000 (03:57 -0400)]
bcachefs: Don't use extent_ptr_decoded_append() in write path (fixup patch)

bch2_extent_ptr_decoded_append() is more general than we need here; we
know we're initializing a new extent so e.g. we're going to need the crc
entry.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: bch2_btree_iter_fix_key_modified()
Kent Overstreet [Wed, 2 Oct 2019 13:56:39 +0000 (09:56 -0400)]
bcachefs: bch2_btree_iter_fix_key_modified()

This is considerably cheaper than bch2_btree_node_iter_fix(), for cases
where the key was only modified and key ordering isn't changing.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Inline more of bch2_trans_commit hot path
Kent Overstreet [Mon, 28 Oct 2019 23:35:13 +0000 (19:35 -0400)]
bcachefs: Inline more of bch2_trans_commit hot path

The main optimization here is that if we let
bch2_replicas_delta_list_apply() fail, we can completely skip calling
bch2_bkey_replicas_marked_locked().

And assorted other small optimizations.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Trust btree alloc info at runtime
Kent Overstreet [Mon, 28 Oct 2019 23:33:59 +0000 (19:33 -0400)]
bcachefs: Trust btree alloc info at runtime

This lets us avoid a cache miss in the write path.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: More bset.c microoptimization
Kent Overstreet [Wed, 23 Oct 2019 23:50:01 +0000 (19:50 -0400)]
bcachefs: More bset.c microoptimization

Improve a few paper cuts that've shown up during profiling.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Initialize btree_node flags field in bch2_btree_root_alloc.
Justin Husted [Sat, 12 Oct 2019 00:56:27 +0000 (17:56 -0700)]
bcachefs: Initialize btree_node flags field in bch2_btree_root_alloc.

Valgrind data indicated that the flags field was only partially
initialized when written to disk.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Further padding fixes in bch2_journal_super_entries_add_common()
Justin Husted [Sat, 12 Oct 2019 00:05:11 +0000 (17:05 -0700)]
bcachefs: Further padding fixes in bch2_journal_super_entries_add_common()

The previous patch 128cb1a to fix uninitialized data was incorrect and
did not initialize the padding space correctly. Furthermore, several
other cases in this function do not initialize their padding space
correctly.

Move initialization into some helper functions in a more robust way.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Initialize padding space after alloc bkey
Justin Husted [Sat, 12 Oct 2019 00:20:30 +0000 (17:20 -0700)]
bcachefs: Initialize padding space after alloc bkey

Packed bkeys are padded up to 64 bit alignment, but the alloc bkey type
was not clearing the pad bytes after the last data byte. This left the
key possibly containing some random garbage at the end.

This problem was found using valgrind.

This patch also changes a path with the inode bkey to clear in the same
way.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Add missing error checking in bch2_find_by_inum_trans()
Kent Overstreet [Fri, 25 Oct 2019 23:06:26 +0000 (19:06 -0400)]
bcachefs: Add missing error checking in bch2_find_by_inum_trans()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix an error path race
Kent Overstreet [Fri, 25 Oct 2019 22:54:58 +0000 (18:54 -0400)]
bcachefs: Fix an error path race

On IO error, bch2_writepages_io_done() will set the page state to
indicate nothing's already reserved (since the write didn't happen, we
don't know what's already reserved). This can race with the buffered IO
path, in between getting a disk reservation and calling
bch2_set_page_dirty().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't reuse bio in retry path
Kent Overstreet [Thu, 24 Oct 2019 18:22:29 +0000 (14:22 -0400)]
bcachefs: Don't reuse bio in retry path

We can't reuse bios without reinitializing them, and in the retry path
it's safer to just make sure we don't reuse them at all.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't use rep movsq for small memcopies
Kent Overstreet [Tue, 22 Oct 2019 21:35:35 +0000 (17:35 -0400)]
bcachefs: Don't use rep movsq for small memcopies

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Avoid calling iter_prev() in extent update path
Kent Overstreet [Tue, 22 Oct 2019 01:15:08 +0000 (21:15 -0400)]
bcachefs: Avoid calling iter_prev() in extent update path

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: kill bch2_extent_merge_inline()
Kent Overstreet [Tue, 22 Oct 2019 01:27:10 +0000 (21:27 -0400)]
bcachefs: kill bch2_extent_merge_inline()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't use FUA unnecessarily
Kent Overstreet [Mon, 21 Oct 2019 23:38:08 +0000 (19:38 -0400)]
bcachefs: Don't use FUA unnecessarily

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Refactor bch2_trans_commit() path
Kent Overstreet [Sat, 19 Oct 2019 23:03:23 +0000 (19:03 -0400)]
bcachefs: Refactor bch2_trans_commit() path

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Make btree_node_type_needs_gc() cheaper
Kent Overstreet [Sun, 20 Oct 2019 04:24:51 +0000 (00:24 -0400)]
bcachefs: Make btree_node_type_needs_gc() cheaper

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Make replicas_delta_list smaller
Kent Overstreet [Sun, 20 Oct 2019 02:22:29 +0000 (22:22 -0400)]
bcachefs: Make replicas_delta_list smaller

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't submit bio in write path under lock
Kent Overstreet [Mon, 21 Oct 2019 23:58:06 +0000 (19:58 -0400)]
bcachefs: Don't submit bio in write path under lock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Drop bch_write_op->io_wq
Kent Overstreet [Tue, 22 Oct 2019 00:40:53 +0000 (20:40 -0400)]
bcachefs: Drop bch_write_op->io_wq

This is dead code

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Limit bios in writepages path to 256M
Kent Overstreet [Sun, 20 Oct 2019 04:22:03 +0000 (00:22 -0400)]
bcachefs: Limit bios in writepages path to 256M

This works around a bug where bio_full() doesn't check for
bio->bi_iter.bi_size overflowing - and, we don't really want to build
bios that are that big anyways.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix an iterator counting bug
Kent Overstreet [Wed, 16 Oct 2019 17:48:12 +0000 (13:48 -0400)]
bcachefs: Fix an iterator counting bug

The iterator counting assumed we're doing an obvious optimization when
only updating the refcount on indirect extents - but we're not doing it
yet.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix flushing held btree writes when there's a fs error
Kent Overstreet [Sat, 12 Oct 2019 20:44:44 +0000 (16:44 -0400)]
bcachefs: Fix flushing held btree writes when there's a fs error

Previously, we'd go into an infinite loop.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix iterator counting for reflink pointers (again)
Kent Overstreet [Sat, 12 Oct 2019 18:44:09 +0000 (14:44 -0400)]
bcachefs: Fix iterator counting for reflink pointers (again)

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix a debug assertion
Kent Overstreet [Sat, 12 Oct 2019 18:13:45 +0000 (14:13 -0400)]
bcachefs: Fix a debug assertion

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Switch to .iterate_shared for readdir
Kent Overstreet [Fri, 11 Oct 2019 19:14:36 +0000 (15:14 -0400)]
bcachefs: Switch to .iterate_shared for readdir

We definitely don't need an exclusive inode lock for readdir.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix creation of lost+found
Kent Overstreet [Fri, 11 Oct 2019 19:03:32 +0000 (15:03 -0400)]
bcachefs: Fix creation of lost+found

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix a subtle race in the btree split path
Kent Overstreet [Fri, 11 Oct 2019 18:45:22 +0000 (14:45 -0400)]
bcachefs: Fix a subtle race in the btree split path

We have to free the old (in memory) btree node _before_ unlocking the
new nodes - else, some other thread with a read lock on the old node
could see stale data after another thread has already updated the new
node.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Kill bchfs_extent_update()
Kent Overstreet [Wed, 9 Oct 2019 16:50:39 +0000 (12:50 -0400)]
bcachefs: Kill bchfs_extent_update()

The generic IO path now handles inode updates for i_size and i_sectors -
this means we can drop a fair amount of code from fs-io.c.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Convert bch2_fpunch to bch2_extent_update()
Kent Overstreet [Thu, 10 Oct 2019 16:47:22 +0000 (12:47 -0400)]
bcachefs: Convert bch2_fpunch to bch2_extent_update()

As before - we're moving non Linux specific code out of fs-io.c.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Split out bchfs_extent_update()
Kent Overstreet [Wed, 9 Oct 2019 16:11:00 +0000 (12:11 -0400)]
bcachefs: Split out bchfs_extent_update()

The next few patches are going to be more moving the logic around
i_size/i_sectors updates to io.c, and better separating the Linux VFS
specific code from core bcachefs code, to better support the fuse port.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Kill some dependencies on ei_inode
Kent Overstreet [Wed, 9 Oct 2019 15:12:48 +0000 (11:12 -0400)]
bcachefs: Kill some dependencies on ei_inode

Moving bch2_extent_update() to io.c will be greatly simplified if we
no longer have to keep ei_inode.bi_size/bi_sectors up to date.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Check if extending inode differently
Kent Overstreet [Wed, 9 Oct 2019 13:44:36 +0000 (09:44 -0400)]
bcachefs: Check if extending inode differently

In bch2_extent_update(), we have to update the inode if i_size is
changing (the file is being extend) or if i_sectors is changing, but we
want to avoid touching the inode if it's not necessary.

Change sum_sector_overwrites() to also check if there's already data
above where we're writing to - this means we're definitely not extending
the file.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix bch2_btree_iter_next() after peek_slot()
Kent Overstreet [Wed, 9 Oct 2019 14:25:32 +0000 (10:25 -0400)]
bcachefs: Fix bch2_btree_iter_next() after peek_slot()

this deserves a unit test

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Refactor bch2_readdir() a bit
Kent Overstreet [Wed, 9 Oct 2019 13:23:30 +0000 (09:23 -0400)]
bcachefs: Refactor bch2_readdir() a bit

The tweaks to ctx->pos handling are also to help the fuse port

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Add a lock to bch_page_state
Kent Overstreet [Wed, 9 Oct 2019 13:19:06 +0000 (09:19 -0400)]
bcachefs: Add a lock to bch_page_state

We can't use the page lock to protect it, because on writeback IO error
we need to access the page state before calling end_page_writeback() and
the page lock semantics are completely insane so that deadlocks.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix erasure coding disk space accounting
Kent Overstreet [Mon, 7 Oct 2019 19:57:47 +0000 (15:57 -0400)]
bcachefs: Fix erasure coding disk space accounting

Disk space accounting for erasure coding + compression was completely
broken - we need to calculate the parity sectors delta the same way we
calculate disk_sectors, by calculating the old and new usage and
subtracting to get the difference.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix ec_stripes_read()
Kent Overstreet [Wed, 9 Oct 2019 02:56:33 +0000 (22:56 -0400)]
bcachefs: Fix ec_stripes_read()

The bkey_s_c returned by btree_iter_(peek|next) points into the btree
iter type, so advancing the iterator and then using the one previously
returned is a bug...

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Limit pointers to being in only one stripe
Kent Overstreet [Tue, 8 Oct 2019 22:45:29 +0000 (18:45 -0400)]
bcachefs: Limit pointers to being in only one stripe

This make the disk accounting code saner, and it's not clear why we'd
ever want the same data to be in multiple stripes simultaneously.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix bch2_extent_ptr_durability()
Kent Overstreet [Mon, 7 Oct 2019 20:22:35 +0000 (16:22 -0400)]
bcachefs: Fix bch2_extent_ptr_durability()

We were looking up the wrong entry in the stripes radix tree.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix bch2_mark_extent()
Kent Overstreet [Wed, 9 Oct 2019 01:33:56 +0000 (21:33 -0400)]
bcachefs: Fix bch2_mark_extent()

If an extent only contained cached or erasure coded pointers, there
won't be any devices in the normal dirty replicas list or an entry to
update.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Initialize journal pad data in bch_replica_entry objects.
Justin Husted [Wed, 9 Oct 2019 02:17:06 +0000 (19:17 -0700)]
bcachefs: Initialize journal pad data in bch_replica_entry objects.

Running the filesystem under valgrind exposed some garbage data being
written to disk in bch2_journal_super_entries_add_common(), in the
portion which encodes bch_replica_entry objects.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix uninitialized data in bch2_gc_btree()
Justin Husted [Wed, 9 Oct 2019 02:16:28 +0000 (19:16 -0700)]
bcachefs: Fix uninitialized data in bch2_gc_btree()

Running the filesystem under valgrind exposed a path where the max_stale
variable in bch2_gc_btree() might not be initialized before use in a
rare case when there are no btree nodes in a transaction.

Signed-off-by: Justin Husted <sigstop@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix incorrect use of bch2_extent_atomic_end()
Kent Overstreet [Mon, 7 Oct 2019 19:09:30 +0000 (15:09 -0400)]
bcachefs: Fix incorrect use of bch2_extent_atomic_end()

bch2_extent_atomic_end counts the number of iterators requried for
marking overwrites - but journal replay never marks overwrites, so that
part was incorrect. And counting iterators for the key being inserted
should be unnecessary because we did that prior to the key being
inserted before it was first journalled.

This should fix an iterator overflow bug - the iterators for walking
overwrites were totally unneeded.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Can't be holding read locks while taking write locks
Kent Overstreet [Sat, 5 Oct 2019 00:40:47 +0000 (20:40 -0400)]
bcachefs: Can't be holding read locks while taking write locks

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't allocate memory under mark_lock
Kent Overstreet [Fri, 4 Oct 2019 23:14:43 +0000 (19:14 -0400)]
bcachefs: Don't allocate memory under mark_lock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: bch2_extent_atomic_end() now traverses iter
Kent Overstreet [Fri, 4 Oct 2019 21:07:20 +0000 (17:07 -0400)]
bcachefs: bch2_extent_atomic_end() now traverses iter

This fixes a bug in io.c bch2_write_index_default() - it was missing the
traverse call, but bch2_extent_atomic_end returns an error now and can
just call it itself.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Factor out fs-common.c
Kent Overstreet [Wed, 2 Oct 2019 22:35:36 +0000 (18:35 -0400)]
bcachefs: Factor out fs-common.c

This refactoring makes the code easier to understand by separating the
bcachefs btree transactional code from the linux VFS code - but more
importantly, it's also to share code with the fuse port.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Don't use sha256 for siphash str hash key
Kent Overstreet [Fri, 4 Oct 2019 19:58:43 +0000 (15:58 -0400)]
bcachefs: Don't use sha256 for siphash str hash key

With the refactoring that's coming to add fuse support, we want
bch2_hash_info_init() to be cheaper so we don't have to rely on anything
cached besides the inode in the btree.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Only look up inode io opts in extents btree
Kent Overstreet [Fri, 4 Oct 2019 18:39:38 +0000 (14:39 -0400)]
bcachefs: Only look up inode io opts in extents btree

We currently don't have a way to propagate inode io opts to indirect
extents. This is a problem...

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix deref of error pointer
Kent Overstreet [Fri, 4 Oct 2019 18:38:41 +0000 (14:38 -0400)]
bcachefs: Fix deref of error pointer

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: bch2_inode_peek()/bch2_inode_write()
Kent Overstreet [Tue, 1 Oct 2019 20:51:57 +0000 (16:51 -0400)]
bcachefs: bch2_inode_peek()/bch2_inode_write()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix undefined behaviour
Kent Overstreet [Wed, 2 Oct 2019 13:14:32 +0000 (09:14 -0400)]
bcachefs: Fix undefined behaviour

roundup_pow_of_two(0) is undefined

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix an error path
Kent Overstreet [Wed, 2 Oct 2019 04:29:37 +0000 (00:29 -0400)]
bcachefs: Fix an error path

It's possible to get -EIO in __btree_iter_traverse_all() after looping,
with orig_iter NULL.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix __bch2_buffered_write() returning -ENOMEM
Kent Overstreet [Tue, 1 Oct 2019 22:51:10 +0000 (18:51 -0400)]
bcachefs: Fix __bch2_buffered_write() returning -ENOMEM

When grab_cache_page_write_begin() fails but we did pin some pages, we
shouldn't return -ENOMEM, we should do a partial write.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Trust inode in btree over bch_inode_info
Kent Overstreet [Thu, 26 Sep 2019 03:11:41 +0000 (23:11 -0400)]
bcachefs: Trust inode in btree over bch_inode_info

This is the start of some refactoring work to make less code depend on
the linux VFS - here the inode cache - to make e.g. the fuse port
easier.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix counting iterators for reflink pointers
Kent Overstreet [Tue, 1 Oct 2019 20:29:17 +0000 (16:29 -0400)]
bcachefs: Fix counting iterators for reflink pointers

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Rework btree iterator lifetimes
Kent Overstreet [Fri, 27 Sep 2019 02:21:39 +0000 (22:21 -0400)]
bcachefs: Rework btree iterator lifetimes

The btree_trans struct needs to memoize/cache btree iterators, so that
on transaction restart we don't have to completely redo btree lookups,
and so that we can do them all at once in the correct order when the
transaction had to restart to avoid a deadlock.

This switches the btree iterator lookups to work based on iterator
position, instead of trying to match them up based on the stack trace.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Kill deferred btree updates
Kent Overstreet [Sun, 22 Sep 2019 22:49:16 +0000 (18:49 -0400)]
bcachefs: Kill deferred btree updates

Will be replaced by cached btree iterators

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Fix for partial buffered writes
Kent Overstreet [Thu, 26 Sep 2019 23:09:08 +0000 (19:09 -0400)]
bcachefs: Fix for partial buffered writes

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: BTREE_ITER_SLOTS isn't a type of btree iter
Kent Overstreet [Sun, 22 Sep 2019 23:35:12 +0000 (19:35 -0400)]
bcachefs: BTREE_ITER_SLOTS isn't a type of btree iter

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Improve error handling for for_each_btree_key_continue()
Kent Overstreet [Wed, 25 Sep 2019 19:57:56 +0000 (15:57 -0400)]
bcachefs: Improve error handling for for_each_btree_key_continue()

Change it to match for_each_btree_key()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Cleanup i_nlink handling
Kent Overstreet [Wed, 25 Sep 2019 20:19:52 +0000 (16:19 -0400)]
bcachefs: Cleanup i_nlink handling

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Trivial cleanup
Kent Overstreet [Wed, 25 Sep 2019 19:26:14 +0000 (15:26 -0400)]
bcachefs: Trivial cleanup

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Convert a BUG_ON() to a warning
Kent Overstreet [Tue, 24 Sep 2019 17:33:11 +0000 (13:33 -0400)]
bcachefs: Convert a BUG_ON() to a warning

We shouldn't ever be writing past i_size - but, apparently there's still
a bug to track down.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Count iterators for reflink_p overwrites correctly
Kent Overstreet [Sun, 22 Sep 2019 21:48:25 +0000 (17:48 -0400)]
bcachefs: Count iterators for reflink_p overwrites correctly

In order to avoid trying to allocate too many btree iterators,
bch2_extent_atomic_end() needs to count how many iterators are going to
be needed for insertions and overwrites - but we weren't counting the
iterators for deleting a reflink_v when the refcount goes to 0.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Drop unnecessary rcu_read_lock()
Kent Overstreet [Sat, 21 Sep 2019 20:30:15 +0000 (16:30 -0400)]
bcachefs: Drop unnecessary rcu_read_lock()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
18 months agobcachefs: Update path microoptimizations
Kent Overstreet [Sat, 21 Sep 2019 19:29:34 +0000 (15:29 -0400)]
bcachefs: Update path microoptimizations

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