mm: move common segment checks to separate helper function (v7)
Subsystems (5)
PATCH 1/2 mm: move common segment checks to separate helper function (v7)
Changes against v6
- remove duplicated code from xfs,ntfs
- export generic_segment_checks, because it used by xfs,nfs now.
- change arguments initialization pocily according to Nick's comments.
Tested with: ltp readv/writev tests
Signed-off-by Monakhov Dmitriy <[email protected]>
--- fs/ntfs/file.c | 21 ++--------- fs/xfs/linux-2.6/xfs_lrw.c | 22 ++---------- include/linux/fs.h | 3 ++ mm/filemap.c | 83 ++++++++++++++++++++++++------------------- 4 files changed, 55 insertions(+), 74 deletions(-)
fs/ntfs/file.c +3 -18
@@ -2129,28 +2129,13 @@ static ssize_t ntfs_file_aio_write_nolock(struct kiocb *iocb,struct address_space *mapping = file->f_mapping;struct inode *inode = mapping->host;loff_t pos; -unsigned long seg;size_t count;/* after file limit checks */ ssize_t written, err; count =0 ; -for (seg =0 ; seg < nr_segs; seg++) { -const struct iovec *iv = &iov[seg]; -/* -* If any segment has a negative length, or the cumulative -* length ever wraps negative then return -EINVAL. -*/ - count += iv->iov_len; -if (unlikely ((ssize_t )(count|iv->iov_len) <0 )) -return -EINVAL ; -if (access_ok (VERIFY_READ , iv->iov_base, iv->iov_len)) -continue ; -if (!seg) -return -EFAULT ; - nr_segs = seg; - count -= iv->iov_len;/* This segment is no good */ -break ; - } + err =generic_segment_checks (iov, &nr_segs, &count,VERIFY_READ ); +if (err) +return err; pos = *ppos;vfs_check_frozen (inode->i_sb,SB_FREEZE_WRITE );/* We can write back this queue in page reclaim. */
fs/xfs/linux-2.6/xfs_lrw.c +3 -19
@@ -639,7 +639,6 @@ xfs_write(xfs_fsize_t isize, new_size;xfs_iocore_t *io;bhv_vnode_t *vp; -unsigned long seg;int iolock;int eventsent =0 ;bhv_vrwlock_t locktype;
@@ -652,24 +651,9 @@ xfs_write( vp =BHV_TO_VNODE (bdp); xip =XFS_BHVTOI (bdp); -for (seg =0 ; seg < segs; seg++) { -const struct iovec *iv = &iovp[seg]; - -/* -* If any segment has a negative length, or the cumulative -* length ever wraps negative then return -EINVAL. -*/ - ocount += iv->iov_len; -if (unlikely ((ssize_t )(ocount|iv->iov_len) <0 )) -return -EINVAL ; -if (access_ok (VERIFY_READ , iv->iov_base, iv->iov_len)) -continue ; -if (seg ==0 ) -return -EFAULT ; - segs = seg; - ocount -= iv->iov_len;/* This segment is no good */ -break ; - } + error =generic_segment_checks (iovp, &segs, &ocount,VERIFY_READ ); +if (error) +return error; count = ocount; pos = *offset;
include/linux/fs.h +3 -0
@@ -1778,6 +1778,9 @@ extern ssize_t generic_file_sendfile(struct file *, loff_t *, size_t, read_actorextern void do_generic_mapping_read (struct address_space *mapping,struct file_ra_state *,struct file *,loff_t *,read_descriptor_t *,read_actor_t ); +extern int generic_segment_checks (const struct iovec *iov, +unsigned long *nr_segs,size_t *count, +unsigned long access_flags);/* fs/splice.c */ extern ssize_t generic_file_splice_read(struct file *, loff_t *,
mm/filemap.c +46 -37
106 lines not on this page · raw message
Signature · 1 line
1.5.0.1