]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/include/sys/abd.h
ZFS: MFV 2.0-rc1-gfd20a8
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / include / sys / abd.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23  * Copyright (c) 2016, 2019 by Delphix. All rights reserved.
24  */
25
26 #ifndef _ABD_H
27 #define _ABD_H
28
29 #include <sys/isa_defs.h>
30 #include <sys/debug.h>
31 #include <sys/zfs_refcount.h>
32 #include <sys/uio.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 struct abd; /* forward declaration */
39 typedef struct abd abd_t;
40
41 typedef int abd_iter_func_t(void *buf, size_t len, void *priv);
42 typedef int abd_iter_func2_t(void *bufa, void *bufb, size_t len, void *priv);
43
44 extern int zfs_abd_scatter_enabled;
45
46 /*
47  * Allocations and deallocations
48  */
49
50 abd_t *abd_alloc(size_t, boolean_t);
51 abd_t *abd_alloc_linear(size_t, boolean_t);
52 abd_t *abd_alloc_gang_abd(void);
53 abd_t *abd_alloc_for_io(size_t, boolean_t);
54 abd_t *abd_alloc_sametype(abd_t *, size_t);
55 void abd_gang_add(abd_t *, abd_t *, boolean_t);
56 void abd_free(abd_t *);
57 void abd_put(abd_t *);
58 abd_t *abd_get_offset(abd_t *, size_t);
59 abd_t *abd_get_offset_size(abd_t *, size_t, size_t);
60 abd_t *abd_get_zeros(size_t);
61 abd_t *abd_get_from_buf(void *, size_t);
62 void abd_cache_reap_now(void);
63
64 /*
65  * Conversion to and from a normal buffer
66  */
67
68 void *abd_to_buf(abd_t *);
69 void *abd_borrow_buf(abd_t *, size_t);
70 void *abd_borrow_buf_copy(abd_t *, size_t);
71 void abd_return_buf(abd_t *, void *, size_t);
72 void abd_return_buf_copy(abd_t *, void *, size_t);
73 void abd_take_ownership_of_buf(abd_t *, boolean_t);
74 void abd_release_ownership_of_buf(abd_t *);
75
76 /*
77  * ABD operations
78  */
79
80 int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *);
81 int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t,
82     abd_iter_func2_t *, void *);
83 void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t);
84 void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t);
85 void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t);
86 int abd_cmp(abd_t *, abd_t *);
87 int abd_cmp_buf_off(abd_t *, const void *, size_t, size_t);
88 void abd_zero_off(abd_t *, size_t, size_t);
89 void abd_verify(abd_t *);
90 uint_t abd_get_size(abd_t *);
91
92 void abd_raidz_gen_iterate(abd_t **cabds, abd_t *dabd,
93         ssize_t csize, ssize_t dsize, const unsigned parity,
94         void (*func_raidz_gen)(void **, const void *, size_t, size_t));
95 void abd_raidz_rec_iterate(abd_t **cabds, abd_t **tabds,
96         ssize_t tsize, const unsigned parity,
97         void (*func_raidz_rec)(void **t, const size_t tsize, void **c,
98         const unsigned *mul),
99         const unsigned *mul);
100
101 /*
102  * Wrappers for calls with offsets of 0
103  */
104
105 static inline void
106 abd_copy(abd_t *dabd, abd_t *sabd, size_t size)
107 {
108         abd_copy_off(dabd, sabd, 0, 0, size);
109 }
110
111 static inline void
112 abd_copy_from_buf(abd_t *abd, const void *buf, size_t size)
113 {
114         abd_copy_from_buf_off(abd, buf, 0, size);
115 }
116
117 static inline void
118 abd_copy_to_buf(void* buf, abd_t *abd, size_t size)
119 {
120         abd_copy_to_buf_off(buf, abd, 0, size);
121 }
122
123 static inline int
124 abd_cmp_buf(abd_t *abd, const void *buf, size_t size)
125 {
126         return (abd_cmp_buf_off(abd, buf, 0, size));
127 }
128
129 static inline void
130 abd_zero(abd_t *abd, size_t size)
131 {
132         abd_zero_off(abd, 0, size);
133 }
134
135 /*
136  * ABD type check functions
137  */
138 boolean_t abd_is_linear(abd_t *);
139 boolean_t abd_is_gang(abd_t *);
140 boolean_t abd_is_linear_page(abd_t *);
141
142 /*
143  * Module lifecycle
144  * Defined in each specific OS's abd_os.c
145  */
146
147 void abd_init(void);
148 void abd_fini(void);
149
150 /*
151  * Linux ABD bio functions
152  */
153 #if defined(__linux__) && defined(_KERNEL)
154 unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t);
155 unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t);
156 #endif
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif  /* _ABD_H */