summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2015-04-07 11:28:12 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2015-04-11 22:29:47 -0400
commit5f380c7fa7e01f15ca0816bd241ece9a64a73192 (patch)
tree2136f54098eb85d21d17ee43f73724a5befd70a1
parent0b8def9d6dfa6b2a9a2740cf81d8d2c134688d39 (diff)
lift generic_write_checks() into callers of __generic_file_write_iter()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/block_dev.c10
-rw-r--r--fs/cifs/file.c39
-rw-r--r--fs/ext4/file.c14
-rw-r--r--fs/udf/file.c10
-rw-r--r--mm/filemap.c17
5 files changed, 60 insertions, 30 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 6e3de63c3055..bcd7f97beab9 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1597,6 +1597,16 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
struct file *file = iocb->ki_filp;
struct blk_plug plug;
ssize_t ret;
+ size_t count = iov_iter_count(from);
+
+ ret = generic_write_checks(file, &iocb->ki_pos, &count, 1);
+ if (ret)
+ return ret;
+
+ if (count == 0)
+ return 0;
+
+ iov_iter_truncate(from, count);
blk_start_plug(&plug);
ret = __generic_file_write_iter(iocb, from);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 3cb04129ddb1..3c5c9bc5cbaf 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2673,8 +2673,8 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
struct inode *inode = file->f_mapping->host;
struct cifsInodeInfo *cinode = CIFS_I(inode);
struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
- ssize_t rc = -EACCES;
- loff_t lock_pos = iocb->ki_pos;
+ ssize_t rc;
+ size_t count;
/*
* We need to hold the sem to be sure nobody modifies lock list
@@ -2682,23 +2682,30 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
*/
down_read(&cinode->lock_sem);
mutex_lock(&inode->i_mutex);
- if (file->f_flags & O_APPEND)
- lock_pos = i_size_read(inode);
- if (!cifs_find_lock_conflict(cfile, lock_pos, iov_iter_count(from),
+
+ count = iov_iter_count(from);
+ rc = generic_write_checks(file, &iocb->ki_pos, &count, 0);
+ if (rc)
+ goto out;
+
+ if (count == 0)
+ goto out;
+
+ iov_iter_truncate(from, count);
+
+ if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(from),
server->vals->exclusive_lock_type, NULL,
- CIFS_WRITE_OP)) {
+ CIFS_WRITE_OP))
rc = __generic_file_write_iter(iocb, from);
- mutex_unlock(&inode->i_mutex);
-
- if (rc > 0) {
- ssize_t err;
+ else
+ rc = -EACCES;
+out:
+ mutex_unlock(&inode->i_mutex);
- err = generic_write_sync(file, iocb->ki_pos - rc, rc);
- if (err < 0)
- rc = err;
- }
- } else {
- mutex_unlock(&inode->i_mutex);
+ if (rc > 0) {
+ ssize_t err = generic_write_sync(file, iocb->ki_pos - rc, rc);
+ if (err < 0)
+ rc = err;
}
up_read(&cinode->lock_sem);
return rc;
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 9ad03036d9f5..f7cca423dded 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -132,9 +132,8 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
ret = -EFBIG;
goto errout;
}
-
- if (pos + length > sbi->s_bitmap_maxbytes)
- iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos);
+ iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos);
+ length = iov_iter_count(from);
}
iocb->private = &overwrite;
@@ -172,7 +171,16 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
}
}
+ ret = generic_write_checks(file, &iocb->ki_pos, &length, 0);
+ if (ret)
+ goto out;
+
+ if (length == 0)
+ goto out;
+
+ iov_iter_truncate(from, length);
ret = __generic_file_write_iter(iocb, from);
+out:
mutex_unlock(&inode->i_mutex);
if (ret > 0) {
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 78d42548b260..35e81ed99405 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -151,7 +151,17 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
} else
up_write(&iinfo->i_data_sem);
+ retval = generic_write_checks(file, &iocb->ki_pos, &count, 0);
+ if (retval)
+ goto out;
+
+ if (count == 0)
+ goto out;
+
+ iov_iter_truncate(from, count);
+
retval = __generic_file_write_iter(iocb, from);
+out:
mutex_unlock(&inode->i_mutex);
if (retval > 0) {
diff --git a/mm/filemap.c b/mm/filemap.c
index 353f82e09e63..a794a7f98743 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2560,19 +2560,9 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
ssize_t written = 0;
ssize_t err;
ssize_t status;
- size_t count = iov_iter_count(from);
/* We can write back this queue in page reclaim */
current->backing_dev_info = inode_to_bdi(inode);
- err = generic_write_checks(file, &iocb->ki_pos, &count, S_ISBLK(inode->i_mode));
- if (err)
- goto out;
-
- if (count == 0)
- goto out;
-
- iov_iter_truncate(from, count);
-
err = file_remove_suid(file);
if (err)
goto out;
@@ -2651,9 +2641,14 @@ ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
struct file *file = iocb->ki_filp;
struct inode *inode = file->f_mapping->host;
ssize_t ret;
+ size_t count = iov_iter_count(from);
mutex_lock(&inode->i_mutex);
- ret = __generic_file_write_iter(iocb, from);
+ ret = generic_write_checks(file, &iocb->ki_pos, &count, 0);
+ if (!ret && count) {
+ iov_iter_truncate(from, count);
+ ret = __generic_file_write_iter(iocb, from);
+ }
mutex_unlock(&inode->i_mutex);
if (ret > 0) {