]> git.proxmox.com Git - mirror_zfs.git/blob - include/sys/abd.h
ABD changes for vectorized RAIDZ
[mirror_zfs.git] / 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 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/int_types.h>
31 #include <sys/debug.h>
32 #include <sys/refcount.h>
33 #ifdef _KERNEL
34 #include <linux/mm.h>
35 #include <linux/bio.h>
36 #include <sys/uio.h>
37 #endif
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 typedef enum abd_flags {
44 ABD_FLAG_LINEAR = 1 << 0, /* is buffer linear (or scattered)? */
45 ABD_FLAG_OWNER = 1 << 1, /* does it own its data buffers? */
46 ABD_FLAG_META = 1 << 2 /* does this represent FS metadata? */
47 } abd_flags_t;
48
49 typedef struct abd {
50 abd_flags_t abd_flags;
51 uint_t abd_size; /* excludes scattered abd_offset */
52 struct abd *abd_parent;
53 refcount_t abd_children;
54 union {
55 struct abd_scatter {
56 uint_t abd_offset;
57 uint_t abd_chunk_size;
58 struct page *abd_chunks[];
59 } abd_scatter;
60 struct abd_linear {
61 void *abd_buf;
62 } abd_linear;
63 } abd_u;
64 } abd_t;
65
66 typedef int abd_iter_func_t(void *buf, size_t len, void *private);
67 typedef int abd_iter_func2_t(void *bufa, void *bufb, size_t len, void *private);
68
69 extern int zfs_abd_scatter_enabled;
70
71 static inline boolean_t
72 abd_is_linear(abd_t *abd)
73 {
74 return ((abd->abd_flags & ABD_FLAG_LINEAR) != 0);
75 }
76
77 /*
78 * Allocations and deallocations
79 */
80
81 abd_t *abd_alloc(size_t, boolean_t);
82 abd_t *abd_alloc_linear(size_t, boolean_t);
83 abd_t *abd_alloc_for_io(size_t, boolean_t);
84 abd_t *abd_alloc_sametype(abd_t *, size_t);
85 void abd_free(abd_t *);
86 abd_t *abd_get_offset(abd_t *, size_t);
87 abd_t *abd_get_offset_size(abd_t *, size_t, size_t);
88 abd_t *abd_get_from_buf(void *, size_t);
89 void abd_put(abd_t *);
90
91 /*
92 * Conversion to and from a normal buffer
93 */
94
95 void *abd_to_buf(abd_t *);
96 void *abd_borrow_buf(abd_t *, size_t);
97 void *abd_borrow_buf_copy(abd_t *, size_t);
98 void abd_return_buf(abd_t *, void *, size_t);
99 void abd_return_buf_copy(abd_t *, void *, size_t);
100 void abd_take_ownership_of_buf(abd_t *, boolean_t);
101 void abd_release_ownership_of_buf(abd_t *);
102
103 /*
104 * ABD operations
105 */
106
107 int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *);
108 int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t,
109 abd_iter_func2_t *, void *);
110 void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t);
111 void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t);
112 void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t);
113 int abd_cmp(abd_t *, abd_t *);
114 int abd_cmp_buf_off(abd_t *, const void *, size_t, size_t);
115 void abd_zero_off(abd_t *, size_t, size_t);
116
117 #if defined(_KERNEL) && defined(HAVE_SPL)
118 unsigned int abd_scatter_bio_map_off(struct bio *, abd_t *, unsigned int,
119 size_t);
120 unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t);
121 #endif
122
123 void abd_raidz_gen_iterate(abd_t **cabds, abd_t *dabd,
124 ssize_t csize, ssize_t dsize, const unsigned parity,
125 void (*func_raidz_gen)(void **, const void *, size_t, size_t));
126 void abd_raidz_rec_iterate(abd_t **cabds, abd_t **tabds,
127 ssize_t tsize, const unsigned parity,
128 void (*func_raidz_rec)(void **t, const size_t tsize, void **c,
129 const unsigned *mul),
130 const unsigned *mul);
131
132 /*
133 * Wrappers for calls with offsets of 0
134 */
135
136 static inline void
137 abd_copy(abd_t *dabd, abd_t *sabd, size_t size)
138 {
139 abd_copy_off(dabd, sabd, 0, 0, size);
140 }
141
142 static inline void
143 abd_copy_from_buf(abd_t *abd, void *buf, size_t size)
144 {
145 abd_copy_from_buf_off(abd, buf, 0, size);
146 }
147
148 static inline void
149 abd_copy_to_buf(void* buf, abd_t *abd, size_t size)
150 {
151 abd_copy_to_buf_off(buf, abd, 0, size);
152 }
153
154 static inline int
155 abd_cmp_buf(abd_t *abd, void *buf, size_t size)
156 {
157 return (abd_cmp_buf_off(abd, buf, 0, size));
158 }
159
160 static inline void
161 abd_zero(abd_t *abd, size_t size)
162 {
163 abd_zero_off(abd, 0, size);
164 }
165
166 /*
167 * Module lifecycle
168 */
169
170 void abd_init(void);
171 void abd_fini(void);
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif /* _ABD_H */