diff options
author | Matthew Wilcox <matthew.r.wilcox@intel.com> | 2015-02-16 18:59:06 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-16 20:56:03 -0500 |
commit | 4c0ccfef2e9f7418a6eb0bf07a2fc8f216365b18 (patch) | |
tree | ca1c0bebddf210eab5e5428bb0416d6bfc71495b /fs/dax.c | |
parent | f7ca90b160307d63aaedab8bd451c24a182db20f (diff) |
dax,ext2: replace xip_truncate_page with dax_truncate_page
It takes a get_block parameter just like nobh_truncate_page() and
block_truncate_page()
Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.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: Randy Dunlap <rdunlap@infradead.org>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
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 | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -462,3 +462,47 @@ int dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf, | |||
462 | return result; | 462 | return result; |
463 | } | 463 | } |
464 | EXPORT_SYMBOL_GPL(dax_fault); | 464 | EXPORT_SYMBOL_GPL(dax_fault); |
465 | |||
466 | /** | ||
467 | * dax_truncate_page - handle a partial page being truncated in a DAX file | ||
468 | * @inode: The file being truncated | ||
469 | * @from: The file offset that is being truncated to | ||
470 | * @get_block: The filesystem method used to translate file offsets to blocks | ||
471 | * | ||
472 | * Similar to block_truncate_page(), this function can be called by a | ||
473 | * filesystem when it is truncating an DAX file to handle the partial page. | ||
474 | * | ||
475 | * 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 | ||
477 | * 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 | ||
479 | * since the file might be mmaped. | ||
480 | */ | ||
481 | int dax_truncate_page(struct inode *inode, loff_t from, get_block_t get_block) | ||
482 | { | ||
483 | struct buffer_head bh; | ||
484 | pgoff_t index = from >> PAGE_CACHE_SHIFT; | ||
485 | unsigned offset = from & (PAGE_CACHE_SIZE-1); | ||
486 | unsigned length = PAGE_CACHE_ALIGN(from) - from; | ||
487 | int err; | ||
488 | |||
489 | /* Block boundary? Nothing to do */ | ||
490 | if (!length) | ||
491 | return 0; | ||
492 | |||
493 | memset(&bh, 0, sizeof(bh)); | ||
494 | bh.b_size = PAGE_CACHE_SIZE; | ||
495 | err = get_block(inode, index, &bh, 0); | ||
496 | if (err < 0) | ||
497 | return err; | ||
498 | if (buffer_written(&bh)) { | ||
499 | void *addr; | ||
500 | err = dax_get_addr(&bh, &addr, inode->i_blkbits); | ||
501 | if (err < 0) | ||
502 | return err; | ||
503 | memset(addr + offset, 0, length); | ||
504 | } | ||
505 | |||
506 | return 0; | ||
507 | } | ||
508 | EXPORT_SYMBOL_GPL(dax_truncate_page); | ||