Commit 2ba39cc4 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

fs: rename and move block_page_mkwrite_return

block_page_mkwrite_return is neither block nor mkwrite specific, and
should not be under CONFIG_BLOCK.  Move it to mm.h and rename it to
vmf_fs_error.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarChristian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20230801172201.1923299-3-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 4a8b719f
...@@ -6140,7 +6140,7 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) ...@@ -6140,7 +6140,7 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
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; goto retry_alloc;
out_ret: out_ret:
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
out: out:
filemap_invalidate_unlock_shared(mapping); filemap_invalidate_unlock_shared(mapping);
sb_end_pagefault(inode->i_sb); sb_end_pagefault(inode->i_sb);
......
...@@ -159,7 +159,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) ...@@ -159,7 +159,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
sb_end_pagefault(inode->i_sb); sb_end_pagefault(inode->i_sb);
err: err:
return block_page_mkwrite_return(err); return vmf_fs_error(err);
} }
static const struct vm_operations_struct f2fs_file_vm_ops = { static const struct vm_operations_struct f2fs_file_vm_ops = {
......
...@@ -432,7 +432,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -432,7 +432,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
err = gfs2_glock_nq(&gh); err = gfs2_glock_nq(&gh);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_uninit; goto out_uninit;
} }
...@@ -474,7 +474,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -474,7 +474,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
err = gfs2_rindex_update(sdp); err = gfs2_rindex_update(sdp);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_unlock; goto out_unlock;
} }
...@@ -482,12 +482,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -482,12 +482,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
ap.target = data_blocks + ind_blocks; ap.target = data_blocks + ind_blocks;
err = gfs2_quota_lock_check(ip, &ap); err = gfs2_quota_lock_check(ip, &ap);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_unlock; goto out_unlock;
} }
err = gfs2_inplace_reserve(ip, &ap); err = gfs2_inplace_reserve(ip, &ap);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_quota_unlock; goto out_quota_unlock;
} }
...@@ -500,7 +500,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -500,7 +500,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
} }
err = gfs2_trans_begin(sdp, rblocks, 0); err = gfs2_trans_begin(sdp, rblocks, 0);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_trans_fail; goto out_trans_fail;
} }
...@@ -508,7 +508,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -508,7 +508,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
if (gfs2_is_stuffed(ip)) { if (gfs2_is_stuffed(ip)) {
err = gfs2_unstuff_dinode(ip); err = gfs2_unstuff_dinode(ip);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_trans_end; goto out_trans_end;
} }
} }
...@@ -524,7 +524,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ...@@ -524,7 +524,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
err = gfs2_allocate_page_backing(page, length); err = gfs2_allocate_page_backing(page, length);
if (err) if (err)
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
out_page_locked: out_page_locked:
if (ret != VM_FAULT_LOCKED) if (ret != VM_FAULT_LOCKED)
...@@ -558,7 +558,7 @@ static vm_fault_t gfs2_fault(struct vm_fault *vmf) ...@@ -558,7 +558,7 @@ static vm_fault_t gfs2_fault(struct vm_fault *vmf)
gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh); gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
err = gfs2_glock_nq(&gh); err = gfs2_glock_nq(&gh);
if (err) { if (err) {
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_uninit; goto out_uninit;
} }
ret = filemap_fault(vmf); ret = filemap_fault(vmf);
......
...@@ -1286,7 +1286,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops) ...@@ -1286,7 +1286,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)
return VM_FAULT_LOCKED; return VM_FAULT_LOCKED;
out_unlock: out_unlock:
folio_unlock(folio); folio_unlock(folio);
return block_page_mkwrite_return(ret); return vmf_fs_error(ret);
} }
EXPORT_SYMBOL_GPL(iomap_page_mkwrite); EXPORT_SYMBOL_GPL(iomap_page_mkwrite);
......
...@@ -108,7 +108,7 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf) ...@@ -108,7 +108,7 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf)
wait_for_stable_page(page); wait_for_stable_page(page);
out: out:
sb_end_pagefault(inode->i_sb); sb_end_pagefault(inode->i_sb);
return block_page_mkwrite_return(ret); return vmf_fs_error(ret);
} }
static const struct vm_operations_struct nilfs_file_vm_ops = { static const struct vm_operations_struct nilfs_file_vm_ops = {
......
...@@ -67,7 +67,7 @@ static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf) ...@@ -67,7 +67,7 @@ static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf)
err = block_commit_write(page, 0, end); err = block_commit_write(page, 0, end);
if (err < 0) { if (err < 0) {
unlock_page(page); unlock_page(page);
ret = block_page_mkwrite_return(err); ret = vmf_fs_error(err);
goto out_unlock; goto out_unlock;
} }
out_dirty: out_dirty:
......
...@@ -291,18 +291,6 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size); ...@@ -291,18 +291,6 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size);
int block_commit_write(struct page *page, unsigned from, unsigned to); int block_commit_write(struct page *page, unsigned from, unsigned to);
int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
get_block_t get_block); get_block_t get_block);
/* Convert errno to return value from ->page_mkwrite() call */
static inline vm_fault_t block_page_mkwrite_return(int err)
{
if (err == 0)
return VM_FAULT_LOCKED;
if (err == -EFAULT || err == -EAGAIN)
return VM_FAULT_NOPAGE;
if (err == -ENOMEM)
return VM_FAULT_OOM;
/* -ENOSPC, -EDQUOT, -EIO ... */
return VM_FAULT_SIGBUS;
}
sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *); sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
int block_truncate_page(struct address_space *, loff_t, get_block_t *); int block_truncate_page(struct address_space *, loff_t, get_block_t *);
......
...@@ -3386,6 +3386,24 @@ static inline vm_fault_t vmf_error(int err) ...@@ -3386,6 +3386,24 @@ static inline vm_fault_t vmf_error(int err)
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
} }
/*
* Convert errno to return value for ->page_mkwrite() calls.
*
* This should eventually be merged with vmf_error() above, but will need a
* careful audit of all vmf_error() callers.
*/
static inline vm_fault_t vmf_fs_error(int err)
{
if (err == 0)
return VM_FAULT_LOCKED;
if (err == -EFAULT || err == -EAGAIN)
return VM_FAULT_NOPAGE;
if (err == -ENOMEM)
return VM_FAULT_OOM;
/* -ENOSPC, -EDQUOT, -EIO ... */
return VM_FAULT_SIGBUS;
}
struct page *follow_page(struct vm_area_struct *vma, unsigned long address, struct page *follow_page(struct vm_area_struct *vma, unsigned long address,
unsigned int foll_flags); unsigned int foll_flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment