bcachefs: Handle ec_buf not being page aligned when allocating bio
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 22 Aug 2019 20:41:50 +0000 (16:41 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:25 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/io.c

index 5db83374403b83534f4c46925c2695a94d57146a..117d1faa99f2e4a56506013cc3f288f4603ffa5a 100644 (file)
@@ -461,7 +461,10 @@ static struct bio *bch2_write_bio_alloc(struct bch_fs *c,
        struct bio *bio;
        unsigned output_available =
                min(wp->sectors_free << 9, src->bi_iter.bi_size);
-       unsigned pages = DIV_ROUND_UP(output_available, PAGE_SIZE);
+       unsigned pages = DIV_ROUND_UP(output_available +
+                                     (buf
+                                      ? ((unsigned long) buf & (PAGE_SIZE - 1))
+                                      : 0), PAGE_SIZE);
 
        bio = bio_alloc_bioset(NULL, pages, 0,
                               GFP_NOIO, &c->bio_write);