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 <[email protected]>
CC: [email protected]
CC: Joel Becker <[email protected]>
CC: Felix Blyakher <[email protected]>
CC: [email protected]
CC: Anton Altaparmakov <[email protected]>
CC: [email protected]
CC: OGAWA Hirofumi <[email protected]>
CC: [email protected]
CC: [email protected]
Acked-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
This commit is contained in:
Jan Kara 2009-08-17 19:52:36 +02:00
commit 148f948ba8
4 changed files with 61 additions and 30 deletions

View file

@ -976,25 +976,15 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
if (ret > 0) {
unsigned long nr_pages;
int err;
*ppos += ret;
nr_pages = (ret + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
/*
* If file or inode is SYNC and we actually wrote some data,
* sync it.
*/
if (unlikely((out->f_flags & O_SYNC) || IS_SYNC(inode))) {
int err;
mutex_lock(&inode->i_mutex);
err = generic_osync_inode(inode, mapping,
OSYNC_METADATA|OSYNC_DATA);
mutex_unlock(&inode->i_mutex);
if (err)
ret = err;
}
err = generic_write_sync(out, *ppos, ret);
if (err)
ret = err;
else
*ppos += ret;
balance_dirty_pages_ratelimited_nr(mapping, nr_pages);
}