mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
bcachefs: Fix misaligned bucket check in journal space calculations
Fix an assertion pop in the tiering_misaligned test: rounding down to bucket size at the end of the journal space calculations leaves cur_entry_sectors == 0, which is incorrect with !cur_entry_err. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
813825d241
commit
f54b2a80d0
1 changed files with 10 additions and 9 deletions
|
@ -83,18 +83,20 @@ static struct journal_space
|
||||||
journal_dev_space_available(struct journal *j, struct bch_dev *ca,
|
journal_dev_space_available(struct journal *j, struct bch_dev *ca,
|
||||||
enum journal_space_from from)
|
enum journal_space_from from)
|
||||||
{
|
{
|
||||||
|
struct bch_fs *c = container_of(j, struct bch_fs, journal);
|
||||||
struct journal_device *ja = &ca->journal;
|
struct journal_device *ja = &ca->journal;
|
||||||
unsigned sectors, buckets, unwritten;
|
unsigned sectors, buckets, unwritten;
|
||||||
|
unsigned bucket_size_aligned = round_down(ca->mi.bucket_size, block_sectors(c));
|
||||||
u64 seq;
|
u64 seq;
|
||||||
|
|
||||||
if (from == journal_space_total)
|
if (from == journal_space_total)
|
||||||
return (struct journal_space) {
|
return (struct journal_space) {
|
||||||
.next_entry = ca->mi.bucket_size,
|
.next_entry = bucket_size_aligned,
|
||||||
.total = ca->mi.bucket_size * ja->nr,
|
.total = bucket_size_aligned * ja->nr,
|
||||||
};
|
};
|
||||||
|
|
||||||
buckets = bch2_journal_dev_buckets_available(j, ja, from);
|
buckets = bch2_journal_dev_buckets_available(j, ja, from);
|
||||||
sectors = ja->sectors_free;
|
sectors = round_down(ja->sectors_free, block_sectors(c));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We that we don't allocate the space for a journal entry
|
* We that we don't allocate the space for a journal entry
|
||||||
|
@ -109,7 +111,7 @@ journal_dev_space_available(struct journal *j, struct bch_dev *ca,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* entry won't fit on this device, skip: */
|
/* entry won't fit on this device, skip: */
|
||||||
if (unwritten > ca->mi.bucket_size)
|
if (unwritten > bucket_size_aligned)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (unwritten >= sectors) {
|
if (unwritten >= sectors) {
|
||||||
|
@ -119,7 +121,7 @@ journal_dev_space_available(struct journal *j, struct bch_dev *ca,
|
||||||
}
|
}
|
||||||
|
|
||||||
buckets--;
|
buckets--;
|
||||||
sectors = ca->mi.bucket_size;
|
sectors = bucket_size_aligned;
|
||||||
}
|
}
|
||||||
|
|
||||||
sectors -= unwritten;
|
sectors -= unwritten;
|
||||||
|
@ -127,12 +129,12 @@ journal_dev_space_available(struct journal *j, struct bch_dev *ca,
|
||||||
|
|
||||||
if (sectors < ca->mi.bucket_size && buckets) {
|
if (sectors < ca->mi.bucket_size && buckets) {
|
||||||
buckets--;
|
buckets--;
|
||||||
sectors = ca->mi.bucket_size;
|
sectors = bucket_size_aligned;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (struct journal_space) {
|
return (struct journal_space) {
|
||||||
.next_entry = sectors,
|
.next_entry = sectors,
|
||||||
.total = sectors + buckets * ca->mi.bucket_size,
|
.total = sectors + buckets * bucket_size_aligned,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +258,7 @@ void bch2_journal_space_available(struct journal *j)
|
||||||
bch2_journal_set_watermark(j);
|
bch2_journal_set_watermark(j);
|
||||||
out:
|
out:
|
||||||
j->cur_entry_sectors = !ret
|
j->cur_entry_sectors = !ret
|
||||||
? round_down(j->space[journal_space_discarded].next_entry,
|
? j->space[journal_space_discarded].next_entry
|
||||||
block_sectors(c))
|
|
||||||
: 0;
|
: 0;
|
||||||
j->cur_entry_error = ret;
|
j->cur_entry_error = ret;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue