aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/f2fs/file.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index b6f3fbf2a376..0b9700216303 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -138,6 +138,17 @@ static inline bool need_do_checkpoint(struct inode *inode)
138 return need_cp; 138 return need_cp;
139} 139}
140 140
141static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
142{
143 struct page *i = find_get_page(NODE_MAPPING(sbi), ino);
144 bool ret = false;
145 /* But we need to avoid that there are some inode updates */
146 if ((i && PageDirty(i)) || need_inode_block_update(sbi, ino))
147 ret = true;
148 f2fs_put_page(i, 0);
149 return ret;
150}
151
141int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) 152int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
142{ 153{
143 struct inode *inode = file->f_mapping->host; 154 struct inode *inode = file->f_mapping->host;
@@ -168,19 +179,21 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
168 return ret; 179 return ret;
169 } 180 }
170 181
182 /* if the inode is dirty, let's recover all the time */
183 if (!datasync && is_inode_flag_set(fi, FI_DIRTY_INODE)) {
184 update_inode_page(inode);
185 goto go_write;
186 }
187
171 /* 188 /*
172 * if there is no written data, don't waste time to write recovery info. 189 * if there is no written data, don't waste time to write recovery info.
173 */ 190 */
174 if (!is_inode_flag_set(fi, FI_APPEND_WRITE) && 191 if (!is_inode_flag_set(fi, FI_APPEND_WRITE) &&
175 !exist_written_data(sbi, ino, APPEND_INO)) { 192 !exist_written_data(sbi, ino, APPEND_INO)) {
176 struct page *i = find_get_page(NODE_MAPPING(sbi), ino);
177 193
178 /* But we need to avoid that there are some inode updates */ 194 /* it may call write_inode just prior to fsync */
179 if ((i && PageDirty(i)) || need_inode_block_update(sbi, ino)) { 195 if (need_inode_page_update(sbi, ino))
180 f2fs_put_page(i, 0);
181 goto go_write; 196 goto go_write;
182 }
183 f2fs_put_page(i, 0);
184 197
185 if (is_inode_flag_set(fi, FI_UPDATE_WRITE) || 198 if (is_inode_flag_set(fi, FI_UPDATE_WRITE) ||
186 exist_written_data(sbi, ino, UPDATE_INO)) 199 exist_written_data(sbi, ino, UPDATE_INO))