aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-10-22bcachefs: for_each_btree_node() now returns errors directlyGravatar Kent Overstreet 8-21/+39
This changes for_each_btree_node() to work like for_each_btree_key(), and to that end bch2_btree_iter_peek_node() and next_node() also return error ptrs. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Improve reflink repair codeGravatar Kent Overstreet 2-10/+43
When a reflink pointer points to an indirect extent that doesn't exist, we need to replace it with a KEY_TYPE_error key. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix check_path() across subvolumesGravatar Kent Overstreet 1-2/+22
Checking of directory structure across subvolumes was broken - we need to look up the snapshot ID of the parent subvolume when crossing subvol boundaries. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix a cache coherency bug in bch2_subvolume_create()Gravatar Kent Overstreet 1-2/+9
Subvolume deletion doesn't flush & evict the btree key cache - ideally it would, but that's tricky, so instead bch2_subvolume_create() needs to make sure the slot doesn't exist in the key cache to avoid triggering assertions. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix compiler warningsGravatar Brett Holman 2-2/+2
Type size_t is architecture-specific. Fix warnings for some non-amd64 arches. Signed-off-by: Brett Holman <bholman.devel@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-22bcachefs: Zero out reflink_p val in bch2_make_extent_indirect()Gravatar Kent Overstreet 1-0/+6
This bug was only discovered when we started using the 2nd word in the val, which should have been zeroed out as those fields had never been used before - ouch. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix __bch2_dirent_read_target()Gravatar Kent Overstreet 1-3/+1
We were shadowing our exist status, oops Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Improve bch2_dump_trans_paths_updates()Gravatar Kent Overstreet 1-6/+11
Also print the key beyng overwritten for each update. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Don't allocate too-big biosGravatar Kent Overstreet 1-0/+2
This fixes a null ptr deref in bio_alloc_bioset() -> biovec_slab() Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix implementation of KEY_TYPE_errorGravatar Kent Overstreet 4-33/+74
When force-removing a device, we were silently dropping extents that we no longer had pointers for - we should have been switching them to KEY_TYPE_error, so that reads for data that was lost return errors. This patch adds the logic for switching a key to KEY_TYPE_error to bch2_bkey_drop_ptr(), and improves the logic somewhat. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix deletion in __bch2_dev_usrdata_drop()Gravatar Kent Overstreet 1-0/+9
With snapshots, __bch2_dev_usr_data_drop() now uses an ALL_SNAPSHOTS iterator, which isn't an extent iterator - meaning we shouldn't be inserting whiteouts with nonzero size to delete. This fixes a bug where we go RO because we tried to insert an invalid key in the device remove path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Add a valgrind memcheck hintGravatar Brett Holman 1-0/+7
Prevent false positives in bch2_varint_decode_fast() Signed-off-by: Brett Holman <bholman.devel@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-22bcachefs: Fix rereplicate_pred()Gravatar Kent Overstreet 1-10/+3
It was switching off of the key type incorrectly - this code must've been quite old, and not rereplicating anything that wasn't a btree_ptr_v1 or a plain old extent. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Snapshot deletion fixGravatar Kent Overstreet 1-7/+23
When we delete a snapshot, we unlink the inode but we don't want to run the inode_rm path - the unlink path deletes the subvolume directly, which does everything we need. Also allowing the inode_rm path to run was getting us "missing subvolume" errors. There's still another bug with snapshot deletion: we need to make snapshot deletion a multi stage process, where we unlink the root dentry, then tear down the page cache, then delete the snapshot. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix a pcpu var splatGravatar Kent Overstreet 1-1/+6
this_cpu_ptr() emits a warning when used without preemption disabled - harmless in this case, as we have other locking where bch2_acc_percpu_u64s() is used. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix bch2_move_btree()Gravatar Kent Overstreet 1-3/+6
bch2_trans_begin() is now required for transaction restarts. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fixes for usrdata/metadata drop pathsGravatar Kent Overstreet 1-9/+12
These paths weren't updated for btree_path and snapshots - a couple of minor fixes. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: More btree iterator fixesGravatar Kent Overstreet 2-4/+24
- check for getting to the end of the btree in bch2_path_verify_locks and __btree_path_traverse_all(), this fixes an infinite loop in __btree_path_traverse_all(). - relax requirement in bch2_btree_node_upgrade() that we must want an intent lock, this fixes bugs with paths that point to interior nodes (nonzero level). - bch2_btree_node_update_key(): fix it to upgrade the path to an intent lock, if necessary Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Ensure btree_path consistent with node iteratorsGravatar Kent Overstreet 1-1/+10
Btree node iterators want the interior btree_path to point to the same pos as the returned btree node - this fixes a regression from the introduction of btree_path, where rewriting/updating keys of btree nodes (e.g. in bch2_dev_metadata_drop()) via btree node iterators. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix bch2_dev_remove_alloc()Gravatar Kent Overstreet 1-3/+6
It was missing a lockrestart_do(), to call bch2_trans_begin() and also handle transaction restarts. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: bch2_subvolume_get()Gravatar Kent Overstreet 5-92/+41
Factor out a little helper. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix allocator shutdown error messageGravatar Kent Overstreet 1-2/+2
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>
2023-10-22bcachefs: Fix a spurious fsck errorGravatar Kent Overstreet 1-16/+33
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>
2023-10-22bcachefs: Fix check_inode_update_hardlinks()Gravatar Kent Overstreet 1-5/+1
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>
2023-10-22bcachefs: Rev the on disk format version for snapshotsGravatar Kent Overstreet 2-14/+10
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>
2023-10-22bcachefs: Fix an assertionGravatar Kent Overstreet 1-1/+2
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>
2023-10-22bcachefs: Snapshot creation, deletionGravatar Kent Overstreet 10-69/+348
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>
2023-10-22bcachefs: Require snapshot id to be setGravatar Kent Overstreet 2-13/+9
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>
2023-10-22bcachefs: Fix unit & perf tests for snapshotsGravatar Kent Overstreet 1-29/+32
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>
2023-10-22bcachefs: Update data move path for snapshotsGravatar Kent Overstreet 6-49/+195
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>
2023-10-22bcachefs: Whiteouts for snapshotsGravatar Kent Overstreet 4-18/+127
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>
2023-10-22bcachefs: Convert io paths for snapshotsGravatar Kent Overstreet 5-93/+144
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>
2023-10-22bcachefs: Update fsck for snapshotsGravatar Kent Overstreet 3-323/+1004
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>
2023-10-22bcachefs: Plumb through subvolume idGravatar Kent Overstreet 23-256/+526
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>
2023-10-22bcachefs: BTREE_ITER_FILTER_SNAPSHOTSGravatar Kent Overstreet 4-15/+166
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>
2023-10-22bcachefs: Add subvolume to ei_inode_infoGravatar Kent Overstreet 3-27/+76
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>
2023-10-22bcachefs: Per subvolume lost+foundGravatar Kent Overstreet 1-10/+84
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>
2023-10-22bcachefs: Add support for dirents that point to subvolumesGravatar Kent Overstreet 4-28/+123
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>
2023-10-22bcachefs: Subvolumes, snapshotsGravatar Kent Overstreet 17-24/+1314
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>
2023-10-22bcachefs: Disable quota supportGravatar Kent Overstreet 1-6/+6
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>
2023-10-22Revert "bcachefs: Add more assertions for locking btree iterators out of order"Gravatar Kent Overstreet 4-32/+10
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>
2023-10-22bcachefs: Improve btree_node_mem_ptr optimizationGravatar Kent Overstreet 1-1/+6
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>
2023-10-22bcachefs: Add a missing bch2_trans_relock() callGravatar Kent Overstreet 1-0/+3
This was causing an assertion to pop in fsck, in one of the repair paths. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Fix some compiler warningsGravatar Kent Overstreet 1-1/+1
gcc couldn't always deduce that written wasn't used uninitialized Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Add missing BTREE_ITER_INTENTGravatar Kent Overstreet 1-1/+1
No reason not to be using it here... Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Better approach to write vs. read lock deadlocksGravatar Kent Overstreet 2-41/+82
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>
2023-10-22bcachefs: normalize_read_intent_locksGravatar Kent Overstreet 1-12/+61
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>
2023-10-22bcachefs: Consolidate intent lock code in btree_path_up_until_good_nodeGravatar Kent Overstreet 1-16/+13
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>
2023-10-22bcachefs: Optimize btree lookups in write pathGravatar Kent Overstreet 4-2/+26
This patch significantly reduces the number of btree lookups required in the extent update path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-10-22bcachefs: Add a missing btree_path_make_mut() callGravatar Kent Overstreet 1-6/+14
Also add another small helper, btree_path_clone(). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>