Skip to content

Commit

Permalink
nilfs2: Convert to new freezing mechanism
Browse files Browse the repository at this point in the history
We change nilfs_page_mkwrite() to provide proper freeze protection for
writeable page faults (we must wait for frozen filesystem even if the
page is fully mapped).

We remove all vfs_check_frozen() checks since they are now handled by
the generic code.

CC: [email protected]
CC: KONISHI Ryusuke <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
jankara authored and Al Viro committed Jul 31, 2012
1 parent fbf8fb7 commit 2c22b33
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
18 changes: 11 additions & 7 deletions fs/nilfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
struct page *page = vmf->page;
struct inode *inode = vma->vm_file->f_dentry->d_inode;
struct nilfs_transaction_info ti;
int ret;
int ret = 0;

if (unlikely(nilfs_near_disk_full(inode->i_sb->s_fs_info)))
return VM_FAULT_SIGBUS; /* -ENOSPC */

sb_start_pagefault(inode->i_sb);
lock_page(page);
if (page->mapping != inode->i_mapping ||
page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
unlock_page(page);
return VM_FAULT_NOPAGE; /* make the VM retry the fault */
ret = -EFAULT; /* make the VM retry the fault */
goto out;
}

/*
Expand Down Expand Up @@ -112,19 +114,21 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
ret = nilfs_transaction_begin(inode->i_sb, &ti, 1);
/* never returns -ENOMEM, but may return -ENOSPC */
if (unlikely(ret))
return VM_FAULT_SIGBUS;
goto out;

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

mapped:
wait_on_page_writeback(page);
return VM_FAULT_LOCKED;
out:
sb_end_pagefault(inode->i_sb);
return block_page_mkwrite_return(ret);
}

static const struct vm_operations_struct nilfs_file_vm_ops = {
Expand Down
2 changes: 0 additions & 2 deletions fs/nilfs2/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,6 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
goto out_free;
}

vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);

ret = nilfs_ioctl_move_blocks(inode->i_sb, &argv[0], kbufs[0]);
if (ret < 0)
printk(KERN_ERR "NILFS: GC failed during preparation: "
Expand Down
5 changes: 4 additions & 1 deletion fs/nilfs2/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int nilfs_transaction_begin(struct super_block *sb,
if (ret > 0)
return 0;

vfs_check_frozen(sb, SB_FREEZE_WRITE);
sb_start_intwrite(sb);

nilfs = sb->s_fs_info;
down_read(&nilfs->ns_segctor_sem);
Expand All @@ -205,6 +205,7 @@ int nilfs_transaction_begin(struct super_block *sb,
current->journal_info = ti->ti_save;
if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC)
kmem_cache_free(nilfs_transaction_cachep, ti);
sb_end_intwrite(sb);
return ret;
}

Expand Down Expand Up @@ -246,6 +247,7 @@ int nilfs_transaction_commit(struct super_block *sb)
err = nilfs_construct_segment(sb);
if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC)
kmem_cache_free(nilfs_transaction_cachep, ti);
sb_end_intwrite(sb);
return err;
}

Expand All @@ -264,6 +266,7 @@ void nilfs_transaction_abort(struct super_block *sb)
current->journal_info = ti->ti_save;
if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC)
kmem_cache_free(nilfs_transaction_cachep, ti);
sb_end_intwrite(sb);
}

void nilfs_relax_pressure_in_lock(struct super_block *sb)
Expand Down

0 comments on commit 2c22b33

Please sign in to comment.