]>
git.proxmox.com Git - mirror_zfs.git/blob - include/sys/abd.h
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 by Delphix. All rights reserved.
29 #include <sys/isa_defs.h>
30 #include <sys/int_types.h>
31 #include <sys/debug.h>
32 #include <sys/refcount.h>
35 #include <linux/bio.h>
43 typedef enum abd_flags
{
44 ABD_FLAG_LINEAR
= 1 << 0, /* is buffer linear (or scattered)? */
45 ABD_FLAG_OWNER
= 1 << 1, /* does it own its data buffers? */
46 ABD_FLAG_META
= 1 << 2, /* does this represent FS metadata? */
47 ABD_FLAG_MULTI_ZONE
= 1 << 3, /* pages split over memory zones */
48 ABD_FLAG_MULTI_CHUNK
= 1 << 4 /* pages split over multiple chunks */
52 abd_flags_t abd_flags
;
53 uint_t abd_size
; /* excludes scattered abd_offset */
54 struct abd
*abd_parent
;
55 refcount_t abd_children
;
60 struct scatterlist
*abd_sgl
;
68 typedef int abd_iter_func_t(void *buf
, size_t len
, void *private);
69 typedef int abd_iter_func2_t(void *bufa
, void *bufb
, size_t len
, void *private);
71 extern int zfs_abd_scatter_enabled
;
73 static inline boolean_t
74 abd_is_linear(abd_t
*abd
)
76 return ((abd
->abd_flags
& ABD_FLAG_LINEAR
) != 0);
80 * Allocations and deallocations
83 abd_t
*abd_alloc(size_t, boolean_t
);
84 abd_t
*abd_alloc_linear(size_t, boolean_t
);
85 abd_t
*abd_alloc_for_io(size_t, boolean_t
);
86 abd_t
*abd_alloc_sametype(abd_t
*, size_t);
87 void abd_free(abd_t
*);
88 abd_t
*abd_get_offset(abd_t
*, size_t);
89 abd_t
*abd_get_offset_size(abd_t
*, size_t, size_t);
90 abd_t
*abd_get_from_buf(void *, size_t);
91 void abd_put(abd_t
*);
94 * Conversion to and from a normal buffer
97 void *abd_to_buf(abd_t
*);
98 void *abd_borrow_buf(abd_t
*, size_t);
99 void *abd_borrow_buf_copy(abd_t
*, size_t);
100 void abd_return_buf(abd_t
*, void *, size_t);
101 void abd_return_buf_copy(abd_t
*, void *, size_t);
102 void abd_take_ownership_of_buf(abd_t
*, boolean_t
);
103 void abd_release_ownership_of_buf(abd_t
*);
109 int abd_iterate_func(abd_t
*, size_t, size_t, abd_iter_func_t
*, void *);
110 int abd_iterate_func2(abd_t
*, abd_t
*, size_t, size_t, size_t,
111 abd_iter_func2_t
*, void *);
112 void abd_copy_off(abd_t
*, abd_t
*, size_t, size_t, size_t);
113 void abd_copy_from_buf_off(abd_t
*, const void *, size_t, size_t);
114 void abd_copy_to_buf_off(void *, abd_t
*, size_t, size_t);
115 int abd_cmp(abd_t
*, abd_t
*);
116 int abd_cmp_buf_off(abd_t
*, const void *, size_t, size_t);
117 void abd_zero_off(abd_t
*, size_t, size_t);
119 #if defined(_KERNEL) && defined(HAVE_SPL)
120 unsigned int abd_scatter_bio_map_off(struct bio
*, abd_t
*, unsigned int,
122 unsigned long abd_nr_pages_off(abd_t
*, unsigned int, size_t);
125 void abd_raidz_gen_iterate(abd_t
**cabds
, abd_t
*dabd
,
126 ssize_t csize
, ssize_t dsize
, const unsigned parity
,
127 void (*func_raidz_gen
)(void **, const void *, size_t, size_t));
128 void abd_raidz_rec_iterate(abd_t
**cabds
, abd_t
**tabds
,
129 ssize_t tsize
, const unsigned parity
,
130 void (*func_raidz_rec
)(void **t
, const size_t tsize
, void **c
,
131 const unsigned *mul
),
132 const unsigned *mul
);
135 * Wrappers for calls with offsets of 0
139 abd_copy(abd_t
*dabd
, abd_t
*sabd
, size_t size
)
141 abd_copy_off(dabd
, sabd
, 0, 0, size
);
145 abd_copy_from_buf(abd_t
*abd
, const void *buf
, size_t size
)
147 abd_copy_from_buf_off(abd
, buf
, 0, size
);
151 abd_copy_to_buf(void* buf
, abd_t
*abd
, size_t size
)
153 abd_copy_to_buf_off(buf
, abd
, 0, size
);
157 abd_cmp_buf(abd_t
*abd
, const void *buf
, size_t size
)
159 return (abd_cmp_buf_off(abd
, buf
, 0, size
));
163 abd_zero(abd_t
*abd
, size_t size
)
165 abd_zero_off(abd
, 0, size
);