Commit 37b10dd06334ebc89f551d405a0fe27e1a622458
Committed by
Theodore Ts'o
1 parent
a115f749c1
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
ext4: use generic_file_fsync() in ext4_file_fsync() in nojournal mode
Just use the generic function instead of duplicating it. We only need to reshuffle the read-only check a bit (which is there to prevent writing to a filesystem which has been remounted read-only after error I assume). Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Showing 1 changed file with 11 additions and 36 deletions Side-by-side Diff
fs/ext4/fsync.c
... | ... | @@ -73,32 +73,6 @@ |
73 | 73 | return ret; |
74 | 74 | } |
75 | 75 | |
76 | -/** | |
77 | - * __sync_file - generic_file_fsync without the locking and filemap_write | |
78 | - * @inode: inode to sync | |
79 | - * @datasync: only sync essential metadata if true | |
80 | - * | |
81 | - * This is just generic_file_fsync without the locking. This is needed for | |
82 | - * nojournal mode to make sure this inodes data/metadata makes it to disk | |
83 | - * properly. The i_mutex should be held already. | |
84 | - */ | |
85 | -static int __sync_inode(struct inode *inode, int datasync) | |
86 | -{ | |
87 | - int err; | |
88 | - int ret; | |
89 | - | |
90 | - ret = sync_mapping_buffers(inode->i_mapping); | |
91 | - if (!(inode->i_state & I_DIRTY)) | |
92 | - return ret; | |
93 | - if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) | |
94 | - return ret; | |
95 | - | |
96 | - err = sync_inode_metadata(inode, 1); | |
97 | - if (ret == 0) | |
98 | - ret = err; | |
99 | - return ret; | |
100 | -} | |
101 | - | |
102 | 76 | /* |
103 | 77 | * akpm: A new design for ext4_sync_file(). |
104 | 78 | * |
... | ... | @@ -116,7 +90,7 @@ |
116 | 90 | struct inode *inode = file->f_mapping->host; |
117 | 91 | struct ext4_inode_info *ei = EXT4_I(inode); |
118 | 92 | journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; |
119 | - int ret, err; | |
93 | + int ret = 0, err; | |
120 | 94 | tid_t commit_tid; |
121 | 95 | bool needs_barrier = false; |
122 | 96 | |
123 | 97 | |
124 | 98 | |
125 | 99 | |
126 | 100 | |
... | ... | @@ -124,21 +98,21 @@ |
124 | 98 | |
125 | 99 | trace_ext4_sync_file_enter(file, datasync); |
126 | 100 | |
127 | - ret = filemap_write_and_wait_range(inode->i_mapping, start, end); | |
128 | - if (ret) | |
129 | - return ret; | |
130 | - mutex_lock(&inode->i_mutex); | |
131 | - | |
132 | 101 | if (inode->i_sb->s_flags & MS_RDONLY) |
133 | - goto out; | |
102 | + goto out_trace; | |
134 | 103 | |
135 | 104 | if (!journal) { |
136 | - ret = __sync_inode(inode, datasync); | |
105 | + ret = generic_file_fsync(file, start, end, datasync); | |
137 | 106 | if (!ret && !hlist_empty(&inode->i_dentry)) |
138 | 107 | ret = ext4_sync_parent(inode); |
139 | - goto out; | |
108 | + goto out_trace; | |
140 | 109 | } |
141 | 110 | |
111 | + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); | |
112 | + if (ret) | |
113 | + return ret; | |
114 | + mutex_lock(&inode->i_mutex); | |
115 | + | |
142 | 116 | /* |
143 | 117 | * data=writeback,ordered: |
144 | 118 | * The caller's filemap_fdatawrite()/wait will sync the data. |
145 | 119 | |
... | ... | @@ -168,8 +142,9 @@ |
168 | 142 | if (!ret) |
169 | 143 | ret = err; |
170 | 144 | } |
171 | - out: | |
145 | +out: | |
172 | 146 | mutex_unlock(&inode->i_mutex); |
147 | +out_trace: | |
173 | 148 | trace_ext4_sync_file_exit(inode, ret); |
174 | 149 | return ret; |
175 | 150 | } |