diff options
author | Matthew Wilcox <matthew.r.wilcox@intel.com> | 2015-02-16 18:59:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-16 20:56:04 -0500 |
commit | 25726bc15731d42112b579cf73f30edbc43d3973 (patch) | |
tree | aa8e2d0e7d0e6c92a581c88559b03027fb8f5589 /fs/dax.c | |
parent | 9c3ce9ec58716733232b97771b10f31901caf62e (diff) |
dax: add dax_zero_page_range
This new function allows us to support hole-punch for DAX files by zeroing
a partial page, as opposed to the dax_truncate_page() function which can
only truncate to the end of the page. Reimplement dax_truncate_page() to
call dax_zero_page_range().
[ross.zwisler@linux.intel.com: ported to 3.13-rc2]
[akpm@linux-foundation.org: fix typos in comments]
Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Andreas Dilger <andreas.dilger@intel.com>
Cc: Boaz Harrosh <boaz@plexistor.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/dax.c')
-rw-r--r-- | fs/dax.c | 38 |
1 files changed, 32 insertions, 6 deletions
@@ -464,31 +464,35 @@ int dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf, | |||
464 | EXPORT_SYMBOL_GPL(dax_fault); | 464 | EXPORT_SYMBOL_GPL(dax_fault); |
465 | 465 | ||
466 | /** | 466 | /** |
467 | * dax_truncate_page - handle a partial page being truncated in a DAX file | 467 | * dax_zero_page_range - zero a range within a page of a DAX file |
468 | * @inode: The file being truncated | 468 | * @inode: The file being truncated |
469 | * @from: The file offset that is being truncated to | 469 | * @from: The file offset that is being truncated to |
470 | * @length: The number of bytes to zero | ||
470 | * @get_block: The filesystem method used to translate file offsets to blocks | 471 | * @get_block: The filesystem method used to translate file offsets to blocks |
471 | * | 472 | * |
472 | * Similar to block_truncate_page(), this function can be called by a | 473 | * This function can be called by a filesystem when it is zeroing part of a |
473 | * filesystem when it is truncating an DAX file to handle the partial page. | 474 | * page in a DAX file. This is intended for hole-punch operations. If |
475 | * you are truncating a file, the helper function dax_truncate_page() may be | ||
476 | * more convenient. | ||
474 | * | 477 | * |
475 | * We work in terms of PAGE_CACHE_SIZE here for commonality with | 478 | * We work in terms of PAGE_CACHE_SIZE here for commonality with |
476 | * block_truncate_page(), but we could go down to PAGE_SIZE if the filesystem | 479 | * block_truncate_page(), but we could go down to PAGE_SIZE if the filesystem |
477 | * took care of disposing of the unnecessary blocks. Even if the filesystem | 480 | * took care of disposing of the unnecessary blocks. Even if the filesystem |
478 | * block size is smaller than PAGE_SIZE, we have to zero the rest of the page | 481 | * block size is smaller than PAGE_SIZE, we have to zero the rest of the page |
479 | * since the file might be mmaped. | 482 | * since the file might be mmapped. |
480 | */ | 483 | */ |
481 | int dax_truncate_page(struct inode *inode, loff_t from, get_block_t get_block) | 484 | int dax_zero_page_range(struct inode *inode, loff_t from, unsigned length, |
485 | get_block_t get_block) | ||
482 | { | 486 | { |
483 | struct buffer_head bh; | 487 | struct buffer_head bh; |
484 | pgoff_t index = from >> PAGE_CACHE_SHIFT; | 488 | pgoff_t index = from >> PAGE_CACHE_SHIFT; |
485 | unsigned offset = from & (PAGE_CACHE_SIZE-1); | 489 | unsigned offset = from & (PAGE_CACHE_SIZE-1); |
486 | unsigned length = PAGE_CACHE_ALIGN(from) - from; | ||
487 | int err; | 490 | int err; |
488 | 491 | ||
489 | /* Block boundary? Nothing to do */ | 492 | /* Block boundary? Nothing to do */ |
490 | if (!length) | 493 | if (!length) |
491 | return 0; | 494 | return 0; |
495 | BUG_ON((offset + length) > PAGE_CACHE_SIZE); | ||
492 | 496 | ||
493 | memset(&bh, 0, sizeof(bh)); | 497 | memset(&bh, 0, sizeof(bh)); |
494 | bh.b_size = PAGE_CACHE_SIZE; | 498 | bh.b_size = PAGE_CACHE_SIZE; |
@@ -505,4 +509,26 @@ int dax_truncate_page(struct inode *inode, loff_t from, get_block_t get_block) | |||
505 | 509 | ||
506 | return 0; | 510 | return 0; |
507 | } | 511 | } |
512 | EXPORT_SYMBOL_GPL(dax_zero_page_range); | ||
513 | |||
514 | /** | ||
515 | * dax_truncate_page - handle a partial page being truncated in a DAX file | ||
516 | * @inode: The file being truncated | ||
517 | * @from: The file offset that is being truncated to | ||
518 | * @get_block: The filesystem method used to translate file offsets to blocks | ||
519 | * | ||
520 | * Similar to block_truncate_page(), this function can be called by a | ||
521 | * filesystem when it is truncating a DAX file to handle the partial page. | ||
522 | * | ||
523 | * We work in terms of PAGE_CACHE_SIZE here for commonality with | ||
524 | * block_truncate_page(), but we could go down to PAGE_SIZE if the filesystem | ||
525 | * took care of disposing of the unnecessary blocks. Even if the filesystem | ||
526 | * block size is smaller than PAGE_SIZE, we have to zero the rest of the page | ||
527 | * since the file might be mmapped. | ||
528 | */ | ||
529 | int dax_truncate_page(struct inode *inode, loff_t from, get_block_t get_block) | ||
530 | { | ||
531 | unsigned length = PAGE_CACHE_ALIGN(from) - from; | ||
532 | return dax_zero_page_range(inode, from, length, get_block); | ||
533 | } | ||
508 | EXPORT_SYMBOL_GPL(dax_truncate_page); | 534 | EXPORT_SYMBOL_GPL(dax_truncate_page); |