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