hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/ext4/fsync.c
....@@ -78,6 +78,43 @@
7878 return ret;
7979 }
8080
81
+static int ext4_fsync_nojournal(struct inode *inode, bool datasync,
82
+ bool *needs_barrier)
83
+{
84
+ int ret, err;
85
+
86
+ ret = sync_mapping_buffers(inode->i_mapping);
87
+ if (!(inode->i_state & I_DIRTY_ALL))
88
+ return ret;
89
+ if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
90
+ return ret;
91
+
92
+ err = sync_inode_metadata(inode, 1);
93
+ if (!ret)
94
+ ret = err;
95
+
96
+ if (!ret)
97
+ ret = ext4_sync_parent(inode);
98
+ if (test_opt(inode->i_sb, BARRIER))
99
+ *needs_barrier = true;
100
+
101
+ return ret;
102
+}
103
+
104
+static int ext4_fsync_journal(struct inode *inode, bool datasync,
105
+ bool *needs_barrier)
106
+{
107
+ struct ext4_inode_info *ei = EXT4_I(inode);
108
+ journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
109
+ tid_t commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
110
+
111
+ if (journal->j_flags & JBD2_BARRIER &&
112
+ !jbd2_trans_will_send_data_barrier(journal, commit_tid))
113
+ *needs_barrier = true;
114
+
115
+ return ext4_fc_commit(journal, commit_tid);
116
+}
117
+
81118 /*
82119 * akpm: A new design for ext4_sync_file().
83120 *
....@@ -89,17 +126,14 @@
89126 * What we do is just kick off a commit and wait on it. This will snapshot the
90127 * inode to disk.
91128 */
92
-
93129 int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
94130 {
95
- struct inode *inode = file->f_mapping->host;
96
- struct ext4_inode_info *ei = EXT4_I(inode);
97
- journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
98131 int ret = 0, err;
99
- tid_t commit_tid;
100132 bool needs_barrier = false;
133
+ struct inode *inode = file->f_mapping->host;
134
+ struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
101135
102
- if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
136
+ if (unlikely(ext4_forced_shutdown(sbi)))
103137 return -EIO;
104138
105139 J_ASSERT(ext4_journal_current_handle() == NULL);
....@@ -109,23 +143,15 @@
109143 if (sb_rdonly(inode->i_sb)) {
110144 /* Make sure that we read updated s_mount_flags value */
111145 smp_rmb();
112
- if (EXT4_SB(inode->i_sb)->s_mount_flags & EXT4_MF_FS_ABORTED)
146
+ if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FS_ABORTED))
113147 ret = -EROFS;
114
- goto out;
115
- }
116
-
117
- if (!journal) {
118
- ret = __generic_file_fsync(file, start, end, datasync);
119
- if (!ret)
120
- ret = ext4_sync_parent(inode);
121
- if (test_opt(inode->i_sb, BARRIER))
122
- goto issue_flush;
123148 goto out;
124149 }
125150
126151 ret = file_write_and_wait_range(file, start, end);
127152 if (ret)
128
- return ret;
153
+ goto out;
154
+
129155 /*
130156 * data=writeback,ordered:
131157 * The caller's filemap_fdatawrite()/wait will sync the data.
....@@ -140,19 +166,15 @@
140166 * (they were dirtied by commit). But that's OK - the blocks are
141167 * safe in-journal, which is all fsync() needs to ensure.
142168 */
143
- if (ext4_should_journal_data(inode)) {
169
+ if (!sbi->s_journal)
170
+ ret = ext4_fsync_nojournal(inode, datasync, &needs_barrier);
171
+ else if (ext4_should_journal_data(inode))
144172 ret = ext4_force_commit(inode->i_sb);
145
- goto out;
146
- }
173
+ else
174
+ ret = ext4_fsync_journal(inode, datasync, &needs_barrier);
147175
148
- commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
149
- if (journal->j_flags & JBD2_BARRIER &&
150
- !jbd2_trans_will_send_data_barrier(journal, commit_tid))
151
- needs_barrier = true;
152
- ret = jbd2_complete_transaction(journal, commit_tid);
153176 if (needs_barrier) {
154
- issue_flush:
155
- err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
177
+ err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL);
156178 if (!ret)
157179 ret = err;
158180 }