aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorNick Piggin <npiggin@suse.de>2007-07-19 04:46:59 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 13:04:41 -0400
commit54cb8821de07f2ffcd28c380ce9b93d5784b40d7 (patch)
tree1de676534963d96af42863b20191bc9f80060dea /fs
parentd00806b183152af6d24f46f0c33f14162ca1262a (diff)
mm: merge populate and nopage into fault (fixes nonlinear)
Nonlinear mappings are (AFAIKS) simply a virtual memory concept that encodes the virtual address -> file offset differently from linear mappings. ->populate is a layering violation because the filesystem/pagecache code should need to know anything about the virtual memory mapping. The hitch here is that the ->nopage handler didn't pass down enough information (ie. pgoff). But it is more logical to pass pgoff rather than have the ->nopage function calculate it itself anyway (because that's a similar layering violation). Having the populate handler install the pte itself is likewise a nasty thing to be doing. This patch introduces a new fault handler that replaces ->nopage and ->populate and (later) ->nopfn. Most of the old mechanism is still in place so there is a lot of duplication and nice cleanups that can be removed if everyone switches over. The rationale for doing this in the first place is that nonlinear mappings are subject to the pagefault vs invalidate/truncate race too, and it seemed stupid to duplicate the synchronisation logic rather than just consolidate the two. After this patch, MAP_NONBLOCK no longer sets up ptes for pages present in pagecache. Seems like a fringe functionality anyway. NOPAGE_REFAULT is removed. This should be implemented with ->fault, and no users have hit mainline yet. [akpm@linux-foundation.org: cleanup] [randy.dunlap@oracle.com: doc. fixes for readahead] [akpm@linux-foundation.org: build fix] Signed-off-by: Nick Piggin <npiggin@suse.de> Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Cc: Mark Fasheh <mark.fasheh@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/gfs2/ops_address.c2
-rw-r--r--fs/gfs2/ops_file.c2
-rw-r--r--fs/gfs2/ops_vm.c36
-rw-r--r--fs/ncpfs/mmap.c23
-rw-r--r--fs/ocfs2/aops.c2
-rw-r--r--fs/ocfs2/mmap.c17
-rw-r--r--fs/xfs/linux-2.6/xfs_file.c23
7 files changed, 53 insertions, 52 deletions
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 26c888890c24..ce90032c010e 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -251,7 +251,7 @@ static int gfs2_readpage(struct file *file, struct page *page)
251 if (file) { 251 if (file) {
252 gf = file->private_data; 252 gf = file->private_data;
253 if (test_bit(GFF_EXLOCK, &gf->f_flags)) 253 if (test_bit(GFF_EXLOCK, &gf->f_flags))
254 /* gfs2_sharewrite_nopage has grabbed the ip->i_gl already */ 254 /* gfs2_sharewrite_fault has grabbed the ip->i_gl already */
255 goto skip_lock; 255 goto skip_lock;
256 } 256 }
257 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh); 257 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index bad0b24cb773..581ac11b2656 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -364,7 +364,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
364 else 364 else
365 vma->vm_ops = &gfs2_vm_ops_private; 365 vma->vm_ops = &gfs2_vm_ops_private;
366 366
367 vma->vm_flags |= VM_CAN_INVALIDATE; 367 vma->vm_flags |= VM_CAN_INVALIDATE|VM_CAN_NONLINEAR;
368 368
369 gfs2_glock_dq_uninit(&i_gh); 369 gfs2_glock_dq_uninit(&i_gh);
370 370
diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c
index d5a98cbfebdc..e9fe6eb74e75 100644
--- a/fs/gfs2/ops_vm.c
+++ b/fs/gfs2/ops_vm.c
@@ -27,13 +27,13 @@
27#include "trans.h" 27#include "trans.h"
28#include "util.h" 28#include "util.h"
29 29
30static struct page *gfs2_private_nopage(struct vm_area_struct *area, 30static struct page *gfs2_private_fault(struct vm_area_struct *vma,
31 unsigned long address, int *type) 31 struct fault_data *fdata)
32{ 32{
33 struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host); 33 struct gfs2_inode *ip = GFS2_I(vma->vm_file->f_mapping->host);
34 34
35 set_bit(GIF_PAGED, &ip->i_flags); 35 set_bit(GIF_PAGED, &ip->i_flags);
36 return filemap_nopage(area, address, type); 36 return filemap_fault(vma, fdata);
37} 37}
38 38
39static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) 39static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
@@ -104,16 +104,14 @@ out:
104 return error; 104 return error;
105} 105}
106 106
107static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, 107static struct page *gfs2_sharewrite_fault(struct vm_area_struct *vma,
108 unsigned long address, int *type) 108 struct fault_data *fdata)
109{ 109{
110 struct file *file = area->vm_file; 110 struct file *file = vma->vm_file;
111 struct gfs2_file *gf = file->private_data; 111 struct gfs2_file *gf = file->private_data;
112 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 112 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
113 struct gfs2_holder i_gh; 113 struct gfs2_holder i_gh;
114 struct page *result = NULL; 114 struct page *result = NULL;
115 unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) +
116 area->vm_pgoff;
117 int alloc_required; 115 int alloc_required;
118 int error; 116 int error;
119 117
@@ -124,23 +122,27 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area,
124 set_bit(GIF_PAGED, &ip->i_flags); 122 set_bit(GIF_PAGED, &ip->i_flags);
125 set_bit(GIF_SW_PAGED, &ip->i_flags); 123 set_bit(GIF_SW_PAGED, &ip->i_flags);
126 124
127 error = gfs2_write_alloc_required(ip, (u64)index << PAGE_CACHE_SHIFT, 125 error = gfs2_write_alloc_required(ip,
128 PAGE_CACHE_SIZE, &alloc_required); 126 (u64)fdata->pgoff << PAGE_CACHE_SHIFT,
129 if (error) 127 PAGE_CACHE_SIZE, &alloc_required);
128 if (error) {
129 fdata->type = VM_FAULT_OOM; /* XXX: are these right? */
130 goto out; 130 goto out;
131 }
131 132
132 set_bit(GFF_EXLOCK, &gf->f_flags); 133 set_bit(GFF_EXLOCK, &gf->f_flags);
133 result = filemap_nopage(area, address, type); 134 result = filemap_fault(vma, fdata);
134 clear_bit(GFF_EXLOCK, &gf->f_flags); 135 clear_bit(GFF_EXLOCK, &gf->f_flags);
135 if (!result || result == NOPAGE_OOM) 136 if (!result)
136 goto out; 137 goto out;
137 138
138 if (alloc_required) { 139 if (alloc_required) {
139 error = alloc_page_backing(ip, result); 140 error = alloc_page_backing(ip, result);
140 if (error) { 141 if (error) {
141 if (area->vm_flags & VM_CAN_INVALIDATE) 142 if (vma->vm_flags & VM_CAN_INVALIDATE)
142 unlock_page(result); 143 unlock_page(result);
143 page_cache_release(result); 144 page_cache_release(result);
145 fdata->type = VM_FAULT_OOM;
144 result = NULL; 146 result = NULL;
145 goto out; 147 goto out;
146 } 148 }
@@ -154,10 +156,10 @@ out:
154} 156}
155 157
156struct vm_operations_struct gfs2_vm_ops_private = { 158struct vm_operations_struct gfs2_vm_ops_private = {
157 .nopage = gfs2_private_nopage, 159 .fault = gfs2_private_fault,
158}; 160};
159 161
160struct vm_operations_struct gfs2_vm_ops_sharewrite = { 162struct vm_operations_struct gfs2_vm_ops_sharewrite = {
161 .nopage = gfs2_sharewrite_nopage, 163 .fault = gfs2_sharewrite_fault,
162}; 164};
163 165
diff --git a/fs/ncpfs/mmap.c b/fs/ncpfs/mmap.c
index 5416673418b8..af48b792ca04 100644
--- a/fs/ncpfs/mmap.c
+++ b/fs/ncpfs/mmap.c
@@ -25,8 +25,8 @@
25/* 25/*
26 * Fill in the supplied page for mmap 26 * Fill in the supplied page for mmap
27 */ 27 */
28static struct page* ncp_file_mmap_nopage(struct vm_area_struct *area, 28static struct page* ncp_file_mmap_fault(struct vm_area_struct *area,
29 unsigned long address, int *type) 29 struct fault_data *fdata)
30{ 30{
31 struct file *file = area->vm_file; 31 struct file *file = area->vm_file;
32 struct dentry *dentry = file->f_path.dentry; 32 struct dentry *dentry = file->f_path.dentry;
@@ -40,15 +40,17 @@ static struct page* ncp_file_mmap_nopage(struct vm_area_struct *area,
40 40
41 page = alloc_page(GFP_HIGHUSER); /* ncpfs has nothing against high pages 41 page = alloc_page(GFP_HIGHUSER); /* ncpfs has nothing against high pages
42 as long as recvmsg and memset works on it */ 42 as long as recvmsg and memset works on it */
43 if (!page) 43 if (!page) {
44 return page; 44 fdata->type = VM_FAULT_OOM;
45 return NULL;
46 }
45 pg_addr = kmap(page); 47 pg_addr = kmap(page);
46 address &= PAGE_MASK; 48 pos = fdata->pgoff << PAGE_SHIFT;
47 pos = address - area->vm_start + (area->vm_pgoff << PAGE_SHIFT);
48 49
49 count = PAGE_SIZE; 50 count = PAGE_SIZE;
50 if (address + PAGE_SIZE > area->vm_end) { 51 if (fdata->address + PAGE_SIZE > area->vm_end) {
51 count = area->vm_end - address; 52 WARN_ON(1); /* shouldn't happen? */
53 count = area->vm_end - fdata->address;
52 } 54 }
53 /* what we can read in one go */ 55 /* what we can read in one go */
54 bufsize = NCP_SERVER(inode)->buffer_size; 56 bufsize = NCP_SERVER(inode)->buffer_size;
@@ -91,15 +93,14 @@ static struct page* ncp_file_mmap_nopage(struct vm_area_struct *area,
91 * fetches from the network, here the analogue of disk. 93 * fetches from the network, here the analogue of disk.
92 * -- wli 94 * -- wli
93 */ 95 */
94 if (type) 96 fdata->type = VM_FAULT_MAJOR;
95 *type = VM_FAULT_MAJOR;
96 count_vm_event(PGMAJFAULT); 97 count_vm_event(PGMAJFAULT);
97 return page; 98 return page;
98} 99}
99 100
100static struct vm_operations_struct ncp_file_mmap = 101static struct vm_operations_struct ncp_file_mmap =
101{ 102{
102 .nopage = ncp_file_mmap_nopage, 103 .fault = ncp_file_mmap_fault,
103}; 104};
104 105
105 106
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 84bf6e79de23..460d440310f2 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -232,7 +232,7 @@ static int ocfs2_readpage(struct file *file, struct page *page)
232 * might now be discovering a truncate that hit on another node. 232 * might now be discovering a truncate that hit on another node.
233 * block_read_full_page->get_block freaks out if it is asked to read 233 * block_read_full_page->get_block freaks out if it is asked to read
234 * beyond the end of a file, so we check here. Callers 234 * beyond the end of a file, so we check here. Callers
235 * (generic_file_read, fault->nopage) are clever enough to check i_size 235 * (generic_file_read, vm_ops->fault) are clever enough to check i_size
236 * and notice that the page they just read isn't needed. 236 * and notice that the page they just read isn't needed.
237 * 237 *
238 * XXX sys_readahead() seems to get that wrong? 238 * XXX sys_readahead() seems to get that wrong?
diff --git a/fs/ocfs2/mmap.c b/fs/ocfs2/mmap.c
index 904f39ff5340..cd75508b1c8a 100644
--- a/fs/ocfs2/mmap.c
+++ b/fs/ocfs2/mmap.c
@@ -60,24 +60,23 @@ static inline int ocfs2_vm_op_unblock_sigs(sigset_t *oldset)
60 return sigprocmask(SIG_SETMASK, oldset, NULL); 60 return sigprocmask(SIG_SETMASK, oldset, NULL);
61} 61}
62 62
63static struct page *ocfs2_nopage(struct vm_area_struct * area, 63static struct page *ocfs2_fault(struct vm_area_struct *area,
64 unsigned long address, 64 struct fault_data *fdata)
65 int *type)
66{ 65{
67 struct page *page = NOPAGE_SIGBUS; 66 struct page *page = NULL;
68 sigset_t blocked, oldset; 67 sigset_t blocked, oldset;
69 int ret; 68 int ret;
70 69
71 mlog_entry("(area=%p, address=%lu, type=%p)\n", area, address, 70 mlog_entry("(area=%p, page offset=%lu)\n", area, fdata->pgoff);
72 type);
73 71
74 ret = ocfs2_vm_op_block_sigs(&blocked, &oldset); 72 ret = ocfs2_vm_op_block_sigs(&blocked, &oldset);
75 if (ret < 0) { 73 if (ret < 0) {
74 fdata->type = VM_FAULT_SIGBUS;
76 mlog_errno(ret); 75 mlog_errno(ret);
77 goto out; 76 goto out;
78 } 77 }
79 78
80 page = filemap_nopage(area, address, type); 79 page = filemap_fault(area, fdata);
81 80
82 ret = ocfs2_vm_op_unblock_sigs(&oldset); 81 ret = ocfs2_vm_op_unblock_sigs(&oldset);
83 if (ret < 0) 82 if (ret < 0)
@@ -209,7 +208,7 @@ out:
209} 208}
210 209
211static struct vm_operations_struct ocfs2_file_vm_ops = { 210static struct vm_operations_struct ocfs2_file_vm_ops = {
212 .nopage = ocfs2_nopage, 211 .fault = ocfs2_fault,
213 .page_mkwrite = ocfs2_page_mkwrite, 212 .page_mkwrite = ocfs2_page_mkwrite,
214}; 213};
215 214
@@ -226,7 +225,7 @@ int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
226 ocfs2_meta_unlock(file->f_dentry->d_inode, lock_level); 225 ocfs2_meta_unlock(file->f_dentry->d_inode, lock_level);
227out: 226out:
228 vma->vm_ops = &ocfs2_file_vm_ops; 227 vma->vm_ops = &ocfs2_file_vm_ops;
229 vma->vm_flags |= VM_CAN_INVALIDATE; 228 vma->vm_flags |= VM_CAN_INVALIDATE | VM_CAN_NONLINEAR;
230 return 0; 229 return 0;
231} 230}
232 231
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index 92b2f225712f..f12e80a69c68 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -213,18 +213,19 @@ xfs_file_fsync(
213 213
214#ifdef CONFIG_XFS_DMAPI 214#ifdef CONFIG_XFS_DMAPI
215STATIC struct page * 215STATIC struct page *
216xfs_vm_nopage( 216xfs_vm_fault(
217 struct vm_area_struct *area, 217 struct vm_area_struct *vma,
218 unsigned long address, 218 struct fault_data *fdata)
219 int *type)
220{ 219{
221 struct inode *inode = area->vm_file->f_path.dentry->d_inode; 220 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
222 bhv_vnode_t *vp = vn_from_inode(inode); 221 bhv_vnode_t *vp = vn_from_inode(inode);
223 222
224 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI); 223 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
225 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), area, 0)) 224 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), vma, 0)) {
225 fdata->type = VM_FAULT_SIGBUS;
226 return NULL; 226 return NULL;
227 return filemap_nopage(area, address, type); 227 }
228 return filemap_fault(vma, fdata);
228} 229}
229#endif /* CONFIG_XFS_DMAPI */ 230#endif /* CONFIG_XFS_DMAPI */
230 231
@@ -310,7 +311,7 @@ xfs_file_mmap(
310 struct vm_area_struct *vma) 311 struct vm_area_struct *vma)
311{ 312{
312 vma->vm_ops = &xfs_file_vm_ops; 313 vma->vm_ops = &xfs_file_vm_ops;
313 vma->vm_flags |= VM_CAN_INVALIDATE; 314 vma->vm_flags |= VM_CAN_INVALIDATE | VM_CAN_NONLINEAR;
314 315
315#ifdef CONFIG_XFS_DMAPI 316#ifdef CONFIG_XFS_DMAPI
316 if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI) 317 if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
@@ -465,14 +466,12 @@ const struct file_operations xfs_dir_file_operations = {
465}; 466};
466 467
467static struct vm_operations_struct xfs_file_vm_ops = { 468static struct vm_operations_struct xfs_file_vm_ops = {
468 .nopage = filemap_nopage, 469 .fault = filemap_fault,
469 .populate = filemap_populate,
470}; 470};
471 471
472#ifdef CONFIG_XFS_DMAPI 472#ifdef CONFIG_XFS_DMAPI
473static struct vm_operations_struct xfs_dmapi_file_vm_ops = { 473static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
474 .nopage = xfs_vm_nopage, 474 .fault = xfs_vm_fault,
475 .populate = filemap_populate,
476#ifdef HAVE_VMOP_MPROTECT 475#ifdef HAVE_VMOP_MPROTECT
477 .mprotect = xfs_vm_mprotect, 476 .mprotect = xfs_vm_mprotect,
478#endif 477#endif