Commit 98c80d6d authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix bch2_journal_seq_blacklist_add()

The old code correctly handled the case where we were blacklisting a
range that exactly matched an existing entry, but not the case where the
new range partially overlaps an existing entry.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 365f64f3
...@@ -66,6 +66,12 @@ blacklist_entry_try_merge(struct bch_fs *c, ...@@ -66,6 +66,12 @@ blacklist_entry_try_merge(struct bch_fs *c,
return bl; return bl;
} }
static bool bl_entry_contig_or_overlaps(struct journal_seq_blacklist_entry *e,
u64 start, u64 end)
{
return !(end < le64_to_cpu(e->start) || le64_to_cpu(e->end) < start);
}
int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end) int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end)
{ {
struct bch_sb_field_journal_seq_blacklist *bl; struct bch_sb_field_journal_seq_blacklist *bl;
...@@ -76,19 +82,13 @@ int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end) ...@@ -76,19 +82,13 @@ int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end)
bl = bch2_sb_get_journal_seq_blacklist(c->disk_sb.sb); bl = bch2_sb_get_journal_seq_blacklist(c->disk_sb.sb);
nr = blacklist_nr_entries(bl); nr = blacklist_nr_entries(bl);
if (bl) {
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct journal_seq_blacklist_entry *e = struct journal_seq_blacklist_entry *e =
bl->start + i; bl->start + i;
if (start == le64_to_cpu(e->start) && if (bl_entry_contig_or_overlaps(e, start, end)) {
end == le64_to_cpu(e->end)) e->start = cpu_to_le64(min(start, le64_to_cpu(e->start)));
goto out; e->end = cpu_to_le64(max(end, le64_to_cpu(e->end)));
if (start <= le64_to_cpu(e->start) &&
end >= le64_to_cpu(e->end)) {
e->start = cpu_to_le64(start);
e->end = cpu_to_le64(end);
if (i + 1 < nr) if (i + 1 < nr)
bl = blacklist_entry_try_merge(c, bl = blacklist_entry_try_merge(c,
...@@ -99,7 +99,6 @@ int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end) ...@@ -99,7 +99,6 @@ int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end)
goto out_write_sb; goto out_write_sb;
} }
} }
}
bl = bch2_sb_resize_journal_seq_blacklist(&c->disk_sb, bl = bch2_sb_resize_journal_seq_blacklist(&c->disk_sb,
sb_blacklist_u64s(nr + 1)); sb_blacklist_u64s(nr + 1));
......
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