Skip to content

Commit 24da4fa

Browse files
jankaraAl Viro
authored andcommitted
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 <[email protected]> Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 7c6e984 commit 24da4fa

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

fs/buffer.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,23 +2332,22 @@ EXPORT_SYMBOL(block_commit_write);
23322332
* beyond EOF, then the page is guaranteed safe against truncation until we
23332333
* unlock the page.
23342334
*/
2335-
int
2336-
block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
2337-
get_block_t get_block)
2335+
int __block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
2336+
get_block_t get_block)
23382337
{
23392338
struct page *page = vmf->page;
23402339
struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
23412340
unsigned long end;
23422341
loff_t size;
2343-
int ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */
2342+
int ret;
23442343

23452344
lock_page(page);
23462345
size = i_size_read(inode);
23472346
if ((page->mapping != inode->i_mapping) ||
23482347
(page_offset(page) > size)) {
2349-
/* page got truncated out from underneath us */
2350-
unlock_page(page);
2351-
goto out;
2348+
/* We overload EFAULT to mean page got truncated */
2349+
ret = -EFAULT;
2350+
goto out_unlock;
23522351
}
23532352

23542353
/* page is wholly or partially inside EOF */
@@ -2361,18 +2360,22 @@ block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
23612360
if (!ret)
23622361
ret = block_commit_write(page, 0, end);
23632362

2364-
if (unlikely(ret)) {
2365-
unlock_page(page);
2366-
if (ret == -ENOMEM)
2367-
ret = VM_FAULT_OOM;
2368-
else /* -ENOSPC, -EIO, etc */
2369-
ret = VM_FAULT_SIGBUS;
2370-
} else
2371-
ret = VM_FAULT_LOCKED;
2372-
2373-
out:
2363+
if (unlikely(ret < 0))
2364+
goto out_unlock;
2365+
return 0;
2366+
out_unlock:
2367+
unlock_page(page);
23742368
return ret;
23752369
}
2370+
EXPORT_SYMBOL(__block_page_mkwrite);
2371+
2372+
int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
2373+
get_block_t get_block)
2374+
{
2375+
int ret = __block_page_mkwrite(vma, vmf, get_block);
2376+
2377+
return block_page_mkwrite_return(ret);
2378+
}
23762379
EXPORT_SYMBOL(block_page_mkwrite);
23772380

23782381
/*

include/linux/buffer_head.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,22 @@ int cont_write_begin(struct file *, struct address_space *, loff_t,
217217
get_block_t *, loff_t *);
218218
int generic_cont_expand_simple(struct inode *inode, loff_t size);
219219
int block_commit_write(struct page *page, unsigned from, unsigned to);
220+
int __block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
221+
get_block_t get_block);
220222
int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
221223
get_block_t get_block);
224+
/* Convert errno to return value from ->page_mkwrite() call */
225+
static inline int block_page_mkwrite_return(int err)
226+
{
227+
if (err == 0)
228+
return VM_FAULT_LOCKED;
229+
if (err == -EFAULT)
230+
return VM_FAULT_NOPAGE;
231+
if (err == -ENOMEM)
232+
return VM_FAULT_OOM;
233+
/* -ENOSPC, -EDQUOT, -EIO ... */
234+
return VM_FAULT_SIGBUS;
235+
}
222236
sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
223237
int block_truncate_page(struct address_space *, loff_t, get_block_t *);
224238
int nobh_write_begin(struct address_space *, loff_t, unsigned, unsigned,

0 commit comments

Comments
 (0)