forked from luck/tmp_suning_uos_patched
vfs: Create __block_page_mkwrite() helper passing error values back
Create __block_page_mkwrite() helper which does all what block_page_mkwrite() does except that it passes back errors from __block_write_begin / block_commit_write calls. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
7c6e984dfc
commit
24da4fab5a
37
fs/buffer.c
37
fs/buffer.c
|
@ -2332,23 +2332,22 @@ EXPORT_SYMBOL(block_commit_write);
|
||||||
* beyond EOF, then the page is guaranteed safe against truncation until we
|
* beyond EOF, then the page is guaranteed safe against truncation until we
|
||||||
* unlock the page.
|
* unlock the page.
|
||||||
*/
|
*/
|
||||||
int
|
int __block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
|
||||||
block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
|
get_block_t get_block)
|
||||||
get_block_t get_block)
|
|
||||||
{
|
{
|
||||||
struct page *page = vmf->page;
|
struct page *page = vmf->page;
|
||||||
struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
|
struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
|
||||||
unsigned long end;
|
unsigned long end;
|
||||||
loff_t size;
|
loff_t size;
|
||||||
int ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */
|
int ret;
|
||||||
|
|
||||||
lock_page(page);
|
lock_page(page);
|
||||||
size = i_size_read(inode);
|
size = i_size_read(inode);
|
||||||
if ((page->mapping != inode->i_mapping) ||
|
if ((page->mapping != inode->i_mapping) ||
|
||||||
(page_offset(page) > size)) {
|
(page_offset(page) > size)) {
|
||||||
/* page got truncated out from underneath us */
|
/* We overload EFAULT to mean page got truncated */
|
||||||
unlock_page(page);
|
ret = -EFAULT;
|
||||||
goto out;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* page is wholly or partially inside EOF */
|
/* page is wholly or partially inside EOF */
|
||||||
|
@ -2361,18 +2360,22 @@ block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = block_commit_write(page, 0, end);
|
ret = block_commit_write(page, 0, end);
|
||||||
|
|
||||||
if (unlikely(ret)) {
|
if (unlikely(ret < 0))
|
||||||
unlock_page(page);
|
goto out_unlock;
|
||||||
if (ret == -ENOMEM)
|
return 0;
|
||||||
ret = VM_FAULT_OOM;
|
out_unlock:
|
||||||
else /* -ENOSPC, -EIO, etc */
|
unlock_page(page);
|
||||||
ret = VM_FAULT_SIGBUS;
|
|
||||||
} else
|
|
||||||
ret = VM_FAULT_LOCKED;
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(__block_page_mkwrite);
|
||||||
|
|
||||||
|
int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
|
||||||
|
get_block_t get_block)
|
||||||
|
{
|
||||||
|
int ret = __block_page_mkwrite(vma, vmf, get_block);
|
||||||
|
|
||||||
|
return block_page_mkwrite_return(ret);
|
||||||
|
}
|
||||||
EXPORT_SYMBOL(block_page_mkwrite);
|
EXPORT_SYMBOL(block_page_mkwrite);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -217,8 +217,22 @@ int cont_write_begin(struct file *, struct address_space *, loff_t,
|
||||||
get_block_t *, loff_t *);
|
get_block_t *, loff_t *);
|
||||||
int generic_cont_expand_simple(struct inode *inode, loff_t size);
|
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,
|
||||||
|
get_block_t get_block);
|
||||||
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 int block_page_mkwrite_return(int err)
|
||||||
|
{
|
||||||
|
if (err == 0)
|
||||||
|
return VM_FAULT_LOCKED;
|
||||||
|
if (err == -EFAULT)
|
||||||
|
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 *);
|
||||||
int nobh_write_begin(struct address_space *, loff_t, unsigned, unsigned,
|
int nobh_write_begin(struct address_space *, loff_t, unsigned, unsigned,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user