]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/linux/spl/sys/uio.h
Update OpenZFS to 2.0.0-rc3-gbd565f
[FreeBSD/FreeBSD.git] / include / os / linux / spl / sys / uio.h
1 /*
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>.
7  *  UCRL-CODE-235197
8  *
9  *  This file is part of the SPL, Solaris Porting Layer.
10  *
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.
15  *
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
19  *  for more details.
20  *
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/>.
23  */
24
25 #ifndef _SPL_UIO_H
26 #define _SPL_UIO_H
27
28 #include <sys/debug.h>
29 #include <linux/uio.h>
30 #include <linux/blkdev.h>
31 #include <linux/blkdev_compat.h>
32 #include <linux/mm.h>
33 #include <linux/bio.h>
34 #include <asm/uaccess.h>
35 #include <sys/types.h>
36
37 typedef struct iovec iovec_t;
38
39 typedef enum uio_rw {
40         UIO_READ =              0,
41         UIO_WRITE =             1,
42 } uio_rw_t;
43
44 typedef enum uio_seg {
45         UIO_USERSPACE =         0,
46         UIO_SYSSPACE =          1,
47         UIO_USERISPACE =        2,
48         UIO_BVEC =              3,
49 } uio_seg_t;
50
51 typedef struct uio {
52         union {
53                 const struct iovec      *uio_iov;
54                 const struct bio_vec    *uio_bvec;
55         };
56         int             uio_iovcnt;
57         offset_t        uio_loffset;
58         uio_seg_t       uio_segflg;
59         boolean_t       uio_fault_disable;
60         uint16_t        uio_fmode;
61         uint16_t        uio_extflg;
62         offset_t        uio_limit;
63         ssize_t         uio_resid;
64         size_t          uio_skip;
65 } uio_t;
66
67 typedef struct aio_req {
68         uio_t           *aio_uio;
69         void            *aio_private;
70 } aio_req_t;
71
72 typedef enum xuio_type {
73         UIOTYPE_ASYNCIO,
74         UIOTYPE_ZEROCOPY,
75 } xuio_type_t;
76
77
78 #define UIOA_IOV_MAX    16
79
80 typedef struct uioa_page_s {
81         int     uioa_pfncnt;
82         void    **uioa_ppp;
83         caddr_t uioa_base;
84         size_t  uioa_len;
85 } uioa_page_t;
86
87 typedef struct xuio {
88         uio_t xu_uio;
89         enum xuio_type xu_type;
90         union {
91                 struct {
92                         uint32_t xu_a_state;
93                         ssize_t xu_a_mbytes;
94                         uioa_page_t *xu_a_lcur;
95                         void **xu_a_lppp;
96                         void *xu_a_hwst[4];
97                         uioa_page_t xu_a_locked[UIOA_IOV_MAX];
98                 } xu_aio;
99
100                 struct {
101                         int xu_zc_rw;
102                         void *xu_zc_priv;
103                 } xu_zc;
104         } xu_ext;
105 } xuio_t;
106
107 #define XUIO_XUZC_PRIV(xuio)    xuio->xu_ext.xu_zc.xu_zc_priv
108 #define XUIO_XUZC_RW(xuio)      xuio->xu_ext.xu_zc.xu_zc_rw
109
110 #define uio_segflg(uio)                 (uio)->uio_segflg
111 #define uio_offset(uio)                 (uio)->uio_loffset
112 #define uio_resid(uio)                  (uio)->uio_resid
113 #define uio_iovcnt(uio)                 (uio)->uio_iovcnt
114 #define uio_iovlen(uio, idx)            (uio)->uio_iov[(idx)].iov_len
115 #define uio_iovbase(uio, idx)           (uio)->uio_iov[(idx)].iov_base
116
117 static inline void
118 uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len)
119 {
120         *base = uio_iovbase(uio, idx);
121         *len = uio_iovlen(uio, idx);
122 }
123
124 static inline void
125 uio_advance(uio_t *uio, size_t size)
126 {
127         uio->uio_resid -= size;
128         uio->uio_loffset += size;
129 }
130
131 static inline offset_t
132 uio_index_at_offset(uio_t *uio, offset_t off, uint_t *vec_idx)
133 {
134         *vec_idx = 0;
135         while (*vec_idx < uio_iovcnt(uio) && off >= uio_iovlen(uio, *vec_idx)) {
136                 off -= uio_iovlen(uio, *vec_idx);
137                 (*vec_idx)++;
138         }
139
140         return (off);
141 }
142
143 #endif /* SPL_UIO_H */