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>
22 #include <sys/int_types.h>
24 #include <sys/stdint.h>
26 #include <sys/debug.h>
27 #include <sys/refcount.h>
36 typedef enum abd_flags {
37 ABD_FLAG_LINEAR = 1 << 0, /* is buffer linear (or scattered)? */
38 ABD_FLAG_OWNER = 1 << 1, /* does it own its data buffers? */
39 ABD_FLAG_META = 1 << 2 /* does this represent FS metadata? */
43 abd_flags_t abd_flags;
44 uint_t abd_size; /* excludes scattered abd_offset */
45 struct abd *abd_parent;
46 refcount_t abd_children;
50 uint_t abd_chunk_size;
59 typedef int abd_iter_func_t(void *, size_t, void *);
60 typedef int abd_iter_func2_t(void *, void *, size_t, void *);
62 extern boolean_t zfs_abd_scatter_enabled;
65 abd_is_linear(abd_t *abd)
67 return ((abd->abd_flags & ABD_FLAG_LINEAR) != 0 ? B_TRUE : B_FALSE);
71 * Allocations and deallocations
74 abd_t *abd_alloc(size_t, boolean_t);
75 abd_t *abd_alloc_linear(size_t, boolean_t);
76 abd_t *abd_alloc_for_io(size_t, boolean_t);
77 abd_t *abd_alloc_sametype(abd_t *, size_t);
78 void abd_free(abd_t *);
79 abd_t *abd_get_offset(abd_t *, size_t);
80 abd_t *abd_get_from_buf(void *, size_t);
81 void abd_put(abd_t *);
84 * Conversion to and from a normal buffer
87 void *abd_to_buf(abd_t *);
88 void *abd_borrow_buf(abd_t *, size_t);
89 void *abd_borrow_buf_copy(abd_t *, size_t);
90 void abd_return_buf(abd_t *, void *, size_t);
91 void abd_return_buf_copy(abd_t *, void *, size_t);
92 void abd_take_ownership_of_buf(abd_t *, boolean_t);
93 void abd_release_ownership_of_buf(abd_t *);
99 int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *);
100 int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t,
101 abd_iter_func2_t *, void *);
102 void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t);
103 void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t);
104 void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t);
105 int abd_cmp(abd_t *, abd_t *, size_t);
106 int abd_cmp_buf_off(abd_t *, const void *, size_t, size_t);
107 void abd_zero_off(abd_t *, size_t, size_t);
110 * Wrappers for calls with offsets of 0
114 abd_copy(abd_t *dabd, abd_t *sabd, size_t size)
116 abd_copy_off(dabd, sabd, 0, 0, size);
120 abd_copy_from_buf(abd_t *abd, const void *buf, size_t size)
122 abd_copy_from_buf_off(abd, buf, 0, size);
126 abd_copy_to_buf(void* buf, abd_t *abd, size_t size)
128 abd_copy_to_buf_off(buf, abd, 0, size);
132 abd_cmp_buf(abd_t *abd, const void *buf, size_t size)
134 return (abd_cmp_buf_off(abd, buf, 0, size));
138 abd_zero(abd_t *abd, size_t size)
140 abd_zero_off(abd, 0, size);