2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Copyright (c) 2015 by Chunwei Chen. All rights reserved.
5 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
9 * This file is part of the SPL, Solaris Porting Layer.
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
28 #include <sys/debug.h>
29 #include <linux/uio.h>
30 #include <linux/blkdev.h>
31 #include <linux/blkdev_compat.h>
33 #include <linux/bio.h>
34 #include <asm/uaccess.h>
35 #include <sys/types.h>
37 typedef struct iovec iovec_t
;
39 typedef enum zfs_uio_rw
{
44 typedef enum zfs_uio_seg
{
48 #if defined(HAVE_VFS_IOV_ITER)
53 typedef struct zfs_uio
{
55 const struct iovec
*uio_iov
;
56 const struct bio_vec
*uio_bvec
;
57 #if defined(HAVE_VFS_IOV_ITER)
58 struct iov_iter
*uio_iter
;
63 zfs_uio_seg_t uio_segflg
;
64 boolean_t uio_fault_disable
;
71 #define zfs_uio_segflg(u) (u)->uio_segflg
72 #define zfs_uio_offset(u) (u)->uio_loffset
73 #define zfs_uio_resid(u) (u)->uio_resid
74 #define zfs_uio_iovcnt(u) (u)->uio_iovcnt
75 #define zfs_uio_iovlen(u, idx) (u)->uio_iov[(idx)].iov_len
76 #define zfs_uio_iovbase(u, idx) (u)->uio_iov[(idx)].iov_base
77 #define zfs_uio_fault_disable(u, set) (u)->uio_fault_disable = set
78 #define zfs_uio_rlimit_fsize(z, u) (0)
79 #define zfs_uio_fault_move(p, n, rw, u) zfs_uiomove((p), (n), (rw), (u))
81 extern int zfs_uio_prefaultpages(ssize_t
, zfs_uio_t
*);
84 zfs_uio_setoffset(zfs_uio_t
*uio
, offset_t off
)
86 uio
->uio_loffset
= off
;
90 zfs_uio_advance(zfs_uio_t
*uio
, size_t size
)
92 uio
->uio_resid
-= size
;
93 uio
->uio_loffset
+= size
;
97 zfs_uio_iovec_init(zfs_uio_t
*uio
, const struct iovec
*iov
,
98 unsigned long nr_segs
, offset_t offset
, zfs_uio_seg_t seg
, ssize_t resid
,
101 ASSERT(seg
== UIO_USERSPACE
|| seg
== UIO_SYSSPACE
);
104 uio
->uio_iovcnt
= nr_segs
;
105 uio
->uio_loffset
= offset
;
106 uio
->uio_segflg
= seg
;
107 uio
->uio_fault_disable
= B_FALSE
;
110 uio
->uio_resid
= resid
;
111 uio
->uio_skip
= skip
;
115 zfs_uio_bvec_init(zfs_uio_t
*uio
, struct bio
*bio
)
117 uio
->uio_bvec
= &bio
->bi_io_vec
[BIO_BI_IDX(bio
)];
118 uio
->uio_iovcnt
= bio
->bi_vcnt
- BIO_BI_IDX(bio
);
119 uio
->uio_loffset
= BIO_BI_SECTOR(bio
) << 9;
120 uio
->uio_segflg
= UIO_BVEC
;
121 uio
->uio_fault_disable
= B_FALSE
;
124 uio
->uio_resid
= BIO_BI_SIZE(bio
);
125 uio
->uio_skip
= BIO_BI_SKIP(bio
);
128 #if defined(HAVE_VFS_IOV_ITER)
130 zfs_uio_iov_iter_init(zfs_uio_t
*uio
, struct iov_iter
*iter
, offset_t offset
,
131 ssize_t resid
, size_t skip
)
133 uio
->uio_iter
= iter
;
134 uio
->uio_iovcnt
= iter
->nr_segs
;
135 uio
->uio_loffset
= offset
;
136 uio
->uio_segflg
= UIO_ITER
;
137 uio
->uio_fault_disable
= B_FALSE
;
140 uio
->uio_resid
= resid
;
141 uio
->uio_skip
= skip
;
145 #endif /* SPL_UIO_H */