From: Milan Broz <mbroz@redhat.com> Subject: [RHEL5.1 PATCH] dm io: fix panic on large request Date: Wed, 23 May 2007 13:58:17 +0200 Bugzilla: 240751 Message-Id: <46542C59.9040308@redhat.com> Changelog: [md] dm io: fix panic on large request RHEL5.1 dm io: panic on large request Resolves: rhbz#240751 Patch is upstream in -mm tree. When creating large (>6TB) dm/lvm mirror volume, bio_alloc_bioset() will return NULL ('num_vecs' is too large). Fix by use bio_get_nr_vecs() to get estimation of maximum number. Tested with simulated big mirror creation request (reproducer script on bugzilla). --- drivers/md/dm-io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) Index: linux-2.6.18/drivers/md/dm-io.c =================================================================== --- linux-2.6.18.orig/drivers/md/dm-io.c 2007-05-21 15:53:01.000000000 +0200 +++ linux-2.6.18/drivers/md/dm-io.c 2007-05-21 16:21:33.000000000 +0200 @@ -357,7 +357,9 @@ static void do_region(int rw, unsigned i * bvec for bio_get/set_region() and decrement bi_max_vecs * to hide it from bio_add_page(). */ - num_bvecs = (remaining / (PAGE_SIZE >> SECTOR_SHIFT)) + 2; + num_bvecs = dm_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)); + num_bvecs = 1 + min_t(int, bio_get_nr_vecs(where->bdev), + num_bvecs); bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, bios(io->client)); bio->bi_sector = where->sector + (where->count - remaining); bio->bi_bdev = where->bdev;