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.
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.
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]
22 * Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23 * Copyright (c) 2016, 2019 by Delphix. All rights reserved.
29 #include <sys/isa_defs.h>
30 #include <sys/debug.h>
31 #include <sys/zfs_refcount.h>
38 struct abd
; /* forward declaration */
39 typedef struct abd abd_t
;
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
);
44 extern int zfs_abd_scatter_enabled
;
47 * Allocations and deallocations
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);
65 * Conversion to and from a normal buffer
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
*);
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
*);
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
,
102 * Wrappers for calls with offsets of 0
106 abd_copy(abd_t
*dabd
, abd_t
*sabd
, size_t size
)
108 abd_copy_off(dabd
, sabd
, 0, 0, size
);
112 abd_copy_from_buf(abd_t
*abd
, const void *buf
, size_t size
)
114 abd_copy_from_buf_off(abd
, buf
, 0, size
);
118 abd_copy_to_buf(void* buf
, abd_t
*abd
, size_t size
)
120 abd_copy_to_buf_off(buf
, abd
, 0, size
);
124 abd_cmp_buf(abd_t
*abd
, const void *buf
, size_t size
)
126 return (abd_cmp_buf_off(abd
, buf
, 0, size
));
130 abd_zero(abd_t
*abd
, size_t size
)
132 abd_zero_off(abd
, 0, size
);
136 * ABD type check functions
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
*);
144 * Defined in each specific OS's abd_os.c
151 * Linux ABD bio functions
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);