diff options
Diffstat (limited to 'fs/sync.c')
-rw-r--r-- | fs/sync.c | 56 |
1 files changed, 47 insertions, 9 deletions
@@ -178,19 +178,23 @@ int file_fsync(struct file *filp, struct dentry *dentry, int datasync) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | /** | 180 | /** |
181 | * vfs_fsync - perform a fsync or fdatasync on a file | 181 | * vfs_fsync_range - helper to sync a range of data & metadata to disk |
182 | * @file: file to sync | 182 | * @file: file to sync |
183 | * @dentry: dentry of @file | 183 | * @dentry: dentry of @file |
184 | * @data: only perform a fdatasync operation | 184 | * @start: offset in bytes of the beginning of data range to sync |
185 | * @end: offset in bytes of the end of data range (inclusive) | ||
186 | * @datasync: perform only datasync | ||
185 | * | 187 | * |
186 | * Write back data and metadata for @file to disk. If @datasync is | 188 | * Write back data in range @start..@end and metadata for @file to disk. If |
187 | * set only metadata needed to access modified file data is written. | 189 | * @datasync is set only metadata needed to access modified file data is |
190 | * written. | ||
188 | * | 191 | * |
189 | * In case this function is called from nfsd @file may be %NULL and | 192 | * In case this function is called from nfsd @file may be %NULL and |
190 | * only @dentry is set. This can only happen when the filesystem | 193 | * only @dentry is set. This can only happen when the filesystem |
191 | * implements the export_operations API. | 194 | * implements the export_operations API. |
192 | */ | 195 | */ |
193 | int vfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 196 | int vfs_fsync_range(struct file *file, struct dentry *dentry, loff_t start, |
197 | loff_t end, int datasync) | ||
194 | { | 198 | { |
195 | const struct file_operations *fop; | 199 | const struct file_operations *fop; |
196 | struct address_space *mapping; | 200 | struct address_space *mapping; |
@@ -214,7 +218,7 @@ int vfs_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
214 | goto out; | 218 | goto out; |
215 | } | 219 | } |
216 | 220 | ||
217 | ret = filemap_fdatawrite(mapping); | 221 | ret = filemap_write_and_wait_range(mapping, start, end); |
218 | 222 | ||
219 | /* | 223 | /* |
220 | * We need to protect against concurrent writers, which could cause | 224 | * We need to protect against concurrent writers, which could cause |
@@ -225,12 +229,29 @@ int vfs_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
225 | if (!ret) | 229 | if (!ret) |
226 | ret = err; | 230 | ret = err; |
227 | mutex_unlock(&mapping->host->i_mutex); | 231 | mutex_unlock(&mapping->host->i_mutex); |
228 | err = filemap_fdatawait(mapping); | 232 | |
229 | if (!ret) | ||
230 | ret = err; | ||
231 | out: | 233 | out: |
232 | return ret; | 234 | return ret; |
233 | } | 235 | } |
236 | EXPORT_SYMBOL(vfs_fsync_range); | ||
237 | |||
238 | /** | ||
239 | * vfs_fsync - perform a fsync or fdatasync on a file | ||
240 | * @file: file to sync | ||
241 | * @dentry: dentry of @file | ||
242 | * @datasync: only perform a fdatasync operation | ||
243 | * | ||
244 | * Write back data and metadata for @file to disk. If @datasync is | ||
245 | * set only metadata needed to access modified file data is written. | ||
246 | * | ||
247 | * In case this function is called from nfsd @file may be %NULL and | ||
248 | * only @dentry is set. This can only happen when the filesystem | ||
249 | * implements the export_operations API. | ||
250 | */ | ||
251 | int vfs_fsync(struct file *file, struct dentry *dentry, int datasync) | ||
252 | { | ||
253 | return vfs_fsync_range(file, dentry, 0, LLONG_MAX, datasync); | ||
254 | } | ||
234 | EXPORT_SYMBOL(vfs_fsync); | 255 | EXPORT_SYMBOL(vfs_fsync); |
235 | 256 | ||
236 | static int do_fsync(unsigned int fd, int datasync) | 257 | static int do_fsync(unsigned int fd, int datasync) |
@@ -256,6 +277,23 @@ SYSCALL_DEFINE1(fdatasync, unsigned int, fd) | |||
256 | return do_fsync(fd, 1); | 277 | return do_fsync(fd, 1); |
257 | } | 278 | } |
258 | 279 | ||
280 | /** | ||
281 | * generic_write_sync - perform syncing after a write if file / inode is sync | ||
282 | * @file: file to which the write happened | ||
283 | * @pos: offset where the write started | ||
284 | * @count: length of the write | ||
285 | * | ||
286 | * This is just a simple wrapper about our general syncing function. | ||
287 | */ | ||
288 | int generic_write_sync(struct file *file, loff_t pos, loff_t count) | ||
289 | { | ||
290 | if (!(file->f_flags & O_SYNC) && !IS_SYNC(file->f_mapping->host)) | ||
291 | return 0; | ||
292 | return vfs_fsync_range(file, file->f_path.dentry, pos, | ||
293 | pos + count - 1, 1); | ||
294 | } | ||
295 | EXPORT_SYMBOL(generic_write_sync); | ||
296 | |||
259 | /* | 297 | /* |
260 | * sys_sync_file_range() permits finely controlled syncing over a segment of | 298 | * sys_sync_file_range() permits finely controlled syncing over a segment of |
261 | * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is | 299 | * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is |