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