summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-01-07bcachefs: Fix rereplicate when we already have a cached pointerbcachefs-data_update_fixKent Overstreet
When we need to add more replicas to an extent, it might be the case that we already have a replica on every device, but some of them are cached. This patch fixes a bug where we'd spin on that extent because the write path fails to find a device we can allocate from: we allow allocating from devices that already have cached replicas on them, and change bch2_data_update_index_update() to drop the cached replica if needed. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Delete a faulty assertionKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Kill bch2_extent_trim_atomic() usageKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix promote path leakKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: bch2_btree_trans_to_text(): print blocked timeKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix bch2_journal_flush_device_pins()Kent Overstreet
It's now legal for the pin fifo to be empty, which means this code needs to be updated in order to not hit an assert. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2023-01-06bcachefs: Check for lru entries with time=0Kent Overstreet
These are invalid. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Improve invalidate_one_bucket() error messagesKent Overstreet
Make sure to check for lru entries that point to buckets that don't exist as well as buckets in the wrong state, and improve the error message we print out. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix move_ctxt_wait_event()Kent Overstreet
We shouldn't be evaluating cond again if it already returned true. This fixes a bug when this helper is used for taking nocow locks. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Plumb saw_error through to btree_err()Kent Overstreet
The btree node read path has the ability to kick off an asynchronous btree node rewrite if we saw and corrected an error. Previously this was only used for errors that caused one of the replicas to be unusable - this patch plumbs it through to all error paths, so that normal fsck errors can be corrected. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Convert btree_err() to a functionKent Overstreet
This makes the code more readable, and reduces text size by 8 kb. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: fix fsck errorKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix deadlock on nocow locks in data move pathKent Overstreet
The recent nocow locking rework introduced a deadlock in the data move path: the new nocow locking scheme uses a hash table with a fixed size array for chaining, meaning on hash collision we may have to wait for other locks to be released before we can lock a bucket. And since the data move path needs to submit writes from the same thread that's taking nocow locks and submitting reads, this introduces a deadlock. This shouldn't happen often in practice, but since the data move path can keep large numbers of IOs in flight simultaneously, it's something we have to handle. This patch makes move_ctxt_wait_event() available to bch2_data_update_init() and uses it when appropriate, which is our normal solution to this kind of thing. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix some memcpy() warningsKent Overstreet
With CONFIG_FORTIFY_SOURCE, the compiler attempts to warn about mempcys that extend past struct field boundaries. This results in some spurious warnings where we use embedded variable length structs, this patch switches to unsafe_mecpy() to fix the warnings. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Add a missing bch2_err_str() callKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Bring back key cache for inodesKent Overstreet
The btree key cache now works for snapshots btrees, where doing a lookup requires searching through keys in older snapshots - we can finaly re-enable it for inodes. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Key cache now works for snapshots btreesKent Overstreet
This switches btree_key_cache_fill() to use a btree iterator, not a btree path, so that it can search for keys in previous snapshots. We also add another iterator flag, BTREE_ITER_KEY_CACHE_FILL, to avoid recursion back into the key cache. This will allow us to re-enable the key cache for inodes in the next patch. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Bring back BTREE_ITER_CACHED_NOFILLKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Kill __btree_trans_peek_key_cache()Kent Overstreet
There was no reason for this to be a separate helper - we always want the relock call that btree_trans_peek_key_cache() did. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: bch2_btree_path_peek_slot_exact()Kent Overstreet
When we start using the key cache for inodes again, it'll be possible for bch2_btree_path_peek_slot() to return a key in a different snapshot with a key cache path. This isn't what we want when triggers are checking what they're overwriting, so introduce a new helper for the commit path. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix __btree_trans_peek_key_cache()Kent Overstreet
We were returning a pointer to a variable on the stack - oops. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: BKEY_INVALID_FROM_JOURNALKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Change bkey_invalid() rw param to flagsKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Be less restrictive when validating journal overwrite entriesKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Make log message at startup a bit cleanerKent Overstreet
Don't print out opts= if no options have been specified. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Rework lru btreeKent Overstreet
This patch changes how the LRU index works: Instead of using KEY_TYPE_lru where the bucket the lru entry points to is part of the value, this switches to KEY_TYPE_set and encoding the bucket we refer to in the low bits of the key. This means that we no longer have to check for collisions when inserting LRU entries. We'll be making using of this in the next patch, which adds a btree write buffer - a pure write buffer for btree updates, where updates are appended to a simple array and then periodically sorted and batch inserted. This is a new on disk format version, and a forced upgrade. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix bch_alloc_to_text()Kent Overstreet
We weren't guarding against the alloc key having an invalid data type. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix alloc_v4_backpointers()Kent Overstreet
BCH_ALLOC_V4_BACKPOINTERS_START() may be unset on older filesystems, and alloc_v4_backpointers() needs to take this into account - because it wasn't, __bch2_alloc_to_v4_mut() was zeroing out all fields, instead of only new ones. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Improved nocow lockingKent Overstreet
This improves the nocow lock table so that hash table entries have multiple locks, and locks specify which bucket they're for - i.e. we can now resolve hash collisions. This is important because the allocator has to skip buckets that are locked in the nocow lock table, and previously hash collisions would cause it to spuriously skip unlocked buckets. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix for long running btree transactions & key cacheKent Overstreet
While a btree transaction is running, we hold a SRCU read lock on the btree key cache that prevents btree key cache keys from being freed - this is so that relock() operations won't access freed memory. The downside of this is that long running btree transactions prevent memory from being freed from the key cache. This adds a check in bch2_trans_begin() - if the transaction has been running longer than 1 second, drop and retake the SRCU read lock and zero out pointers to unlock key cache paths. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Recover from blacklisted journal entriesKent Overstreet
If it so happens that we crash while dirty, meaning we don't have the superblock clean section, and we erroneously mark a journal entry we wrote as blacklisted, we won't be able to recover. This patch fixes this by adding a fallback: if we've got no superblock clean section, and no non-ignored journal entries, we try the most recent ignored journal entry. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Log more messages in the journalKent Overstreet
This patch - Adds a mechanism for queuing up journal entries prior to the journal being started, which will be used for early journal log messages - Adds bch2_fs_log_msg() and improves bch2_trans_log_msg(), which now take format strings. bch2_fs_log_msg() can be used before or after the journal has been started, and will use the appropriate mechanism. - Deletes the now obsolete bch2_journal_log_msg() - And adds more log messages to the recovery path - messages for journal/filesystem started, journal entries being blacklisted, and journal replay starting/finishing. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Use bch2_trans_kmalloc_nomemzero in bch2_bkey_allocKent Overstreet
We're using bkey_init() which already does the memset(), no need to do it twice. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Suppress expected -EROFS error messagesKent Overstreet
These errors are expected during the shutdown process, and shouldn't be printed. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Go RW before check_alloc_info()Kent Overstreet
It's possible to do btree updates before going RW by adding them to the list of updates for journal replay to do, but this is limited by what fits in RAM. This patch switches the second alloc info phase to run after going RW - btree_gc has already ensured the alloc btree itself is correct - and tweaks the allocation path to deal with the potential small inconsistencies. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix btree_gc when multiple passes requiredKent Overstreet
We weren't resetting filesystem & device usage when restarting gc, which was spotted when free bucket counters overflowed - whoops. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Convert EAGAIN errors to private error codesKent Overstreet
More error code cleanup, for better error messages and debugability. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Convert EROFS errors to private error codesKent Overstreet
More error code improvements - this gets us more useful error messages. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix error path in bch2_trans_commit_write_locked()Kent Overstreet
Previously, we were journalling extra_journal_entries (which is used for new btree roots, and irreversably mutates system state) before calling bch2_trans_fs_usage_apply(), which can fail - whoops. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: handle failed data_update_init cleanupDaniel Hill
data_update_init allocates several resources, but we forget to clean these up when it fails. Signed-off-by: Daniel Hill <daniel@gluo.nz>
2023-01-06bcachefs: expose nocow_lock table in sysfsDaniel Hill
Signed-off-by: Daniel Hill <daniel@gluo.nz>
2023-01-06bcachefs: add skipped_nocow to bucket_alloc_fail tracepointDaniel Hill
Signed-off-by: Daniel Hill <daniel@gluo.nz>
2023-01-06bcachefs: Add a tracepoint for evacuate_bucketKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Add a missing bch2_btree_path_traverse() callKent Overstreet
bch2_btree_iter_peek_upto() in snapshots mode may need to keep a btree_path for the insert position, not just the position of the key we're returning. The code was incorrectly assuming this would be in the same btree node - we were missing a bch2_btree_path_traverse() call. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix bch2_journal_keys_peek_upto()Kent Overstreet
bch2_journal_keys_peek_upto() was comparing against btree_id & level incorrectly - fix this by using __journal_key_cmp(). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Kill btree_insert_ret enumKent Overstreet
Replace with standard bcachefs-private error codes. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix alloc key compat codeKent Overstreet
The format for bch_alloc_v4 allows for adding new fields, but bch2_alloc_to_v4_mut() was buggy - it was allocating a buffer sized based on the current key, not including new fields being added. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Trivial backpointers cleanup & fixesKent Overstreet
- Fix rare error path memory leaks - Use new bch2_bkey_alloc() helper Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Fix compat path for old inode formatsKent Overstreet
Old inode formats don't have all the fields of the current inode format: when unpacking inodes in the current format we can thus skip zeroing out the destination buffer, but that doesn't work on for the old formats. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-06bcachefs: Allow for more btreesKent Overstreet
Expand some bitfields so we can keep adding more btrees. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>