Commit 84f16387 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: bch_sb_field_downgrade



Add 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.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 8b16413c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ bcachefs-y := \
	reflink.o		\
	replicas.o		\
	sb-clean.o		\
	sb-downgrade.o		\
	sb-errors.o		\
	sb-members.o		\
	siphash.o		\
+19 −1
Original line number Diff line number Diff line
@@ -1220,7 +1220,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,
@@ -1638,6 +1639,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: */

/*
@@ -1651,6 +1664,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)					\
+2 −0
Original line number Diff line number Diff line
@@ -95,6 +95,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)			\
+23 −1
Original line number Diff line number Diff line
@@ -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"
@@ -744,6 +745,27 @@ int bch2_fs_recovery(struct bch_fs *c)
			printbuf_exit(&buf);
		}

		if (bch2_check_version_downgrade(c)) {
			struct printbuf buf = PRINTBUF;

			prt_str(&buf, "Version downgrade required:\n");

			__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, "  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);
			write_sb = true;
		}

		if (check_version_upgrade(c))
			write_sb = true;

@@ -1022,7 +1044,7 @@ int bch2_fs_initialize(struct bch_fs *c)
	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);

	bch2_sb_maybe_downgrade(c);
	bch2_check_version_downgrade(c);

	if (c->opts.version_upgrade != BCH_VERSION_UPGRADE_none) {
		bch2_sb_upgrade(c, bcachefs_metadata_version_current);
+0 −2
Original line number Diff line number Diff line
@@ -332,8 +332,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);
Loading