Print this page
3742 zfs comments need cleaner, more consistent style
Submitted by: Will Andrews <willa@spectralogic.com>
Submitted by: Alan Somers <alans@spectralogic.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/sa_impl.h
+++ new/usr/src/uts/common/fs/zfs/sys/sa_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #ifndef _SYS_SA_IMPL_H
27 27 #define _SYS_SA_IMPL_H
28 28
29 29 #include <sys/dmu.h>
30 30 #include <sys/refcount.h>
31 31 #include <sys/list.h>
32 32
33 33 /*
34 34 * Array of known attributes and their
35 35 * various characteristics.
36 36 */
37 37 typedef struct sa_attr_table {
38 38 sa_attr_type_t sa_attr;
39 39 uint8_t sa_registered;
40 40 uint16_t sa_length;
41 41 sa_bswap_type_t sa_byteswap;
42 42 char *sa_name;
43 43 } sa_attr_table_t;
44 44
45 45 /*
46 46 * Zap attribute format for attribute registration
47 47 *
48 48 * 64 56 48 40 32 24 16 8 0
49 49 * +-------+-------+-------+-------+-------+-------+-------+-------+
50 50 * | unused | len | bswap | attr num |
51 51 * +-------+-------+-------+-------+-------+-------+-------+-------+
52 52 *
53 53 * Zap attribute format for layout information.
54 54 *
55 55 * layout information is stored as an array of attribute numbers
56 56 * The name of the attribute is the layout number (0, 1, 2, ...)
57 57 *
58 58 * 16 0
59 59 * +---- ---+
60 60 * | attr # |
61 61 * +--------+
62 62 * | attr # |
63 63 * +--- ----+
64 64 * ......
65 65 *
66 66 */
67 67
68 68 #define ATTR_BSWAP(x) BF32_GET(x, 16, 8)
69 69 #define ATTR_LENGTH(x) BF32_GET(x, 24, 16)
70 70 #define ATTR_NUM(x) BF32_GET(x, 0, 16)
71 71 #define ATTR_ENCODE(x, attr, length, bswap) \
72 72 { \
73 73 BF64_SET(x, 24, 16, length); \
74 74 BF64_SET(x, 16, 8, bswap); \
75 75 BF64_SET(x, 0, 16, attr); \
76 76 }
77 77
78 78 #define TOC_OFF(x) BF32_GET(x, 0, 23)
79 79 #define TOC_ATTR_PRESENT(x) BF32_GET(x, 31, 1)
80 80 #define TOC_LEN_IDX(x) BF32_GET(x, 24, 4)
81 81 #define TOC_ATTR_ENCODE(x, len_idx, offset) \
82 82 { \
83 83 BF32_SET(x, 31, 1, 1); \
84 84 BF32_SET(x, 24, 7, len_idx); \
85 85 BF32_SET(x, 0, 24, offset); \
86 86 }
87 87
88 88 #define SA_LAYOUTS "LAYOUTS"
89 89 #define SA_REGISTRY "REGISTRY"
90 90
91 91 /*
92 92 * Each unique layout will have their own table
93 93 * sa_lot (layout_table)
94 94 */
95 95 typedef struct sa_lot {
96 96 avl_node_t lot_num_node;
97 97 avl_node_t lot_hash_node;
98 98 uint64_t lot_num;
99 99 uint64_t lot_hash;
100 100 sa_attr_type_t *lot_attrs; /* array of attr #'s */
101 101 uint32_t lot_var_sizes; /* how many aren't fixed size */
102 102 uint32_t lot_attr_count; /* total attr count */
103 103 list_t lot_idx_tab; /* should be only a couple of entries */
104 104 int lot_instance; /* used with lot_hash to identify entry */
105 105 } sa_lot_t;
106 106
107 107 /* index table of offsets */
108 108 typedef struct sa_idx_tab {
109 109 list_node_t sa_next;
110 110 sa_lot_t *sa_layout;
111 111 uint16_t *sa_variable_lengths;
112 112 refcount_t sa_refcount;
113 113 uint32_t *sa_idx_tab; /* array of offsets */
114 114 } sa_idx_tab_t;
115 115
116 116 /*
117 117 * Since the offset/index information into the actual data
118 118 * will usually be identical we can share that information with
119 119 * all handles that have the exact same offsets.
120 120 *
121 121 * You would typically only have a large number of different table of
122 122 * contents if you had a several variable sized attributes.
123 123 *
124 124 * Two AVL trees are used to track the attribute layout numbers.
125 125 * one is keyed by number and will be consulted when a DMU_OT_SA
126 126 * object is first read. The second tree is keyed by the hash signature
127 127 * of the attributes and will be consulted when an attribute is added
128 128 * to determine if we already have an instance of that layout. Both
129 129 * of these tree's are interconnected. The only difference is that
130 130 * when an entry is found in the "hash" tree the list of attributes will
131 131 * need to be compared against the list of attributes you have in hand.
132 132 * The assumption is that typically attributes will just be updated and
133 133 * adding a completely new attribute is a very rare operation.
134 134 */
135 135 struct sa_os {
136 136 kmutex_t sa_lock;
137 137 boolean_t sa_need_attr_registration;
138 138 boolean_t sa_force_spill;
139 139 uint64_t sa_master_obj;
140 140 uint64_t sa_reg_attr_obj;
141 141 uint64_t sa_layout_attr_obj;
142 142 int sa_num_attrs;
↓ open down ↓ |
142 lines elided |
↑ open up ↑ |
143 143 sa_attr_table_t *sa_attr_table; /* private attr table */
144 144 sa_update_cb_t *sa_update_cb;
145 145 avl_tree_t sa_layout_num_tree; /* keyed by layout number */
146 146 avl_tree_t sa_layout_hash_tree; /* keyed by layout hash value */
147 147 int sa_user_table_sz;
148 148 sa_attr_type_t *sa_user_table; /* user name->attr mapping table */
149 149 };
150 150
151 151 /*
152 152 * header for all bonus and spill buffers.
153 + *
153 154 * The header has a fixed portion with a variable number
154 155 * of "lengths" depending on the number of variable sized
155 156 * attribues which are determined by the "layout number"
156 157 */
157 158
158 159 #define SA_MAGIC 0x2F505A /* ZFS SA */
159 160 typedef struct sa_hdr_phys {
160 161 uint32_t sa_magic;
161 - uint16_t sa_layout_info; /* Encoded with hdrsize and layout number */
162 + /*
163 + * Encoded with hdrsize and layout number as follows:
164 + * 16 10 0
165 + * +--------+-------+
166 + * | hdrsz |layout |
167 + * +--------+-------+
168 + *
169 + * Bits 0-10 are the layout number
170 + * Bits 11-16 are the size of the header.
171 + * The hdrsize is the number * 8
172 + *
173 + * For example.
174 + * hdrsz of 1 ==> 8 byte header
175 + * 2 ==> 16 byte header
176 + *
177 + */
178 + uint16_t sa_layout_info;
162 179 uint16_t sa_lengths[1]; /* optional sizes for variable length attrs */
163 180 /* ... Data follows the lengths. */
164 181 } sa_hdr_phys_t;
165 182
166 -/*
167 - * sa_hdr_phys -> sa_layout_info
168 - *
169 - * 16 10 0
170 - * +--------+-------+
171 - * | hdrsz |layout |
172 - * +--------+-------+
173 - *
174 - * Bits 0-10 are the layout number
175 - * Bits 11-16 are the size of the header.
176 - * The hdrsize is the number * 8
177 - *
178 - * For example.
179 - * hdrsz of 1 ==> 8 byte header
180 - * 2 ==> 16 byte header
181 - *
182 - */
183 -
184 183 #define SA_HDR_LAYOUT_NUM(hdr) BF32_GET(hdr->sa_layout_info, 0, 10)
185 184 #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 6, 3, 0)
186 185 #define SA_HDR_LAYOUT_INFO_ENCODE(x, num, size) \
187 186 { \
188 187 BF32_SET_SB(x, 10, 6, 3, 0, size); \
189 188 BF32_SET(x, 0, 10, num); \
190 189 }
191 190
192 191 typedef enum sa_buf_type {
193 192 SA_BONUS = 1,
194 193 SA_SPILL = 2
195 194 } sa_buf_type_t;
196 195
197 196 typedef enum sa_data_op {
198 197 SA_LOOKUP,
199 198 SA_UPDATE,
200 199 SA_ADD,
201 200 SA_REPLACE,
202 201 SA_REMOVE
203 202 } sa_data_op_t;
204 203
205 204 /*
206 205 * Opaque handle used for most sa functions
207 206 *
208 207 * This needs to be kept as small as possible.
209 208 */
210 209
211 210 struct sa_handle {
212 211 kmutex_t sa_lock;
213 212 dmu_buf_t *sa_bonus;
214 213 dmu_buf_t *sa_spill;
215 214 objset_t *sa_os;
216 215 void *sa_userp;
217 216 sa_idx_tab_t *sa_bonus_tab; /* idx of bonus */
218 217 sa_idx_tab_t *sa_spill_tab; /* only present if spill activated */
219 218 };
220 219
221 220 #define SA_GET_DB(hdl, type) \
222 221 (dmu_buf_impl_t *)((type == SA_BONUS) ? hdl->sa_bonus : hdl->sa_spill)
223 222
224 223 #define SA_GET_HDR(hdl, type) \
225 224 ((sa_hdr_phys_t *)((dmu_buf_impl_t *)(SA_GET_DB(hdl, \
226 225 type))->db.db_data))
227 226
228 227 #define SA_IDX_TAB_GET(hdl, type) \
229 228 (type == SA_BONUS ? hdl->sa_bonus_tab : hdl->sa_spill_tab)
230 229
231 230 #define IS_SA_BONUSTYPE(a) \
232 231 ((a == DMU_OT_SA) ? B_TRUE : B_FALSE)
233 232
234 233 #define SA_BONUSTYPE_FROM_DB(db) \
235 234 (dmu_get_bonustype((dmu_buf_t *)db))
236 235
237 236 #define SA_BLKPTR_SPACE (DN_MAX_BONUSLEN - sizeof (blkptr_t))
238 237
239 238 #define SA_LAYOUT_NUM(x, type) \
240 239 ((!IS_SA_BONUSTYPE(type) ? 0 : (((IS_SA_BONUSTYPE(type)) && \
241 240 ((SA_HDR_LAYOUT_NUM(x)) == 0)) ? 1 : SA_HDR_LAYOUT_NUM(x))))
242 241
243 242
244 243 #define SA_REGISTERED_LEN(sa, attr) sa->sa_attr_table[attr].sa_length
245 244
246 245 #define SA_ATTR_LEN(sa, idx, attr, hdr) ((SA_REGISTERED_LEN(sa, attr) == 0) ?\
247 246 hdr->sa_lengths[TOC_LEN_IDX(idx->sa_idx_tab[attr])] : \
248 247 SA_REGISTERED_LEN(sa, attr))
249 248
250 249 #define SA_SET_HDR(hdr, num, size) \
251 250 { \
252 251 hdr->sa_magic = SA_MAGIC; \
253 252 SA_HDR_LAYOUT_INFO_ENCODE(hdr->sa_layout_info, num, size); \
254 253 }
255 254
256 255 #define SA_ATTR_INFO(sa, idx, hdr, attr, bulk, type, hdl) \
257 256 { \
258 257 bulk.sa_size = SA_ATTR_LEN(sa, idx, attr, hdr); \
259 258 bulk.sa_buftype = type; \
260 259 bulk.sa_addr = \
261 260 (void *)((uintptr_t)TOC_OFF(idx->sa_idx_tab[attr]) + \
262 261 (uintptr_t)hdr); \
263 262 }
264 263
265 264 #define SA_HDR_SIZE_MATCH_LAYOUT(hdr, tb) \
266 265 (SA_HDR_SIZE(hdr) == (sizeof (sa_hdr_phys_t) + \
267 266 (tb->lot_var_sizes > 1 ? P2ROUNDUP((tb->lot_var_sizes - 1) * \
268 267 sizeof (uint16_t), 8) : 0)))
269 268
270 269 int sa_add_impl(sa_handle_t *, sa_attr_type_t,
271 270 uint32_t, sa_data_locator_t, void *, dmu_tx_t *);
272 271
273 272 void sa_register_update_callback_locked(objset_t *, sa_update_cb_t *);
274 273 int sa_size_locked(sa_handle_t *, sa_attr_type_t, int *);
275 274
276 275 void sa_default_locator(void **, uint32_t *, uint32_t, boolean_t, void *);
277 276 int sa_attr_size(sa_os_t *, sa_idx_tab_t *, sa_attr_type_t,
278 277 uint16_t *, sa_hdr_phys_t *);
279 278
280 279 #ifdef __cplusplus
281 280 extern "C" {
282 281 #endif
283 282
284 283 #ifdef __cplusplus
285 284 }
286 285 #endif
287 286
288 287 #endif /* _SYS_SA_IMPL_H */
↓ open down ↓ |
95 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX