Skip to content

Commit

Permalink
fs: add IOCB_SYNC and IOCB_DSYNC
Browse files Browse the repository at this point in the history
This will allow us to do per-I/O sync file writes, as required by a lot
of fileservers or storage targets.

XXX: Will need a few additional audits for O_DSYNC

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Christoph Hellwig authored and Al Viro committed May 1, 2016
1 parent 716b9bc commit dde0c2e
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
ret = __generic_file_write_iter(iocb, from);
if (ret > 0) {
ssize_t err;
err = generic_write_sync(file, iocb->ki_pos - ret, ret);
err = generic_write_sync(iocb, iocb->ki_pos - ret, ret);
if (err < 0)
ret = err;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
BTRFS_I(inode)->last_sub_trans = root->log_transid;
spin_unlock(&BTRFS_I(inode)->lock);
if (num_written > 0) {
err = generic_write_sync(file, pos, num_written);
err = generic_write_sync(iocb, pos, num_written);
if (err < 0)
num_written = err;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,7 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
inode_unlock(inode);

if (rc > 0) {
ssize_t err = generic_write_sync(file, iocb->ki_pos - rc, rc);
ssize_t err = generic_write_sync(iocb, iocb->ki_pos - rc, rc);
if (err < 0)
rc = err;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, bool is_async)
if (dio->rw & WRITE) {
int err;

err = generic_write_sync(dio->iocb->ki_filp, offset,
err = generic_write_sync(dio->iocb, offset,
transferred);
if (err < 0 && ret > 0)
ret = err;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (ret > 0) {
ssize_t err;

err = generic_write_sync(file, iocb->ki_pos - ret, ret);
err = generic_write_sync(iocb, iocb->ki_pos - ret, ret);
if (err < 0)
ret = err;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/f2fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (ret > 0) {
ssize_t err;

err = generic_write_sync(file, iocb->ki_pos - ret, ret);
err = generic_write_sync(iocb, iocb->ki_pos - ret, ret);
if (err < 0)
ret = err;
}
Expand Down
5 changes: 4 additions & 1 deletion fs/gfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,10 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
mark_inode_dirty(inode);
}

return generic_write_sync(file, pos, count);
if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host))
return vfs_fsync_range(file, pos, pos + count - 1,
(file->f_flags & __O_SYNC) ? 0 : 1);
return 0;

out_trans_fail:
gfs2_inplace_release(ip);
Expand Down
2 changes: 1 addition & 1 deletion fs/nfs/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
if (i_size_read(inode) < iocb->ki_pos)
i_size_write(inode, iocb->ki_pos);
spin_unlock(&inode->i_lock);
generic_write_sync(file, pos, result);
generic_write_sync(iocb, pos, result);
}
}
nfs_direct_req_release(dreq);
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
current->backing_dev_info = NULL;
inode_unlock(vi);
if (likely(written > 0)) {
err = generic_write_sync(file, iocb->ki_pos, written);
err = generic_write_sync(iocb, iocb->ki_pos, written);
if (err < 0)
written = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/udf/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)

if (retval > 0) {
mark_inode_dirty(inode);
err = generic_write_sync(file, iocb->ki_pos - retval, retval);
err = generic_write_sync(iocb, iocb->ki_pos - retval, retval);
if (err < 0)
retval = err;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/xfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ xfs_file_write_iter(
XFS_STATS_ADD(ip->i_mount, xs_write_bytes, ret);

/* Handle various SYNC-type writes */
err = generic_write_sync(file, iocb->ki_pos - ret, ret);
err = generic_write_sync(iocb, iocb->ki_pos - ret, ret);
if (err < 0)
ret = err;
}
Expand Down
14 changes: 10 additions & 4 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ struct writeback_control;
#define IOCB_APPEND (1 << 1)
#define IOCB_DIRECT (1 << 2)
#define IOCB_HIPRI (1 << 3)
#define IOCB_DSYNC (1 << 4)
#define IOCB_SYNC (1 << 5)

struct kiocb {
struct file *ki_filp;
Expand Down Expand Up @@ -2485,12 +2487,12 @@ extern int filemap_fdatawrite_range(struct address_space *mapping,
extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
int datasync);
extern int vfs_fsync(struct file *file, int datasync);
static inline int generic_write_sync(struct file *file, loff_t pos, loff_t count)
static inline int generic_write_sync(struct kiocb *iocb, loff_t pos, loff_t count)
{
if (!(file->f_flags & O_DSYNC) && !IS_SYNC(file->f_mapping->host))
if (!(iocb->ki_flags & IOCB_DSYNC))
return 0;
return vfs_fsync_range(file, pos, pos + count - 1,
(file->f_flags & __O_SYNC) ? 0 : 1);
return vfs_fsync_range(iocb->ki_filp, pos, pos + count - 1,
(iocb->ki_flags & IOCB_SYNC) ? 0 : 1);
}
extern void emergency_sync(void);
extern void emergency_remount(void);
Expand Down Expand Up @@ -2942,6 +2944,10 @@ static inline int iocb_flags(struct file *file)
res |= IOCB_APPEND;
if (io_is_direct(file))
res |= IOCB_DIRECT;
if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host))
res |= IOCB_DSYNC;
if (file->f_flags & __O_SYNC)
res |= IOCB_SYNC;
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2794,7 +2794,7 @@ ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (ret > 0) {
ssize_t err;

err = generic_write_sync(file, iocb->ki_pos - ret, ret);
err = generic_write_sync(iocb, iocb->ki_pos - ret, ret);
if (err < 0)
ret = err;
}
Expand Down

0 comments on commit dde0c2e

Please sign in to comment.