fsync.c (97eb3f24352ec6632c2127b35d8087d2a809a9b9) fsync.c (0562e0bad483d10e9651fbb8f21dc3d0bad57374)
1/*
2 * linux/fs/ext4/fsync.c
3 *
4 * Copyright (C) 1993 Stephen Tweedie (sct@redhat.com)
5 * from
6 * Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

--- 150 unchanged lines hidden (view full) ---

159 struct inode *inode = file->f_mapping->host;
160 struct ext4_inode_info *ei = EXT4_I(inode);
161 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
162 int ret;
163 tid_t commit_tid;
164
165 J_ASSERT(ext4_journal_current_handle() == NULL);
166
1/*
2 * linux/fs/ext4/fsync.c
3 *
4 * Copyright (C) 1993 Stephen Tweedie (sct@redhat.com)
5 * from
6 * Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

--- 150 unchanged lines hidden (view full) ---

159 struct inode *inode = file->f_mapping->host;
160 struct ext4_inode_info *ei = EXT4_I(inode);
161 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
162 int ret;
163 tid_t commit_tid;
164
165 J_ASSERT(ext4_journal_current_handle() == NULL);
166
167 trace_ext4_sync_file(file, datasync);
167 trace_ext4_sync_file_enter(file, datasync);
168
169 if (inode->i_sb->s_flags & MS_RDONLY)
170 return 0;
171
172 ret = ext4_flush_completed_IO(inode);
173 if (ret < 0)
168
169 if (inode->i_sb->s_flags & MS_RDONLY)
170 return 0;
171
172 ret = ext4_flush_completed_IO(inode);
173 if (ret < 0)
174 return ret;
174 goto out;
175
176 if (!journal) {
177 ret = generic_file_fsync(file, datasync);
178 if (!ret && !list_empty(&inode->i_dentry))
179 ext4_sync_parent(inode);
175
176 if (!journal) {
177 ret = generic_file_fsync(file, datasync);
178 if (!ret && !list_empty(&inode->i_dentry))
179 ext4_sync_parent(inode);
180 return ret;
180 goto out;
181 }
182
183 /*
184 * data=writeback,ordered:
185 * The caller's filemap_fdatawrite()/wait will sync the data.
186 * Metadata is in the journal, we wait for proper transaction to
187 * commit here.
188 *
189 * data=journal:
190 * filemap_fdatawrite won't do anything (the buffers are clean).
191 * ext4_force_commit will write the file data into the journal and
192 * will wait on that.
193 * filemap_fdatawait() will encounter a ton of newly-dirtied pages
194 * (they were dirtied by commit). But that's OK - the blocks are
195 * safe in-journal, which is all fsync() needs to ensure.
196 */
181 }
182
183 /*
184 * data=writeback,ordered:
185 * The caller's filemap_fdatawrite()/wait will sync the data.
186 * Metadata is in the journal, we wait for proper transaction to
187 * commit here.
188 *
189 * data=journal:
190 * filemap_fdatawrite won't do anything (the buffers are clean).
191 * ext4_force_commit will write the file data into the journal and
192 * will wait on that.
193 * filemap_fdatawait() will encounter a ton of newly-dirtied pages
194 * (they were dirtied by commit). But that's OK - the blocks are
195 * safe in-journal, which is all fsync() needs to ensure.
196 */
197 if (ext4_should_journal_data(inode))
198 return ext4_force_commit(inode->i_sb);
197 if (ext4_should_journal_data(inode)) {
198 ret = ext4_force_commit(inode->i_sb);
199 goto out;
200 }
199
200 commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
201 if (jbd2_log_start_commit(journal, commit_tid)) {
202 /*
203 * When the journal is on a different device than the
204 * fs data disk, we need to issue the barrier in
205 * writeback mode. (In ordered mode, the jbd2 layer
206 * will take care of issuing the barrier. In
207 * data=journal, all of the data blocks are written to
208 * the journal device.)
209 */
210 if (ext4_should_writeback_data(inode) &&
211 (journal->j_fs_dev != journal->j_dev) &&
212 (journal->j_flags & JBD2_BARRIER))
213 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL,
214 NULL);
215 ret = jbd2_log_wait_commit(journal, commit_tid);
216 } else if (journal->j_flags & JBD2_BARRIER)
217 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
201
202 commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
203 if (jbd2_log_start_commit(journal, commit_tid)) {
204 /*
205 * When the journal is on a different device than the
206 * fs data disk, we need to issue the barrier in
207 * writeback mode. (In ordered mode, the jbd2 layer
208 * will take care of issuing the barrier. In
209 * data=journal, all of the data blocks are written to
210 * the journal device.)
211 */
212 if (ext4_should_writeback_data(inode) &&
213 (journal->j_fs_dev != journal->j_dev) &&
214 (journal->j_flags & JBD2_BARRIER))
215 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL,
216 NULL);
217 ret = jbd2_log_wait_commit(journal, commit_tid);
218 } else if (journal->j_flags & JBD2_BARRIER)
219 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
220 out:
221 trace_ext4_sync_file_exit(inode, ret);
218 return ret;
219}
222 return ret;
223}