dax,ext2: replace the XIP page fault handler with the DAX page fault handler
[firefly-linux-kernel-4.4.55.git] / fs / ext2 / xip.c
1 /*
2  *  linux/fs/ext2/xip.c
3  *
4  * Copyright (C) 2005 IBM Corporation
5  * Author: Carsten Otte (cotte@de.ibm.com)
6  */
7
8 #include <linux/mm.h>
9 #include <linux/fs.h>
10 #include <linux/genhd.h>
11 #include <linux/buffer_head.h>
12 #include <linux/blkdev.h>
13 #include "ext2.h"
14 #include "xip.h"
15
16 static inline long __inode_direct_access(struct inode *inode, sector_t block,
17                                 void **kaddr, unsigned long *pfn, long size)
18 {
19         struct block_device *bdev = inode->i_sb->s_bdev;
20         sector_t sector = block * (PAGE_SIZE / 512);
21         return bdev_direct_access(bdev, sector, kaddr, pfn, size);
22 }
23
24 static inline int
25 __ext2_get_block(struct inode *inode, pgoff_t pgoff, int create,
26                    sector_t *result)
27 {
28         struct buffer_head tmp;
29         int rc;
30
31         memset(&tmp, 0, sizeof(struct buffer_head));
32         tmp.b_size = 1 << inode->i_blkbits;
33         rc = ext2_get_block(inode, pgoff, &tmp, create);
34         *result = tmp.b_blocknr;
35
36         /* did we get a sparse block (hole in the file)? */
37         if (!tmp.b_blocknr && !rc) {
38                 BUG_ON(create);
39                 rc = -ENODATA;
40         }
41
42         return rc;
43 }
44
45 void ext2_xip_verify_sb(struct super_block *sb)
46 {
47         struct ext2_sb_info *sbi = EXT2_SB(sb);
48
49         if ((sbi->s_mount_opt & EXT2_MOUNT_XIP) &&
50             !sb->s_bdev->bd_disk->fops->direct_access) {
51                 sbi->s_mount_opt &= (~EXT2_MOUNT_XIP);
52                 ext2_msg(sb, KERN_WARNING,
53                              "warning: ignoring xip option - "
54                              "not supported by bdev");
55         }
56 }
57
58 int ext2_get_xip_mem(struct address_space *mapping, pgoff_t pgoff, int create,
59                                 void **kmem, unsigned long *pfn)
60 {
61         long rc;
62         sector_t block;
63
64         /* first, retrieve the sector number */
65         rc = __ext2_get_block(mapping->host, pgoff, create, &block);
66         if (rc)
67                 return rc;
68
69         /* retrieve address of the target data */
70         rc = __inode_direct_access(mapping->host, block, kmem, pfn, PAGE_SIZE);
71         return (rc < 0) ? rc : 0;
72 }