]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/linux/spl/sys/uio.h
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[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  *  For details, see <http://zfsonlinux.org/>.
11  *
12  *  The SPL is free software; you can redistribute it and/or modify it
13  *  under the terms of the GNU General Public License as published by the
14  *  Free Software Foundation; either version 2 of the License, or (at your
15  *  option) any later version.
16  *
17  *  The SPL is distributed in the hope that it will be useful, but WITHOUT
18  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20  *  for more details.
21  *
22  *  You should have received a copy of the GNU General Public License along
23  *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26 #ifndef _SPL_UIO_H
27 #define _SPL_UIO_H
28
29 #include <sys/debug.h>
30 #include <linux/uio.h>
31 #include <linux/blkdev.h>
32 #include <linux/blkdev_compat.h>
33 #include <linux/mm.h>
34 #include <linux/bio.h>
35 #include <asm/uaccess.h>
36 #include <sys/types.h>
37
38 typedef struct iovec iovec_t;
39
40 typedef enum uio_rw {
41         UIO_READ =              0,
42         UIO_WRITE =             1,
43 } uio_rw_t;
44
45 typedef enum uio_seg {
46         UIO_USERSPACE =         0,
47         UIO_SYSSPACE =          1,
48         UIO_USERISPACE =        2,
49         UIO_BVEC =              3,
50 } uio_seg_t;
51
52 typedef struct uio {
53         union {
54                 const struct iovec      *uio_iov;
55                 const struct bio_vec    *uio_bvec;
56         };
57         int             uio_iovcnt;
58         offset_t        uio_loffset;
59         uio_seg_t       uio_segflg;
60         boolean_t       uio_fault_disable;
61         uint16_t        uio_fmode;
62         uint16_t        uio_extflg;
63         offset_t        uio_limit;
64         ssize_t         uio_resid;
65         size_t          uio_skip;
66 } uio_t;
67
68 typedef struct aio_req {
69         uio_t           *aio_uio;
70         void            *aio_private;
71 } aio_req_t;
72
73 typedef enum xuio_type {
74         UIOTYPE_ASYNCIO,
75         UIOTYPE_ZEROCOPY,
76 } xuio_type_t;
77
78
79 #define UIOA_IOV_MAX    16
80
81 typedef struct uioa_page_s {
82         int     uioa_pfncnt;
83         void    **uioa_ppp;
84         caddr_t uioa_base;
85         size_t  uioa_len;
86 } uioa_page_t;
87
88 typedef struct xuio {
89         uio_t xu_uio;
90         enum xuio_type xu_type;
91         union {
92                 struct {
93                         uint32_t xu_a_state;
94                         ssize_t xu_a_mbytes;
95                         uioa_page_t *xu_a_lcur;
96                         void **xu_a_lppp;
97                         void *xu_a_hwst[4];
98                         uioa_page_t xu_a_locked[UIOA_IOV_MAX];
99                 } xu_aio;
100
101                 struct {
102                         int xu_zc_rw;
103                         void *xu_zc_priv;
104                 } xu_zc;
105         } xu_ext;
106 } xuio_t;
107
108 #define XUIO_XUZC_PRIV(xuio)    xuio->xu_ext.xu_zc.xu_zc_priv
109 #define XUIO_XUZC_RW(xuio)      xuio->xu_ext.xu_zc.xu_zc_rw
110
111 #define uio_segflg(uio)                 (uio)->uio_segflg
112 #define uio_offset(uio)                 (uio)->uio_loffset
113 #define uio_resid(uio)                  (uio)->uio_resid
114 #define uio_iovcnt(uio)                 (uio)->uio_iovcnt
115 #define uio_iovlen(uio, idx)            (uio)->uio_iov[(idx)].iov_len
116 #define uio_iovbase(uio, idx)           (uio)->uio_iov[(idx)].iov_base
117
118 static inline void
119 uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len)
120 {
121         *base = uio_iovbase(uio, idx);
122         *len = uio_iovlen(uio, idx);
123 }
124
125 static inline void
126 uio_advance(uio_t *uio, size_t size)
127 {
128         uio->uio_resid -= size;
129         uio->uio_loffset += size;
130 }
131
132 static inline offset_t
133 uio_index_at_offset(uio_t *uio, offset_t off, uint_t *vec_idx)
134 {
135         *vec_idx = 0;
136         while (*vec_idx < uio_iovcnt(uio) && off >= uio_iovlen(uio, *vec_idx)) {
137                 off -= uio_iovlen(uio, *vec_idx);
138                 (*vec_idx)++;
139         }
140
141         return (off);
142 }
143
144 #endif /* SPL_UIO_H */