aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sync.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2009-08-17 13:52:36 -0400
committerJan Kara <jack@suse.cz>2009-09-14 11:08:15 -0400
commit148f948ba877f4d3cdef036b1ff6d9f68986706a (patch)
treec07963f08bf8c2119ec00df64e4293e2e60acaa1 /fs/sync.c
parenteef99380679e20e7edc096aa4d8a98b875404d79 (diff)
vfs: Introduce new helpers for syncing after writing to O_SYNC file or IS_SYNC inode
Introduce new function for generic inode syncing (vfs_fsync_range) and use it from fsync() path. Introduce also new helper for syncing after a sync write (generic_write_sync) using the generic function. Use these new helpers for syncing from generic VFS functions. This makes O_SYNC writes to block devices acquire i_mutex for syncing. If we really care about this, we can make block_fsync() drop the i_mutex and reacquire it before it returns. CC: Evgeniy Polyakov <zbr@ioremap.net> CC: ocfs2-devel@oss.oracle.com CC: Joel Becker <joel.becker@oracle.com> CC: Felix Blyakher <felixb@sgi.com> CC: xfs@oss.sgi.com CC: Anton Altaparmakov <aia21@cantab.net> CC: linux-ntfs-dev@lists.sourceforge.net CC: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> CC: linux-ext4@vger.kernel.org CC: tytso@mit.edu Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/sync.c')
-rw-r--r--fs/sync.c55
1 files changed, 48 insertions, 7 deletions
diff --git a/fs/sync.c b/fs/sync.c
index 103cc7fdd3df..4e15da01923c 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -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 */
193int vfs_fsync(struct file *file, struct dentry *dentry, int datasync) 196int 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_fdatawrite_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,32 @@ 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
233 err = filemap_fdatawait_range(mapping, start, end);
229 if (!ret) 234 if (!ret)
230 ret = err; 235 ret = err;
231out: 236out:
232 return ret; 237 return ret;
233} 238}
239EXPORT_SYMBOL(vfs_fsync_range);
240
241/**
242 * vfs_fsync - perform a fsync or fdatasync on a file
243 * @file: file to sync
244 * @dentry: dentry of @file
245 * @datasync: only perform a fdatasync operation
246 *
247 * Write back data and metadata for @file to disk. If @datasync is
248 * set only metadata needed to access modified file data is written.
249 *
250 * In case this function is called from nfsd @file may be %NULL and
251 * only @dentry is set. This can only happen when the filesystem
252 * implements the export_operations API.
253 */
254int vfs_fsync(struct file *file, struct dentry *dentry, int datasync)
255{
256 return vfs_fsync_range(file, dentry, 0, LLONG_MAX, datasync);
257}
234EXPORT_SYMBOL(vfs_fsync); 258EXPORT_SYMBOL(vfs_fsync);
235 259
236static int do_fsync(unsigned int fd, int datasync) 260static int do_fsync(unsigned int fd, int datasync)
@@ -256,6 +280,23 @@ SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
256 return do_fsync(fd, 1); 280 return do_fsync(fd, 1);
257} 281}
258 282
283/**
284 * generic_write_sync - perform syncing after a write if file / inode is sync
285 * @file: file to which the write happened
286 * @pos: offset where the write started
287 * @count: length of the write
288 *
289 * This is just a simple wrapper about our general syncing function.
290 */
291int generic_write_sync(struct file *file, loff_t pos, loff_t count)
292{
293 if (!(file->f_flags & O_SYNC) && !IS_SYNC(file->f_mapping->host))
294 return 0;
295 return vfs_fsync_range(file, file->f_path.dentry, pos,
296 pos + count - 1, 1);
297}
298EXPORT_SYMBOL(generic_write_sync);
299
259/* 300/*
260 * sys_sync_file_range() permits finely controlled syncing over a segment of 301 * 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 302 * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is