fsync.c (d59729f4e794f814b25ccd2aebfbe606242c4544) | fsync.c (60ad4466821a96913a9b567115e194ed1087c2d7) |
---|---|
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) --- 153 unchanged lines hidden (view full) --- 162 ret = sync_inode(inode, &wbc); 163 if (ret) 164 break; 165 } 166 iput(inode); 167 return ret; 168} 169 | 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) --- 153 unchanged lines hidden (view full) --- 162 ret = sync_inode(inode, &wbc); 163 if (ret) 164 break; 165 } 166 iput(inode); 167 return ret; 168} 169 |
170/** 171 * __sync_file - generic_file_fsync without the locking and filemap_write 172 * @inode: inode to sync 173 * @datasync: only sync essential metadata if true 174 * 175 * This is just generic_file_fsync without the locking. This is needed for 176 * nojournal mode to make sure this inodes data/metadata makes it to disk 177 * properly. The i_mutex should be held already. 178 */ 179static int __sync_inode(struct inode *inode, int datasync) 180{ 181 int err; 182 int ret; 183 184 ret = sync_mapping_buffers(inode->i_mapping); 185 if (!(inode->i_state & I_DIRTY)) 186 return ret; 187 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) 188 return ret; 189 190 err = sync_inode_metadata(inode, 1); 191 if (ret == 0) 192 ret = err; 193 return ret; 194} 195 |
|
170/* 171 * akpm: A new design for ext4_sync_file(). 172 * 173 * This is only called from sys_fsync(), sys_fdatasync() and sys_msync(). 174 * There cannot be a transaction open by this task. 175 * Another task could have dirtied this inode. Its data can be in any 176 * state in the journalling system. 177 * 178 * What we do is just kick off a commit and wait on it. This will snapshot the 179 * inode to disk. 180 * 181 * i_mutex lock is held when entering and exiting this function 182 */ 183 | 196/* 197 * akpm: A new design for ext4_sync_file(). 198 * 199 * This is only called from sys_fsync(), sys_fdatasync() and sys_msync(). 200 * There cannot be a transaction open by this task. 201 * Another task could have dirtied this inode. Its data can be in any 202 * state in the journalling system. 203 * 204 * What we do is just kick off a commit and wait on it. This will snapshot the 205 * inode to disk. 206 * 207 * i_mutex lock is held when entering and exiting this function 208 */ 209 |
184int ext4_sync_file(struct file *file, int datasync) | 210int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) |
185{ 186 struct inode *inode = file->f_mapping->host; 187 struct ext4_inode_info *ei = EXT4_I(inode); 188 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; 189 int ret; 190 tid_t commit_tid; 191 bool needs_barrier = false; 192 193 J_ASSERT(ext4_journal_current_handle() == NULL); 194 195 trace_ext4_sync_file_enter(file, datasync); 196 | 211{ 212 struct inode *inode = file->f_mapping->host; 213 struct ext4_inode_info *ei = EXT4_I(inode); 214 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; 215 int ret; 216 tid_t commit_tid; 217 bool needs_barrier = false; 218 219 J_ASSERT(ext4_journal_current_handle() == NULL); 220 221 trace_ext4_sync_file_enter(file, datasync); 222 |
223 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 224 if (ret) 225 return ret; 226 mutex_lock(&inode->i_mutex); 227 |
|
197 if (inode->i_sb->s_flags & MS_RDONLY) | 228 if (inode->i_sb->s_flags & MS_RDONLY) |
198 return 0; | 229 goto out; |
199 200 ret = ext4_flush_completed_IO(inode); 201 if (ret < 0) 202 goto out; 203 204 if (!journal) { | 230 231 ret = ext4_flush_completed_IO(inode); 232 if (ret < 0) 233 goto out; 234 235 if (!journal) { |
205 ret = generic_file_fsync(file, datasync); | 236 ret = __sync_inode(inode, datasync); |
206 if (!ret && !list_empty(&inode->i_dentry)) 207 ret = ext4_sync_parent(inode); 208 goto out; 209 } 210 211 /* 212 * data=writeback,ordered: 213 * The caller's filemap_fdatawrite()/wait will sync the data. --- 17 unchanged lines hidden (view full) --- 231 if (journal->j_flags & JBD2_BARRIER && 232 !jbd2_trans_will_send_data_barrier(journal, commit_tid)) 233 needs_barrier = true; 234 jbd2_log_start_commit(journal, commit_tid); 235 ret = jbd2_log_wait_commit(journal, commit_tid); 236 if (needs_barrier) 237 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 238 out: | 237 if (!ret && !list_empty(&inode->i_dentry)) 238 ret = ext4_sync_parent(inode); 239 goto out; 240 } 241 242 /* 243 * data=writeback,ordered: 244 * The caller's filemap_fdatawrite()/wait will sync the data. --- 17 unchanged lines hidden (view full) --- 262 if (journal->j_flags & JBD2_BARRIER && 263 !jbd2_trans_will_send_data_barrier(journal, commit_tid)) 264 needs_barrier = true; 265 jbd2_log_start_commit(journal, commit_tid); 266 ret = jbd2_log_wait_commit(journal, commit_tid); 267 if (needs_barrier) 268 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 269 out: |
270 mutex_unlock(&inode->i_mutex); |
|
239 trace_ext4_sync_file_exit(inode, ret); 240 return ret; 241} | 271 trace_ext4_sync_file_exit(inode, ret); 272 return ret; 273} |