fs: Convert return type int to vm_fault_t
Subsystems (3)
PATCH v2 1/1 fs: Convert return type int to vm_fault_t
Return type for fault handlers in ext4 and nilfs are changed to use vm_fault_t.
Return type of block_page_mkwrite() is changed from int to vm_fault_t. The function signature of block_page_mkwrite() is changed to add one new parameter int *err. This will provide a way for caller functions to get error value along with return value and use it further.
Return type of block_page_mkwrite_return() is also changed to use new vm_fault_t type.
---
v2: return type of nilfs_page_mkwrite() changed to vm_fault_t
Address Ryusuke's comment. remove err =0.
fs/buffer.c | 20 +++++++++++--------- fs/ext4/ext4.h | 4 ++-- fs/ext4/inode.c | 31 +++++++++++++++---------------- fs/nilfs2/file.c | 17 ++++++++++------- include/linux/buffer_head.h | 7 ++++--- 5 files changed, 42 insertions(+), 37 deletions(-)
fs/buffer.c +11 -9
@@ -2444,21 +2444,21 @@ int block_commit_write(struct page *page, unsigned from, unsigned to)* Direct callers of this function should protect against filesystem freezing * using sb_start_pagefault() - sb_end_pagefault() functions. */ -int block_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf, -get_block_t get_block) +vm_fault_t block_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf, +get_block_t get_block,int *err) {struct page *page = vmf->page;struct inode *inode =file_inode (vma->vm_file);unsigned long end;loff_t size; -int ret; +int err1;lock_page (page); size =i_size_read (inode);if ((page->mapping != inode->i_mapping) || (page_offset (page) > size)) {/* We overload EFAULT to mean page got truncated */ - ret = -EFAULT ; + err1 = -EFAULT ; goto out_unlock; }
@@ -2468,18 +2468,20 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,else end =PAGE_SIZE ; - ret =__block_write_begin (page,0 , end, get_block); -if (!ret) - ret =block_commit_write (page,0 , end); + err1 =__block_write_begin (page,0 , end, get_block); +if (!err1) + err1 =block_commit_write (page,0 , end); -if (unlikely (ret <0 )) +if (unlikely (err1 <0 )) goto out_unlock; + *err = err1;set_page_dirty (page);wait_for_stable_page (page);return 0 ; out_unlock:unlock_page (page); -return ret; + *err = err1; +return block_page_mkwrite_return (err1); }EXPORT_SYMBOL (block_page_mkwrite);
fs/ext4/ext4.h +2 -2
@@ -2465,8 +2465,8 @@ int do_journal_get_write_access(handle_t *handle,extern int ext4_chunk_trans_blocks (struct inode *,int nrblocks);extern int ext4_zero_partial_blocks (handle_t *handle,struct inode *inode,loff_t lstart,loff_t lend); -extern int ext4_page_mkwrite (struct vm_fault *vmf); -extern int ext4_filemap_fault (struct vm_fault *vmf); +extern vm_fault_t ext4_page_mkwrite (struct vm_fault *vmf); +extern vm_fault_t ext4_filemap_fault (struct vm_fault *vmf);extern qsize_t *ext4_get_reserved_space (struct inode *inode);extern int ext4_get_projid (struct inode *inode,kprojid_t *projid); extern void ext4_da_update_reserve_space(struct inode *inode,
fs/ext4/inode.c +15 -16
@@ -6109,27 +6109,27 @@ static int ext4_bh_unmapped(handle_t *handle, struct buffer_head *bh)return !buffer_mapped (bh); } -int ext4_page_mkwrite (struct vm_fault *vmf) +vm_fault_t ext4_page_mkwrite (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *page = vmf->page;loff_t size;unsigned long len; -int ret; +vm_fault_t ret;struct file *file = vma->vm_file;struct inode *inode =file_inode (file);struct address_space *mapping = inode->i_mapping;handle_t *handle;get_block_t *get_block; -int retries =0 ; +int retries =0 , err;sb_start_pagefault (inode->i_sb);file_update_time (vma->vm_file);down_read (&EXT4_I (inode)->i_mmap_sem); - ret =ext4_convert_inline_data (inode); -if (ret) + err =ext4_convert_inline_data (inode); +if (err) goto out_ret;/* Delalloc case is easy... */
@@ -6138,10 +6138,10 @@ int ext4_page_mkwrite(struct vm_fault *vmf) !ext4_nonda_switch(inode->i_sb)) {do { ret =block_page_mkwrite (vma, vmf, - ext4_da_get_block_prep); - }while (ret == -ENOSPC && + ext4_da_get_block_prep, &err); + }while (err == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)); - goto out_ret; + goto out; }lock_page (page);
@@ -6184,36 +6184,35 @@ int ext4_page_mkwrite(struct vm_fault *vmf) ret =VM_FAULT_SIGBUS ; goto out; } - ret =block_page_mkwrite (vma, vmf, get_block); + ret =block_page_mkwrite (vma, vmf, get_block, &err);if (!ret &&ext4_should_journal_data (inode)) {if (ext4_walk_page_buffers (handle,page_buffers (page),0 ,PAGE_SIZE ,NULL , do_journal_get_write_access)) {unlock_page (page); - ret =VM_FAULT_SIGBUS ;ext4_journal_stop (handle); goto out; }ext4_set_inode_state (inode,EXT4_STATE_JDATA ); }ext4_journal_stop (handle); -if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) +if (err == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry_alloc; out_ret: - ret =block_page_mkwrite_return (ret); + ret =block_page_mkwrite_return (err); out:up_read (&EXT4_I (inode)->i_mmap_sem);sb_end_pagefault (inode->i_sb);return ret; } -int ext4_filemap_fault (struct vm_fault *vmf) +vm_fault_t ext4_filemap_fault (struct vm_fault *vmf) {struct inode *inode =file_inode (vmf->vma->vm_file); -int err; +vm_fault_t ret;down_read (&EXT4_I (inode)->i_mmap_sem); - err =filemap_fault (vmf); + ret =filemap_fault (vmf);up_read (&EXT4_I (inode)->i_mmap_sem); -return err; +return ret; }
fs/nilfs2/file.c +10 -7
@@ -51,13 +51,14 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)return err; } -static int nilfs_page_mkwrite (struct vm_fault *vmf) +static vm_fault_t nilfs_page_mkwrite (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *page = vmf->page;struct inode *inode =file_inode (vma->vm_file);struct nilfs_transaction_info ti; -int ret =0 ; +vm_fault_t ret =VM_FAULT_LOCKED ; +int err =0 ;if (unlikely (nilfs_near_disk_full (inode->i_sb->s_fs_info)))return VM_FAULT_SIGBUS ;/* -ENOSPC */
@@ -67,7 +68,7 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)if (page->mapping != inode->i_mapping ||page_offset (page) >=i_size_read (inode) || !PageUptodate (page)) {unlock_page (page); - ret = -EFAULT ;/* make the VM retry the fault */ + ret =VM_FAULT_NOPAGE ;/* make the VM retry the fault */ goto out; }
@@ -99,13 +100,15 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)/* * fill hole blocks */ - ret =nilfs_transaction_begin (inode->i_sb, &ti,1 ); + err =nilfs_transaction_begin (inode->i_sb, &ti,1 );/* never returns -ENOMEM, but may return -ENOSPC */ -if (unlikely (ret)) +if (unlikely (err)) { + ret =block_page_mkwrite_return (err); goto out; + }file_update_time (vma->vm_file); - ret =block_page_mkwrite (vma, vmf, nilfs_get_block); + ret =block_page_mkwrite (vma, vmf, nilfs_get_block, &err);if (ret) {nilfs_transaction_abort (inode->i_sb); goto out;
@@ -117,7 +120,7 @@ static int nilfs_page_mkwrite(struct vm_fault *vmf)wait_for_stable_page (page); out:sb_end_pagefault (inode->i_sb); -return block_page_mkwrite_return (ret); +return ret; }static const struct vm_operations_struct nilfs_file_vm_ops = {
include/linux/buffer_head.h +4 -3
@@ -14,6 +14,7 @@#include <linux/pagemap.h> #include <linux/wait.h> #include <linux/atomic.h> +#include <linux/mm_types.h> #ifdef CONFIG_BLOCK
@@ -239,10 +240,10 @@ int cont_write_begin(struct file *, struct address_space *, loff_t, get_block_t *, loff_t *);int generic_cont_expand_simple (struct inode *inode,loff_t size);int block_commit_write (struct page *page,unsigned from,unsigned to); -int block_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf, -get_block_t get_block); +vm_fault_t block_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf, +get_block_t get_block,int *err);/* Convert errno to return value from ->page_mkwrite() call */ -static inline int block_page_mkwrite_return (int err) +static inline vm_fault_t block_page_mkwrite_return (int err) {if (err ==0 )return VM_FAULT_LOCKED ;
Signature · 1 line
1.9.1
Quoted 15 lines · On Thu, 30 Aug 2018 22:55:47 +0530 Souptick Joarder <[email protected]>…
Return type for fault handlers in ext4 and nilfs are changed to use
vm_fault_t.Return type of
block_page_mkwrite()is changed from int tovm_fault_t. The function signature ofblock_page_mkwrite()is changed to add one new parameter int *err. This will provide a way for caller functions to get error value along with return value and use it further.Return type of
block_page_mkwrite_return()is also changed to use newvm_fault_ttype.
fs/nilfs2/file.c int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 54
Quoted 5 lines
fs/nilfs2/file.c +1
-1@@ -51,13 +51,14 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)return err; } -static int nilfs_page_mkwrite (struct vm_fault *vmf) +static vm_fault_t nilfs_page_mkwrite (struct vm_fault *vmf)
nilfs_page_mkwrite() already has return type vm_fault_t in Linus's kernel, due to the now-merged fs-nilfs2-adding-new-return-type-vm_fault_t.patch. Looks like a simple fix.
I'm beginning to feel vm_fault_t exhaustion. Please remind me what benefit we're going to get out of all this churn?
Quoted 3 lines
...
Quoted 29 lines · Andrew Morton
Quoted 15 lines · On Thu, 30 Aug 2018 22:55:47 +0530 Souptick Joarder <[email protected]>…
Return type for fault handlers in ext4 and nilfs are changed to use
vm_fault_t.Return type of
block_page_mkwrite()is changed from int tovm_fault_t. The function signature ofblock_page_mkwrite()is changed to add one new parameter int *err. This will provide a way for caller functions to get error value along with return value and use it further.Return type of
block_page_mkwrite_return()is also changed to use newvm_fault_ttype.fs/nilfs2/file.c int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 54
Quoted 5 lines
fs/nilfs2/file.c +1
-1@@ -51,13 +51,14 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)return err; } -static int nilfs_page_mkwrite (struct vm_fault *vmf) +static vm_fault_t nilfs_page_mkwrite (struct vm_fault *vmf)
nilfs_page_mkwrite()already has return typevm_fault_tin Linus's kernel, due to the now-merged fs-nilfs2-adding-new-return-type-vm_fault_t.patch. Looks like a simple fix.
Quoted 2 lines
I'm beginning to feel
vm_fault_texhaustion. Please remind me what benefit we're going to get out of all this churn?
The problem and benefit of these changes was discussed under this mail thread when the first vm_fault_t patch was posted.
Quoted 16 lines · On Fri, 31 Aug 2018 11:33:48 +0530 Souptick Joarder <[email protected]>…
Quoted 16 lines
fs/nilfs2/file.c int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 54
Quoted 10 lines
Return type of
block_page_mkwrite_return()is also changed to use newvm_fault_ttype.fs/nilfs2/file.c +1
-1@@ -51,13 +51,14 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)return err; } -static int nilfs_page_mkwrite (struct vm_fault *vmf) +static vm_fault_t nilfs_page_mkwrite (struct vm_fault *vmf)
nilfs_page_mkwrite()already has return typevm_fault_tin Linus's kernel, due to the now-merged fs-nilfs2-adding-new-return-type-vm_fault_t.patch. Looks like a simple fix.
Quoted 7 lines
Quoted 2 lines
I'm beginning to feel
vm_fault_texhaustion. Please remind me what benefit we're going to get out of all this churn?The problem and benefit of these changes was discussed under this mail thread when the first
vm_fault_tpatch was posted.
That tells us about the merging plans. But not much about what actual benefit anyone gets from this.
This?
: There's some interesting patterns and commonalities between drivers : (not to mention a few outright bugs) that we've noticed, and this'll be : a good time to clean them up.
That is terribly vague.
Quoted 2 lines · Andrew Morton
Quoted 2 lines
Quoted 2 lines
I'm beginning to feel
vm_fault_texhaustion. Please remind me what benefit we're going to get out of all this churn?
Hi Andrew,
The primary benefit is to help driver writers. At the moment, there is nothing to stop them returning -ENOMEM instead of VM_FAULT_NOMEM. There were one or two examples of this in the tree, but I think they're all gone now.
Secondarily, there are a number of places which translate between error codes and vm_fault codes. Those places are reduced as a result of these patches, if not entirely eliminated yet. There was some pretty extreme cargo-culting of errno to vm_fault switch statements, particularly in the DRM drivers.
There were also several places which were just ignoring the return value of vm_insert_foo(), and as a result of this audit, those have been fixed. Those errors are going to be rare, but can cause inappropriate decisions to be made by the OOM killer.
Now that I think about it, vmf_insert_foo() should probably get marked with __must_check to prevent those kinds of errors from being introduced again.
Hi Souptick,
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 30 Aug 2018 22:55:47 +0530 Souptick Joarder wrote:
Return type for fault handlers in ext4 and nilfs are changed to use
vm_fault_t.Return type of
block_page_mkwrite()is changed from int tovm_fault_t. The function signature ofblock_page_mkwrite()is changed to add one new parameter int *err. This will provide a way for caller functions to get error value along with return value and use it further.Return type of
block_page_mkwrite_return()is also changed to use newvm_fault_ttype.fs/nilfs2/file.c +0
-0@@ -51,13 +51,14 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)return err; }
Quoted 7 lines
fs/nilfs2/file.c int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 54
Quoted 2 lines
fs/nilfs2/file.c +1
-1-static int nilfs_page_mkwrite (struct vm_fault *vmf) +static vm_fault_t nilfs_page_mkwrite (struct vm_fault *vmf)
nilfs_page_mkwrite()already has return typevm_fault_tin Linus's kernel, due to the now-merged fs-nilfs2-adding-new-return-type-vm_fault_t.patch. Looks like a simple fix.
In the first patch in this thread, this return type change was excluded correctly for nilfs_page_mkwrite() though the changelog was inaccurate in that sense.
Please confirm your base point of the revised patch.
Regards,
Ryusuke Konishi
Quoted 7 lines
I'm beginning to feel
vm_fault_texhaustion. Please remind me what benefit we're going to get out of all this churn?Quoted 3 lines
...
Quoted 32 lines · Ryusuke Konishi
Hi Souptick,
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 30 Aug 2018 22:55:47 +0530 Souptick Joarder wrote:
Return type for fault handlers in ext4 and nilfs are changed to use
vm_fault_t.Return type of
block_page_mkwrite()is changed from int tovm_fault_t. The function signature ofblock_page_mkwrite()is changed to add one new parameter int *err. This will provide a way for caller functions to get error value along with return value and use it further.Return type of
block_page_mkwrite_return()is also changed to use newvm_fault_ttype.fs/nilfs2/file.c +0
-0@@ -51,13 +51,14 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)return err; }Quoted 7 lines
fs/nilfs2/file.c int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 54
Quoted 2 lines
fs/nilfs2/file.c +1
-1-static int nilfs_page_mkwrite (struct vm_fault *vmf) +static vm_fault_t nilfs_page_mkwrite (struct vm_fault *vmf)
nilfs_page_mkwrite()already has return typevm_fault_tin Linus's kernel, due to the now-merged fs-nilfs2-adding-new-return-type-vm_fault_t.patch. Looks like a simple fix.
Quoted 6 lines
In the first patch in this thread, this return type change was excluded correctly for
nilfs_page_mkwrite()though the changelog was inaccurate in that sense.Please confirm your base point of the revised patch.
Ryusuku,
Base point of revised patch is to address your comment by removing err = 0. Nothing else was suppose to there in v2.
But unfortunately I mixed up my local branches and created v2 against old branch which leads to confusion of v1 -> v2 delta changes. Sorry for creating more confusions.
Quoted 8 lines
Quoted 8 lines
I'm beginning to feel
vm_fault_texhaustion. Please remind me what benefit we're going to get out of all this churn?Quoted 3 lines
...
Quoted 10 lines · On Thu, 30 Aug 2018 22:55:47 +0530 Souptick Joarder <[email protected]>…
Return type for fault handlers in ext4 and nilfs are changed to use
vm_fault_t.Return type of
block_page_mkwrite()is changed from int tovm_fault_t. The function signature ofblock_page_mkwrite()is changed to add one new parameter int *err. This will provide a way for caller functions to get error value along with return value and use it further.
Quoted 7 lines
Return type of
block_page_mkwrite_return()is also changed to use newvm_fault_ttype.Signed-off-by Souptick Joarder <[email protected]>---
v2: return type ofnilfs_page_mkwrite()changed tovm_fault_t
Address Ryusuke's comment. remove err =0.
The v1->v2 delta (below) reveals unchangelogged ext4 changes?
fs/ext4/inode.c renamed from fs/ext4/inode.c~fs-convert-return-type-int-to-vm_fault_t-v2 +2 -5
@@ -6174,14 +6174,13 @@ vm_fault_t ext4_page_mkwrite(struct vm_fif (err) goto out_ret; - err =0 ;/* Delalloc case is easy... */ if (test_opt (inode->i_sb,DELALLOC ) && !ext4_should_journal_data (inode) && !ext4_nonda_switch (inode->i_sb)) {do { ret =block_page_mkwrite (vma, vmf, - ext4_da_get_block_prep, &err); + ext4_da_get_block_prep, &err); }while (err == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)); goto out;
@@ -6227,7 +6226,6 @@ retry_alloc: ret =VM_FAULT_SIGBUS ; goto out; } - err =0 ; ret =block_page_mkwrite (vma, vmf, get_block, &err);if (!ret &&ext4_should_journal_data (inode)) { if (ext4_walk_page_buffers(handle, page_buffers(page), 0,
@@ -6239,8 +6237,7 @@ retry_alloc:ext4_set_inode_state (inode,EXT4_STATE_JDATA ); }ext4_journal_stop (handle); -if (err == -ENOSPC && -ext4_should_retry_alloc (inode->i_sb, &retries)) +if (err == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry_alloc; out_ret: ret =block_page_mkwrite_return (err);
fs/nilfs2/file.c renamed from fs/nilfs2/file.c~fs-convert-return-type-int-to-vm_fault_t-v2 +0 -1
@@ -107,7 +107,6 @@ static vm_fault_t nilfs_page_mkwrite(str goto out; } - err =0 ;file_update_time (vma->vm_file); ret =block_page_mkwrite (vma, vmf, nilfs_get_block, &err);if (ret) {
_
Theodore Y. Ts'o
maintainerQuoted 2 lines · Andrew Morton
The
v1->v2delta (below) reveals unchangelogged ext4 changes?
Souptick, please don't make unrelated changes in a vm_fault_t patch.
Especially please don't make whitespace changes that will cause checkpatch.pl to whine about line lengths longer than 80 characters. There's a *reason* for the original indentation.
fs/ext4/inode.c retry_alloc: · line 6243
Quoted 10 lines
fs/ext4/inode.c renamed from fs/ext4/inode.c~fs-convert-return-type-int-to-vm_fault_t-v2 +1
-2@@ -6239,8 +6237,7 @@ retry_alloc:ext4_set_inode_state (inode,EXT4_STATE_JDATA ); }ext4_journal_stop (handle); -if (err == -ENOSPC && -ext4_should_retry_alloc (inode->i_sb, &retries)) +if (err == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry_alloc; out_ret: ret =block_page_mkwrite_return (err);
The fact that this is not a non-trivials set of changes means anything to make reviews harder is really not appreciated.
Also, the fact that the patch series involves multiple file system is a massive pain. It means I'm going to have to do a separate regression test --- or preferably, I would ask *you* to run a file system regression test[1] --- to make sure what is *not* a trivial patch doesn't break things. Also, it means that this patch series is going to get more complicated to get into kernel, and we may have to deal with patch conflicts if this goes in via some third party tree (such as Andrew's tree).
[1] https:/thunk.org/gce-xfstests
One way to make life easier is to add the new function with the new interface first, and then wait a release cycle, and then move file systems over in independant patches.
- Ted
Quoted 10 lines
Also, the fact that the patch series involves multiple file system is a massive pain. It means I'm going to have to do a separate regression test --- or preferably, I would ask *you* to run a file system regression test[1] --- to make sure what is *not* a trivial patch doesn't break things. Also, it means that this patch series is going to get more complicated to get into kernel, and we may have to deal with patch conflicts if this goes in via some third party tree (such as Andrew's tree).
[1] https:/thunk.org/gce-xfstests
Sure, I will run the regression.
Quoted 4 lines
One way to make life easier is to add the new function with the new interface first, and then wait a release cycle, and then move file systems over in independant patches.
In last review, you left it to me either to add new function or modify the input parameters of block_page_mkwrite() to return err to caller. As block_page_mkwrite() is getting called from 2 places in ext4 & nilfs, I choose to add new input argument in block_page_mkwrite() rather than introducing new function and put everything in a single commit.
fs/buffer.c int block_commit_write(struct page *page, unsigned from, unsigned to) · line 2448
Quoted 2 lines · Souptick Joarder
fs/buffer.c +2
-0+vm_fault_t block_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf, +get_block_t get_block,int *err)
I don't like returning both the errno and the vm_fault_t. To me that's a sign we need to rethink this interface.
I have two suggestions. First, we could allocate a new VM_FAULT_NOSPC bit. Second, we could repurpose one of the existing bits, such as VM_FAULT_RETRY for this purpose.
fs/ext4/inode.c static int ext4_bh_unmapped(handle_t *handle, struct buffer_head *bh) · line 6112
Quoted 2 lines
fs/ext4/inode.c +1
-1-int ext4_page_mkwrite (struct vm_fault *vmf) +vm_fault_t ext4_page_mkwrite (struct vm_fault *vmf)
I also think perhaps we could start by _not_ converting block_page_mkwrite(). Just convert ext4_page_mkwrite(), and save converting block_page_mkwrite() for later.