Skip to content

Commit 5b5b4ff

Browse files
riteshharjanijankara
authored andcommitted
ext4: Use generic_buffers_fsync_noflush() implementation
ext4 when got converted to iomap for dio, it copied __generic_file_fsync implementation to avoid taking inode_lock in order to avoid any deadlock (since iomap takes an inode_lock while calling generic_write_sync()). The previous patch already added generic_buffers_fsync*() which does not take any inode_lock(). Hence kill the redundant code and use generic_buffers_fsync_noflush() function instead. Tested-by: Disha Goel <disgoel@linux.ibm.com> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Message-Id: <b43d4bb4403061ed86510c9587673e30a461ba14.1682069716.git.ritesh.list@gmail.com>
1 parent 31b2ebc commit 5b5b4ff

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

fs/ext4/fsync.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/sched.h>
2929
#include <linux/writeback.h>
3030
#include <linux/blkdev.h>
31+
#include <linux/buffer_head.h>
3132

3233
#include "ext4.h"
3334
#include "ext4_jbd2.h"
@@ -78,21 +79,13 @@ static int ext4_sync_parent(struct inode *inode)
7879
return ret;
7980
}
8081

81-
static int ext4_fsync_nojournal(struct inode *inode, bool datasync,
82-
bool *needs_barrier)
82+
static int ext4_fsync_nojournal(struct file *file, loff_t start, loff_t end,
83+
int datasync, bool *needs_barrier)
8384
{
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;
85+
struct inode *inode = file->f_inode;
86+
int ret;
9587

88+
ret = generic_buffers_fsync_noflush(file, start, end, datasync);
9689
if (!ret)
9790
ret = ext4_sync_parent(inode);
9891
if (test_opt(inode->i_sb, BARRIER))
@@ -148,6 +141,14 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
148141
goto out;
149142
}
150143

144+
if (!sbi->s_journal) {
145+
ret = ext4_fsync_nojournal(file, start, end, datasync,
146+
&needs_barrier);
147+
if (needs_barrier)
148+
goto issue_flush;
149+
goto out;
150+
}
151+
151152
ret = file_write_and_wait_range(file, start, end);
152153
if (ret)
153154
goto out;
@@ -157,11 +158,9 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
157158
* Metadata is in the journal, we wait for proper transaction to
158159
* commit here.
159160
*/
160-
if (!sbi->s_journal)
161-
ret = ext4_fsync_nojournal(inode, datasync, &needs_barrier);
162-
else
163-
ret = ext4_fsync_journal(inode, datasync, &needs_barrier);
161+
ret = ext4_fsync_journal(inode, datasync, &needs_barrier);
164162

163+
issue_flush:
165164
if (needs_barrier) {
166165
err = blkdev_issue_flush(inode->i_sb->s_bdev);
167166
if (!ret)

0 commit comments

Comments
 (0)