Commit 4ede80a9 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Allocator now copes with unaligned buckets



We had a buggy release of bcachefs-tools that wasn't properly aligning
bucket sizes.

We can't ask users to reformat - and it's easy to teach the allocator to
make sure writes are properly aligned.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 387df331
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1425,6 +1425,8 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
	open_bucket_for_each(c, &wp->ptrs, ob, i)
		wp->sectors_free = min(wp->sectors_free, ob->sectors_free);

	wp->sectors_free = rounddown(wp->sectors_free, block_sectors(c));

	BUG_ON(!wp->sectors_free || wp->sectors_free == UINT_MAX);

	return 0;
+3 −1
Original line number Diff line number Diff line
@@ -110,7 +110,9 @@ static inline void bch2_alloc_sectors_done_inlined(struct bch_fs *c, struct writ
	unsigned i;

	open_bucket_for_each(c, &wp->ptrs, ob, i)
		ob_push(c, !ob->sectors_free ? &ptrs : &keep, ob);
		ob_push(c, ob->sectors_free < block_sectors(c)
			? &ptrs
			: &keep, ob);
	wp->ptrs = keep;

	mutex_unlock(&wp->lock);