Print this page
4171 clean up spa_feature_*() interfaces
4172 implement extensible_dataset feature for use by other zpool features
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/zap.h
+++ new/usr/src/uts/common/fs/zfs/sys/zap.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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #ifndef _SYS_ZAP_H
27 27 #define _SYS_ZAP_H
28 28
29 29 /*
30 30 * ZAP - ZFS Attribute Processor
31 31 *
32 32 * The ZAP is a module which sits on top of the DMU (Data Management
33 33 * Unit) and implements a higher-level storage primitive using DMU
34 34 * objects. Its primary consumer is the ZPL (ZFS Posix Layer).
35 35 *
36 36 * A "zapobj" is a DMU object which the ZAP uses to stores attributes.
37 37 * Users should use only zap routines to access a zapobj - they should
38 38 * not access the DMU object directly using DMU routines.
39 39 *
40 40 * The attributes stored in a zapobj are name-value pairs. The name is
41 41 * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including
42 42 * terminating NULL). The value is an array of integers, which may be
43 43 * 1, 2, 4, or 8 bytes long. The total space used by the array (number
44 44 * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes.
45 45 * Note that an 8-byte integer value can be used to store the location
46 46 * (object number) of another dmu object (which may be itself a zapobj).
47 47 * Note that you can use a zero-length attribute to store a single bit
48 48 * of information - the attribute is present or not.
49 49 *
50 50 * The ZAP routines are thread-safe. However, you must observe the
51 51 * DMU's restriction that a transaction may not be operated on
52 52 * concurrently.
53 53 *
54 54 * Any of the routines that return an int may return an I/O error (EIO
55 55 * or ECHECKSUM).
56 56 *
57 57 *
58 58 * Implementation / Performance Notes:
59 59 *
60 60 * The ZAP is intended to operate most efficiently on attributes with
61 61 * short (49 bytes or less) names and single 8-byte values, for which
62 62 * the microzap will be used. The ZAP should be efficient enough so
63 63 * that the user does not need to cache these attributes.
64 64 *
65 65 * The ZAP's locking scheme makes its routines thread-safe. Operations
66 66 * on different zapobjs will be processed concurrently. Operations on
67 67 * the same zapobj which only read data will be processed concurrently.
68 68 * Operations on the same zapobj which modify data will be processed
69 69 * concurrently when there are many attributes in the zapobj (because
70 70 * the ZAP uses per-block locking - more than 128 * (number of cpus)
71 71 * small attributes will suffice).
72 72 */
73 73
74 74 /*
75 75 * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C
76 76 * strings) for the names of attributes, rather than a byte string
77 77 * bounded by an explicit length. If some day we want to support names
78 78 * in character sets which have embedded zeros (eg. UTF-16, UTF-32),
79 79 * we'll have to add routines for using length-bounded strings.
80 80 */
81 81
82 82 #include <sys/dmu.h>
83 83
84 84 #ifdef __cplusplus
85 85 extern "C" {
86 86 #endif
87 87
88 88 /*
89 89 * Specifies matching criteria for ZAP lookups.
90 90 */
91 91 typedef enum matchtype
92 92 {
93 93 /* Only find an exact match (non-normalized) */
94 94 MT_EXACT,
95 95 /*
96 96 * If there is an exact match, find that, otherwise find the
97 97 * first normalized match.
98 98 */
99 99 MT_BEST,
100 100 /*
101 101 * Find the "first" normalized (case and Unicode form) match;
102 102 * the designated "first" match will not change as long as the
103 103 * set of entries with this normalization doesn't change.
104 104 */
105 105 MT_FIRST
106 106 } matchtype_t;
107 107
108 108 typedef enum zap_flags {
109 109 /* Use 64-bit hash value (serialized cursors will always use 64-bits) */
110 110 ZAP_FLAG_HASH64 = 1 << 0,
111 111 /* Key is binary, not string (zap_add_uint64() can be used) */
112 112 ZAP_FLAG_UINT64_KEY = 1 << 1,
113 113 /*
114 114 * First word of key (which must be an array of uint64) is
115 115 * already randomly distributed.
116 116 */
117 117 ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
118 118 } zap_flags_t;
119 119
120 120 /*
121 121 * Create a new zapobj with no attributes and return its object number.
122 122 * MT_EXACT will cause the zap object to only support MT_EXACT lookups,
123 123 * otherwise any matchtype can be used for lookups.
124 124 *
125 125 * normflags specifies what normalization will be done. values are:
126 126 * 0: no normalization (legacy on-disk format, supports MT_EXACT matching
127 127 * only)
128 128 * U8_TEXTPREP_TOLOWER: case normalization will be performed.
129 129 * MT_FIRST/MT_BEST matching will find entries that match without
130 130 * regard to case (eg. looking for "foo" can find an entry "Foo").
131 131 * Eventually, other flags will permit unicode normalization as well.
132 132 */
133 133 uint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
↓ open down ↓ |
133 lines elided |
↑ open up ↑ |
134 134 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
135 135 uint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
136 136 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
137 137 uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
138 138 dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
139 139 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
140 140 uint64_t zap_create_link(objset_t *os, dmu_object_type_t ot,
141 141 uint64_t parent_obj, const char *name, dmu_tx_t *tx);
142 142
143 143 /*
144 + * Initialize an already-allocated object.
145 + */
146 +void mzap_create_impl(objset_t *os, uint64_t obj, int normflags,
147 + zap_flags_t flags, dmu_tx_t *tx);
148 +
149 +/*
144 150 * Create a new zapobj with no attributes from the given (unallocated)
145 151 * object number.
146 152 */
147 153 int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
148 154 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
149 155 int zap_create_claim_norm(objset_t *ds, uint64_t obj,
150 156 int normflags, dmu_object_type_t ot,
151 157 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
152 158
153 159 /*
154 160 * The zapobj passed in must be a valid ZAP object for all of the
155 161 * following routines.
156 162 */
157 163
158 164 /*
159 165 * Destroy this zapobj and all its attributes.
160 166 *
161 167 * Frees the object number using dmu_object_free.
162 168 */
163 169 int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
164 170
165 171 /*
166 172 * Manipulate attributes.
167 173 *
168 174 * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
169 175 */
170 176
171 177 /*
172 178 * Retrieve the contents of the attribute with the given name.
173 179 *
174 180 * If the requested attribute does not exist, the call will fail and
175 181 * return ENOENT.
176 182 *
177 183 * If 'integer_size' is smaller than the attribute's integer size, the
178 184 * call will fail and return EINVAL.
179 185 *
180 186 * If 'integer_size' is equal to or larger than the attribute's integer
181 187 * size, the call will succeed and return 0.
182 188 *
183 189 * When converting to a larger integer size, the integers will be treated as
184 190 * unsigned (ie. no sign-extension will be performed).
185 191 *
186 192 * 'num_integers' is the length (in integers) of 'buf'.
187 193 *
188 194 * If the attribute is longer than the buffer, as many integers as will
189 195 * fit will be transferred to 'buf'. If the entire attribute was not
190 196 * transferred, the call will return EOVERFLOW.
191 197 */
192 198 int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
193 199 uint64_t integer_size, uint64_t num_integers, void *buf);
194 200
195 201 /*
196 202 * If rn_len is nonzero, realname will be set to the name of the found
197 203 * entry (which may be different from the requested name if matchtype is
198 204 * not MT_EXACT).
199 205 *
200 206 * If normalization_conflictp is not NULL, it will be set if there is
201 207 * another name with the same case/unicode normalized form.
202 208 */
203 209 int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
204 210 uint64_t integer_size, uint64_t num_integers, void *buf,
205 211 matchtype_t mt, char *realname, int rn_len,
206 212 boolean_t *normalization_conflictp);
207 213 int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
208 214 int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
209 215 int zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
210 216 int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
211 217 int key_numints);
212 218
213 219 int zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
214 220 int add, uint64_t *towrite, uint64_t *tooverwrite);
215 221
216 222 /*
217 223 * Create an attribute with the given name and value.
218 224 *
219 225 * If an attribute with the given name already exists, the call will
220 226 * fail and return EEXIST.
221 227 */
222 228 int zap_add(objset_t *ds, uint64_t zapobj, const char *key,
223 229 int integer_size, uint64_t num_integers,
224 230 const void *val, dmu_tx_t *tx);
225 231 int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
226 232 int key_numints, int integer_size, uint64_t num_integers,
227 233 const void *val, dmu_tx_t *tx);
228 234
229 235 /*
230 236 * Set the attribute with the given name to the given value. If an
231 237 * attribute with the given name does not exist, it will be created. If
232 238 * an attribute with the given name already exists, the previous value
233 239 * will be overwritten. The integer_size may be different from the
234 240 * existing attribute's integer size, in which case the attribute's
235 241 * integer size will be updated to the new value.
236 242 */
237 243 int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
238 244 int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
239 245 int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
240 246 int key_numints,
241 247 int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
242 248
243 249 /*
244 250 * Get the length (in integers) and the integer size of the specified
245 251 * attribute.
246 252 *
247 253 * If the requested attribute does not exist, the call will fail and
248 254 * return ENOENT.
249 255 */
250 256 int zap_length(objset_t *ds, uint64_t zapobj, const char *name,
251 257 uint64_t *integer_size, uint64_t *num_integers);
252 258 int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
253 259 int key_numints, uint64_t *integer_size, uint64_t *num_integers);
254 260
255 261 /*
256 262 * Remove the specified attribute.
257 263 *
258 264 * If the specified attribute does not exist, the call will fail and
259 265 * return ENOENT.
260 266 */
261 267 int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
262 268 int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
263 269 matchtype_t mt, dmu_tx_t *tx);
264 270 int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
265 271 int key_numints, dmu_tx_t *tx);
266 272
267 273 /*
268 274 * Returns (in *count) the number of attributes in the specified zap
269 275 * object.
270 276 */
271 277 int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
272 278
273 279 /*
274 280 * Returns (in name) the name of the entry whose (value & mask)
275 281 * (za_first_integer) is value, or ENOENT if not found. The string
276 282 * pointed to by name must be at least 256 bytes long. If mask==0, the
277 283 * match must be exact (ie, same as mask=-1ULL).
278 284 */
279 285 int zap_value_search(objset_t *os, uint64_t zapobj,
280 286 uint64_t value, uint64_t mask, char *name);
281 287
282 288 /*
283 289 * Transfer all the entries from fromobj into intoobj. Only works on
284 290 * int_size=8 num_integers=1 values. Fails if there are any duplicated
285 291 * entries.
286 292 */
287 293 int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
288 294
289 295 /* Same as zap_join, but set the values to 'value'. */
290 296 int zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
291 297 uint64_t value, dmu_tx_t *tx);
292 298
293 299 /* Same as zap_join, but add together any duplicated entries. */
294 300 int zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
295 301 dmu_tx_t *tx);
296 302
297 303 /*
298 304 * Manipulate entries where the name + value are the "same" (the name is
299 305 * a stringified version of the value).
300 306 */
301 307 int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
302 308 int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
303 309 int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
304 310 int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
305 311 dmu_tx_t *tx);
306 312
307 313 /* Here the key is an int and the value is a different int. */
308 314 int zap_add_int_key(objset_t *os, uint64_t obj,
309 315 uint64_t key, uint64_t value, dmu_tx_t *tx);
310 316 int zap_update_int_key(objset_t *os, uint64_t obj,
311 317 uint64_t key, uint64_t value, dmu_tx_t *tx);
312 318 int zap_lookup_int_key(objset_t *os, uint64_t obj,
313 319 uint64_t key, uint64_t *valuep);
314 320
315 321 int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
316 322 dmu_tx_t *tx);
317 323
318 324 struct zap;
319 325 struct zap_leaf;
320 326 typedef struct zap_cursor {
321 327 /* This structure is opaque! */
322 328 objset_t *zc_objset;
323 329 struct zap *zc_zap;
324 330 struct zap_leaf *zc_leaf;
325 331 uint64_t zc_zapobj;
326 332 uint64_t zc_serialized;
327 333 uint64_t zc_hash;
328 334 uint32_t zc_cd;
329 335 } zap_cursor_t;
330 336
331 337 typedef struct {
332 338 int za_integer_length;
333 339 /*
334 340 * za_normalization_conflict will be set if there are additional
335 341 * entries with this normalized form (eg, "foo" and "Foo").
336 342 */
337 343 boolean_t za_normalization_conflict;
338 344 uint64_t za_num_integers;
339 345 uint64_t za_first_integer; /* no sign extension for <8byte ints */
340 346 char za_name[MAXNAMELEN];
341 347 } zap_attribute_t;
342 348
343 349 /*
344 350 * The interface for listing all the attributes of a zapobj can be
345 351 * thought of as cursor moving down a list of the attributes one by
346 352 * one. The cookie returned by the zap_cursor_serialize routine is
347 353 * persistent across system calls (and across reboot, even).
348 354 */
349 355
350 356 /*
351 357 * Initialize a zap cursor, pointing to the "first" attribute of the
352 358 * zapobj. You must _fini the cursor when you are done with it.
353 359 */
354 360 void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
355 361 void zap_cursor_fini(zap_cursor_t *zc);
356 362
357 363 /*
358 364 * Get the attribute currently pointed to by the cursor. Returns
359 365 * ENOENT if at the end of the attributes.
360 366 */
361 367 int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
362 368
363 369 /*
364 370 * Advance the cursor to the next attribute.
365 371 */
366 372 void zap_cursor_advance(zap_cursor_t *zc);
367 373
368 374 /*
369 375 * Get a persistent cookie pointing to the current position of the zap
370 376 * cursor. The low 4 bits in the cookie are always zero, and thus can
371 377 * be used as to differentiate a serialized cookie from a different type
372 378 * of value. The cookie will be less than 2^32 as long as there are
373 379 * fewer than 2^22 (4.2 million) entries in the zap object.
374 380 */
375 381 uint64_t zap_cursor_serialize(zap_cursor_t *zc);
376 382
377 383 /*
378 384 * Initialize a zap cursor pointing to the position recorded by
379 385 * zap_cursor_serialize (in the "serialized" argument). You can also
380 386 * use a "serialized" argument of 0 to start at the beginning of the
381 387 * zapobj (ie. zap_cursor_init_serialized(..., 0) is equivalent to
382 388 * zap_cursor_init(...).)
383 389 */
384 390 void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
385 391 uint64_t zapobj, uint64_t serialized);
386 392
387 393
388 394 #define ZAP_HISTOGRAM_SIZE 10
389 395
390 396 typedef struct zap_stats {
391 397 /*
392 398 * Size of the pointer table (in number of entries).
393 399 * This is always a power of 2, or zero if it's a microzap.
394 400 * In general, it should be considerably greater than zs_num_leafs.
395 401 */
396 402 uint64_t zs_ptrtbl_len;
397 403
398 404 uint64_t zs_blocksize; /* size of zap blocks */
399 405
400 406 /*
401 407 * The number of blocks used. Note that some blocks may be
402 408 * wasted because old ptrtbl's and large name/value blocks are
403 409 * not reused. (Although their space is reclaimed, we don't
404 410 * reuse those offsets in the object.)
405 411 */
406 412 uint64_t zs_num_blocks;
407 413
408 414 /*
409 415 * Pointer table values from zap_ptrtbl in the zap_phys_t
410 416 */
411 417 uint64_t zs_ptrtbl_nextblk; /* next (larger) copy start block */
412 418 uint64_t zs_ptrtbl_blks_copied; /* number source blocks copied */
413 419 uint64_t zs_ptrtbl_zt_blk; /* starting block number */
414 420 uint64_t zs_ptrtbl_zt_numblks; /* number of blocks */
415 421 uint64_t zs_ptrtbl_zt_shift; /* bits to index it */
416 422
417 423 /*
418 424 * Values of the other members of the zap_phys_t
419 425 */
420 426 uint64_t zs_block_type; /* ZBT_HEADER */
421 427 uint64_t zs_magic; /* ZAP_MAGIC */
422 428 uint64_t zs_num_leafs; /* The number of leaf blocks */
423 429 uint64_t zs_num_entries; /* The number of zap entries */
424 430 uint64_t zs_salt; /* salt to stir into hash function */
425 431
426 432 /*
427 433 * Histograms. For all histograms, the last index
428 434 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
429 435 * than what can be represented. For example
430 436 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
431 437 * of leafs with more than 45 entries.
432 438 */
433 439
434 440 /*
435 441 * zs_leafs_with_n_pointers[n] is the number of leafs with
436 442 * 2^n pointers to it.
437 443 */
438 444 uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
439 445
440 446 /*
441 447 * zs_leafs_with_n_entries[n] is the number of leafs with
442 448 * [n*5, (n+1)*5) entries. In the current implementation, there
443 449 * can be at most 55 entries in any block, but there may be
444 450 * fewer if the name or value is large, or the block is not
445 451 * completely full.
446 452 */
447 453 uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
448 454
449 455 /*
450 456 * zs_leafs_n_tenths_full[n] is the number of leafs whose
451 457 * fullness is in the range [n/10, (n+1)/10).
452 458 */
453 459 uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
454 460
455 461 /*
456 462 * zs_entries_using_n_chunks[n] is the number of entries which
457 463 * consume n 24-byte chunks. (Note, large names/values only use
458 464 * one chunk, but contribute to zs_num_blocks_large.)
459 465 */
460 466 uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
461 467
462 468 /*
463 469 * zs_buckets_with_n_entries[n] is the number of buckets (each
464 470 * leaf has 64 buckets) with n entries.
465 471 * zs_buckets_with_n_entries[1] should be very close to
466 472 * zs_num_entries.
467 473 */
468 474 uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
469 475 } zap_stats_t;
470 476
471 477 /*
472 478 * Get statistics about a ZAP object. Note: you need to be aware of the
473 479 * internal implementation of the ZAP to correctly interpret some of the
474 480 * statistics. This interface shouldn't be relied on unless you really
475 481 * know what you're doing.
476 482 */
477 483 int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
478 484
479 485 #ifdef __cplusplus
480 486 }
481 487 #endif
482 488
483 489 #endif /* _SYS_ZAP_H */
↓ open down ↓ |
330 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX