Skip to content

Commit

Permalink
nilfs2: fix data loss in mmap page write for hole blocks
Browse files Browse the repository at this point in the history
From the result of a function test of mmap, mmap write to shared pages
turned out to be broken for hole blocks.  It doesn't write out filled
blocks and the data will be lost after umount.  This is due to a bug
that the target file is not queued for log writer when filling hole
blocks.

Also, nilfs_page_mkwrite function exits normal code path even after
successfully filled hole blocks due to a change of block_page_mkwrite
function; just after nilfs was merged into the mainline,
block_page_mkwrite() started to return VM_FAULT_LOCKED instead of zero
by the patch "mm: close page_mkwrite races" (commit:
b827e49).  The current nilfs_page_mkwrite() is not handling
this value properly.

This corrects nilfs_page_mkwrite() and will resolve the data loss
problem in mmap write.

[This should be applied to every kernel since 2.6.30 but a fix is
 needed for 2.6.37 and prior kernels]

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Tested-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: stable <stable@kernel.org>  [2.6.38]
  • Loading branch information
Ryusuke Konishi committed Mar 30, 2011
1 parent 0ce790e commit 3409453
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions fs/nilfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
/*
* check to see if the page is mapped already (no holes)
*/
if (PageMappedToDisk(page)) {
unlock_page(page);
if (PageMappedToDisk(page))
goto mapped;
}

if (page_has_buffers(page)) {
struct buffer_head *bh, *head;
int fully_mapped = 1;
Expand All @@ -90,7 +89,6 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)

if (fully_mapped) {
SetPageMappedToDisk(page);
unlock_page(page);
goto mapped;
}
}
Expand All @@ -105,16 +103,17 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
return VM_FAULT_SIGBUS;

ret = block_page_mkwrite(vma, vmf, nilfs_get_block);
if (unlikely(ret)) {
if (ret != VM_FAULT_LOCKED) {
nilfs_transaction_abort(inode->i_sb);
return ret;
}
nilfs_set_file_dirty(inode, 1 << (PAGE_SHIFT - inode->i_blkbits));
nilfs_transaction_commit(inode->i_sb);

mapped:
SetPageChecked(page);
wait_on_page_writeback(page);
return 0;
return VM_FAULT_LOCKED;
}

static const struct vm_operations_struct nilfs_file_vm_ops = {
Expand Down

0 comments on commit 3409453

Please sign in to comment.