switch generic_write_checks() to iocb and iter
... returning -E... upon error and amount of data left in iter after (possible) truncation upon success. Note, that normal case gives a non-zero (positive) return value, so any tests for != 0 _must_ be updated. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Conflicts: fs/ext4/file.c
This commit is contained in:
@@ -97,9 +97,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
||||
struct blk_plug plug;
|
||||
int o_direct = io_is_direct(file);
|
||||
int overwrite = 0;
|
||||
size_t length = iov_iter_count(from);
|
||||
ssize_t ret;
|
||||
loff_t pos;
|
||||
|
||||
/*
|
||||
* Unaligned direct AIO must be serialized; see comment above
|
||||
@@ -116,16 +114,10 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
||||
}
|
||||
|
||||
mutex_lock(&inode->i_mutex);
|
||||
ret = generic_write_checks(file, &iocb->ki_pos, &length);
|
||||
if (ret)
|
||||
ret = generic_write_checks(iocb, from);
|
||||
if (ret <= 0)
|
||||
goto out;
|
||||
|
||||
if (length == 0)
|
||||
goto out;
|
||||
|
||||
iov_iter_truncate(from, length);
|
||||
pos = iocb->ki_pos;
|
||||
|
||||
/*
|
||||
* If we have encountered a bitmap-format file, the size limit
|
||||
* is smaller than s_maxbytes, which is for extent-mapped files.
|
||||
@@ -133,19 +125,19 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
||||
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
|
||||
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
|
||||
|
||||
if (pos >= sbi->s_bitmap_maxbytes) {
|
||||
if (iocb->ki_pos >= sbi->s_bitmap_maxbytes) {
|
||||
ret = -EFBIG;
|
||||
goto out;
|
||||
}
|
||||
iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos);
|
||||
iov_iter_truncate(from, sbi->s_bitmap_maxbytes - iocb->ki_pos);
|
||||
}
|
||||
|
||||
iocb->private = &overwrite;
|
||||
if (o_direct) {
|
||||
length = iov_iter_count(from);
|
||||
size_t length = iov_iter_count(from);
|
||||
loff_t pos = iocb->ki_pos;
|
||||
blk_start_plug(&plug);
|
||||
|
||||
|
||||
/* check whether we do a DIO overwrite or not */
|
||||
if (ext4_should_dioread_nolock(inode) && !aio_mutex &&
|
||||
!file->f_mapping->nrpages && pos + length <= i_size_read(inode)) {
|
||||
|
Reference in New Issue
Block a user