add patch remove-unneeded-test-in-ext4_alloc_file_blocks
[ext4-patch-queue.git] / cleanup-ext4_sync_parent
blobdb1134a80fa3c1af4d1bfb09433511017092709c
1 ext4: cleanup ext4_sync_parent()
3 From: Jan Kara <jack@suse.cz>
5 A condition !hlist_empty(&inode->i_dentry) is always true for open file.
6 Just remove it. Also ext4_sync_parent() could use some explanation why
7 races with rmdir() are not an issue - add a comment explaining that.
9 Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
10 Signed-off-by: Jan Kara <jack@suse.cz>
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 ---
13  fs/ext4/fsync.c | 9 ++++++++-
14  1 file changed, 8 insertions(+), 1 deletion(-)
16 diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c
17 index 5c43725..88effb1 100644
18 --- a/fs/ext4/fsync.c
19 +++ b/fs/ext4/fsync.c
20 @@ -61,6 +61,13 @@ static int ext4_sync_parent(struct inode *inode)
21                         break;
22                 iput(inode);
23                 inode = next;
24 +               /*
25 +                * The directory inode may have gone through rmdir by now. But
26 +                * the inode itself and its blocks are still allocated (we hold
27 +                * a reference to the inode so it didn't go through
28 +                * ext4_evict_inode()) and so we are safe to flush metadata
29 +                * blocks and the inode.
30 +                */
31                 ret = sync_mapping_buffers(inode->i_mapping);
32                 if (ret)
33                         break;
34 @@ -107,7 +114,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
36         if (!journal) {
37                 ret = __generic_file_fsync(file, start, end, datasync);
38 -               if (!ret && !hlist_empty(&inode->i_dentry))
39 +               if (!ret)
40                         ret = ext4_sync_parent(inode);
41                 if (test_opt(inode->i_sb, BARRIER))
42                         goto issue_flush;