Merge commit '5e2a074725cb7c16ea1c6554da11ab4d6b4e7aee'
[unleashed.git] / kernel / fs / zfs / sys / abd.h
blobcb49d70ab11ada59235252a0d885622cbc7c96d4
1 /*
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
5 * 1.0 of the CDDL.
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.
17 #ifndef _ABD_H
18 #define _ABD_H
20 #include <sys/isa_defs.h>
21 #include <sys/int_types.h>
22 #include <sys/debug.h>
23 #include <sys/refcount.h>
24 #ifdef _KERNEL
25 #include <sys/uio.h>
26 #endif
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
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? */
36 } abd_flags_t;
38 typedef struct abd {
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;
43 union {
44 struct abd_scatter {
45 uint_t abd_offset;
46 uint_t abd_chunk_size;
47 void *abd_chunks[];
48 } abd_scatter;
49 struct abd_linear {
50 void *abd_buf;
51 } abd_linear;
52 } abd_u;
53 } abd_t;
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;
60 inline boolean_t
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 *);
92 * ABD operations
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
109 inline void
110 abd_copy(abd_t *dabd, abd_t *sabd, size_t size)
112 abd_copy_off(dabd, sabd, 0, 0, size);
115 inline void
116 abd_copy_from_buf(abd_t *abd, void *buf, size_t size)
118 abd_copy_from_buf_off(abd, buf, 0, size);
121 inline void
122 abd_copy_to_buf(void* buf, abd_t *abd, size_t size)
124 abd_copy_to_buf_off(buf, abd, 0, size);
127 inline int
128 abd_cmp_buf(abd_t *abd, void *buf, size_t size)
130 return (abd_cmp_buf_off(abd, buf, 0, size));
133 inline void
134 abd_zero(abd_t *abd, size_t size)
136 abd_zero_off(abd, 0, size);
140 * Module lifecycle
143 void abd_init(void);
144 void abd_fini(void);
146 #ifdef __cplusplus
148 #endif
150 #endif /* _ABD_H */