Commit e3804b55 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_version_to_text()

Add a new helper for printing out metadata versions in a standard
format.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f33c58fc
...@@ -11,11 +11,6 @@ ...@@ -11,11 +11,6 @@
#define x(t, n) [n] = #t, #define x(t, n) [n] = #t,
const char * const bch2_metadata_versions[] = {
BCH_METADATA_VERSIONS()
NULL
};
const char * const bch2_error_actions[] = { const char * const bch2_error_actions[] = {
BCH_ERROR_ACTIONS() BCH_ERROR_ACTIONS()
NULL NULL
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include "bcachefs_format.h" #include "bcachefs_format.h"
extern const char * const bch2_metadata_versions[];
extern const char * const bch2_error_actions[]; extern const char * const bch2_error_actions[];
extern const char * const bch2_sb_features[]; extern const char * const bch2_sb_features[];
extern const char * const bch2_sb_compat[]; extern const char * const bch2_sb_compat[];
......
...@@ -1146,17 +1146,22 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1146,17 +1146,22 @@ int bch2_fs_recovery(struct bch_fs *c)
goto err; goto err;
} }
if (!c->opts.nochanges) { if (!c->opts.nochanges &&
if (c->sb.version < bcachefs_metadata_required_upgrade_below) { c->sb.version < bcachefs_metadata_required_upgrade_below) {
bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required", struct printbuf buf = PRINTBUF;
bch2_metadata_versions[c->sb.version],
c->sb.version, prt_str(&buf, "version ");
bch2_metadata_versions[bcachefs_metadata_required_upgrade_below], bch2_version_to_text(&buf, c->sb.version);
bcachefs_metadata_required_upgrade_below); prt_str(&buf, " prior to ");
c->opts.version_upgrade = true; bch2_version_to_text(&buf, bcachefs_metadata_required_upgrade_below);
c->opts.fsck = true; prt_str(&buf, ", upgrade and fsck required");
c->opts.fix_errors = FSCK_OPT_YES;
} bch_info(c, "%s", buf.buf);
printbuf_exit(&buf);
c->opts.version_upgrade = true;
c->opts.fsck = true;
c->opts.fix_errors = FSCK_OPT_YES;
} }
if (c->opts.fsck && c->opts.norecovery) { if (c->opts.fsck && c->opts.norecovery) {
......
...@@ -26,6 +26,21 @@ ...@@ -26,6 +26,21 @@
static const struct blk_holder_ops bch2_sb_handle_bdev_ops = { static const struct blk_holder_ops bch2_sb_handle_bdev_ops = {
}; };
static const char * const bch2_metadata_versions[] = {
#define x(t, n) [n] = #t,
BCH_METADATA_VERSIONS()
#undef x
};
void bch2_version_to_text(struct printbuf *out, unsigned v)
{
const char *str = v < ARRAY_SIZE(bch2_metadata_versions)
? bch2_metadata_versions[v]
: "(unknown version)";
prt_printf(out, "%u: %s", v, str);
}
const char * const bch2_sb_fields[] = { const char * const bch2_sb_fields[] = {
#define x(name, nr) #name, #define x(name, nr) #name,
BCH_SB_FIELDS() BCH_SB_FIELDS()
...@@ -1510,12 +1525,12 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1510,12 +1525,12 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
prt_str(out, "Version:"); prt_str(out, "Version:");
prt_tab(out); prt_tab(out);
prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version)]); bch2_version_to_text(out, le16_to_cpu(sb->version));
prt_newline(out); prt_newline(out);
prt_printf(out, "Oldest version on disk:"); prt_printf(out, "Oldest version on disk:");
prt_tab(out); prt_tab(out);
prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version_min)]); bch2_version_to_text(out, le16_to_cpu(sb->version_min));
prt_newline(out); prt_newline(out);
prt_printf(out, "Created:"); prt_printf(out, "Created:");
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <asm/byteorder.h> #include <asm/byteorder.h>
void bch2_version_to_text(struct printbuf *, unsigned);
struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type); struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type);
struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *, struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *,
enum bch_sb_field_type, unsigned); enum bch_sb_field_type, unsigned);
......
...@@ -877,7 +877,8 @@ static void print_mount_opts(struct bch_fs *c) ...@@ -877,7 +877,8 @@ static void print_mount_opts(struct bch_fs *c)
struct printbuf p = PRINTBUF; struct printbuf p = PRINTBUF;
bool first = true; bool first = true;
prt_printf(&p, "mounted version=%s", bch2_metadata_versions[c->sb.version]); prt_str(&p, "mounted version ");
bch2_version_to_text(&p, c->sb.version);
if (c->opts.read_only) { if (c->opts.read_only) {
prt_str(&p, " opts="); prt_str(&p, " opts=");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment