2017-03-17 06:18:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include "bcachefs.h"
|
2018-10-06 04:46:55 +00:00
|
|
|
#include "alloc_background.h"
|
2024-03-24 00:07:46 +00:00
|
|
|
#include "bkey_buf.h"
|
2023-08-05 20:08:44 +00:00
|
|
|
#include "btree_journal_iter.h"
|
2024-03-12 03:11:46 +00:00
|
|
|
#include "btree_node_scan.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "btree_update.h"
|
|
|
|
#include "btree_update_interior.h"
|
|
|
|
#include "btree_io.h"
|
2019-01-25 01:25:40 +00:00
|
|
|
#include "buckets.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "dirent.h"
|
2023-12-28 01:59:01 +00:00
|
|
|
#include "disk_accounting.h"
|
2022-07-18 23:42:58 +00:00
|
|
|
#include "errcode.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "error.h"
|
2019-10-02 22:35:36 +00:00
|
|
|
#include "fs-common.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "journal_io.h"
|
2019-04-12 02:39:39 +00:00
|
|
|
#include "journal_reclaim.h"
|
2019-04-05 01:53:12 +00:00
|
|
|
#include "journal_seq_blacklist.h"
|
2023-08-27 22:27:41 +00:00
|
|
|
#include "logged_ops.h"
|
2021-03-22 22:39:16 +00:00
|
|
|
#include "move.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "quota.h"
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
#include "rebalance.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "recovery.h"
|
2024-03-24 00:07:46 +00:00
|
|
|
#include "recovery_passes.h"
|
2019-01-25 00:09:49 +00:00
|
|
|
#include "replicas.h"
|
2023-08-05 19:54:38 +00:00
|
|
|
#include "sb-clean.h"
|
2023-12-29 20:25:07 +00:00
|
|
|
#include "sb-downgrade.h"
|
2023-08-16 20:54:33 +00:00
|
|
|
#include "snapshot.h"
|
2017-03-17 06:18:50 +00:00
|
|
|
#include "super-io.h"
|
|
|
|
|
2019-04-12 02:39:39 +00:00
|
|
|
#include <linux/sort.h>
|
2017-03-17 06:18:50 +00:00
|
|
|
#include <linux/stat.h>
|
|
|
|
|
|
|
|
#define QSTR(n) { { { .len = strlen(n) } }, .name = n }
|
|
|
|
|
2024-03-16 03:03:42 +00:00
|
|
|
void bch2_btree_lost_data(struct bch_fs *c, enum btree_id btree)
|
|
|
|
{
|
2024-05-19 21:08:15 +00:00
|
|
|
if (btree >= BTREE_ID_NR_MAX)
|
|
|
|
return;
|
|
|
|
|
2024-03-16 03:03:42 +00:00
|
|
|
u64 b = BIT_ULL(btree);
|
|
|
|
|
|
|
|
if (!(c->sb.btrees_lost_data & b)) {
|
|
|
|
bch_err(c, "flagging btree %s lost data", bch2_btree_id_str(btree));
|
|
|
|
|
|
|
|
mutex_lock(&c->sb_lock);
|
|
|
|
bch2_sb_field_get(c->disk_sb.sb, ext)->btrees_lost_data |= cpu_to_le64(b);
|
|
|
|
bch2_write_super(c);
|
|
|
|
mutex_unlock(&c->sb_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 01:20:16 +00:00
|
|
|
/* for -o reconstruct_alloc: */
|
2024-03-19 22:56:26 +00:00
|
|
|
static void bch2_reconstruct_alloc(struct bch_fs *c)
|
2020-10-25 01:20:16 +00:00
|
|
|
{
|
2024-03-12 01:15:26 +00:00
|
|
|
bch2_journal_log_msg(c, "dropping alloc info");
|
|
|
|
bch_info(c, "dropping and reconstructing all alloc info");
|
|
|
|
|
|
|
|
mutex_lock(&c->sb_lock);
|
|
|
|
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
|
|
|
|
|
|
|
|
__set_bit_le64(BCH_RECOVERY_PASS_STABLE_check_allocations, ext->recovery_passes_required);
|
|
|
|
__set_bit_le64(BCH_RECOVERY_PASS_STABLE_check_alloc_info, ext->recovery_passes_required);
|
|
|
|
__set_bit_le64(BCH_RECOVERY_PASS_STABLE_check_lrus, ext->recovery_passes_required);
|
|
|
|
__set_bit_le64(BCH_RECOVERY_PASS_STABLE_check_extents_to_backpointers, ext->recovery_passes_required);
|
|
|
|
__set_bit_le64(BCH_RECOVERY_PASS_STABLE_check_alloc_to_lru_refs, ext->recovery_passes_required);
|
|
|
|
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_ptr_to_missing_alloc_key, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_ptr_gen_newer_than_bucket_gen, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_stale_dirty_ptr, ext->errors_silent);
|
2024-04-07 21:05:01 +00:00
|
|
|
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_dev_usage_buckets_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_dev_usage_sectors_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_dev_usage_fragmented_wrong, ext->errors_silent);
|
|
|
|
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_fs_usage_btree_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_fs_usage_cached_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_fs_usage_persistent_reserved_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_fs_usage_replicas_wrong, ext->errors_silent);
|
|
|
|
|
2024-03-12 01:15:26 +00:00
|
|
|
__set_bit_le64(BCH_FSCK_ERR_alloc_key_data_type_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_alloc_key_gen_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_alloc_key_dirty_sectors_wrong, ext->errors_silent);
|
2024-04-07 21:05:01 +00:00
|
|
|
__set_bit_le64(BCH_FSCK_ERR_alloc_key_cached_sectors_wrong, ext->errors_silent);
|
2024-03-12 01:15:26 +00:00
|
|
|
__set_bit_le64(BCH_FSCK_ERR_alloc_key_stripe_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_alloc_key_stripe_redundancy_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_need_discard_key_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_freespace_key_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_bucket_gens_key_wrong, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_freespace_hole_missing, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_ptr_to_missing_backpointer, ext->errors_silent);
|
|
|
|
__set_bit_le64(BCH_FSCK_ERR_lru_entry_bad, ext->errors_silent);
|
2023-12-27 23:31:46 +00:00
|
|
|
__set_bit_le64(BCH_FSCK_ERR_accounting_mismatch, ext->errors_silent);
|
2024-03-12 01:15:26 +00:00
|
|
|
c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
|
|
|
|
|
2024-09-02 02:39:42 +00:00
|
|
|
c->opts.recovery_passes |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
|
2024-03-12 01:15:26 +00:00
|
|
|
|
2024-10-25 17:13:05 +00:00
|
|
|
bch2_write_super(c);
|
|
|
|
mutex_unlock(&c->sb_lock);
|
2024-03-17 01:22:47 +00:00
|
|
|
|
2024-03-19 22:56:26 +00:00
|
|
|
bch2_shoot_down_journal_keys(c, BTREE_ID_alloc,
|
|
|
|
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
|
|
|
|
bch2_shoot_down_journal_keys(c, BTREE_ID_backpointers,
|
|
|
|
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
|
|
|
|
bch2_shoot_down_journal_keys(c, BTREE_ID_need_discard,
|
|
|
|
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
|
|
|
|
bch2_shoot_down_journal_keys(c, BTREE_ID_freespace,
|
|
|
|
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
|
|
|
|
bch2_shoot_down_journal_keys(c, BTREE_ID_bucket_gens,
|
|
|
|
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
|
2020-10-25 01:20:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 18:33:06 +00:00
|
|
|
/*
|
|
|
|
* Btree node pointers have a field to stack a pointer to the in memory btree
|
|
|
|
* node; we need to zero out this field when reading in btree nodes, or when
|
|
|
|
* reading in keys from the journal:
|
|
|
|
*/
|
|
|
|
static void zero_out_btree_mem_ptr(struct journal_keys *keys)
|
|
|
|
{
|
2024-02-24 05:19:09 +00:00
|
|
|
darray_for_each(*keys, i)
|
2021-07-30 18:33:06 +00:00
|
|
|
if (i->k->k.type == KEY_TYPE_btree_ptr_v2)
|
|
|
|
bkey_i_to_btree_ptr_v2(i->k)->v.mem_ptr = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-12 02:39:39 +00:00
|
|
|
/* journal replay: */
|
|
|
|
|
|
|
|
static void replay_now_at(struct journal *j, u64 seq)
|
|
|
|
{
|
|
|
|
BUG_ON(seq < j->replay_journal_seq);
|
2022-04-12 05:31:33 +00:00
|
|
|
|
|
|
|
seq = min(seq, j->replay_journal_seq_end);
|
2019-04-12 02:39:39 +00:00
|
|
|
|
|
|
|
while (j->replay_journal_seq < seq)
|
|
|
|
bch2_journal_pin_put(j, j->replay_journal_seq++);
|
|
|
|
}
|
|
|
|
|
2023-12-28 01:59:01 +00:00
|
|
|
static int bch2_journal_replay_accounting_key(struct btree_trans *trans,
|
|
|
|
struct journal_key *k)
|
|
|
|
{
|
|
|
|
struct btree_iter iter;
|
|
|
|
bch2_trans_node_iter_init(trans, &iter, k->btree_id, k->k->k.p,
|
|
|
|
BTREE_MAX_DEPTH, k->level,
|
|
|
|
BTREE_ITER_intent);
|
|
|
|
int ret = bch2_btree_iter_traverse(&iter);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
struct bkey u;
|
|
|
|
struct bkey_s_c old = bch2_btree_path_peek_slot(btree_iter_path(trans, &iter), &u);
|
|
|
|
|
|
|
|
/* Has this delta already been applied to the btree? */
|
2024-09-26 19:49:17 +00:00
|
|
|
if (bversion_cmp(old.k->bversion, k->k->k.bversion) >= 0) {
|
2023-12-28 01:59:01 +00:00
|
|
|
ret = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bkey_i *new = k->k;
|
|
|
|
if (old.k->type == KEY_TYPE_accounting) {
|
|
|
|
new = bch2_bkey_make_mut_noupdate(trans, bkey_i_to_s_c(k->k));
|
|
|
|
ret = PTR_ERR_OR_ZERO(new);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
bch2_accounting_accumulate(bkey_i_to_accounting(new),
|
|
|
|
bkey_s_c_to_accounting(old));
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->journal_res.seq = k->journal_seq;
|
|
|
|
|
|
|
|
ret = bch2_trans_update(trans, &iter, new, BTREE_TRIGGER_norun);
|
|
|
|
out:
|
|
|
|
bch2_trans_iter_exit(trans, &iter);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-28 04:10:06 +00:00
|
|
|
static int bch2_journal_replay_key(struct btree_trans *trans,
|
|
|
|
struct journal_key *k)
|
2019-12-31 21:17:42 +00:00
|
|
|
{
|
2021-08-30 19:18:31 +00:00
|
|
|
struct btree_iter iter;
|
2021-10-26 21:35:58 +00:00
|
|
|
unsigned iter_flags =
|
2024-04-07 22:05:34 +00:00
|
|
|
BTREE_ITER_intent|
|
|
|
|
BTREE_ITER_not_extents;
|
|
|
|
unsigned update_flags = BTREE_TRIGGER_norun;
|
2020-03-09 20:15:54 +00:00
|
|
|
int ret;
|
2019-12-31 21:17:42 +00:00
|
|
|
|
2023-11-10 02:02:58 +00:00
|
|
|
if (k->overwritten)
|
|
|
|
return 0;
|
|
|
|
|
2023-11-09 03:00:00 +00:00
|
|
|
trans->journal_res.seq = k->journal_seq;
|
|
|
|
|
2023-06-25 22:04:46 +00:00
|
|
|
/*
|
2024-04-07 22:05:34 +00:00
|
|
|
* BTREE_UPDATE_key_cache_reclaim disables key cache lookup/update to
|
2023-06-25 22:04:46 +00:00
|
|
|
* keep the key cache coherent with the underlying btree. Nothing
|
|
|
|
* besides the allocator is doing updates yet so we don't need key cache
|
|
|
|
* coherency for non-alloc btrees, and key cache fills for snapshots
|
2024-04-07 22:05:34 +00:00
|
|
|
* btrees use BTREE_ITER_filter_snapshots, which isn't available until
|
2023-06-25 22:04:46 +00:00
|
|
|
* the snapshots recovery pass runs.
|
|
|
|
*/
|
2021-10-26 21:35:58 +00:00
|
|
|
if (!k->level && k->btree_id == BTREE_ID_alloc)
|
2024-04-07 22:05:34 +00:00
|
|
|
iter_flags |= BTREE_ITER_cached;
|
2023-06-25 22:04:46 +00:00
|
|
|
else
|
2024-04-07 22:05:34 +00:00
|
|
|
update_flags |= BTREE_UPDATE_key_cache_reclaim;
|
2021-10-26 21:35:58 +00:00
|
|
|
|
|
|
|
bch2_trans_node_iter_init(trans, &iter, k->btree_id, k->k->k.p,
|
|
|
|
BTREE_MAX_DEPTH, k->level,
|
|
|
|
iter_flags);
|
2021-12-31 22:54:13 +00:00
|
|
|
ret = bch2_btree_iter_traverse(&iter);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2024-03-09 00:57:22 +00:00
|
|
|
struct btree_path *path = btree_iter_path(trans, &iter);
|
|
|
|
if (unlikely(!btree_path_node(path, k->level))) {
|
|
|
|
bch2_trans_iter_exit(trans, &iter);
|
|
|
|
bch2_trans_node_iter_init(trans, &iter, k->btree_id, k->k->k.p,
|
|
|
|
BTREE_MAX_DEPTH, 0, iter_flags);
|
|
|
|
ret = bch2_btree_iter_traverse(&iter) ?:
|
|
|
|
bch2_btree_increase_depth(trans, iter.path, 0) ?:
|
|
|
|
-BCH_ERR_transaction_restart_nested;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-12-31 22:54:13 +00:00
|
|
|
/* Must be checked with btree locked: */
|
|
|
|
if (k->overwritten)
|
|
|
|
goto out;
|
|
|
|
|
2023-12-28 01:59:01 +00:00
|
|
|
if (k->k->k.type == KEY_TYPE_accounting) {
|
|
|
|
ret = bch2_trans_update_buffered(trans, BTREE_ID_accounting, k->k);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2023-06-25 22:04:46 +00:00
|
|
|
ret = bch2_trans_update(trans, &iter, k->k, update_flags);
|
2021-12-31 22:54:13 +00:00
|
|
|
out:
|
2021-08-30 19:18:31 +00:00
|
|
|
bch2_trans_iter_exit(trans, &iter);
|
2020-03-09 20:15:54 +00:00
|
|
|
return ret;
|
2019-12-31 21:17:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 16:54:53 +00:00
|
|
|
static int journal_sort_seq_cmp(const void *_l, const void *_r)
|
|
|
|
{
|
2021-12-29 20:55:25 +00:00
|
|
|
const struct journal_key *l = *((const struct journal_key **)_l);
|
|
|
|
const struct journal_key *r = *((const struct journal_key **)_r);
|
2019-10-05 16:54:53 +00:00
|
|
|
|
2024-08-22 00:49:07 +00:00
|
|
|
/*
|
|
|
|
* Map 0 to U64_MAX, so that keys with journal_seq === 0 come last
|
|
|
|
*
|
|
|
|
* journal_seq == 0 means that the key comes from early repair, and
|
|
|
|
* should be inserted last so as to avoid overflowing the journal
|
|
|
|
*/
|
|
|
|
return cmp_int(l->journal_seq - 1, r->journal_seq - 1);
|
2019-10-05 16:54:53 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 00:07:46 +00:00
|
|
|
int bch2_journal_replay(struct bch_fs *c)
|
2019-04-12 02:39:39 +00:00
|
|
|
{
|
2021-12-29 20:55:25 +00:00
|
|
|
struct journal_keys *keys = &c->journal_keys;
|
2023-11-10 02:02:58 +00:00
|
|
|
DARRAY(struct journal_key *) keys_sorted = { 0 };
|
2019-04-12 02:39:39 +00:00
|
|
|
struct journal *j = &c->journal;
|
2023-07-09 02:33:29 +00:00
|
|
|
u64 start_seq = c->journal_replay_seq_start;
|
|
|
|
u64 end_seq = c->journal_replay_seq_start;
|
2024-04-10 03:23:08 +00:00
|
|
|
struct btree_trans *trans = NULL;
|
2024-03-28 06:36:10 +00:00
|
|
|
bool immediate_flush = false;
|
2023-12-10 17:21:42 +00:00
|
|
|
int ret = 0;
|
2021-12-29 20:55:25 +00:00
|
|
|
|
2022-12-14 15:39:04 +00:00
|
|
|
if (keys->nr) {
|
2023-03-22 12:27:58 +00:00
|
|
|
ret = bch2_journal_log_msg(c, "Starting journal replay (%zu keys in entries %llu-%llu)",
|
|
|
|
keys->nr, start_seq, end_seq);
|
2022-12-14 15:39:04 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2023-11-18 04:13:49 +00:00
|
|
|
BUG_ON(!atomic_read(&keys->ref));
|
|
|
|
|
2024-03-17 01:22:47 +00:00
|
|
|
move_gap(keys, keys->nr);
|
2024-04-10 03:23:08 +00:00
|
|
|
trans = bch2_trans_get(c);
|
2024-03-17 01:22:47 +00:00
|
|
|
|
2023-12-28 01:59:01 +00:00
|
|
|
/*
|
|
|
|
* Replay accounting keys first: we can't allow the write buffer to
|
|
|
|
* flush accounting keys until we're done
|
|
|
|
*/
|
|
|
|
darray_for_each(*keys, k) {
|
|
|
|
if (!(k->k->k.type == KEY_TYPE_accounting && !k->allocated))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cond_resched();
|
|
|
|
|
|
|
|
ret = commit_do(trans, NULL, NULL,
|
|
|
|
BCH_TRANS_COMMIT_no_enospc|
|
|
|
|
BCH_TRANS_COMMIT_journal_reclaim|
|
2023-11-09 19:22:46 +00:00
|
|
|
BCH_TRANS_COMMIT_skip_accounting_apply|
|
2024-10-12 06:44:38 +00:00
|
|
|
BCH_TRANS_COMMIT_no_journal_res|
|
|
|
|
BCH_WATERMARK_reclaim,
|
2023-12-28 01:59:01 +00:00
|
|
|
bch2_journal_replay_accounting_key(trans, k));
|
|
|
|
if (bch2_fs_fatal_err_on(ret, c, "error replaying accounting; %s", bch2_err_str(ret)))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
k->overwritten = true;
|
|
|
|
}
|
|
|
|
|
2023-11-17 05:23:07 +00:00
|
|
|
set_bit(BCH_FS_accounting_replay_done, &c->flags);
|
|
|
|
|
2023-11-10 02:02:58 +00:00
|
|
|
/*
|
|
|
|
* First, attempt to replay keys in sorted order. This is more
|
|
|
|
* efficient - better locality of btree access - but some might fail if
|
|
|
|
* that would cause a journal deadlock.
|
|
|
|
*/
|
2024-02-24 05:19:09 +00:00
|
|
|
darray_for_each(*keys, k) {
|
2023-11-10 02:02:58 +00:00
|
|
|
cond_resched();
|
|
|
|
|
2024-03-28 06:36:10 +00:00
|
|
|
/*
|
|
|
|
* k->allocated means the key wasn't read in from the journal,
|
|
|
|
* rather it was from early repair code
|
|
|
|
*/
|
|
|
|
if (k->allocated)
|
|
|
|
immediate_flush = true;
|
|
|
|
|
2023-11-10 02:02:58 +00:00
|
|
|
/* Skip fastpath if we're low on space in the journal */
|
|
|
|
ret = c->journal.watermark ? -1 :
|
|
|
|
commit_do(trans, NULL, NULL,
|
2023-11-11 21:31:50 +00:00
|
|
|
BCH_TRANS_COMMIT_no_enospc|
|
|
|
|
BCH_TRANS_COMMIT_journal_reclaim|
|
2023-11-09 19:22:46 +00:00
|
|
|
BCH_TRANS_COMMIT_skip_accounting_apply|
|
2023-11-11 21:31:50 +00:00
|
|
|
(!k->allocated ? BCH_TRANS_COMMIT_no_journal_res : 0),
|
2023-11-10 02:02:58 +00:00
|
|
|
bch2_journal_replay_key(trans, k));
|
2023-12-28 01:59:01 +00:00
|
|
|
BUG_ON(!ret && !k->overwritten && k->k->k.type != KEY_TYPE_accounting);
|
2023-11-10 02:02:58 +00:00
|
|
|
if (ret) {
|
|
|
|
ret = darray_push(&keys_sorted, k);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2021-12-29 20:55:25 +00:00
|
|
|
|
2024-08-20 16:10:33 +00:00
|
|
|
bch2_trans_unlock_long(trans);
|
2023-11-10 02:02:58 +00:00
|
|
|
/*
|
|
|
|
* Now, replay any remaining keys in the order in which they appear in
|
|
|
|
* the journal, unpinning those journal entries as we go:
|
|
|
|
*/
|
|
|
|
sort(keys_sorted.data, keys_sorted.nr,
|
|
|
|
sizeof(keys_sorted.data[0]),
|
|
|
|
journal_sort_seq_cmp, NULL);
|
|
|
|
|
|
|
|
darray_for_each(keys_sorted, kp) {
|
2019-04-12 02:39:39 +00:00
|
|
|
cond_resched();
|
2019-10-05 16:54:53 +00:00
|
|
|
|
2023-11-10 02:02:58 +00:00
|
|
|
struct journal_key *k = *kp;
|
|
|
|
|
2024-04-16 03:53:12 +00:00
|
|
|
if (k->journal_seq)
|
|
|
|
replay_now_at(j, k->journal_seq);
|
|
|
|
else
|
|
|
|
replay_now_at(j, j->replay_journal_seq_end);
|
2019-10-05 16:54:53 +00:00
|
|
|
|
2023-11-10 02:02:58 +00:00
|
|
|
ret = commit_do(trans, NULL, NULL,
|
2023-11-11 21:31:50 +00:00
|
|
|
BCH_TRANS_COMMIT_no_enospc|
|
2023-11-09 19:22:46 +00:00
|
|
|
BCH_TRANS_COMMIT_skip_accounting_apply|
|
2023-11-10 02:02:58 +00:00
|
|
|
(!k->allocated
|
2023-11-11 21:31:50 +00:00
|
|
|
? BCH_TRANS_COMMIT_no_journal_res|BCH_WATERMARK_reclaim
|
2023-11-10 02:02:58 +00:00
|
|
|
: 0),
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_journal_replay_key(trans, k));
|
2023-11-10 02:02:58 +00:00
|
|
|
bch_err_msg(c, ret, "while replaying key at btree %s level %u:",
|
|
|
|
bch2_btree_id_str(k->btree_id), k->level);
|
|
|
|
if (ret)
|
2019-10-05 16:54:53 +00:00
|
|
|
goto err;
|
2023-11-10 02:02:58 +00:00
|
|
|
|
2023-12-28 01:59:01 +00:00
|
|
|
BUG_ON(k->btree_id != BTREE_ID_accounting && !k->overwritten);
|
2019-03-29 23:13:54 +00:00
|
|
|
}
|
2019-04-12 02:39:39 +00:00
|
|
|
|
2023-11-10 02:02:58 +00:00
|
|
|
/*
|
|
|
|
* We need to put our btree_trans before calling flush_all_pins(), since
|
|
|
|
* that will use a btree_trans internally
|
|
|
|
*/
|
|
|
|
bch2_trans_put(trans);
|
|
|
|
trans = NULL;
|
|
|
|
|
2024-03-12 03:11:46 +00:00
|
|
|
if (!c->opts.retain_recovery_info &&
|
2024-03-29 01:34:14 +00:00
|
|
|
c->recovery_pass_done >= BCH_RECOVERY_PASS_journal_replay)
|
2023-11-18 04:13:49 +00:00
|
|
|
bch2_journal_keys_put_initial(c);
|
|
|
|
|
2019-04-12 02:39:39 +00:00
|
|
|
replay_now_at(j, j->replay_journal_seq_end);
|
|
|
|
j->replay_journal_seq = 0;
|
|
|
|
|
|
|
|
bch2_journal_set_replay_done(j);
|
2022-03-10 19:25:16 +00:00
|
|
|
|
2024-03-28 06:36:10 +00:00
|
|
|
/* if we did any repair, flush it immediately */
|
|
|
|
if (immediate_flush) {
|
|
|
|
bch2_journal_flush_all_pins(&c->journal);
|
|
|
|
ret = bch2_journal_meta(&c->journal);
|
|
|
|
}
|
|
|
|
|
2023-11-10 04:43:35 +00:00
|
|
|
if (keys->nr)
|
2023-03-22 12:27:58 +00:00
|
|
|
bch2_journal_log_msg(c, "journal replay finished");
|
2019-10-05 16:54:53 +00:00
|
|
|
err:
|
2023-11-10 02:02:58 +00:00
|
|
|
if (trans)
|
|
|
|
bch2_trans_put(trans);
|
|
|
|
darray_exit(&keys_sorted);
|
|
|
|
bch_err_fn(c, ret);
|
2019-10-05 16:54:53 +00:00
|
|
|
return ret;
|
2019-03-29 23:13:54 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 02:39:39 +00:00
|
|
|
/* journal replay early: */
|
2019-03-29 23:13:54 +00:00
|
|
|
|
2019-01-25 00:09:49 +00:00
|
|
|
static int journal_replay_entry_early(struct bch_fs *c,
|
|
|
|
struct jset_entry *entry)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (entry->type) {
|
|
|
|
case BCH_JSET_ENTRY_btree_root: {
|
2019-06-24 22:11:35 +00:00
|
|
|
struct btree_root *r;
|
|
|
|
|
2024-06-17 13:26:54 +00:00
|
|
|
if (fsck_err_on(entry->btree_id >= BTREE_ID_NR_MAX,
|
|
|
|
c, invalid_btree_id,
|
|
|
|
"invalid btree id %u (max %u)",
|
|
|
|
entry->btree_id, BTREE_ID_NR_MAX))
|
|
|
|
return 0;
|
|
|
|
|
2023-06-29 02:09:13 +00:00
|
|
|
while (entry->btree_id >= c->btree_roots_extra.nr + BTREE_ID_NR) {
|
|
|
|
ret = darray_push(&c->btree_roots_extra, (struct btree_root) { NULL });
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-06-24 22:11:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 02:09:13 +00:00
|
|
|
r = bch2_btree_id_root(c, entry->btree_id);
|
2019-01-25 00:09:49 +00:00
|
|
|
|
|
|
|
if (entry->u64s) {
|
|
|
|
r->level = entry->level;
|
2023-10-31 22:05:22 +00:00
|
|
|
bkey_copy(&r->key, (struct bkey_i *) entry->start);
|
2019-01-25 00:09:49 +00:00
|
|
|
r->error = 0;
|
|
|
|
} else {
|
2024-02-06 22:24:18 +00:00
|
|
|
r->error = -BCH_ERR_btree_node_read_error;
|
2019-01-25 00:09:49 +00:00
|
|
|
}
|
|
|
|
r->alive = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BCH_JSET_ENTRY_usage: {
|
|
|
|
struct jset_entry_usage *u =
|
|
|
|
container_of(entry, struct jset_entry_usage, entry);
|
|
|
|
|
2019-02-10 00:20:57 +00:00
|
|
|
switch (entry->btree_id) {
|
2021-12-31 22:06:29 +00:00
|
|
|
case BCH_FS_USAGE_key_version:
|
2023-12-28 03:09:25 +00:00
|
|
|
atomic64_set(&c->key_version, le64_to_cpu(u->v));
|
2019-01-25 00:09:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-02-10 00:20:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-05 01:53:12 +00:00
|
|
|
case BCH_JSET_ENTRY_blacklist: {
|
|
|
|
struct jset_entry_blacklist *bl_entry =
|
|
|
|
container_of(entry, struct jset_entry_blacklist, entry);
|
|
|
|
|
|
|
|
ret = bch2_journal_seq_blacklist_add(c,
|
|
|
|
le64_to_cpu(bl_entry->seq),
|
|
|
|
le64_to_cpu(bl_entry->seq) + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BCH_JSET_ENTRY_blacklist_v2: {
|
|
|
|
struct jset_entry_blacklist_v2 *bl_entry =
|
|
|
|
container_of(entry, struct jset_entry_blacklist_v2, entry);
|
|
|
|
|
|
|
|
ret = bch2_journal_seq_blacklist_add(c,
|
|
|
|
le64_to_cpu(bl_entry->start),
|
|
|
|
le64_to_cpu(bl_entry->end) + 1);
|
|
|
|
break;
|
|
|
|
}
|
2021-01-21 20:28:59 +00:00
|
|
|
case BCH_JSET_ENTRY_clock: {
|
|
|
|
struct jset_entry_clock *clock =
|
|
|
|
container_of(entry, struct jset_entry_clock, entry);
|
|
|
|
|
2021-05-23 21:04:13 +00:00
|
|
|
atomic64_set(&c->io_clock[clock->rw].now, le64_to_cpu(clock->time));
|
2021-01-21 20:28:59 +00:00
|
|
|
}
|
2019-01-25 00:09:49 +00:00
|
|
|
}
|
2024-06-17 13:26:54 +00:00
|
|
|
fsck_err:
|
2019-01-25 00:09:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-05 01:53:12 +00:00
|
|
|
static int journal_replay_early(struct bch_fs *c,
|
2022-03-21 04:15:53 +00:00
|
|
|
struct bch_sb_field_clean *clean)
|
2017-03-17 06:18:50 +00:00
|
|
|
{
|
2019-03-29 23:13:54 +00:00
|
|
|
if (clean) {
|
2023-12-17 07:19:23 +00:00
|
|
|
for (struct jset_entry *entry = clean->start;
|
2019-03-29 23:13:54 +00:00
|
|
|
entry != vstruct_end(&clean->field);
|
|
|
|
entry = vstruct_next(entry)) {
|
2023-12-17 07:19:23 +00:00
|
|
|
int ret = journal_replay_entry_early(c, entry);
|
2019-03-29 23:13:54 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-21 04:15:53 +00:00
|
|
|
struct genradix_iter iter;
|
|
|
|
struct journal_replay *i, **_i;
|
|
|
|
|
|
|
|
genradix_for_each(&c->journal_entries, iter, _i) {
|
|
|
|
i = *_i;
|
|
|
|
|
2024-02-25 23:48:21 +00:00
|
|
|
if (journal_replay_ignore(i))
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
continue;
|
2019-03-29 23:13:54 +00:00
|
|
|
|
|
|
|
vstruct_for_each(&i->j, entry) {
|
2023-12-17 07:19:23 +00:00
|
|
|
int ret = journal_replay_entry_early(c, entry);
|
2019-03-29 23:13:54 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
}
|
2019-03-22 02:19:57 +00:00
|
|
|
}
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2019-03-29 23:13:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-12 02:39:39 +00:00
|
|
|
/* sb clean section: */
|
|
|
|
|
2019-03-29 23:13:54 +00:00
|
|
|
static int read_btree_roots(struct bch_fs *c)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2024-03-12 03:11:46 +00:00
|
|
|
for (unsigned i = 0; i < btree_id_nr_alive(c); i++) {
|
2023-06-29 02:09:13 +00:00
|
|
|
struct btree_root *r = bch2_btree_id_root(c, i);
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2019-03-29 23:13:54 +00:00
|
|
|
if (!r->alive)
|
|
|
|
continue;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2024-03-12 01:15:26 +00:00
|
|
|
if (btree_id_is_alloc(i) && c->opts.reconstruct_alloc)
|
2017-03-17 06:18:50 +00:00
|
|
|
continue;
|
|
|
|
|
2024-03-12 03:11:46 +00:00
|
|
|
if (mustfix_fsck_err_on((ret = r->error),
|
|
|
|
c, btree_root_bkey_invalid,
|
|
|
|
"invalid btree root %s",
|
|
|
|
bch2_btree_id_str(i)) ||
|
|
|
|
mustfix_fsck_err_on((ret = r->error = bch2_btree_root_read(c, i, &r->key, r->level)),
|
|
|
|
c, btree_root_read_error,
|
|
|
|
"error reading btree root %s l=%u: %s",
|
|
|
|
bch2_btree_id_str(i), r->level, bch2_err_str(ret))) {
|
|
|
|
if (btree_id_is_alloc(i)) {
|
2024-09-02 02:39:42 +00:00
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_allocations);
|
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_info);
|
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_lrus);
|
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_extents_to_backpointers);
|
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_to_lru_refs);
|
2021-04-05 01:57:35 +00:00
|
|
|
c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
|
2024-03-12 03:11:46 +00:00
|
|
|
r->error = 0;
|
2024-09-02 02:39:42 +00:00
|
|
|
} else if (!(c->opts.recovery_passes & BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes))) {
|
2024-03-12 03:11:46 +00:00
|
|
|
bch_info(c, "will run btree node scan");
|
2024-09-02 02:39:42 +00:00
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes);
|
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
|
2024-03-12 03:11:46 +00:00
|
|
|
}
|
2019-03-29 23:13:54 +00:00
|
|
|
|
2023-09-26 21:21:21 +00:00
|
|
|
ret = 0;
|
2024-03-16 03:03:42 +00:00
|
|
|
bch2_btree_lost_data(c, i);
|
2019-03-29 23:13:54 +00:00
|
|
|
}
|
2017-03-17 06:18:50 +00:00
|
|
|
}
|
2019-03-29 23:13:54 +00:00
|
|
|
|
2024-03-12 03:11:46 +00:00
|
|
|
for (unsigned i = 0; i < BTREE_ID_NR; i++) {
|
2023-06-29 02:09:13 +00:00
|
|
|
struct btree_root *r = bch2_btree_id_root(c, i);
|
2023-02-13 00:24:34 +00:00
|
|
|
|
2024-03-12 03:11:46 +00:00
|
|
|
if (!r->b && !r->error) {
|
2023-02-13 00:24:34 +00:00
|
|
|
r->alive = false;
|
|
|
|
r->level = 0;
|
2024-03-15 02:17:40 +00:00
|
|
|
bch2_btree_root_alloc_fake(c, i, 0);
|
2023-02-13 00:24:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-17 06:18:50 +00:00
|
|
|
fsck_err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-04 02:01:37 +00:00
|
|
|
static bool check_version_upgrade(struct bch_fs *c)
|
2023-06-28 23:59:56 +00:00
|
|
|
{
|
2023-06-28 02:09:35 +00:00
|
|
|
unsigned latest_version = bcachefs_metadata_version_current;
|
2024-02-13 01:05:48 +00:00
|
|
|
unsigned latest_compatible = min(latest_version,
|
|
|
|
bch2_latest_compatible_version(c->sb.version));
|
2023-06-28 02:09:35 +00:00
|
|
|
unsigned old_version = c->sb.version_upgrade_complete ?: c->sb.version;
|
|
|
|
unsigned new_version = 0;
|
|
|
|
|
|
|
|
if (old_version < bcachefs_metadata_required_upgrade_below) {
|
|
|
|
if (c->opts.version_upgrade == BCH_VERSION_UPGRADE_incompatible ||
|
|
|
|
latest_compatible < bcachefs_metadata_required_upgrade_below)
|
|
|
|
new_version = latest_version;
|
|
|
|
else
|
|
|
|
new_version = latest_compatible;
|
|
|
|
} else {
|
|
|
|
switch (c->opts.version_upgrade) {
|
|
|
|
case BCH_VERSION_UPGRADE_compatible:
|
|
|
|
new_version = latest_compatible;
|
|
|
|
break;
|
|
|
|
case BCH_VERSION_UPGRADE_incompatible:
|
|
|
|
new_version = latest_version;
|
|
|
|
break;
|
|
|
|
case BCH_VERSION_UPGRADE_none:
|
2024-02-13 01:05:48 +00:00
|
|
|
new_version = min(old_version, latest_version);
|
2023-06-28 02:09:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-06-28 23:59:56 +00:00
|
|
|
|
2023-06-28 02:09:35 +00:00
|
|
|
if (new_version > old_version) {
|
2023-06-28 23:59:56 +00:00
|
|
|
struct printbuf buf = PRINTBUF;
|
|
|
|
|
2023-06-28 02:09:35 +00:00
|
|
|
if (old_version < bcachefs_metadata_required_upgrade_below)
|
|
|
|
prt_str(&buf, "Version upgrade required:\n");
|
|
|
|
|
|
|
|
if (old_version != c->sb.version) {
|
|
|
|
prt_str(&buf, "Version upgrade from ");
|
|
|
|
bch2_version_to_text(&buf, c->sb.version_upgrade_complete);
|
|
|
|
prt_str(&buf, " to ");
|
2023-06-28 03:34:02 +00:00
|
|
|
bch2_version_to_text(&buf, c->sb.version);
|
2023-06-28 02:09:35 +00:00
|
|
|
prt_str(&buf, " incomplete\n");
|
2023-06-28 03:34:02 +00:00
|
|
|
}
|
2023-06-28 23:59:56 +00:00
|
|
|
|
2023-06-28 02:09:35 +00:00
|
|
|
prt_printf(&buf, "Doing %s version upgrade from ",
|
|
|
|
BCH_VERSION_MAJOR(old_version) != BCH_VERSION_MAJOR(new_version)
|
|
|
|
? "incompatible" : "compatible");
|
|
|
|
bch2_version_to_text(&buf, old_version);
|
|
|
|
prt_str(&buf, " to ");
|
|
|
|
bch2_version_to_text(&buf, new_version);
|
|
|
|
prt_newline(&buf);
|
|
|
|
|
2024-01-04 02:01:37 +00:00
|
|
|
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
|
|
|
|
__le64 passes = ext->recovery_passes_required[0];
|
|
|
|
bch2_sb_set_upgrade(c, old_version, new_version);
|
|
|
|
passes = ext->recovery_passes_required[0] & ~passes;
|
2023-06-28 23:59:56 +00:00
|
|
|
|
2024-01-04 02:01:37 +00:00
|
|
|
if (passes) {
|
|
|
|
prt_str(&buf, " running recovery passes: ");
|
|
|
|
prt_bitflags(&buf, bch2_recovery_passes,
|
|
|
|
bch2_recovery_passes_from_stable(le64_to_cpu(passes)));
|
2023-07-10 17:42:26 +00:00
|
|
|
}
|
2023-06-28 23:59:56 +00:00
|
|
|
|
2023-07-10 17:42:26 +00:00
|
|
|
bch_info(c, "%s", buf.buf);
|
2023-06-28 02:09:35 +00:00
|
|
|
|
2023-07-10 16:23:01 +00:00
|
|
|
bch2_sb_upgrade(c, new_version);
|
2023-06-28 02:09:35 +00:00
|
|
|
|
|
|
|
printbuf_exit(&buf);
|
2023-12-29 20:15:14 +00:00
|
|
|
return true;
|
2023-06-28 23:59:56 +00:00
|
|
|
}
|
2023-12-29 20:15:14 +00:00
|
|
|
|
|
|
|
return false;
|
2023-06-28 23:59:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
int bch2_fs_recovery(struct bch_fs *c)
|
|
|
|
{
|
2019-04-05 01:53:12 +00:00
|
|
|
struct bch_sb_field_clean *clean = NULL;
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
struct jset *last_journal_entry = NULL;
|
2023-09-28 04:54:12 +00:00
|
|
|
u64 last_seq = 0, blacklist_seq, journal_seq;
|
2021-04-24 22:02:59 +00:00
|
|
|
int ret = 0;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2023-08-05 19:54:38 +00:00
|
|
|
if (c->sb.clean) {
|
|
|
|
clean = bch2_read_superblock_clean(c);
|
|
|
|
ret = PTR_ERR_OR_ZERO(clean);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2019-04-05 01:53:12 +00:00
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
bch_info(c, "recovering from clean shutdown, journal seq %llu",
|
|
|
|
le64_to_cpu(clean->journal_seq));
|
2023-08-05 19:54:38 +00:00
|
|
|
} else {
|
2021-11-15 20:03:06 +00:00
|
|
|
bch_info(c, "recovering from unclean shutdown");
|
2023-08-05 19:54:38 +00:00
|
|
|
}
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2021-02-20 05:00:23 +00:00
|
|
|
if (!(c->sb.features & (1ULL << BCH_FEATURE_new_extent_overwrite))) {
|
|
|
|
bch_err(c, "feature new_extent_overwrite not set, filesystem no longer supported");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-03-21 20:20:40 +00:00
|
|
|
if (!c->sb.clean &&
|
|
|
|
!(c->sb.features & (1ULL << BCH_FEATURE_extents_above_btree_updates))) {
|
|
|
|
bch_err(c, "filesystem needs recovery from older version; run fsck from older bcachefs-tools to fix");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2024-03-29 01:34:14 +00:00
|
|
|
if (c->opts.norecovery)
|
|
|
|
c->opts.recovery_pass_last = BCH_RECOVERY_PASS_journal_replay - 1;
|
2022-04-21 17:13:57 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
mutex_lock(&c->sb_lock);
|
|
|
|
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
|
|
|
|
bool write_sb = false;
|
2023-12-29 20:15:14 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
if (BCH_SB_HAS_TOPOLOGY_ERRORS(c->disk_sb.sb)) {
|
|
|
|
ext->recovery_passes_required[0] |=
|
|
|
|
cpu_to_le64(bch2_recovery_passes_to_stable(BIT_ULL(BCH_RECOVERY_PASS_check_topology)));
|
|
|
|
write_sb = true;
|
|
|
|
}
|
2023-12-29 20:15:14 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
u64 sb_passes = bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
|
|
|
|
if (sb_passes) {
|
|
|
|
struct printbuf buf = PRINTBUF;
|
|
|
|
prt_str(&buf, "superblock requires following recovery passes to be run:\n ");
|
|
|
|
prt_bitflags(&buf, bch2_recovery_passes, sb_passes);
|
|
|
|
bch_info(c, "%s", buf.buf);
|
|
|
|
printbuf_exit(&buf);
|
|
|
|
}
|
2023-12-29 20:25:07 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
if (bch2_check_version_downgrade(c)) {
|
|
|
|
struct printbuf buf = PRINTBUF;
|
2023-12-29 20:25:07 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
prt_str(&buf, "Version downgrade required:");
|
2023-12-29 20:25:07 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
__le64 passes = ext->recovery_passes_required[0];
|
|
|
|
bch2_sb_set_downgrade(c,
|
|
|
|
BCH_VERSION_MINOR(bcachefs_metadata_version_current),
|
|
|
|
BCH_VERSION_MINOR(c->sb.version));
|
|
|
|
passes = ext->recovery_passes_required[0] & ~passes;
|
|
|
|
if (passes) {
|
|
|
|
prt_str(&buf, "\n running recovery passes: ");
|
|
|
|
prt_bitflags(&buf, bch2_recovery_passes,
|
|
|
|
bch2_recovery_passes_from_stable(le64_to_cpu(passes)));
|
2023-12-29 20:25:07 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
bch_info(c, "%s", buf.buf);
|
|
|
|
printbuf_exit(&buf);
|
|
|
|
write_sb = true;
|
|
|
|
}
|
2023-12-29 20:15:14 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
if (check_version_upgrade(c))
|
|
|
|
write_sb = true;
|
2023-12-29 20:15:14 +00:00
|
|
|
|
2024-09-02 02:39:42 +00:00
|
|
|
c->opts.recovery_passes |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
|
2024-06-20 23:42:39 +00:00
|
|
|
|
2024-04-29 01:24:45 +00:00
|
|
|
if (write_sb)
|
|
|
|
bch2_write_super(c);
|
|
|
|
mutex_unlock(&c->sb_lock);
|
2023-12-29 20:15:14 +00:00
|
|
|
|
|
|
|
if (c->opts.fsck && IS_ENABLED(CONFIG_BCACHEFS_DEBUG))
|
2024-09-02 02:39:42 +00:00
|
|
|
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
|
2023-12-29 20:15:14 +00:00
|
|
|
|
2024-01-01 00:41:45 +00:00
|
|
|
if (c->opts.fsck)
|
|
|
|
set_bit(BCH_FS_fsck_running, &c->flags);
|
2024-09-26 20:19:58 +00:00
|
|
|
if (c->sb.clean)
|
|
|
|
set_bit(BCH_FS_clean_recovery, &c->flags);
|
2024-01-01 00:41:45 +00:00
|
|
|
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
ret = bch2_blacklist_table_initialize(c);
|
|
|
|
if (ret) {
|
|
|
|
bch_err(c, "error initializing blacklist table");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2024-04-26 04:32:56 +00:00
|
|
|
bch2_journal_pos_from_member_info_resume(c);
|
|
|
|
|
2024-03-31 02:42:29 +00:00
|
|
|
if (!c->sb.clean || c->opts.retain_recovery_info) {
|
2022-03-21 04:15:53 +00:00
|
|
|
struct genradix_iter iter;
|
|
|
|
struct journal_replay **i;
|
2019-04-05 01:53:12 +00:00
|
|
|
|
2022-01-04 05:06:49 +00:00
|
|
|
bch_verbose(c, "starting journal read");
|
2022-12-14 15:39:04 +00:00
|
|
|
ret = bch2_journal_read(c, &last_seq, &blacklist_seq, &journal_seq);
|
2017-03-17 06:18:50 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2022-12-01 16:17:18 +00:00
|
|
|
/*
|
|
|
|
* note: cmd_list_journal needs the blacklist table fully up to date so
|
|
|
|
* it can asterisk ignored journal entries:
|
|
|
|
*/
|
|
|
|
if (c->opts.read_journal_only)
|
|
|
|
goto out;
|
|
|
|
|
2022-03-21 04:15:53 +00:00
|
|
|
genradix_for_each_reverse(&c->journal_entries, iter, i)
|
2024-02-25 23:48:21 +00:00
|
|
|
if (!journal_replay_ignore(*i)) {
|
2022-03-21 04:15:53 +00:00
|
|
|
last_journal_entry = &(*i)->j;
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mustfix_fsck_err_on(c->sb.clean &&
|
|
|
|
last_journal_entry &&
|
|
|
|
!journal_entry_empty(last_journal_entry), c,
|
2023-10-25 00:44:36 +00:00
|
|
|
clean_but_journal_not_empty,
|
2019-03-11 18:59:58 +00:00
|
|
|
"filesystem marked clean but journal not empty")) {
|
2021-04-05 01:57:35 +00:00
|
|
|
c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
|
2019-03-11 18:59:58 +00:00
|
|
|
SET_BCH_SB_CLEAN(c->disk_sb.sb, false);
|
|
|
|
c->sb.clean = false;
|
|
|
|
}
|
2019-04-05 01:53:12 +00:00
|
|
|
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
if (!last_journal_entry) {
|
2023-10-25 00:44:36 +00:00
|
|
|
fsck_err_on(!c->sb.clean, c,
|
|
|
|
dirty_but_no_journal_entries,
|
|
|
|
"no journal entries found");
|
2022-12-14 19:47:42 +00:00
|
|
|
if (clean)
|
|
|
|
goto use_clean;
|
|
|
|
|
|
|
|
genradix_for_each_reverse(&c->journal_entries, iter, i)
|
|
|
|
if (*i) {
|
|
|
|
last_journal_entry = &(*i)->j;
|
2024-02-25 23:48:21 +00:00
|
|
|
(*i)->ignore_blacklisted = false;
|
|
|
|
(*i)->ignore_not_dirty= false;
|
2023-11-03 15:55:44 +00:00
|
|
|
/*
|
|
|
|
* This was probably a NO_FLUSH entry,
|
|
|
|
* so last_seq was garbage - but we know
|
|
|
|
* we're only using a single journal
|
|
|
|
* entry, set it here:
|
|
|
|
*/
|
|
|
|
(*i)->j.last_seq = (*i)->j.seq;
|
2022-12-14 19:47:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-05 01:53:12 +00:00
|
|
|
}
|
|
|
|
|
2023-08-05 20:08:44 +00:00
|
|
|
ret = bch2_journal_keys_sort(c);
|
2022-03-21 04:15:53 +00:00
|
|
|
if (ret)
|
2019-04-12 02:39:39 +00:00
|
|
|
goto err;
|
|
|
|
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
if (c->sb.clean && last_journal_entry) {
|
2023-08-05 19:54:38 +00:00
|
|
|
ret = bch2_verify_superblock_clean(c, &clean,
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
last_journal_entry);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
use_clean:
|
|
|
|
if (!clean) {
|
|
|
|
bch_err(c, "no superblock clean section found");
|
2022-07-19 21:20:18 +00:00
|
|
|
ret = -BCH_ERR_fsck_repair_impossible;
|
2019-03-29 23:13:54 +00:00
|
|
|
goto err;
|
2019-04-05 01:53:12 +00:00
|
|
|
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
}
|
|
|
|
blacklist_seq = journal_seq = le64_to_cpu(clean->journal_seq) + 1;
|
2019-04-05 01:53:12 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 02:33:29 +00:00
|
|
|
c->journal_replay_seq_start = last_seq;
|
2023-08-07 16:04:05 +00:00
|
|
|
c->journal_replay_seq_end = blacklist_seq - 1;
|
2023-07-09 02:33:29 +00:00
|
|
|
|
2024-03-12 01:15:26 +00:00
|
|
|
if (c->opts.reconstruct_alloc)
|
2024-03-19 22:56:26 +00:00
|
|
|
bch2_reconstruct_alloc(c);
|
2020-10-25 01:20:16 +00:00
|
|
|
|
2021-07-30 18:33:06 +00:00
|
|
|
zero_out_btree_mem_ptr(&c->journal_keys);
|
|
|
|
|
2022-03-21 04:15:53 +00:00
|
|
|
ret = journal_replay_early(c, clean);
|
2019-04-05 01:53:12 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2022-01-05 00:41:23 +00:00
|
|
|
/*
|
|
|
|
* After an unclean shutdown, skip then next few journal sequence
|
|
|
|
* numbers as they may have been referenced by btree writes that
|
|
|
|
* happened before their corresponding journal writes - those btree
|
|
|
|
* writes need to be ignored, by skipping and blacklisting the next few
|
|
|
|
* journal sequence numbers:
|
|
|
|
*/
|
|
|
|
if (!c->sb.clean)
|
|
|
|
journal_seq += 8;
|
|
|
|
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
if (blacklist_seq != journal_seq) {
|
2023-03-22 12:27:58 +00:00
|
|
|
ret = bch2_journal_log_msg(c, "blacklisting entries %llu-%llu",
|
|
|
|
blacklist_seq, journal_seq) ?:
|
2022-12-14 15:39:04 +00:00
|
|
|
bch2_journal_seq_blacklist_add(c,
|
bcachefs: Don't require flush/fua on every journal write
This patch adds a flag to journal entries which, if set, indicates that
they weren't done as flush/fua writes.
- non flush/fua journal writes don't update last_seq (i.e. they don't
free up space in the journal), thus the journal free space
calculations now check whether nonflush journal writes are currently
allowed (i.e. are we low on free space, or would doing a flush write
free up a lot of space in the journal)
- write_delay_ms, the user configurable option for when open journal
entries are automatically written, is now interpreted as the max
delay between flush journal writes (default 1 second).
- bch2_journal_flush_seq_async is changed to ensure a flush write >=
the requested sequence number has happened
- journal read/replay must now ignore, and blacklist, any journal
entries newer than the most recent flush entry in the journal. Also,
the way the read_entire_journal option is handled has been improved;
struct journal_replay now has an entry, 'ignore', for entries that
were read but should not be used.
- assorted refactoring and improvements related to journal read in
journal_io.c and recovery.c
Previously, we'd have to issue a flush/fua write every time we
accumulated a full journal entry - typically the bucket size. Now we
need to issue them much less frequently: when an fsync is requested, or
it's been more than write_delay_ms since the last flush, or when we need
to free up space in the journal. This is a significant performance
improvement on many write heavy workloads.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2020-11-14 14:59:58 +00:00
|
|
|
blacklist_seq, journal_seq);
|
2019-04-05 01:53:12 +00:00
|
|
|
if (ret) {
|
2024-03-07 17:30:49 +00:00
|
|
|
bch_err_msg(c, ret, "error creating new journal seq blacklist entry");
|
2019-03-29 23:13:54 +00:00
|
|
|
goto err;
|
2019-04-05 01:53:12 +00:00
|
|
|
}
|
2019-06-18 23:37:39 +00:00
|
|
|
}
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2023-03-22 12:27:58 +00:00
|
|
|
ret = bch2_journal_log_msg(c, "starting journal at entry %llu, replaying %llu-%llu",
|
|
|
|
journal_seq, last_seq, blacklist_seq - 1) ?:
|
2022-12-14 15:39:04 +00:00
|
|
|
bch2_fs_journal_start(&c->journal, journal_seq);
|
2019-03-29 23:13:54 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2022-04-21 17:13:57 +00:00
|
|
|
/*
|
|
|
|
* Skip past versions that might have possibly been used (as nonces),
|
|
|
|
* but hadn't had their pointers written:
|
|
|
|
*/
|
|
|
|
if (c->sb.encryption_type && !c->sb.clean)
|
|
|
|
atomic64_add(1 << 16, &c->key_version);
|
|
|
|
|
2019-03-29 23:13:54 +00:00
|
|
|
ret = read_btree_roots(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2024-04-26 00:45:00 +00:00
|
|
|
set_bit(BCH_FS_btree_running, &c->flags);
|
|
|
|
|
|
|
|
ret = bch2_sb_set_upgrade_extra(c);
|
|
|
|
|
2023-07-07 06:42:28 +00:00
|
|
|
ret = bch2_run_recovery_passes(c);
|
2018-11-23 07:50:33 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2024-10-31 07:33:36 +00:00
|
|
|
/*
|
|
|
|
* Normally set by the appropriate recovery pass: when cleared, this
|
|
|
|
* indicates we're in early recovery and btree updates should be done by
|
|
|
|
* being applied to the journal replay keys. _Must_ be cleared before
|
|
|
|
* multithreaded use:
|
|
|
|
*/
|
|
|
|
set_bit(BCH_FS_may_go_rw, &c->flags);
|
2024-01-01 00:41:45 +00:00
|
|
|
clear_bit(BCH_FS_fsck_running, &c->flags);
|
|
|
|
|
2024-09-22 06:10:30 +00:00
|
|
|
/* in case we don't run journal replay, i.e. norecovery mode */
|
|
|
|
set_bit(BCH_FS_accounting_replay_done, &c->flags);
|
|
|
|
|
2024-03-28 06:36:10 +00:00
|
|
|
/* fsync if we fixed errors */
|
2024-05-23 00:17:05 +00:00
|
|
|
if (test_bit(BCH_FS_errors_fixed, &c->flags) &&
|
|
|
|
bch2_write_ref_tryget(c, BCH_WRITE_REF_fsync)) {
|
2024-03-28 06:36:10 +00:00
|
|
|
bch2_journal_flush_all_pins(&c->journal);
|
|
|
|
bch2_journal_meta(&c->journal);
|
2024-05-23 00:17:05 +00:00
|
|
|
bch2_write_ref_put(c, BCH_WRITE_REF_fsync);
|
2024-03-28 06:36:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 00:19:58 +00:00
|
|
|
/* If we fixed errors, verify that fs is actually clean now: */
|
|
|
|
if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG) &&
|
2023-11-26 22:05:02 +00:00
|
|
|
test_bit(BCH_FS_errors_fixed, &c->flags) &&
|
|
|
|
!test_bit(BCH_FS_errors_not_fixed, &c->flags) &&
|
|
|
|
!test_bit(BCH_FS_error, &c->flags)) {
|
2023-11-14 00:57:09 +00:00
|
|
|
bch2_flush_fsck_errs(c);
|
|
|
|
|
2023-08-03 00:19:58 +00:00
|
|
|
bch_info(c, "Fixed errors, running fsck a second time to verify fs is clean");
|
2023-11-26 22:05:02 +00:00
|
|
|
clear_bit(BCH_FS_errors_fixed, &c->flags);
|
2023-08-03 00:19:58 +00:00
|
|
|
|
|
|
|
c->curr_recovery_pass = BCH_RECOVERY_PASS_check_alloc_info;
|
|
|
|
|
|
|
|
ret = bch2_run_recovery_passes(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-11-26 22:05:02 +00:00
|
|
|
if (test_bit(BCH_FS_errors_fixed, &c->flags) ||
|
|
|
|
test_bit(BCH_FS_errors_not_fixed, &c->flags)) {
|
2023-08-03 00:19:58 +00:00
|
|
|
bch_err(c, "Second fsck run was not clean");
|
2023-11-26 22:05:02 +00:00
|
|
|
set_bit(BCH_FS_errors_not_fixed, &c->flags);
|
2023-08-03 00:19:58 +00:00
|
|
|
}
|
|
|
|
|
2023-11-26 22:05:02 +00:00
|
|
|
set_bit(BCH_FS_errors_fixed, &c->flags);
|
2023-08-03 00:19:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 23:13:54 +00:00
|
|
|
if (enabled_qtypes(c)) {
|
2019-04-17 22:21:19 +00:00
|
|
|
bch_verbose(c, "reading quotas");
|
2019-03-29 23:13:54 +00:00
|
|
|
ret = bch2_fs_quota_read(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
bch_verbose(c, "quotas done");
|
|
|
|
}
|
|
|
|
|
2018-11-01 19:10:01 +00:00
|
|
|
mutex_lock(&c->sb_lock);
|
2024-04-29 01:24:45 +00:00
|
|
|
ext = bch2_sb_field_get(c->disk_sb.sb, ext);
|
|
|
|
write_sb = false;
|
2023-12-29 20:15:14 +00:00
|
|
|
|
2023-12-29 22:18:56 +00:00
|
|
|
if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) != le16_to_cpu(c->disk_sb.sb->version)) {
|
|
|
|
SET_BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb, le16_to_cpu(c->disk_sb.sb->version));
|
2019-03-11 18:59:58 +00:00
|
|
|
write_sb = true;
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:05:02 +00:00
|
|
|
if (!test_bit(BCH_FS_error, &c->flags) &&
|
2023-12-29 20:15:14 +00:00
|
|
|
!(c->disk_sb.sb->compat[0] & cpu_to_le64(1ULL << BCH_COMPAT_alloc_info))) {
|
2021-05-23 21:04:13 +00:00
|
|
|
c->disk_sb.sb->compat[0] |= cpu_to_le64(1ULL << BCH_COMPAT_alloc_info);
|
2019-03-11 18:59:58 +00:00
|
|
|
write_sb = true;
|
2018-07-15 01:06:51 +00:00
|
|
|
}
|
|
|
|
|
2024-03-30 22:57:53 +00:00
|
|
|
if (!test_bit(BCH_FS_error, &c->flags) &&
|
2024-03-31 02:25:45 +00:00
|
|
|
!bch2_is_zero(ext->errors_silent, sizeof(ext->errors_silent))) {
|
2024-03-30 22:57:53 +00:00
|
|
|
memset(ext->errors_silent, 0, sizeof(ext->errors_silent));
|
|
|
|
write_sb = true;
|
2023-12-29 20:15:14 +00:00
|
|
|
}
|
|
|
|
|
2024-03-16 03:03:42 +00:00
|
|
|
if (c->opts.fsck &&
|
|
|
|
!test_bit(BCH_FS_error, &c->flags) &&
|
|
|
|
c->recovery_pass_done == BCH_RECOVERY_PASS_NR - 1 &&
|
|
|
|
ext->btrees_lost_data) {
|
|
|
|
ext->btrees_lost_data = 0;
|
|
|
|
write_sb = true;
|
|
|
|
}
|
|
|
|
|
2019-03-28 13:34:55 +00:00
|
|
|
if (c->opts.fsck &&
|
2023-11-26 22:05:02 +00:00
|
|
|
!test_bit(BCH_FS_error, &c->flags) &&
|
|
|
|
!test_bit(BCH_FS_errors_not_fixed, &c->flags)) {
|
2019-03-28 13:34:55 +00:00
|
|
|
SET_BCH_SB_HAS_ERRORS(c->disk_sb.sb, 0);
|
2021-04-24 20:32:35 +00:00
|
|
|
SET_BCH_SB_HAS_TOPOLOGY_ERRORS(c->disk_sb.sb, 0);
|
2019-03-11 18:59:58 +00:00
|
|
|
write_sb = true;
|
2019-03-28 13:34:55 +00:00
|
|
|
}
|
2019-03-11 18:59:58 +00:00
|
|
|
|
2024-04-21 02:19:48 +00:00
|
|
|
if (bch2_blacklist_entries_gc(c))
|
|
|
|
write_sb = true;
|
|
|
|
|
2019-03-11 18:59:58 +00:00
|
|
|
if (write_sb)
|
|
|
|
bch2_write_super(c);
|
2018-11-01 19:10:01 +00:00
|
|
|
mutex_unlock(&c->sb_lock);
|
2019-04-05 01:53:12 +00:00
|
|
|
|
2021-12-28 01:05:07 +00:00
|
|
|
if (!(c->sb.compat & (1ULL << BCH_COMPAT_extents_above_btree_updates_done)) ||
|
2023-07-07 02:47:42 +00:00
|
|
|
c->sb.version_min < bcachefs_metadata_version_btree_ptr_sectors_written) {
|
2021-12-28 01:05:07 +00:00
|
|
|
struct bch_move_stats stats;
|
|
|
|
|
2022-11-14 01:01:42 +00:00
|
|
|
bch2_move_stats_init(&stats, "recovery");
|
2021-12-28 01:05:07 +00:00
|
|
|
|
2023-11-17 02:40:58 +00:00
|
|
|
struct printbuf buf = PRINTBUF;
|
|
|
|
bch2_version_to_text(&buf, c->sb.version_min);
|
|
|
|
bch_info(c, "scanning for old btree nodes: min_version %s", buf.buf);
|
|
|
|
printbuf_exit(&buf);
|
|
|
|
|
|
|
|
ret = bch2_fs_read_write_early(c) ?:
|
2023-06-20 17:49:25 +00:00
|
|
|
bch2_scan_old_btree_nodes(c, &stats);
|
2021-12-28 01:05:07 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
bch_info(c, "scanning for old btree nodes done");
|
|
|
|
}
|
|
|
|
|
2019-04-17 22:21:19 +00:00
|
|
|
ret = 0;
|
2021-04-24 22:02:59 +00:00
|
|
|
out:
|
2019-04-17 22:21:19 +00:00
|
|
|
bch2_flush_fsck_errs(c);
|
2019-09-07 16:42:27 +00:00
|
|
|
|
2024-03-12 03:11:46 +00:00
|
|
|
if (!c->opts.retain_recovery_info) {
|
2023-11-18 04:13:49 +00:00
|
|
|
bch2_journal_keys_put_initial(c);
|
2024-03-12 03:11:46 +00:00
|
|
|
bch2_find_btree_nodes_exit(&c->found_btree_nodes);
|
|
|
|
}
|
2024-05-03 14:55:17 +00:00
|
|
|
if (!IS_ERR(clean))
|
|
|
|
kfree(clean);
|
2022-07-14 05:10:24 +00:00
|
|
|
|
2023-12-23 22:50:29 +00:00
|
|
|
if (!ret &&
|
|
|
|
test_bit(BCH_FS_need_delete_dead_snapshots, &c->flags) &&
|
|
|
|
!c->opts.nochanges) {
|
2022-07-14 05:10:24 +00:00
|
|
|
bch2_fs_read_write_early(c);
|
|
|
|
bch2_delete_dead_snapshots_async(c);
|
|
|
|
}
|
|
|
|
|
2023-12-17 03:43:41 +00:00
|
|
|
bch_err_fn(c, ret);
|
2017-03-17 06:18:50 +00:00
|
|
|
return ret;
|
2021-04-24 22:02:59 +00:00
|
|
|
err:
|
|
|
|
fsck_err:
|
|
|
|
bch2_fs_emergency_read_only(c);
|
|
|
|
goto out;
|
2017-03-17 06:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int bch2_fs_initialize(struct bch_fs *c)
|
|
|
|
{
|
|
|
|
struct bch_inode_unpacked root_inode, lostfound_inode;
|
|
|
|
struct bkey_inode_buf packed_inode;
|
|
|
|
struct qstr lostfound = QSTR("lost+found");
|
2024-10-26 00:15:49 +00:00
|
|
|
struct bch_member *m;
|
2017-03-17 06:18:50 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
bch_notice(c, "initializing new filesystem");
|
2024-03-28 02:50:19 +00:00
|
|
|
set_bit(BCH_FS_new_fs, &c->flags);
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2019-01-25 01:25:40 +00:00
|
|
|
mutex_lock(&c->sb_lock);
|
2021-05-23 21:04:13 +00:00
|
|
|
c->disk_sb.sb->compat[0] |= cpu_to_le64(1ULL << BCH_COMPAT_extents_above_btree_updates_done);
|
|
|
|
c->disk_sb.sb->compat[0] |= cpu_to_le64(1ULL << BCH_COMPAT_bformat_overflow_done);
|
2020-06-03 20:20:22 +00:00
|
|
|
|
2023-12-29 20:25:07 +00:00
|
|
|
bch2_check_version_downgrade(c);
|
2023-07-10 16:23:01 +00:00
|
|
|
|
2023-06-28 03:34:02 +00:00
|
|
|
if (c->opts.version_upgrade != BCH_VERSION_UPGRADE_none) {
|
2023-07-10 16:23:01 +00:00
|
|
|
bch2_sb_upgrade(c, bcachefs_metadata_version_current);
|
2023-06-28 03:34:02 +00:00
|
|
|
SET_BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb, bcachefs_metadata_version_current);
|
2021-03-21 20:20:40 +00:00
|
|
|
bch2_write_super(c);
|
|
|
|
}
|
2024-10-26 00:15:49 +00:00
|
|
|
|
|
|
|
for_each_member_device(c, ca) {
|
|
|
|
m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
|
|
|
|
SET_BCH_MEMBER_FREESPACE_INITIALIZED(m, false);
|
|
|
|
ca->mi = bch2_mi_to_cpu(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
bch2_write_super(c);
|
2020-06-03 20:20:22 +00:00
|
|
|
mutex_unlock(&c->sb_lock);
|
|
|
|
|
2024-03-24 00:07:46 +00:00
|
|
|
c->curr_recovery_pass = BCH_RECOVERY_PASS_NR;
|
2024-04-26 00:45:00 +00:00
|
|
|
set_bit(BCH_FS_btree_running, &c->flags);
|
2023-11-26 22:05:02 +00:00
|
|
|
set_bit(BCH_FS_may_go_rw, &c->flags);
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2023-12-17 04:47:29 +00:00
|
|
|
for (unsigned i = 0; i < BTREE_ID_NR; i++)
|
2024-03-15 02:17:40 +00:00
|
|
|
bch2_btree_root_alloc_fake(c, i, 0);
|
2018-11-24 22:09:44 +00:00
|
|
|
|
2023-10-21 17:54:39 +00:00
|
|
|
ret = bch2_fs_journal_alloc(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* journal_res_get() will crash if called before this has
|
|
|
|
* set up the journal.pin FIFO and journal.cur pointer:
|
|
|
|
*/
|
2022-03-21 04:15:53 +00:00
|
|
|
bch2_fs_journal_start(&c->journal, 1);
|
2023-11-17 05:23:07 +00:00
|
|
|
set_bit(BCH_FS_accounting_replay_done, &c->flags);
|
2017-03-17 06:18:50 +00:00
|
|
|
bch2_journal_set_replay_done(&c->journal);
|
|
|
|
|
2020-10-17 01:36:26 +00:00
|
|
|
ret = bch2_fs_read_write_early(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-11-09 19:22:46 +00:00
|
|
|
for_each_member_device(c, ca) {
|
2024-02-12 03:48:05 +00:00
|
|
|
ret = bch2_dev_usage_init(ca, false);
|
2023-11-09 19:22:46 +00:00
|
|
|
if (ret) {
|
|
|
|
bch2_dev_put(ca);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 01:36:26 +00:00
|
|
|
/*
|
|
|
|
* Write out the superblock and journal buckets, now that we can do
|
|
|
|
* btree updates
|
|
|
|
*/
|
2022-01-10 01:48:31 +00:00
|
|
|
bch_verbose(c, "marking superblocks");
|
2023-10-21 17:54:39 +00:00
|
|
|
ret = bch2_trans_mark_dev_sbs(c);
|
|
|
|
bch_err_msg(c, ret, "marking superblocks");
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2021-12-24 09:22:20 +00:00
|
|
|
|
2023-12-17 04:47:29 +00:00
|
|
|
for_each_online_member(c, ca)
|
2021-12-24 09:22:20 +00:00
|
|
|
ca->new_fs_bucket_idx = 0;
|
2020-10-17 01:36:26 +00:00
|
|
|
|
2021-12-11 22:13:09 +00:00
|
|
|
ret = bch2_fs_freespace_init(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-07-07 06:42:28 +00:00
|
|
|
ret = bch2_initialize_subvolumes(c);
|
2021-03-16 04:42:25 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
bch_verbose(c, "reading snapshots table");
|
2023-07-07 06:42:28 +00:00
|
|
|
ret = bch2_snapshots_read(c);
|
2021-03-16 04:42:25 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
bch_verbose(c, "reading snapshots done");
|
|
|
|
|
2022-10-22 19:59:53 +00:00
|
|
|
bch2_inode_init(c, &root_inode, 0, 0, S_IFDIR|0755, 0, NULL);
|
2021-03-16 04:42:25 +00:00
|
|
|
root_inode.bi_inum = BCACHEFS_ROOT_INO;
|
|
|
|
root_inode.bi_subvol = BCACHEFS_ROOT_SUBVOL;
|
2022-10-21 17:21:03 +00:00
|
|
|
bch2_inode_pack(&packed_inode, &root_inode);
|
bcachefs: Start using bpos.snapshot field
This patch starts treating the bpos.snapshot field like part of the key
in the btree code:
* bpos_successor() and bpos_predecessor() now include the snapshot field
* Keys in btrees that will be using snapshots (extents, inodes, dirents
and xattrs) now always have their snapshot field set to U32_MAX
The btree iterator code gets a new flag, BTREE_ITER_ALL_SNAPSHOTS, that
determines whether we're iterating over keys in all snapshots or not -
internally, this controlls whether bkey_(successor|predecessor)
increment/decrement the snapshot field, or only the higher bits of the
key.
We add a new member to struct btree_iter, iter->snapshot: when
BTREE_ITER_ALL_SNAPSHOTS is not set, iter->pos.snapshot should always
equal iter->snapshot, which will be 0 for btrees that don't use
snapshots, and alsways U32_MAX for btrees that will use snapshots
(until we enable snapshot creation).
This patch also introduces a new metadata version number, and compat
code for reading from/writing to older versions - this isn't a forced
upgrade (yet).
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2021-03-24 22:02:16 +00:00
|
|
|
packed_inode.inode.k.p.snapshot = U32_MAX;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2024-06-03 20:47:31 +00:00
|
|
|
ret = bch2_btree_insert(c, BTREE_ID_inodes, &packed_inode.inode.k_i, NULL, 0, 0);
|
2023-12-17 03:43:41 +00:00
|
|
|
bch_err_msg(c, ret, "creating root directory");
|
|
|
|
if (ret)
|
2017-03-17 06:18:50 +00:00
|
|
|
goto err;
|
|
|
|
|
2019-10-02 22:35:36 +00:00
|
|
|
bch2_inode_init_early(c, &lostfound_inode);
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2024-10-14 01:53:26 +00:00
|
|
|
ret = bch2_trans_commit_do(c, NULL, NULL, 0,
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_create_trans(trans,
|
2021-03-16 04:28:17 +00:00
|
|
|
BCACHEFS_ROOT_SUBVOL_INUM,
|
2019-10-02 22:35:36 +00:00
|
|
|
&root_inode, &lostfound_inode,
|
|
|
|
&lostfound,
|
2019-11-10 03:15:40 +00:00
|
|
|
0, 0, S_IFDIR|0700, 0,
|
2021-03-17 03:28:43 +00:00
|
|
|
NULL, NULL, (subvol_inum) { 0 }, 0));
|
2023-12-17 03:43:41 +00:00
|
|
|
bch_err_msg(c, ret, "creating lost+found");
|
|
|
|
if (ret)
|
2017-03-17 06:18:50 +00:00
|
|
|
goto err;
|
|
|
|
|
2024-03-24 00:07:46 +00:00
|
|
|
c->recovery_pass_done = BCH_RECOVERY_PASS_NR - 1;
|
2023-12-10 17:42:49 +00:00
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
if (enabled_qtypes(c)) {
|
|
|
|
ret = bch2_fs_quota_read(c);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-11-15 22:30:11 +00:00
|
|
|
ret = bch2_journal_flush(&c->journal);
|
2023-12-17 03:43:41 +00:00
|
|
|
bch_err_msg(c, ret, "writing first journal entry");
|
|
|
|
if (ret)
|
2017-03-17 06:18:50 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
mutex_lock(&c->sb_lock);
|
|
|
|
SET_BCH_SB_INITIALIZED(c->disk_sb.sb, true);
|
|
|
|
SET_BCH_SB_CLEAN(c->disk_sb.sb, false);
|
|
|
|
|
|
|
|
bch2_write_super(c);
|
|
|
|
mutex_unlock(&c->sb_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
2023-12-17 04:47:29 +00:00
|
|
|
bch_err_fn(c, ret);
|
2017-03-17 06:18:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|