Commit c4e382e2 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Convert journal validation to bkey_invalid_flags

This fixes a bug where we were already passing bkey_invalid_flags
around, but treating the parameter as just read/write - so the compat
code wasn't being run correctly.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a8712967
......@@ -242,7 +242,7 @@ static void journal_entry_err_msg(struct printbuf *out,
journal_entry_err_msg(&buf, version, jset, entry); \
prt_printf(&buf, msg, ##__VA_ARGS__); \
\
switch (write) { \
switch (flags & BKEY_INVALID_WRITE) { \
case READ: \
mustfix_fsck_err(c, "%s", buf.buf); \
break; \
......@@ -269,8 +269,10 @@ static int journal_validate_key(struct bch_fs *c,
struct jset_entry *entry,
unsigned level, enum btree_id btree_id,
struct bkey_i *k,
unsigned version, int big_endian, int write)
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
int write = flags & BKEY_INVALID_WRITE;
void *next = vstruct_next(entry);
struct printbuf buf = PRINTBUF;
int ret = 0;
......@@ -316,6 +318,7 @@ static int journal_validate_key(struct bch_fs *c,
__btree_node_type(level, btree_id), write, &buf);
mustfix_fsck_err(c, "%s", buf.buf);
BUG();
le16_add_cpu(&entry->u64s, -((u16) k->k.u64s));
memmove(k, bkey_next(k), next - (void *) bkey_next(k));
......@@ -334,9 +337,10 @@ static int journal_validate_key(struct bch_fs *c,
}
static int journal_entry_btree_keys_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct bkey_i *k = entry->start;
......@@ -345,7 +349,7 @@ static int journal_entry_btree_keys_validate(struct bch_fs *c,
entry->level,
entry->btree_id,
k, version, big_endian,
write|BKEY_INVALID_JOURNAL);
flags|BKEY_INVALID_JOURNAL);
if (ret == FSCK_DELETED_KEY)
continue;
......@@ -373,9 +377,10 @@ static void journal_entry_btree_keys_to_text(struct printbuf *out, struct bch_fs
}
static int journal_entry_btree_root_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct bkey_i *k = entry->start;
int ret = 0;
......@@ -396,7 +401,7 @@ static int journal_entry_btree_root_validate(struct bch_fs *c,
}
return journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
version, big_endian, write);
version, big_endian, flags);
fsck_err:
return ret;
}
......@@ -408,9 +413,10 @@ static void journal_entry_btree_root_to_text(struct printbuf *out, struct bch_fs
}
static int journal_entry_prio_ptrs_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
/* obsolete, don't care: */
return 0;
......@@ -422,9 +428,10 @@ static void journal_entry_prio_ptrs_to_text(struct printbuf *out, struct bch_fs
}
static int journal_entry_blacklist_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
int ret = 0;
......@@ -447,9 +454,10 @@ static void journal_entry_blacklist_to_text(struct printbuf *out, struct bch_fs
}
static int journal_entry_blacklist_v2_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct jset_entry_blacklist_v2 *bl_entry;
int ret = 0;
......@@ -486,9 +494,10 @@ static void journal_entry_blacklist_v2_to_text(struct printbuf *out, struct bch_
}
static int journal_entry_usage_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct jset_entry_usage *u =
container_of(entry, struct jset_entry_usage, entry);
......@@ -518,9 +527,10 @@ static void journal_entry_usage_to_text(struct printbuf *out, struct bch_fs *c,
}
static int journal_entry_data_usage_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct jset_entry_data_usage *u =
container_of(entry, struct jset_entry_data_usage, entry);
......@@ -550,9 +560,10 @@ static void journal_entry_data_usage_to_text(struct printbuf *out, struct bch_fs
}
static int journal_entry_clock_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct jset_entry_clock *clock =
container_of(entry, struct jset_entry_clock, entry);
......@@ -585,9 +596,10 @@ static void journal_entry_clock_to_text(struct printbuf *out, struct bch_fs *c,
}
static int journal_entry_dev_usage_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
struct jset_entry_dev_usage *u =
container_of(entry, struct jset_entry_dev_usage, entry);
......@@ -645,9 +657,10 @@ static void journal_entry_dev_usage_to_text(struct printbuf *out, struct bch_fs
}
static int journal_entry_log_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
return 0;
}
......@@ -662,9 +675,10 @@ static void journal_entry_log_to_text(struct printbuf *out, struct bch_fs *c,
}
static int journal_entry_overwrite_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
return journal_entry_btree_keys_validate(c, jset, entry,
version, big_endian, READ);
......@@ -678,7 +692,8 @@ static void journal_entry_overwrite_to_text(struct printbuf *out, struct bch_fs
struct jset_entry_ops {
int (*validate)(struct bch_fs *, struct jset *,
struct jset_entry *, unsigned, int, int);
struct jset_entry *, unsigned, int,
enum bkey_invalid_flags);
void (*to_text)(struct printbuf *, struct bch_fs *, struct jset_entry *);
};
......@@ -695,11 +710,12 @@ static const struct jset_entry_ops bch2_jset_entry_ops[] = {
int bch2_journal_entry_validate(struct bch_fs *c,
struct jset *jset,
struct jset_entry *entry,
unsigned version, int big_endian, int write)
unsigned version, int big_endian,
enum bkey_invalid_flags flags)
{
return entry->type < BCH_JSET_ENTRY_NR
? bch2_jset_entry_ops[entry->type].validate(c, jset, entry,
version, big_endian, write)
version, big_endian, flags)
: 0;
}
......@@ -715,7 +731,7 @@ void bch2_journal_entry_to_text(struct printbuf *out, struct bch_fs *c,
}
static int jset_validate_entries(struct bch_fs *c, struct jset *jset,
int write)
enum bkey_invalid_flags flags)
{
struct jset_entry *entry;
unsigned version = le32_to_cpu(jset->version);
......@@ -730,7 +746,7 @@ static int jset_validate_entries(struct bch_fs *c, struct jset *jset,
}
ret = bch2_journal_entry_validate(c, jset, entry,
version, JSET_BIG_ENDIAN(jset), write);
version, JSET_BIG_ENDIAN(jset), flags);
if (ret)
break;
}
......@@ -741,7 +757,7 @@ static int jset_validate_entries(struct bch_fs *c, struct jset *jset,
static int jset_validate(struct bch_fs *c,
struct bch_dev *ca,
struct jset *jset, u64 sector,
int write)
enum bkey_invalid_flags flags)
{
unsigned version;
int ret = 0;
......@@ -780,7 +796,7 @@ static int jset_validate(struct bch_fs *c,
return JOURNAL_ENTRY_BAD;
}
ret = jset_validate_entries(c, jset, write);
ret = jset_validate_entries(c, jset, flags);
fsck_err:
return ret;
}
......@@ -793,7 +809,7 @@ static int jset_validate_early(struct bch_fs *c,
{
size_t bytes = vstruct_bytes(jset);
unsigned version;
int write = READ;
enum bkey_invalid_flags flags = BKEY_INVALID_JOURNAL;
int ret = 0;
if (le64_to_cpu(jset->magic) != jset_magic(c))
......@@ -1133,7 +1149,7 @@ int bch2_journal_read(struct bch_fs *c,
* those entries will be blacklisted:
*/
genradix_for_each_reverse(&c->journal_entries, radix_iter, _i) {
int write = READ;
enum bkey_invalid_flags flags = BKEY_INVALID_JOURNAL;
i = *_i;
......
......@@ -50,7 +50,8 @@ static inline struct jset_entry *__jset_entry_type_next(struct jset *jset,
jset_entry_for_each_key(entry, k)
int bch2_journal_entry_validate(struct bch_fs *, struct jset *,
struct jset_entry *, unsigned, int, int);
struct jset_entry *, unsigned, int,
enum bkey_invalid_flags);
void bch2_journal_entry_to_text(struct printbuf *, struct bch_fs *,
struct jset_entry *);
......
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