aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/file.c
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-04-06 22:01:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-07 11:31:15 -0400
commit9ff05123e3bfbb1d2b68ba1d9bf1f7d1dffc1453 (patch)
tree056c7bdc2395c8baf77bc63a54a1f747cbf5b650 /fs/nilfs2/file.c
parent64b5a32e0b3680a9655b3f2e668a646068e71d33 (diff)
nilfs2: segment constructor
This adds the segment constructor (also called log writer). The segment constructor collects dirty buffers for every dirty inode, makes summaries of the buffers, assigns disk block addresses to the buffers, and then submits BIOs for the buffers. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2/file.c')
-rw-r--r--fs/nilfs2/file.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index 7ddd42e24f77..8031086db8d5 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -73,10 +73,66 @@ nilfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
73 return ret; 73 return ret;
74} 74}
75 75
76static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct page *page) 76static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
77{ 77{
78 if (!(vma->vm_flags & (VM_WRITE | VM_MAYWRITE))) 78 struct page *page = vmf->page;
79 return -EPERM; 79 struct inode *inode = vma->vm_file->f_dentry->d_inode;
80 struct nilfs_transaction_info ti;
81 int ret;
82
83 if (unlikely(nilfs_near_disk_full(NILFS_SB(inode->i_sb)->s_nilfs)))
84 return VM_FAULT_SIGBUS; /* -ENOSPC */
85
86 lock_page(page);
87 if (page->mapping != inode->i_mapping ||
88 page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
89 unlock_page(page);
90 return VM_FAULT_NOPAGE; /* make the VM retry the fault */
91 }
92
93 /*
94 * check to see if the page is mapped already (no holes)
95 */
96 if (PageMappedToDisk(page)) {
97 unlock_page(page);
98 goto mapped;
99 }
100 if (page_has_buffers(page)) {
101 struct buffer_head *bh, *head;
102 int fully_mapped = 1;
103
104 bh = head = page_buffers(page);
105 do {
106 if (!buffer_mapped(bh)) {
107 fully_mapped = 0;
108 break;
109 }
110 } while (bh = bh->b_this_page, bh != head);
111
112 if (fully_mapped) {
113 SetPageMappedToDisk(page);
114 unlock_page(page);
115 goto mapped;
116 }
117 }
118 unlock_page(page);
119
120 /*
121 * fill hole blocks
122 */
123 ret = nilfs_transaction_begin(inode->i_sb, &ti, 1);
124 /* never returns -ENOMEM, but may return -ENOSPC */
125 if (unlikely(ret))
126 return VM_FAULT_SIGBUS;
127
128 ret = block_page_mkwrite(vma, vmf, nilfs_get_block);
129 if (unlikely(ret)) {
130 nilfs_transaction_abort(inode->i_sb);
131 return ret;
132 }
133 nilfs_transaction_commit(inode->i_sb);
134
135 mapped:
80 SetPageChecked(page); 136 SetPageChecked(page);
81 wait_on_page_writeback(page); 137 wait_on_page_writeback(page);
82 return 0; 138 return 0;