summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-10-03bcachefs: Fix allocator shutdown error messageKent Overstreet
We return 1 to indicate kthread_should_stop() returned true - we shouldn't be printing an error. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Fix a spurious fsck errorKent Overstreet
We were getting spurious "multiple types of data in same bucket" errors in fsck, because the check was running for (cached) stale pointers - oops. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Fix check_inode_update_hardlinks()Kent Overstreet
We were incorrectly using bch2_inode_write(), which gets the snapshot ID from the iterator, with a BTREE_ITER_ALL_SNAPSHOTS iterator - fortunately caught by an assertion in the update path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Rev the on disk format version for snapshotsKent Overstreet
This will cause the compat code to be run that creates entries in the subvolumes and snapshots btrees. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Fix an assertionKent Overstreet
We can end up in a strange situation where a btree_path points to a node being freed even after pointers to it should have been replaced by pointers to the new node - if the btree node has been reused since the pointer to it was created. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Snapshot creation, deletionKent Overstreet
This is the final patch in the patch series implementing snapshots. This patch implements two new ioctls that work like creation and deletion of directories, but fancier. - BCH_IOCTL_SUBVOLUME_CREATE, for creating new subvolumes and snaphots - BCH_IOCTL_SUBVOLUME_DESTROY, for deleting subvolumes and snapshots Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Require snapshot id to be setKent Overstreet
Now that all the existing code has been converted for snapshots, this patch changes the code for initializing a btree iterator to require a snapshot to be specified, and also change bkey_invalid() to allow for non U32_MAX snapshot IDs. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Fix unit & perf tests for snapshotsKent Overstreet
This finishes updating the unit & perf tests for snapshots - btrees that use snapshots now always require the snapshot field of the start position to be a valid snapshot ID. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Update data move path for snapshotsKent Overstreet
The data move path operates on existing extents, and not within a subvolume as the regular IO paths do. It needs to change because it may cause existing extents to be split, and when splitting an existing extent in an ancestor snapshot we need to make sure the new split has the same visibility in child snapshots as the existing extent. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Whiteouts for snapshotsKent Overstreet
This patch adds KEY_TYPE_whiteout, a new type of whiteout for snapshots, when we're deleting and the key being deleted is in an ancestor snapshot - and updates the transaction update/commit path to use it. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Convert io paths for snapshotsKent Overstreet
This plumbs around the subvolume ID as was done previously for other filesystem code, but now for the IO paths - the control flow in the IO paths is trickier so the changes in this patch are more involved. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Update fsck for snapshotsKent Overstreet
This updates the fsck algorithms to handle snapshots - meaning there will be multiple versions of the same key (extents, inodes, dirents, xattrs) in different snapshots, and we have to carefully consider which keys are visible in which snapshot. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Plumb through subvolume idKent Overstreet
To implement snapshots, we need every filesystem btree operation (every btree operation without a subvolume) to start by looking up the subvolume and getting the current snapshot ID, with bch2_subvolume_get_snapshot() - then, that snapshot ID is used for doing btree lookups in BTREE_ITER_FILTER_SNAPSHOTS mode. This patch adds those bch2_subvolume_get_snapshot() calls, and also switches to passing around a subvol_inum instead of just an inode number. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: BTREE_ITER_FILTER_SNAPSHOTSKent Overstreet
For snapshots, we need to implement btree lookups that return the first key that's an ancestor of the snapshot ID the lookup is being done in - and filter out keys in unrelated snapshots. This patch adds the btree iterator flag BTREE_ITER_FILTER_SNAPSHOTS which does that filtering. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add subvolume to ei_inode_infoKent Overstreet
Filesystem operations generally operate within a subvolume: at the start of every btree transaction we'll be looking up (and locking) the subvolume to get the current snapshot ID, which we then use for our other btree lookups in BTREE_ITER_FILTER_SNAPSHOTS mode. But inodes don't record what subvolume they're in - they can't, because if they did we'd have to update every single inode within a subvolume when taking a snapshot in order to keep that field up to date. So it needs to be tracked in memory, based on how we got to that inode. Hence this patch adds a subvolume field to ei_inode_info, and switches to iget5() so we can index by it in the inode hash table. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Per subvolume lost+foundKent Overstreet
On existing filesystems, we have a single global lost+found. Introducing subvolumes means we need to introduce per subvolume lost+found directories, because inodes are added to lost+found by their inode number, and inode numbers are now only unique within a subvolume. This patch adds support to fsck for per subvolume lost+found. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add support for dirents that point to subvolumesKent Overstreet
Dirents currently always point to inodes. Subvolumes add a new type of dirent, with d_type DT_SUBVOL, that instead points to an entry in the subvolumes btree, and the subvolume has a pointer to the root inode. This patch adds bch2_dirent_read_target() to get the inode (and potentially subvolume) a dirent points to, and changes existing code to use that instead of reading from d_inum directly. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Subvolumes, snapshotsKent Overstreet
This patch adds subvolume.c - support for the subvolumes and snapshots btrees and related data types and on disk data structures. The next patches will start hooking up this new code to existing code. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Disable btree key cache for inodesKent Overstreet
Snapshots breaks using the btree key cache for inodes, for now: filling in a key cache entry does a btree lookup in FILTER_SNAPSHOTS mode, which means cached inodes at different positions (ancestor snapshots) need to be flushed for the FILTER_SNAPHSOTS lookup to work correctly - and we currently don't have a good way of doing that flush. Thus, this workaround for now. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Disable quota supportKent Overstreet
Existing quota support breaks badly with snapshots. We're not deleting the code because some of it will be needed when we reimplement quotas along the lines of btrfs subvolume quotas. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03Revert "bcachefs: Add more assertions for locking btree iterators out of order"Kent Overstreet
Figured out the bug we were chasing, and it had nothing to do with locking btree iterators/paths out of order. This reverts commit ff08733dd298c969aec7c7828095458f73fd5374. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Improve btree_node_mem_ptr optimizationKent Overstreet
This patch checks b->hash_val before attempting to lock the node in the btree, which makes it more equivalent to the "lookup in hash table" path - and potentially avoids an unnecessary transaction restart if btree_node_mem_ptr(k) no longer points to the node we want. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add a missing bch2_trans_relock() callKent Overstreet
This was causing an assertion to pop in fsck, in one of the repair paths. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Fix some compiler warningsKent Overstreet
gcc couldn't always deduce that written wasn't used uninitialized Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add missing BTREE_ITER_INTENTKent Overstreet
No reason not to be using it here... Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Better approach to write vs. read lock deadlocksKent Overstreet
Instead of unconditionally upgrading read locks to intent locks in do_bch2_trans_commit(), this patch changes the path that takes write locks to first trylock, and then if trylock fails check if we have a conflicting read lock, and restart the transaction if necessary. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: normalize_read_intent_locksKent Overstreet
This is a new approach to avoiding the self deadlock we'd get if we tried to take a write lock on a node while holding a read lock - we simply upgrade the readers to intent. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Consolidate intent lock code in btree_path_up_until_good_nodeKent Overstreet
We need to take all needed intent locks when relocking an iterator: bch2_btree_path_traverse() had a special cased, faster version of this, but it really should be in up_until_good_node() so that set_pos() can use it too. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Make trans_for_each_path_inorder() fasterKent Overstreet
Again, getting rid of data dependencies. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Inline array of sorted paths in btree_transKent Overstreet
It's small, and frequently used - this gets rid of a data dependency load. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Optimize btree lookups in write pathKent Overstreet
This patch significantly reduces the number of btree lookups required in the extent update path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add a missing btree_path_make_mut() callKent Overstreet
Also add another small helper, btree_path_clone(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Enabled shard_inode_numbers by defaultKent Overstreet
We'd like performance increasing options to be on by default. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: No need to clone iterators for updateKent Overstreet
Since btree_path is now internally refcounted, we don't need to clone an iterator before calling bch2_trans_update() if we'll be mutating it. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Kill retry loop in btree merge pathKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Drop some fast path tracepointsKent Overstreet
These haven't turned out to be useful Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add more assertions for locking btree iterators out of orderKent Overstreet
btree_path_traverse_all() traverses btree iterators in sorted order, and thus shouldn't see transaction restarts due to potential deadlocks - but sometimes we do. This patch adds some more assertions and tracks some more state to help track this down. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Tighten up btree locking invariantsKent Overstreet
New rule is: if a btree path holds any locks it should be holding precisely the locks wanted (accoringing to path->level and path->locks_want). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Extent btree iterators are no longer specialKent Overstreet
Since iter->real_pos was introduced, we no longer have to deal with extent btree iterators that have skipped past deleted keys - this is a real performance improvement on btree updates. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Fix initialization of bch_write_op.nonceKent Overstreet
If an extent ends up with a replica that is encrypted an a replica that isn't encrypted (due the user changing options), and then copygc/rebalance moves one of the replicas by reading from the unencrypted replica, we had a bug where we wouldn't correctly initialize op->nonce - for each crc field in an extent, crc.offset + crc.nonce must be equal. This patch fixes that by moving op.nonce initialization to bch2_migrate_write_init. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Improve an error messageKent Overstreet
When we detect an invalid key being inserted, we should print what code was doing the update. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Add an assertion for removing btree nodes from cacheKent Overstreet
Chasing a bug that has something to do with the btree node cache. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Kill BTREE_ITER_NODESKent Overstreet
We really only need to distinguish between btree iterators and btree key cache iterators - this is more prep work for btree_path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Kill BTREE_ITER_NEED_PEEKKent Overstreet
This was used for an optimization that hasn't existing in quite awhile - iter->uptodate will probably be going away as well. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Prefer using btree_insert_entry to btree_iterKent Overstreet
This moves some data dependencies forward, to improve pipelining. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Kill bpos_diff()Kent Overstreet
This improves the btree iterator lookup code by using trans_for_each_iter_inorder(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Btree iterators are always sortedKent Overstreet
No need to actually resort, can just replace it with an debug assert. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: More renamingKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Clean up/rename bch2_trans_node_* fnsKent Overstreet
These utility functions are for managing btree node state within a btree_trans - rename them for consistency, and drop some unneeded arguments. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2022-10-03bcachefs: Further reduce iter->trans usageKent Overstreet
This is prep work for splitting btree_path out from btree_iter - btree_path will not have a pointer to btree_trans. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>