]> git.proxmox.com Git - mirror_ubuntu-kernels.git/log
mirror_ubuntu-kernels.git
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>
13 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>