Skip to content

Commit 4142e0d

Browse files
committed
Merge branch 'osync_cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6
* 'osync_cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6: fsync: wait for data writeout completion before calling ->fsync vfs: Remove generic_osync_inode() and sync_page_range{_nolock}() fat: Opencode sync_page_range_nolock() pohmelfs: Use new syncing helper xfs: Convert sync_page_range() to simple filemap_write_and_wait_range() ocfs2: Update syncing after splicing to match generic version ntfs: Use new syncing helpers and update comments ext4: Remove syncing logic from ext4_file_write ext3: Remove syncing logic from ext3_file_write ext2: Update comment about generic_osync_inode vfs: Introduce new helpers for syncing after writing to O_SYNC file or IS_SYNC inode vfs: Rename generic_file_aio_write_nolock ocfs2: Use __generic_file_aio_write instead of generic_file_aio_write_nolock pohmelfs: Use __generic_file_aio_write instead of generic_file_aio_write_nolock vfs: Remove syncing from generic_file_direct_write() and generic_file_buffered_write() vfs: Export __generic_file_aio_write() and add some comments vfs: Introduce filemap_fdatawait_range
2 parents 33f1de6 + 2daea67 commit 4142e0d

18 files changed

Lines changed: 204 additions & 380 deletions

File tree

‎drivers/char/raw.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static const struct file_operations raw_fops = {
246246
.read = do_sync_read,
247247
.aio_read = generic_file_aio_read,
248248
.write = do_sync_write,
249-
.aio_write = generic_file_aio_write_nolock,
249+
.aio_write = blkdev_aio_write,
250250
.open = raw_open,
251251
.release= raw_release,
252252
.ioctl = raw_ioctl,

‎drivers/staging/pohmelfs/inode.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,16 +921,16 @@ ssize_t pohmelfs_write(struct file *file, const char __user *buf,
921921
if (ret)
922922
goto err_out_unlock;
923923

924-
ret = generic_file_aio_write_nolock(&kiocb, &iov, 1, pos);
924+
ret = __generic_file_aio_write(&kiocb, &iov, 1, &kiocb.ki_pos);
925925
*ppos = kiocb.ki_pos;
926926

927927
mutex_unlock(&inode->i_mutex);
928928
WARN_ON(ret < 0);
929929

930-
if (ret > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
930+
if (ret > 0) {
931931
ssize_t err;
932932

933-
err = sync_page_range(inode, mapping, pos, ret);
933+
err = generic_write_sync(file, pos, ret);
934934
if (err < 0)
935935
ret = err;
936936
WARN_ON(ret < 0);

‎fs/block_dev.c‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,33 @@ static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
14041404
return blkdev_ioctl(bdev, mode, cmd, arg);
14051405
}
14061406

1407+
/*
1408+
* Write data to the block device. Only intended for the block device itself
1409+
* and the raw driver which basically is a fake block device.
1410+
*
1411+
* Does not take i_mutex for the write and thus is not for general purpose
1412+
* use.
1413+
*/
1414+
ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov,
1415+
unsigned long nr_segs, loff_t pos)
1416+
{
1417+
struct file *file = iocb->ki_filp;
1418+
ssize_t ret;
1419+
1420+
BUG_ON(iocb->ki_pos != pos);
1421+
1422+
ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
1423+
if (ret > 0 || ret == -EIOCBQUEUED) {
1424+
ssize_t err;
1425+
1426+
err = generic_write_sync(file, pos, ret);
1427+
if (err < 0 && ret > 0)
1428+
ret = err;
1429+
}
1430+
return ret;
1431+
}
1432+
EXPORT_SYMBOL_GPL(blkdev_aio_write);
1433+
14071434
/*
14081435
* Try to release a page associated with block device when the system
14091436
* is under memory pressure.
@@ -1436,7 +1463,7 @@ const struct file_operations def_blk_fops = {
14361463
.read = do_sync_read,
14371464
.write = do_sync_write,
14381465
.aio_read = generic_file_aio_read,
1439-
.aio_write = generic_file_aio_write_nolock,
1466+
.aio_write = blkdev_aio_write,
14401467
.mmap = generic_file_mmap,
14411468
.fsync = block_fsync,
14421469
.unlocked_ioctl = block_ioctl,

‎fs/ext2/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int ext2_alloc_branch(struct inode *inode,
482482
unlock_buffer(bh);
483483
mark_buffer_dirty_inode(bh, inode);
484484
/* We used to sync bh here if IS_SYNC(inode).
485-
* But we now rely upon generic_osync_inode()
485+
* But we now rely upon generic_write_sync()
486486
* and b_inode_buffers. But not for directories.
487487
*/
488488
if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode))

‎fs/ext3/file.c‎

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -51,71 +51,12 @@ static int ext3_release_file (struct inode * inode, struct file * filp)
5151
return 0;
5252
}
5353

54-
static ssize_t
55-
ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
56-
unsigned long nr_segs, loff_t pos)
57-
{
58-
struct file *file = iocb->ki_filp;
59-
struct inode *inode = file->f_path.dentry->d_inode;
60-
ssize_t ret;
61-
int err;
62-
63-
ret = generic_file_aio_write(iocb, iov, nr_segs, pos);
64-
65-
/*
66-
* Skip flushing if there was an error, or if nothing was written.
67-
*/
68-
if (ret <= 0)
69-
return ret;
70-
71-
/*
72-
* If the inode is IS_SYNC, or is O_SYNC and we are doing data
73-
* journalling then we need to make sure that we force the transaction
74-
* to disk to keep all metadata uptodate synchronously.
75-
*/
76-
if (file->f_flags & O_SYNC) {
77-
/*
78-
* If we are non-data-journaled, then the dirty data has
79-
* already been flushed to backing store by generic_osync_inode,
80-
* and the inode has been flushed too if there have been any
81-
* modifications other than mere timestamp updates.
82-
*
83-
* Open question --- do we care about flushing timestamps too
84-
* if the inode is IS_SYNC?
85-
*/
86-
if (!ext3_should_journal_data(inode))
87-
return ret;
88-
89-
goto force_commit;
90-
}
91-
92-
/*
93-
* So we know that there has been no forced data flush. If the inode
94-
* is marked IS_SYNC, we need to force one ourselves.
95-
*/
96-
if (!IS_SYNC(inode))
97-
return ret;
98-
99-
/*
100-
* Open question #2 --- should we force data to disk here too? If we
101-
* don't, the only impact is that data=writeback filesystems won't
102-
* flush data to disk automatically on IS_SYNC, only metadata (but
103-
* historically, that is what ext2 has done.)
104-
*/
105-
106-
force_commit:
107-
err = ext3_force_commit(inode->i_sb);
108-
if (err)
109-
return err;
110-
return ret;
111-
}
112-
11354
const struct file_operations ext3_file_operations = {
11455
.llseek = generic_file_llseek,
11556
.read = do_sync_read,
11657
.write = do_sync_write,
11758
.aio_read = generic_file_aio_read,
118-
.aio_write = ext3_file_write,
59+
.aio_write = generic_file_aio_write,
11960
.unlocked_ioctl = ext3_ioctl,
12061
#ifdef CONFIG_COMPAT
12162
.compat_ioctl = ext3_compat_ioctl,

‎fs/ext4/file.c‎

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ static ssize_t
5858
ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
5959
unsigned long nr_segs, loff_t pos)
6060
{
61-
struct file *file = iocb->ki_filp;
62-
struct inode *inode = file->f_path.dentry->d_inode;
63-
ssize_t ret;
64-
int err;
61+
struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
6562

6663
/*
6764
* If we have encountered a bitmap-format file, the size limit
@@ -81,53 +78,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
8178
}
8279
}
8380

84-
ret = generic_file_aio_write(iocb, iov, nr_segs, pos);
85-
/*
86-
* Skip flushing if there was an error, or if nothing was written.
87-
*/
88-
if (ret <= 0)
89-
return ret;
90-
91-
/*
92-
* If the inode is IS_SYNC, or is O_SYNC and we are doing data
93-
* journalling then we need to make sure that we force the transaction
94-
* to disk to keep all metadata uptodate synchronously.
95-
*/
96-
if (file->f_flags & O_SYNC) {
97-
/*
98-
* If we are non-data-journaled, then the dirty data has
99-
* already been flushed to backing store by generic_osync_inode,
100-
* and the inode has been flushed too if there have been any
101-
* modifications other than mere timestamp updates.
102-
*
103-
* Open question --- do we care about flushing timestamps too
104-
* if the inode is IS_SYNC?
105-
*/
106-
if (!ext4_should_journal_data(inode))
107-
return ret;
108-
109-
goto force_commit;
110-
}
111-
112-
/*
113-
* So we know that there has been no forced data flush. If the inode
114-
* is marked IS_SYNC, we need to force one ourselves.
115-
*/
116-
if (!IS_SYNC(inode))
117-
return ret;
118-
119-
/*
120-
* Open question #2 --- should we force data to disk here too? If we
121-
* don't, the only impact is that data=writeback filesystems won't
122-
* flush data to disk automatically on IS_SYNC, only metadata (but
123-
* historically, that is what ext2 has done.)
124-
*/
125-
126-
force_commit:
127-
err = ext4_force_commit(inode->i_sb);
128-
if (err)
129-
return err;
130-
return ret;
81+
return generic_file_aio_write(iocb, iov, nr_segs, pos);
13182
}
13283

13384
static struct vm_operations_struct ext4_file_vm_ops = {

‎fs/fat/file.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,26 @@ static int fat_cont_expand(struct inode *inode, loff_t size)
176176

177177
inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
178178
mark_inode_dirty(inode);
179-
if (IS_SYNC(inode))
180-
err = sync_page_range_nolock(inode, mapping, start, count);
179+
if (IS_SYNC(inode)) {
180+
int err2;
181+
182+
/*
183+
* Opencode syncing since we don't have a file open to use
184+
* standard fsync path.
185+
*/
186+
err = filemap_fdatawrite_range(mapping, start,
187+
start + count - 1);
188+
err2 = sync_mapping_buffers(mapping);
189+
if (!err)
190+
err = err2;
191+
err2 = write_inode_now(inode, 1);
192+
if (!err)
193+
err = err2;
194+
if (!err) {
195+
err = filemap_fdatawait_range(mapping, start,
196+
start + count - 1);
197+
}
198+
}
181199
out:
182200
return err;
183201
}

‎fs/fat/misc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
119119
MSDOS_I(inode)->i_start = new_dclus;
120120
MSDOS_I(inode)->i_logstart = new_dclus;
121121
/*
122-
* Since generic_osync_inode() synchronize later if
123-
* this is not directory, we don't here.
122+
* Since generic_write_sync() synchronizes regular files later,
123+
* we sync here only directories.
124124
*/
125125
if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode)) {
126126
ret = fat_sync_inode(inode);

‎fs/fs-writeback.c‎

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,57 +1242,3 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc)
12421242
return ret;
12431243
}
12441244
EXPORT_SYMBOL(sync_inode);
1245-
1246-
/**
1247-
* generic_osync_inode - flush all dirty data for a given inode to disk
1248-
* @inode: inode to write
1249-
* @mapping: the address_space that should be flushed
1250-
* @what: what to write and wait upon
1251-
*
1252-
* This can be called by file_write functions for files which have the
1253-
* O_SYNC flag set, to flush dirty writes to disk.
1254-
*
1255-
* @what is a bitmask, specifying which part of the inode's data should be
1256-
* written and waited upon.
1257-
*
1258-
* OSYNC_DATA: i_mapping's dirty data
1259-
* OSYNC_METADATA: the buffers at i_mapping->private_list
1260-
* OSYNC_INODE: the inode itself
1261-
*/
1262-
1263-
int generic_osync_inode(struct inode *inode, struct address_space *mapping, int what)
1264-
{
1265-
int err = 0;
1266-
int need_write_inode_now = 0;
1267-
int err2;
1268-
1269-
if (what & OSYNC_DATA)
1270-
err = filemap_fdatawrite(mapping);
1271-
if (what & (OSYNC_METADATA|OSYNC_DATA)) {
1272-
err2 = sync_mapping_buffers(mapping);
1273-
if (!err)
1274-
err = err2;
1275-
}
1276-
if (what & OSYNC_DATA) {
1277-
err2 = filemap_fdatawait(mapping);
1278-
if (!err)
1279-
err = err2;
1280-
}
1281-
1282-
spin_lock(&inode_lock);
1283-
if ((inode->i_state & I_DIRTY) &&
1284-
((what & OSYNC_INODE) || (inode->i_state & I_DIRTY_DATASYNC)))
1285-
need_write_inode_now = 1;
1286-
spin_unlock(&inode_lock);
1287-
1288-
if (need_write_inode_now) {
1289-
err2 = write_inode_now(inode, 1);
1290-
if (!err)
1291-
err = err2;
1292-
}
1293-
else
1294-
inode_sync_wait(inode);
1295-
1296-
return err;
1297-
}
1298-
EXPORT_SYMBOL(generic_osync_inode);

‎fs/ntfs/file.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,14 +2076,6 @@ static ssize_t ntfs_file_buffered_write(struct kiocb *iocb,
20762076
*ppos = pos;
20772077
if (cached_page)
20782078
page_cache_release(cached_page);
2079-
/* For now, when the user asks for O_SYNC, we actually give O_DSYNC. */
2080-
if (likely(!status)) {
2081-
if (unlikely((file->f_flags & O_SYNC) || IS_SYNC(vi))) {
2082-
if (!mapping->a_ops->writepage || !is_sync_kiocb(iocb))
2083-
status = generic_osync_inode(vi, mapping,
2084-
OSYNC_METADATA|OSYNC_DATA);
2085-
}
2086-
}
20872079
pagevec_lru_add_file(&lru_pvec);
20882080
ntfs_debug("Done. Returning %s (written 0x%lx, status %li).",
20892081
written ? "written" : "status", (unsigned long)written,
@@ -2145,8 +2137,8 @@ static ssize_t ntfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
21452137
mutex_lock(&inode->i_mutex);
21462138
ret = ntfs_file_aio_write_nolock(iocb, iov, nr_segs, &iocb->ki_pos);
21472139
mutex_unlock(&inode->i_mutex);
2148-
if (ret > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
2149-
int err = sync_page_range(inode, mapping, pos, ret);
2140+
if (ret > 0) {
2141+
int err = generic_write_sync(file, pos, ret);
21502142
if (err < 0)
21512143
ret = err;
21522144
}
@@ -2173,8 +2165,8 @@ static ssize_t ntfs_file_writev(struct file *file, const struct iovec *iov,
21732165
if (ret == -EIOCBQUEUED)
21742166
ret = wait_on_sync_kiocb(&kiocb);
21752167
mutex_unlock(&inode->i_mutex);
2176-
if (ret > 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
2177-
int err = sync_page_range(inode, mapping, *ppos - ret, ret);
2168+
if (ret > 0) {
2169+
int err = generic_write_sync(file, *ppos - ret, ret);
21782170
if (err < 0)
21792171
ret = err;
21802172
}

0 commit comments

Comments
 (0)