2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2014 by Chunwei Chen. All rights reserved.
14 * Copyright (c) 2016 by Delphix. All rights reserved.
20 #include <sys/isa_defs.h>
21 #include <sys/int_types.h>
22 #include <sys/debug.h>
23 #include <sys/refcount.h>
32 typedef enum abd_flags
{
33 ABD_FLAG_LINEAR
= 1 << 0, /* is buffer linear (or scattered)? */
34 ABD_FLAG_OWNER
= 1 << 1, /* does it own its data buffers? */
35 ABD_FLAG_META
= 1 << 2 /* does this represent FS metadata? */
39 abd_flags_t abd_flags
;
40 uint_t abd_size
; /* excludes scattered abd_offset */
41 struct abd
*abd_parent
;
42 refcount_t abd_children
;
46 uint_t abd_chunk_size
;
55 typedef int abd_iter_func_t(void *, size_t, void *);
56 typedef int abd_iter_func2_t(void *, void *, size_t, void *);
58 extern boolean_t zfs_abd_scatter_enabled
;
61 abd_is_linear(abd_t
*abd
)
63 return ((abd
->abd_flags
& ABD_FLAG_LINEAR
) != 0 ? B_TRUE
: B_FALSE
);
67 * Allocations and deallocations
70 abd_t
*abd_alloc(size_t, boolean_t
);
71 abd_t
*abd_alloc_linear(size_t, boolean_t
);
72 abd_t
*abd_alloc_for_io(size_t, boolean_t
);
73 abd_t
*abd_alloc_sametype(abd_t
*, size_t);
74 void abd_free(abd_t
*);
75 abd_t
*abd_get_offset(abd_t
*, size_t);
76 abd_t
*abd_get_from_buf(void *, size_t);
77 void abd_put(abd_t
*);
80 * Conversion to and from a normal buffer
83 void *abd_to_buf(abd_t
*);
84 void *abd_borrow_buf(abd_t
*, size_t);
85 void *abd_borrow_buf_copy(abd_t
*, size_t);
86 void abd_return_buf(abd_t
*, void *, size_t);
87 void abd_return_buf_copy(abd_t
*, void *, size_t);
88 void abd_take_ownership_of_buf(abd_t
*, boolean_t
);
89 void abd_release_ownership_of_buf(abd_t
*);
95 int abd_iterate_func(abd_t
*, size_t, size_t, abd_iter_func_t
*, void *);
96 int abd_iterate_func2(abd_t
*, abd_t
*, size_t, size_t, size_t,
97 abd_iter_func2_t
*, void *);
98 void abd_copy_off(abd_t
*, abd_t
*, size_t, size_t, size_t);
99 void abd_copy_from_buf_off(abd_t
*, const void *, size_t, size_t);
100 void abd_copy_to_buf_off(void *, abd_t
*, size_t, size_t);
101 int abd_cmp(abd_t
*, abd_t
*, size_t);
102 int abd_cmp_buf_off(abd_t
*, const void *, size_t, size_t);
103 void abd_zero_off(abd_t
*, size_t, size_t);
106 * Wrappers for calls with offsets of 0
110 abd_copy(abd_t
*dabd
, abd_t
*sabd
, size_t size
)
112 abd_copy_off(dabd
, sabd
, 0, 0, size
);
116 abd_copy_from_buf(abd_t
*abd
, const void *buf
, size_t size
)
118 abd_copy_from_buf_off(abd
, buf
, 0, size
);
122 abd_copy_to_buf(void* buf
, abd_t
*abd
, size_t size
)
124 abd_copy_to_buf_off(buf
, abd
, 0, size
);
128 abd_cmp_buf(abd_t
*abd
, const void *buf
, size_t size
)
130 return (abd_cmp_buf_off(abd
, buf
, 0, size
));
134 abd_zero(abd_t
*abd
, size_t size
)
136 abd_zero_off(abd
, 0, size
);