diff options
Diffstat (limited to 'fs/f2fs/file.c')
-rw-r--r-- | fs/f2fs/file.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index a8e97f8ed163..060aee65aee8 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -115,6 +115,25 @@ static int get_parent_ino(struct inode *inode, nid_t *pino) | |||
115 | return 1; | 115 | return 1; |
116 | } | 116 | } |
117 | 117 | ||
118 | static inline bool need_do_checkpoint(struct inode *inode) | ||
119 | { | ||
120 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
121 | bool need_cp = false; | ||
122 | |||
123 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) | ||
124 | need_cp = true; | ||
125 | else if (file_wrong_pino(inode)) | ||
126 | need_cp = true; | ||
127 | else if (!space_for_roll_forward(sbi)) | ||
128 | need_cp = true; | ||
129 | else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) | ||
130 | need_cp = true; | ||
131 | else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi))) | ||
132 | need_cp = true; | ||
133 | |||
134 | return need_cp; | ||
135 | } | ||
136 | |||
118 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | 137 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) |
119 | { | 138 | { |
120 | struct inode *inode = file->f_mapping->host; | 139 | struct inode *inode = file->f_mapping->host; |
@@ -159,23 +178,12 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
159 | /* guarantee free sections for fsync */ | 178 | /* guarantee free sections for fsync */ |
160 | f2fs_balance_fs(sbi); | 179 | f2fs_balance_fs(sbi); |
161 | 180 | ||
162 | down_read(&fi->i_sem); | ||
163 | |||
164 | /* | 181 | /* |
165 | * Both of fdatasync() and fsync() are able to be recovered from | 182 | * Both of fdatasync() and fsync() are able to be recovered from |
166 | * sudden-power-off. | 183 | * sudden-power-off. |
167 | */ | 184 | */ |
168 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) | 185 | down_read(&fi->i_sem); |
169 | need_cp = true; | 186 | need_cp = need_do_checkpoint(inode); |
170 | else if (file_wrong_pino(inode)) | ||
171 | need_cp = true; | ||
172 | else if (!space_for_roll_forward(sbi)) | ||
173 | need_cp = true; | ||
174 | else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) | ||
175 | need_cp = true; | ||
176 | else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi))) | ||
177 | need_cp = true; | ||
178 | |||
179 | up_read(&fi->i_sem); | 187 | up_read(&fi->i_sem); |
180 | 188 | ||
181 | if (need_cp) { | 189 | if (need_cp) { |