From 6a4f458a4835b37b044927dc7ef44e3b3b5faddd Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 19 Dec 2021 21:55:09 -0500 Subject: [PATCH] fix init_layout() It was incorrectly failing when we did have enough space for the superblocks - >= should have been >. Also, give it a better error message. Signed-off-by: Kent Overstreet --- libbcachefs.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libbcachefs.c b/libbcachefs.c index 85523c62..74a38f83 100644 --- a/libbcachefs.c +++ b/libbcachefs.c @@ -40,6 +40,7 @@ static void init_layout(struct bch_sb_layout *l, unsigned sb_size, u64 sb_start, u64 sb_end) { + u64 sb_pos = sb_start; unsigned i; memset(l, 0, sizeof(*l)); @@ -51,15 +52,16 @@ static void init_layout(struct bch_sb_layout *l, /* Create two superblocks in the allowed range: */ for (i = 0; i < l->nr_superblocks; i++) { - if (sb_start != BCH_SB_SECTOR) - sb_start = round_up(sb_start, block_size); + if (sb_pos != BCH_SB_SECTOR) + sb_pos = round_up(sb_pos, block_size); - l->sb_offset[i] = cpu_to_le64(sb_start); - sb_start += sb_size; + l->sb_offset[i] = cpu_to_le64(sb_pos); + sb_pos += sb_size; } - if (sb_start >= sb_end) - die("insufficient space for superblocks"); + if (sb_pos > sb_end) + die("insufficient space for superblocks: start %llu end %llu > %llu size %u", + sb_start, sb_pos, sb_end, sb_size); } void bch2_pick_bucket_size(struct bch_opts opts, struct dev_opts *dev)