dm-bufio.c (6fbeb0048e6b93f7b7f195864f3ddc876ac4d42e) | dm-bufio.c (88dca4ca5a93d2c09e5bbc6a62fbfc3af83c4fca) |
---|---|
1/* 2 * Copyright (C) 2009-2011 Red Hat, Inc. 3 * 4 * Author: Mikulas Patocka <mpatocka@redhat.com> 5 * 6 * This file is released under the GPL. 7 */ 8 --- 386 unchanged lines hidden (view full) --- 395 * with GFP_KERNEL, no matter what was specified as gfp_mask. 396 * 397 * Consequently, we must set per-process flag PF_MEMALLOC_NOIO so that 398 * all allocations done by this process (including pagetables) are done 399 * as if GFP_NOIO was specified. 400 */ 401 if (gfp_mask & __GFP_NORETRY) { 402 unsigned noio_flag = memalloc_noio_save(); | 1/* 2 * Copyright (C) 2009-2011 Red Hat, Inc. 3 * 4 * Author: Mikulas Patocka <mpatocka@redhat.com> 5 * 6 * This file is released under the GPL. 7 */ 8 --- 386 unchanged lines hidden (view full) --- 395 * with GFP_KERNEL, no matter what was specified as gfp_mask. 396 * 397 * Consequently, we must set per-process flag PF_MEMALLOC_NOIO so that 398 * all allocations done by this process (including pagetables) are done 399 * as if GFP_NOIO was specified. 400 */ 401 if (gfp_mask & __GFP_NORETRY) { 402 unsigned noio_flag = memalloc_noio_save(); |
403 void *ptr = __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL); | 403 void *ptr = __vmalloc(c->block_size, gfp_mask); |
404 405 memalloc_noio_restore(noio_flag); 406 return ptr; 407 } 408 | 404 405 memalloc_noio_restore(noio_flag); 406 return ptr; 407 } 408 |
409 return __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL); | 409 return __vmalloc(c->block_size, gfp_mask); |
410} 411 412/* 413 * Free buffer's data. 414 */ 415static void free_buffer_data(struct dm_bufio_client *c, 416 void *data, unsigned char data_mode) 417{ --- 208 unchanged lines hidden (view full) --- 626 627 len -= this_step; 628 ptr += this_step; 629 } while (len > 0); 630 631 submit_bio(bio); 632} 633 | 410} 411 412/* 413 * Free buffer's data. 414 */ 415static void free_buffer_data(struct dm_bufio_client *c, 416 void *data, unsigned char data_mode) 417{ --- 208 unchanged lines hidden (view full) --- 626 627 len -= this_step; 628 ptr += this_step; 629 } while (len > 0); 630 631 submit_bio(bio); 632} 633 |
634static inline sector_t block_to_sector(struct dm_bufio_client *c, sector_t block) 635{ 636 sector_t sector; 637 638 if (likely(c->sectors_per_block_bits >= 0)) 639 sector = block << c->sectors_per_block_bits; 640 else 641 sector = block * (c->block_size >> SECTOR_SHIFT); 642 sector += c->start; 643 644 return sector; 645} 646 | |
647static void submit_io(struct dm_buffer *b, int rw, void (*end_io)(struct dm_buffer *, blk_status_t)) 648{ 649 unsigned n_sectors; 650 sector_t sector; 651 unsigned offset, end; 652 653 b->end_io = end_io; 654 | 634static void submit_io(struct dm_buffer *b, int rw, void (*end_io)(struct dm_buffer *, blk_status_t)) 635{ 636 unsigned n_sectors; 637 sector_t sector; 638 unsigned offset, end; 639 640 b->end_io = end_io; 641 |
655 sector = block_to_sector(b->c, b->block); | 642 if (likely(b->c->sectors_per_block_bits >= 0)) 643 sector = b->block << b->c->sectors_per_block_bits; 644 else 645 sector = b->block * (b->c->block_size >> SECTOR_SHIFT); 646 sector += b->c->start; |
656 657 if (rw != REQ_OP_WRITE) { 658 n_sectors = b->c->block_size >> SECTOR_SHIFT; 659 offset = 0; 660 } else { 661 if (b->c->write_callback) 662 b->c->write_callback(b); 663 offset = b->write_start; --- 666 unchanged lines hidden (view full) --- 1330 1331 BUG_ON(dm_bufio_in_request()); 1332 1333 return dm_io(&io_req, 1, &io_reg, NULL); 1334} 1335EXPORT_SYMBOL_GPL(dm_bufio_issue_flush); 1336 1337/* | 647 648 if (rw != REQ_OP_WRITE) { 649 n_sectors = b->c->block_size >> SECTOR_SHIFT; 650 offset = 0; 651 } else { 652 if (b->c->write_callback) 653 b->c->write_callback(b); 654 offset = b->write_start; --- 666 unchanged lines hidden (view full) --- 1321 1322 BUG_ON(dm_bufio_in_request()); 1323 1324 return dm_io(&io_req, 1, &io_reg, NULL); 1325} 1326EXPORT_SYMBOL_GPL(dm_bufio_issue_flush); 1327 1328/* |
1338 * Use dm-io to send a discard request to flush the device. 1339 */ 1340int dm_bufio_issue_discard(struct dm_bufio_client *c, sector_t block, sector_t count) 1341{ 1342 struct dm_io_request io_req = { 1343 .bi_op = REQ_OP_DISCARD, 1344 .bi_op_flags = REQ_SYNC, 1345 .mem.type = DM_IO_KMEM, 1346 .mem.ptr.addr = NULL, 1347 .client = c->dm_io, 1348 }; 1349 struct dm_io_region io_reg = { 1350 .bdev = c->bdev, 1351 .sector = block_to_sector(c, block), 1352 .count = block_to_sector(c, count), 1353 }; 1354 1355 BUG_ON(dm_bufio_in_request()); 1356 1357 return dm_io(&io_req, 1, &io_reg, NULL); 1358} 1359EXPORT_SYMBOL_GPL(dm_bufio_issue_discard); 1360 1361/* 1362 * Free the specified range of buffers. If a buffer is held by other process, it 1363 * is not freed. If a buffer is dirty, it is discarded without writeback. 1364 * Finally, send the discard request to the device. 1365 */ 1366int dm_bufio_discard_buffers(struct dm_bufio_client *c, sector_t block, sector_t count) 1367{ 1368 sector_t i; 1369 1370 for (i = block; i < block + count; i++) { 1371 struct dm_buffer *b; 1372 dm_bufio_lock(c); 1373 b = __find(c, i); 1374 if (b && likely(!b->hold_count)) { 1375 wait_on_bit_io(&b->state, B_READING, TASK_UNINTERRUPTIBLE); 1376 wait_on_bit_io(&b->state, B_WRITING, TASK_UNINTERRUPTIBLE); 1377 __unlink_buffer(b); 1378 __free_buffer_wake(b); 1379 } 1380 dm_bufio_unlock(c); 1381 } 1382 1383 return dm_bufio_issue_discard(c, block, count); 1384} 1385EXPORT_SYMBOL_GPL(dm_bufio_discard_buffers); 1386 1387/* | |
1388 * We first delete any other buffer that may be at that new location. 1389 * 1390 * Then, we write the buffer to the original location if it was dirty. 1391 * 1392 * Then, if we are the only one who is holding the buffer, relink the buffer 1393 * in the buffer tree for the new location. 1394 * 1395 * If there was someone else holding the buffer, we write it to the new --- 691 unchanged lines hidden --- | 1329 * We first delete any other buffer that may be at that new location. 1330 * 1331 * Then, we write the buffer to the original location if it was dirty. 1332 * 1333 * Then, if we are the only one who is holding the buffer, relink the buffer 1334 * in the buffer tree for the new location. 1335 * 1336 * If there was someone else holding the buffer, we write it to the new --- 691 unchanged lines hidden --- |