aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMilan Broz <mbroz@redhat.com>2012-03-07 14:09:37 -0500
committerAlasdair G Kergon <agk@redhat.com>2012-03-07 14:09:37 -0500
commit0c535e0d6f463365c29623350dbd91642363c39b (patch)
tree33217f386886b01e5a033ac8c0cf5fb46f5c3464 /drivers
parent902c6a96a7cb9c50d2a8aed1788efad0a5d8f04c (diff)
dm io: fix discard support
This patch fixes a crash by recognising discards in dm_io. Currently dm_mirror can send REQ_DISCARD bios if running over a discard-enabled device and without support in dm_io the system crashes badly. BUG: unable to handle kernel paging request at 00800000 IP: __bio_add_page.part.17+0xf5/0x1e0 ... bio_add_page+0x56/0x70 dispatch_io+0x1cf/0x240 [dm_mod] ? km_get_page+0x50/0x50 [dm_mod] ? vm_next_page+0x20/0x20 [dm_mod] ? mirror_flush+0x130/0x130 [dm_mirror] dm_io+0xdc/0x2b0 [dm_mod] ... Introduced in 2.6.38-rc1 by commit 5fc2ffeabb9ee0fc0e71ff16b49f34f0ed3d05b4 (dm raid1: support discard). Signed-off-by: Milan Broz <mbroz@redhat.com> Cc: stable@kernel.org Acked-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/dm-io.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index ad2eba40e319..ea5dd289fe2a 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -296,6 +296,8 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
296 unsigned offset; 296 unsigned offset;
297 unsigned num_bvecs; 297 unsigned num_bvecs;
298 sector_t remaining = where->count; 298 sector_t remaining = where->count;
299 struct request_queue *q = bdev_get_queue(where->bdev);
300 sector_t discard_sectors;
299 301
300 /* 302 /*
301 * where->count may be zero if rw holds a flush and we need to 303 * where->count may be zero if rw holds a flush and we need to
@@ -305,9 +307,12 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
305 /* 307 /*
306 * Allocate a suitably sized-bio. 308 * Allocate a suitably sized-bio.
307 */ 309 */
308 num_bvecs = dm_sector_div_up(remaining, 310 if (rw & REQ_DISCARD)
309 (PAGE_SIZE >> SECTOR_SHIFT)); 311 num_bvecs = 1;
310 num_bvecs = min_t(int, bio_get_nr_vecs(where->bdev), num_bvecs); 312 else
313 num_bvecs = min_t(int, bio_get_nr_vecs(where->bdev),
314 dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)));
315
311 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios); 316 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios);
312 bio->bi_sector = where->sector + (where->count - remaining); 317 bio->bi_sector = where->sector + (where->count - remaining);
313 bio->bi_bdev = where->bdev; 318 bio->bi_bdev = where->bdev;
@@ -315,10 +320,14 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
315 bio->bi_destructor = dm_bio_destructor; 320 bio->bi_destructor = dm_bio_destructor;
316 store_io_and_region_in_bio(bio, io, region); 321 store_io_and_region_in_bio(bio, io, region);
317 322
318 /* 323 if (rw & REQ_DISCARD) {
319 * Try and add as many pages as possible. 324 discard_sectors = min_t(sector_t, q->limits.max_discard_sectors, remaining);
320 */ 325 bio->bi_size = discard_sectors << SECTOR_SHIFT;
321 while (remaining) { 326 remaining -= discard_sectors;
327 } else while (remaining) {
328 /*
329 * Try and add as many pages as possible.
330 */
322 dp->get_page(dp, &page, &len, &offset); 331 dp->get_page(dp, &page, &len, &offset);
323 len = min(len, to_bytes(remaining)); 332 len = min(len, to_bytes(remaining));
324 if (!bio_add_page(bio, page, len, offset)) 333 if (!bio_add_page(bio, page, len, offset))