bcachefs: Add persistent identifiers for recovery passes
PATCH 1/3 bcachefs: Add persistent identifiers for recovery passes
The next patch will start to refer to recovery passes from the superblock; naturally, we now need identifiers that don't change, since the existing enum is in the order in which they are run and is not fixed.
--- fs/bcachefs/recovery.c | 34 ++++++++++++++- fs/bcachefs/recovery.h | 3 ++ fs/bcachefs/recovery_types.h | 84 ++++++++++++++++++++---------------- 3 files changed, 83 insertions(+), 38 deletions(-)
fs/bcachefs/recovery.c +32 -2
@@ -503,7 +503,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct bch_fs *c) } const char * const bch2_recovery_passes[] = { -#define x(_fn, _when) #_fn, +#define x(_fn, ...) #_fn, BCH_RECOVERY_PASSES() #undef x NULL
@@ -539,11 +539,41 @@ struct recovery_pass_fn { };static struct recovery_pass_fn recovery_pass_fns[] = { -#define x(_fn, _when) { .fn = bch2_##_fn, .when = _when }, +#define x(_fn, _id, _when) { .fn = bch2_##_fn, .when = _when },BCH_RECOVERY_PASSES () #undef x }; +u64 bch2_recovery_passes_to_stable (u64 v) +{ +static const u8 map[] = { +#define x(n, id, ...) [BCH_RECOVERY_PASS_##n] = BCH_RECOVERY_PASS_STABLE_##n, +BCH_RECOVERY_PASSES () +#undef x + }; + +u64 ret =0 ; +for (unsigned i =0 ; i <ARRAY_SIZE (map); i++) +if (v &BIT_ULL (i)) + ret |=BIT_ULL (map[i]); +return ret; +} + +u64 bch2_recovery_passes_from_stable (u64 v) +{ +static const u8 map[] = { +#define x(n, id, ...) [BCH_RECOVERY_PASS_STABLE_##n] = BCH_RECOVERY_PASS_##n, +BCH_RECOVERY_PASSES () +#undef x + }; + +u64 ret =0 ; +for (unsigned i =0 ; i <ARRAY_SIZE (map); i++) +if (v &BIT_ULL (i)) + ret |=BIT_ULL (map[i]); +return ret; +} +static void check_version_upgrade (struct bch_fs *c) {unsigned latest_compatible =bch2_latest_compatible_version (c->sb.version);
fs/bcachefs/recovery.h +3 -0
@@ -4,6 +4,9 @@extern const char *const bch2_recovery_passes[]; +u64 bch2_recovery_passes_to_stable (u64 v); +u64 bch2_recovery_passes_from_stable (u64 v); +/* * For when we need to rewind recovery passes and run a pass we skipped: */
fs/bcachefs/recovery_types.h +48 -36
93 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 2/3 bcachefs: bch_sb.recovery_passes_required
Add two new superblock fields. Since the main section of the superblock is now fully, we have to add a new variable length section for them - bch_sb_field_ext.
- recovery_passes_requried: recovery passes that must be run on the next mount
- errors_silent: errors that will be silently fixed
These are to improve upgrading and dwongrading: these fields won't be cleared until after recovery successfully completes, so there won't be any issues with crashing partway through an upgrade or a downgrade.
--- fs/bcachefs/bcachefs.h | 1 + fs/bcachefs/bcachefs_format.h | 33 +++++++++------ fs/bcachefs/errcode.h | 1 + fs/bcachefs/error.c | 3 ++ fs/bcachefs/recovery.c | 76 ++++++++++++++++++++++++++++------- fs/bcachefs/sb-errors.c | 2 +- fs/bcachefs/sb-errors.h | 2 + fs/bcachefs/super-io.c | 73 +++++++++++++++++++++++++++++++++ fs/bcachefs/super-io.h | 10 +++++ 9 files changed, 172 insertions(+), 29 deletions(-)
fs/bcachefs/bcachefs.h +1 -0
@@ -796,6 +796,7 @@ struct bch_fs {unsigned nsec_per_time_unit;u64 features;u64 compat; +unsigned long errors_silent[BITS_TO_LONGS (BCH_SB_ERR_MAX )]; } sb;
fs/bcachefs/bcachefs_format.h +20 -13
@@ -1214,19 +1214,20 @@ struct bch_sb_field { };#define BCH_SB_FIELDS () \ - x(journal, 0) \ - x(members_v1, 1) \ - x(crypt, 2) \ - x(replicas_v0, 3) \ - x(quota, 4) \ - x(disk_groups, 5) \ - x(clean, 6) \ - x(replicas, 7) \ - x(journal_seq_blacklist, 8) \ - x(journal_v2, 9) \ - x(counters, 10) \ - x(members_v2, 11) \ - x(errors, 12) + x(journal, 0) \ + x(members_v1, 1) \ + x(crypt, 2) \ + x(replicas_v0, 3) \ + x(quota, 4) \ + x(disk_groups, 5) \ + x(clean, 6) \ + x(replicas, 7) \ + x(journal_seq_blacklist, 8) \ + x(journal_v2, 9) \ + x(counters, 10) \ + x(members_v2, 11) \ + x(errors, 12) \ + x(ext, 13)enum bch_sb_field_type {#define x(f, nr) BCH_SB_FIELD_##f = nr,
@@ -1641,6 +1642,12 @@ struct bch_sb_field_errors { LE64_BITMASK(BCH_SB_ERROR_ENTRY_ID, struct bch_sb_field_error_entry, v, 0, 16); LE64_BITMASK(BCH_SB_ERROR_ENTRY_NR, struct bch_sb_field_error_entry, v, 16, 64); +struct bch_sb_field_ext { +struct bch_sb_field field; +__le64 recovery_passes_required[2 ]; +__le64 errors_silent[8 ]; +}; +/* Superblock: */ /*
fs/bcachefs/errcode.h +1 -0
@@ -218,6 +218,7 @@ x(BCH_ERR_invalid_sb, invalid_sb_quota) \ x(BCH_ERR_invalid_sb, invalid_sb_errors) \ x(BCH_ERR_invalid_sb, invalid_sb_opt_compression) \ + x(BCH_ERR_invalid_sb, invalid_sb_ext) \ x(BCH_ERR_invalid, invalid_bkey) \ x(BCH_ERR_operation_blocked, nocow_lock_blocked) \x (EIO , btree_node_read_err) \
fs/bcachefs/error.c +3 -0
@@ -152,6 +152,9 @@ int bch2_fsck_err(struct bch_fs *c,struct printbuf buf =PRINTBUF , *out = &buf;int ret = -BCH_ERR_fsck_ignore; +if (test_bit (err, c->sb.errors_silent)) +return -BCH_ERR_fsck_fix; +bch2_sb_error_count (c, err);va_start (args, fmt);
fs/bcachefs/recovery.c +61 -15
142 lines not on this page · raw message
fs/bcachefs/sb-errors.c +1 -1
@@ -4,7 +4,7 @@#include "sb-errors.h" #include "super-io.h" -static const char *const bch2_sb_error_strs[] = { +const char *const bch2_sb_error_strs[] = { #define x(t, n, ...) [n] = #t, BCH_SB_ERRS()NULL
fs/bcachefs/sb-errors.h +2 -0
@@ -4,6 +4,8 @@#include "sb-errors_types.h" +extern const char *const bch2_sb_error_strs[]; +extern const struct bch_sb_field_ops bch_sb_field_ops_errors;void bch2_sb_error_count (struct bch_fs *,enum bch_sb_error_id );
fs/bcachefs/super-io.c +73 -0
97 lines not on this page · raw message
fs/bcachefs/super-io.h +10 -0
@@ -40,6 +40,16 @@ struct bch_sb_field *bch2_sb_field_resize_id(struct bch_sb_handle *,#define bch2_sb_field_resize (_sb, _name, _u64s) \ field_to_type(bch2_sb_field_resize_id(_sb, BCH_SB_FIELD_##_name, _u64s), _name) +struct bch_sb_field *bch2_sb_field_get_minsize_id (struct bch_sb_handle *, +enum bch_sb_field_type ,unsigned ); +#define bch2_sb_field_get_minsize (_sb, _name, _u64s) \ + field_to_type(bch2_sb_field_get_minsize_id(_sb, BCH_SB_FIELD_##_name, _u64s), _name) + +#define bch2_sb_field_nr_entries (_f) \ + (_f ? ((bch2_sb_field_bytes(&_f->field) - sizeof(*_f)) / \ + sizeof(_f->entries[0])) \ + : 0) +void bch2_sb_field_delete (struct bch_sb_handle *,enum bch_sb_field_type );extern const char *const bch2_sb_fields[];
Signature · 1 line
2.43.0
PATCH 3/3 bcachefs: bch_sb_field_downgrade
In reply to Kent OverstreetAdd a new superblock section that contains a list of
{ minor version, recovery passes, errors_to_fix }
that is - a list of recovery passes that must be run when downgrading past a given version, and a list of errors to silently fix.
The upcoming disk accounting rewrite is not going to be fully
compatible: we're going to have to regenerate accounting both when upgrading to the new version, and also from downgrading from the new version, since the new method of doing disk space accounting is a completely different architecture based on deltas, and synchronizing them for every jounal entry write to maintain compatibility is going to be too expensive and impractical.
--- fs/bcachefs/Makefile | 1 + fs/bcachefs/bcachefs_format.h | 20 +++- fs/bcachefs/errcode.h | 2 + fs/bcachefs/recovery.c | 29 ++++++ fs/bcachefs/sb-clean.c | 2 - fs/bcachefs/sb-downgrade.c | 190 ++++++++++++++++++++++++++++++++++ fs/bcachefs/sb-downgrade.h | 10 ++ fs/bcachefs/sb-errors.c | 4 +- fs/bcachefs/super-io.c | 6 ++ 9 files changed, 258 insertions(+), 6 deletions(-) create mode 100644 fs/bcachefs/sb-downgrade.c create mode 100644 fs/bcachefs/sb-downgrade.h
fs/bcachefs/Makefile +1 -0
@@ -71,6 +71,7 @@ bcachefs-y := \ reflink.o \ replicas.o \ sb-clean.o \ + sb-downgrade.o \ sb-errors.o \ sb-members.o \ siphash.o \
fs/bcachefs/bcachefs_format.h +19 -1
@@ -1227,7 +1227,8 @@ struct bch_sb_field { x(counters, 10) \ x(members_v2, 11) \ x(errors, 12) \ - x(ext, 13) + x(ext, 13) \ + x(downgrade, 14)enum bch_sb_field_type {#define x(f, nr) BCH_SB_FIELD_##f = nr,
@@ -1648,6 +1649,18 @@ struct bch_sb_field_ext {__le64 errors_silent[8 ]; }; +struct bch_sb_field_downgrade_entry { +__le16 version; +__le64 recovery_passes[2 ]; +__le16 nr_errors; + __le16 errors[] __counted_by(nr_errors); +} __packed__aligned(2) ; + +struct bch_sb_field_downgrade { +struct bch_sb_field field; +struct bch_sb_field_downgrade_entry entries[]; +}; +/* Superblock: */ /*
@@ -1661,6 +1674,11 @@ struct bch_sb_field_ext {#define RECOVERY_PASS_ALL_FSCK (1ULL << 63) +/* +* field 1: version name +* field 2: BCH_VERSION(major, minor) +* field 3: recovery passess required on upgrade +*/ #define BCH_METADATA_VERSIONS () \ x(bkey_renumber, BCH_VERSION(0, 10), \ RECOVERY_PASS_ALL_FSCK) \
fs/bcachefs/errcode.h +2 -0
@@ -94,6 +94,7 @@ x(ENOSPC, ENOSPC_sb_members) \ x(ENOSPC, ENOSPC_sb_members_v2) \ x(ENOSPC, ENOSPC_sb_crypt) \ + x(ENOSPC, ENOSPC_sb_downgrade) \ x(ENOSPC, ENOSPC_btree_slot) \ x(ENOSPC, ENOSPC_snapshot_tree) \x (ENOENT , ENOENT_bkey_type_mismatch) \
@@ -219,6 +220,7 @@ x(BCH_ERR_invalid_sb, invalid_sb_errors) \ x(BCH_ERR_invalid_sb, invalid_sb_opt_compression) \ x(BCH_ERR_invalid_sb, invalid_sb_ext) \ + x(BCH_ERR_invalid_sb, invalid_sb_downgrade) \ x(BCH_ERR_invalid, invalid_bkey) \ x(BCH_ERR_operation_blocked, nocow_lock_blocked) \x (EIO , btree_node_read_err) \
fs/bcachefs/recovery.c +29 -0
@@ -27,6 +27,7 @@#include "recovery.h" #include "replicas.h" #include "sb-clean.h" +#include "sb-downgrade.h" #include "snapshot.h" #include "subvolume.h" #include "super-io.h"
@@ -800,6 +801,34 @@ int bch2_fs_recovery(struct bch_fs *c) c->recovery_passes_explicit |= sb_passes; } +if (bcachefs_metadata_version_current < c->sb.version) { +struct printbuf buf =PRINTBUF ; + +prt_str (&buf,"Version downgrade required:\n" ); + +u64 passes = ext->recovery_passes_required[0 ]; + ret =bch2_sb_set_downgrade (c, +BCH_VERSION_MINOR (bcachefs_metadata_version_current), +BCH_VERSION_MINOR (c->sb.version)); +if (ret) { +mutex_unlock (&c->sb_lock); + goto err; + } + + passes = ext->recovery_passes_required[0 ] & ~passes; +if (passes) { +prt_str (&buf," running recovery passes: " ); +prt_bitflags (&buf, bch2_recovery_passes, +bch2_recovery_passes_from_stable (le64_to_cpu (passes))); + } + +bch_info (c,"%s" , buf.buf); +printbuf_exit (&buf); + +bch2_sb_maybe_downgrade (c); + write_sb = true; + } +if (check_version_upgrade (c)) write_sb = true;
fs/bcachefs/sb-clean.c +0 -2
@@ -328,8 +328,6 @@ int bch2_fs_mark_dirty(struct bch_fs *c)mutex_lock (&c->sb_lock);SET_BCH_SB_CLEAN (c->disk_sb.sb, false); - -bch2_sb_maybe_downgrade (c); c->disk_sb.sb->features[0 ] |=cpu_to_le64 (BCH_SB_FEATURES_ALWAYS ); ret =bch2_write_super (c);
fs/bcachefs/sb-downgrade.c new file +190 -0
190 lines not on this page · raw message
fs/bcachefs/sb-downgrade.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_SB_DOWNGRADE_H +#define _BCACHEFS_SB_DOWNGRADE_H + +extern const struct bch_sb_field_ops bch_sb_field_ops_downgrade; + +int bch2_sb_downgrade_update (struct bch_fs *); +int bch2_sb_set_downgrade (struct bch_fs *,unsigned ,unsigned ); + +#endif /* _BCACHEFS_SB_DOWNGRADE_H */
fs/bcachefs/sb-errors.c +1 -3
@@ -20,9 +20,7 @@ static void bch2_sb_error_id_to_text(struct printbuf *out, enum bch_sb_error_idstatic inline unsigned bch2_sb_field_errors_nr_entries (struct bch_sb_field_errors *e) { -return e - ? (bch2_sb_field_bytes (&e->field) -sizeof (*e)) /sizeof (e->entries[0 ]) - :0 ; +return bch2_sb_field_nr_entries (e); }static inline unsigned bch2_sb_field_errors_u64s (unsigned nr)
fs/bcachefs/super-io.c +6 -0
@@ -13,6 +13,7 @@#include "replicas.h" #include "quota.h" #include "sb-clean.h" +#include "sb-downgrade.h" #include "sb-errors.h" #include "sb-members.h" #include "super-io.h"
@@ -958,6 +959,7 @@ int bch2_write_super(struct bch_fs *c)bch2_sb_members_from_cpu (c);bch2_sb_members_cpy_v2_v1 (&c->disk_sb);bch2_sb_errors_from_cpu (c); +bch2_sb_downgrade_update (c);for_each_online_member (c, ca)bch2_sb_from_fs (c, ca);
@@ -1114,6 +1116,10 @@ void bch2_sb_upgrade(struct bch_fs *c, unsigned new_version) {lockdep_assert_held (&c->sb_lock); +if (BCH_VERSION_MAJOR (new_version) > +BCH_VERSION_MAJOR (le16_to_cpu (c->disk_sb.sb->version))) +bch2_sb_field_resize (&c->disk_sb, downgrade,0 ); + c->disk_sb.sb->version =cpu_to_le16 (new_version); c->disk_sb.sb->features[0 ] |=cpu_to_le64 (BCH_SB_FEATURES_ALL ); }
Signature · 1 line
2.43.0