aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <matthew.r.wilcox@intel.com>2015-02-16 18:59:06 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-16 20:56:03 -0500
commit4c0ccfef2e9f7418a6eb0bf07a2fc8f216365b18 (patch)
treeca1c0bebddf210eab5e5428bb0416d6bfc71495b
parentf7ca90b160307d63aaedab8bd451c24a182db20f (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>
-rw-r--r--fs/dax.c44
-rw-r--r--fs/ext2/inode.c2
-rw-r--r--include/linux/fs.h10
-rw-r--r--mm/filemap_xip.c40
4 files changed, 46 insertions, 50 deletions
diff --git a/fs/dax.c b/fs/dax.c
index 553e55b93495..ebf9b2231b0f 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -462,3 +462,47 @@ int dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf,
462 return result; 462 return result;
463} 463}
464EXPORT_SYMBOL_GPL(dax_fault); 464EXPORT_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 */
481int 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}
508EXPORT_SYMBOL_GPL(dax_truncate_page);
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 52978b853226..5ac0a3461b3c 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1210,7 +1210,7 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)
1210 inode_dio_wait(inode); 1210 inode_dio_wait(inode);
1211 1211
1212 if (IS_DAX(inode)) 1212 if (IS_DAX(inode))
1213 error = xip_truncate_page(inode->i_mapping, newsize); 1213 error = dax_truncate_page(inode, newsize, ext2_get_block);
1214 else if (test_opt(inode->i_sb, NOBH)) 1214 else if (test_opt(inode->i_sb, NOBH))
1215 error = nobh_truncate_page(inode->i_mapping, 1215 error = nobh_truncate_page(inode->i_mapping,
1216 newsize, ext2_get_block); 1216 newsize, ext2_get_block);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6bad6d4c579b..2c8f9055af38 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2591,18 +2591,10 @@ extern int nonseekable_open(struct inode * inode, struct file * filp);
2591ssize_t dax_do_io(int rw, struct kiocb *, struct inode *, struct iov_iter *, 2591ssize_t dax_do_io(int rw, struct kiocb *, struct inode *, struct iov_iter *,
2592 loff_t, get_block_t, dio_iodone_t, int flags); 2592 loff_t, get_block_t, dio_iodone_t, int flags);
2593int dax_clear_blocks(struct inode *, sector_t block, long size); 2593int dax_clear_blocks(struct inode *, sector_t block, long size);
2594int dax_truncate_page(struct inode *, loff_t from, get_block_t);
2594int dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t); 2595int dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t);
2595#define dax_mkwrite(vma, vmf, gb) dax_fault(vma, vmf, gb) 2596#define dax_mkwrite(vma, vmf, gb) dax_fault(vma, vmf, gb)
2596 2597
2597#ifdef CONFIG_FS_XIP
2598extern int xip_truncate_page(struct address_space *mapping, loff_t from);
2599#else
2600static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
2601{
2602 return 0;
2603}
2604#endif
2605
2606#ifdef CONFIG_BLOCK 2598#ifdef CONFIG_BLOCK
2607typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode, 2599typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,
2608 loff_t file_offset); 2600 loff_t file_offset);
diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index 59fb387b2238..8e3f99b61959 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -22,43 +22,3 @@
22#include <asm/tlbflush.h> 22#include <asm/tlbflush.h>
23#include <asm/io.h> 23#include <asm/io.h>
24 24
25/*
26 * truncate a page used for execute in place
27 * functionality is analog to block_truncate_page but does use get_xip_mem
28 * to get the page instead of page cache
29 */
30int
31xip_truncate_page(struct address_space *mapping, loff_t from)
32{
33 pgoff_t index = from >> PAGE_CACHE_SHIFT;
34 unsigned offset = from & (PAGE_CACHE_SIZE-1);
35 unsigned blocksize;
36 unsigned length;
37 void *xip_mem;
38 unsigned long xip_pfn;
39 int err;
40
41 BUG_ON(!mapping->a_ops->get_xip_mem);
42
43 blocksize = 1 << mapping->host->i_blkbits;
44 length = offset & (blocksize - 1);
45
46 /* Block boundary? Nothing to do */
47 if (!length)
48 return 0;
49
50 length = blocksize - length;
51
52 err = mapping->a_ops->get_xip_mem(mapping, index, 0,
53 &xip_mem, &xip_pfn);
54 if (unlikely(err)) {
55 if (err == -ENODATA)
56 /* Hole? No need to truncate */
57 return 0;
58 else
59 return err;
60 }
61 memset(xip_mem + offset, 0, length);
62 return 0;
63}
64EXPORT_SYMBOL_GPL(xip_truncate_page);