diff options
Diffstat (limited to 'module/zfs/zpl_file.c')
-rw-r--r-- | module/zfs/zpl_file.c | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/module/zfs/zpl_file.c b/module/zfs/zpl_file.c index 547114012..a23bc7d8d 100644 --- a/module/zfs/zpl_file.c +++ b/module/zfs/zpl_file.c @@ -20,6 +20,7 @@ */ /* * Copyright (c) 2011, Lawrence Livermore National Security, LLC. + * Copyright (c) 2015 by Chunwei Chen. All rights reserved. */ @@ -202,17 +203,18 @@ zpl_aio_fsync(struct kiocb *kiocb, int datasync) #error "Unsupported fops->fsync() implementation" #endif -static inline ssize_t +static ssize_t zpl_read_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count, - unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, - int flags, cred_t *cr) + unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, int flags, + cred_t *cr, size_t skip) { ssize_t read; uio_t uio; int error; fstrans_cookie_t cookie; - uio.uio_iov = (struct iovec *)iovp; + uio.uio_iov = iovp; + uio.uio_skip = skip; uio.uio_resid = count; uio.uio_iovcnt = nr_segs; uio.uio_loffset = *ppos; @@ -242,7 +244,7 @@ zpl_read_common(struct inode *ip, const char *buf, size_t len, loff_t *ppos, iov.iov_len = len; return (zpl_read_common_iovec(ip, &iov, len, 1, ppos, segment, - flags, cr)); + flags, cr, 0)); } static ssize_t @@ -261,24 +263,17 @@ zpl_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos) static ssize_t zpl_iter_read_common(struct kiocb *kiocb, const struct iovec *iovp, - unsigned long nr_segs, size_t count) + unsigned long nr_segs, size_t count, uio_seg_t seg, size_t skip) { cred_t *cr = CRED(); struct file *filp = kiocb->ki_filp; ssize_t read; - size_t alloc_size = sizeof (struct iovec) * nr_segs; - struct iovec *iov_tmp = kmem_alloc(alloc_size, KM_SLEEP); - bcopy(iovp, iov_tmp, alloc_size); - - ASSERT(iovp); crhold(cr); - read = zpl_read_common_iovec(filp->f_mapping->host, iov_tmp, count, - nr_segs, &kiocb->ki_pos, UIO_USERSPACE, filp->f_flags, cr); + read = zpl_read_common_iovec(filp->f_mapping->host, iovp, count, + nr_segs, &kiocb->ki_pos, seg, filp->f_flags, cr, skip); crfree(cr); - kmem_free(iov_tmp, alloc_size); - return (read); } @@ -286,22 +281,32 @@ zpl_iter_read_common(struct kiocb *kiocb, const struct iovec *iovp, static ssize_t zpl_iter_read(struct kiocb *kiocb, struct iov_iter *to) { - return (zpl_iter_read_common(kiocb, to->iov, to->nr_segs, - iov_iter_count(to))); + ssize_t ret; + uio_seg_t seg = UIO_USERSPACE; + if (to->type & ITER_KVEC) + seg = UIO_SYSSPACE; + if (to->type & ITER_BVEC) + seg = UIO_BVEC; + ret = zpl_iter_read_common(kiocb, to->iov, to->nr_segs, + iov_iter_count(to), seg, to->iov_offset); + if (ret > 0) + iov_iter_advance(to, ret); + return (ret); } #else static ssize_t zpl_aio_read(struct kiocb *kiocb, const struct iovec *iovp, unsigned long nr_segs, loff_t pos) { - return (zpl_iter_read_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes)); + return (zpl_iter_read_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes, + UIO_USERSPACE, 0)); } #endif /* HAVE_VFS_RW_ITERATE */ -static inline ssize_t +static ssize_t zpl_write_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count, - unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, - int flags, cred_t *cr) + unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, int flags, + cred_t *cr, size_t skip) { ssize_t wrote; uio_t uio; @@ -311,7 +316,8 @@ zpl_write_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count, if (flags & O_APPEND) *ppos = i_size_read(ip); - uio.uio_iov = (struct iovec *)iovp; + uio.uio_iov = iovp; + uio.uio_skip = skip; uio.uio_resid = count; uio.uio_iovcnt = nr_segs; uio.uio_loffset = *ppos; @@ -340,7 +346,7 @@ zpl_write_common(struct inode *ip, const char *buf, size_t len, loff_t *ppos, iov.iov_len = len; return (zpl_write_common_iovec(ip, &iov, len, 1, ppos, segment, - flags, cr)); + flags, cr, 0)); } static ssize_t @@ -359,24 +365,17 @@ zpl_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos) static ssize_t zpl_iter_write_common(struct kiocb *kiocb, const struct iovec *iovp, - unsigned long nr_segs, size_t count) + unsigned long nr_segs, size_t count, uio_seg_t seg, size_t skip) { cred_t *cr = CRED(); struct file *filp = kiocb->ki_filp; ssize_t wrote; - size_t alloc_size = sizeof (struct iovec) * nr_segs; - struct iovec *iov_tmp = kmem_alloc(alloc_size, KM_SLEEP); - bcopy(iovp, iov_tmp, alloc_size); - - ASSERT(iovp); crhold(cr); - wrote = zpl_write_common_iovec(filp->f_mapping->host, iov_tmp, count, - nr_segs, &kiocb->ki_pos, UIO_USERSPACE, filp->f_flags, cr); + wrote = zpl_write_common_iovec(filp->f_mapping->host, iovp, count, + nr_segs, &kiocb->ki_pos, seg, filp->f_flags, cr, skip); crfree(cr); - kmem_free(iov_tmp, alloc_size); - return (wrote); } @@ -384,15 +383,25 @@ zpl_iter_write_common(struct kiocb *kiocb, const struct iovec *iovp, static ssize_t zpl_iter_write(struct kiocb *kiocb, struct iov_iter *from) { - return (zpl_iter_write_common(kiocb, from->iov, from->nr_segs, - iov_iter_count(from))); + ssize_t ret; + uio_seg_t seg = UIO_USERSPACE; + if (from->type & ITER_KVEC) + seg = UIO_SYSSPACE; + if (from->type & ITER_BVEC) + seg = UIO_BVEC; + ret = zpl_iter_write_common(kiocb, from->iov, from->nr_segs, + iov_iter_count(from), seg, from->iov_offset); + if (ret > 0) + iov_iter_advance(from, ret); + return (ret); } #else static ssize_t zpl_aio_write(struct kiocb *kiocb, const struct iovec *iovp, unsigned long nr_segs, loff_t pos) { - return (zpl_iter_write_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes)); + return (zpl_iter_write_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes, + UIO_USERSPACE, 0)); } #endif /* HAVE_VFS_RW_ITERATE */ |