Skip to content

Commit

Permalink
fuse: lock page in mkwrite
Browse files Browse the repository at this point in the history
Lock the page in fuse_page_mkwrite() to protect against a race with
fuse_writepage() where the page is redirtied before the actual writeback
begins.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
  • Loading branch information
Miklos Szeredi committed Oct 1, 2013
1 parent 385b126 commit cca2437
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,14 +1618,17 @@ static void fuse_vma_close(struct vm_area_struct *vma)
static int fuse_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
{
struct page *page = vmf->page;
/*
* Don't use page->mapping as it may become NULL from a
* concurrent truncate.
*/
struct inode *inode = vma->vm_file->f_mapping->host;
struct inode *inode = file_inode(vma->vm_file);

file_update_time(vma->vm_file);
lock_page(page);
if (page->mapping != inode->i_mapping) {
unlock_page(page);
return VM_FAULT_NOPAGE;
}

fuse_wait_on_page_writeback(inode, page->index);
return 0;
return VM_FAULT_LOCKED;
}

static const struct vm_operations_struct fuse_file_vm_ops = {
Expand Down

0 comments on commit cca2437

Please sign in to comment.