dm-io.c (818b930bc15077fc00ff16bb22c5df1857f05afa) dm-io.c (70d6c400acc386ea910c77318688541fc32e7ce8)
1/*
2 * Copyright (C) 2003 Sistina Software
3 * Copyright (C) 2006 Red Hat GmbH
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm.h"

--- 273 unchanged lines hidden (view full) ---

282{
283 struct bio *bio;
284 struct page *page;
285 unsigned long len;
286 unsigned offset;
287 unsigned num_bvecs;
288 sector_t remaining = where->count;
289 struct request_queue *q = bdev_get_queue(where->bdev);
1/*
2 * Copyright (C) 2003 Sistina Software
3 * Copyright (C) 2006 Red Hat GmbH
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm.h"

--- 273 unchanged lines hidden (view full) ---

282{
283 struct bio *bio;
284 struct page *page;
285 unsigned long len;
286 unsigned offset;
287 unsigned num_bvecs;
288 sector_t remaining = where->count;
289 struct request_queue *q = bdev_get_queue(where->bdev);
290 sector_t discard_sectors;
290 unsigned short logical_block_size = queue_logical_block_size(q);
291 sector_t num_sectors;
291
292 /*
293 * where->count may be zero if rw holds a flush and we need to
294 * send a zero-sized flush.
295 */
296 do {
297 /*
298 * Allocate a suitably sized-bio.
299 */
292
293 /*
294 * where->count may be zero if rw holds a flush and we need to
295 * send a zero-sized flush.
296 */
297 do {
298 /*
299 * Allocate a suitably sized-bio.
300 */
300 if (rw & REQ_DISCARD)
301 if ((rw & REQ_DISCARD) || (rw & REQ_WRITE_SAME))
301 num_bvecs = 1;
302 else
303 num_bvecs = min_t(int, bio_get_nr_vecs(where->bdev),
304 dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)));
305
306 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios);
307 bio->bi_sector = where->sector + (where->count - remaining);
308 bio->bi_bdev = where->bdev;
309 bio->bi_end_io = endio;
310 store_io_and_region_in_bio(bio, io, region);
311
312 if (rw & REQ_DISCARD) {
302 num_bvecs = 1;
303 else
304 num_bvecs = min_t(int, bio_get_nr_vecs(where->bdev),
305 dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)));
306
307 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios);
308 bio->bi_sector = where->sector + (where->count - remaining);
309 bio->bi_bdev = where->bdev;
310 bio->bi_end_io = endio;
311 store_io_and_region_in_bio(bio, io, region);
312
313 if (rw & REQ_DISCARD) {
313 discard_sectors = min_t(sector_t, q->limits.max_discard_sectors, remaining);
314 bio->bi_size = discard_sectors << SECTOR_SHIFT;
315 remaining -= discard_sectors;
314 num_sectors = min_t(sector_t, q->limits.max_discard_sectors, remaining);
315 bio->bi_size = num_sectors << SECTOR_SHIFT;
316 remaining -= num_sectors;
317 } else if (rw & REQ_WRITE_SAME) {
318 /*
319 * WRITE SAME only uses a single page.
320 */
321 dp->get_page(dp, &page, &len, &offset);
322 bio_add_page(bio, page, logical_block_size, offset);
323 num_sectors = min_t(sector_t, q->limits.max_write_same_sectors, remaining);
324 bio->bi_size = num_sectors << SECTOR_SHIFT;
325
326 offset = 0;
327 remaining -= num_sectors;
328 dp->next_page(dp);
316 } else while (remaining) {
317 /*
318 * Try and add as many pages as possible.
319 */
320 dp->get_page(dp, &page, &len, &offset);
321 len = min(len, to_bytes(remaining));
322 if (!bio_add_page(bio, page, len, offset))
323 break;

--- 189 unchanged lines hidden ---
329 } else while (remaining) {
330 /*
331 * Try and add as many pages as possible.
332 */
333 dp->get_page(dp, &page, &len, &offset);
334 len = min(len, to_bytes(remaining));
335 if (!bio_add_page(bio, page, len, offset))
336 break;

--- 189 unchanged lines hidden ---