]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
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. | |
7 | * | |
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. | |
12 | * | |
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] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
9b7b9cd3 | 21 | |
34dc7c2f | 22 | /* |
428870ff | 23 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
64fc7762 | 24 | * Copyright (c) 2012, 2017 by Delphix. All rights reserved. |
3a17a7a9 | 25 | * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. |
788eb90c | 26 | * Copyright (c) 2013, Joyent, Inc. All rights reserved. |
0c66c32d | 27 | * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved. |
9c43027b | 28 | * Copyright (c) 2015, STRATO AG, Inc. All rights reserved. |
a0bd735a | 29 | * Copyright (c) 2016 Actifio, Inc. All rights reserved. |
9b7b9cd3 | 30 | * Copyright 2017 Nexenta Systems, Inc. |
c0daec32 | 31 | * Copyright (c) 2017 Open-E, Inc. All Rights Reserved. |
34dc7c2f BB |
32 | */ |
33 | ||
428870ff BB |
34 | /* Portions Copyright 2010 Robert Milkowski */ |
35 | ||
1de321e6 | 36 | #include <sys/zfeature.h> |
34dc7c2f BB |
37 | #include <sys/cred.h> |
38 | #include <sys/zfs_context.h> | |
39 | #include <sys/dmu_objset.h> | |
40 | #include <sys/dsl_dir.h> | |
41 | #include <sys/dsl_dataset.h> | |
42 | #include <sys/dsl_prop.h> | |
43 | #include <sys/dsl_pool.h> | |
44 | #include <sys/dsl_synctask.h> | |
45 | #include <sys/dsl_deleg.h> | |
46 | #include <sys/dnode.h> | |
47 | #include <sys/dbuf.h> | |
48 | #include <sys/zvol.h> | |
49 | #include <sys/dmu_tx.h> | |
34dc7c2f BB |
50 | #include <sys/zap.h> |
51 | #include <sys/zil.h> | |
52 | #include <sys/dmu_impl.h> | |
53 | #include <sys/zfs_ioctl.h> | |
428870ff | 54 | #include <sys/sa.h> |
572e2857 | 55 | #include <sys/zfs_onexit.h> |
13fe0198 | 56 | #include <sys/dsl_destroy.h> |
9c43027b | 57 | #include <sys/vdev.h> |
f74b821a | 58 | #include <sys/policy.h> |
1de321e6 | 59 | #include <sys/spa_impl.h> |
b5256303 | 60 | #include <sys/dmu_send.h> |
572e2857 BB |
61 | |
62 | /* | |
63 | * Needed to close a window in dnode_move() that allows the objset to be freed | |
64 | * before it can be safely accessed. | |
65 | */ | |
66 | krwlock_t os_lock; | |
67 | ||
9c43027b | 68 | /* |
4e33ba4c | 69 | * Tunable to overwrite the maximum number of threads for the parallelization |
9c43027b AJ |
70 | * of dmu_objset_find_dp, needed to speed up the import of pools with many |
71 | * datasets. | |
72 | * Default is 4 times the number of leaf vdevs. | |
73 | */ | |
74 | int dmu_find_threads = 0; | |
75 | ||
68cbd56e NB |
76 | /* |
77 | * Backfill lower metadnode objects after this many have been freed. | |
78 | * Backfilling negatively impacts object creation rates, so only do it | |
79 | * if there are enough holes to fill. | |
80 | */ | |
81 | int dmu_rescan_dnode_threshold = 1 << DN_MAX_INDBLKSHIFT; | |
82 | ||
c0daec32 AB |
83 | static char *upgrade_tag = "upgrade_tag"; |
84 | ||
9c43027b AJ |
85 | static void dmu_objset_find_dp_cb(void *arg); |
86 | ||
1de321e6 JX |
87 | static void dmu_objset_upgrade(objset_t *os, dmu_objset_upgrade_cb_t cb); |
88 | static void dmu_objset_upgrade_stop(objset_t *os); | |
89 | ||
572e2857 BB |
90 | void |
91 | dmu_objset_init(void) | |
92 | { | |
93 | rw_init(&os_lock, NULL, RW_DEFAULT, NULL); | |
94 | } | |
95 | ||
96 | void | |
97 | dmu_objset_fini(void) | |
98 | { | |
99 | rw_destroy(&os_lock); | |
100 | } | |
34dc7c2f BB |
101 | |
102 | spa_t * | |
103 | dmu_objset_spa(objset_t *os) | |
104 | { | |
428870ff | 105 | return (os->os_spa); |
34dc7c2f BB |
106 | } |
107 | ||
108 | zilog_t * | |
109 | dmu_objset_zil(objset_t *os) | |
110 | { | |
428870ff | 111 | return (os->os_zil); |
34dc7c2f BB |
112 | } |
113 | ||
114 | dsl_pool_t * | |
115 | dmu_objset_pool(objset_t *os) | |
116 | { | |
117 | dsl_dataset_t *ds; | |
118 | ||
428870ff | 119 | if ((ds = os->os_dsl_dataset) != NULL && ds->ds_dir) |
34dc7c2f BB |
120 | return (ds->ds_dir->dd_pool); |
121 | else | |
428870ff | 122 | return (spa_get_dsl(os->os_spa)); |
34dc7c2f BB |
123 | } |
124 | ||
125 | dsl_dataset_t * | |
126 | dmu_objset_ds(objset_t *os) | |
127 | { | |
428870ff | 128 | return (os->os_dsl_dataset); |
34dc7c2f BB |
129 | } |
130 | ||
131 | dmu_objset_type_t | |
132 | dmu_objset_type(objset_t *os) | |
133 | { | |
428870ff | 134 | return (os->os_phys->os_type); |
34dc7c2f BB |
135 | } |
136 | ||
137 | void | |
138 | dmu_objset_name(objset_t *os, char *buf) | |
139 | { | |
428870ff | 140 | dsl_dataset_name(os->os_dsl_dataset, buf); |
34dc7c2f BB |
141 | } |
142 | ||
143 | uint64_t | |
144 | dmu_objset_id(objset_t *os) | |
145 | { | |
428870ff | 146 | dsl_dataset_t *ds = os->os_dsl_dataset; |
34dc7c2f BB |
147 | |
148 | return (ds ? ds->ds_object : 0); | |
149 | } | |
150 | ||
50c957f7 NB |
151 | uint64_t |
152 | dmu_objset_dnodesize(objset_t *os) | |
153 | { | |
154 | return (os->os_dnodesize); | |
155 | } | |
156 | ||
faf0f58c | 157 | zfs_sync_type_t |
428870ff BB |
158 | dmu_objset_syncprop(objset_t *os) |
159 | { | |
160 | return (os->os_sync); | |
161 | } | |
162 | ||
faf0f58c | 163 | zfs_logbias_op_t |
428870ff BB |
164 | dmu_objset_logbias(objset_t *os) |
165 | { | |
166 | return (os->os_logbias); | |
167 | } | |
168 | ||
34dc7c2f BB |
169 | static void |
170 | checksum_changed_cb(void *arg, uint64_t newval) | |
171 | { | |
428870ff | 172 | objset_t *os = arg; |
34dc7c2f BB |
173 | |
174 | /* | |
175 | * Inheritance should have been done by now. | |
176 | */ | |
177 | ASSERT(newval != ZIO_CHECKSUM_INHERIT); | |
178 | ||
428870ff | 179 | os->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE); |
34dc7c2f BB |
180 | } |
181 | ||
182 | static void | |
183 | compression_changed_cb(void *arg, uint64_t newval) | |
184 | { | |
428870ff | 185 | objset_t *os = arg; |
34dc7c2f BB |
186 | |
187 | /* | |
188 | * Inheritance and range checking should have been done by now. | |
189 | */ | |
190 | ASSERT(newval != ZIO_COMPRESS_INHERIT); | |
191 | ||
99197f03 JG |
192 | os->os_compress = zio_compress_select(os->os_spa, newval, |
193 | ZIO_COMPRESS_ON); | |
34dc7c2f BB |
194 | } |
195 | ||
196 | static void | |
197 | copies_changed_cb(void *arg, uint64_t newval) | |
198 | { | |
428870ff | 199 | objset_t *os = arg; |
34dc7c2f BB |
200 | |
201 | /* | |
202 | * Inheritance and range checking should have been done by now. | |
203 | */ | |
204 | ASSERT(newval > 0); | |
428870ff | 205 | ASSERT(newval <= spa_max_replication(os->os_spa)); |
34dc7c2f | 206 | |
428870ff BB |
207 | os->os_copies = newval; |
208 | } | |
209 | ||
210 | static void | |
211 | dedup_changed_cb(void *arg, uint64_t newval) | |
212 | { | |
213 | objset_t *os = arg; | |
214 | spa_t *spa = os->os_spa; | |
215 | enum zio_checksum checksum; | |
216 | ||
217 | /* | |
218 | * Inheritance should have been done by now. | |
219 | */ | |
220 | ASSERT(newval != ZIO_CHECKSUM_INHERIT); | |
221 | ||
222 | checksum = zio_checksum_dedup_select(spa, newval, ZIO_CHECKSUM_OFF); | |
223 | ||
224 | os->os_dedup_checksum = checksum & ZIO_CHECKSUM_MASK; | |
225 | os->os_dedup_verify = !!(checksum & ZIO_CHECKSUM_VERIFY); | |
34dc7c2f BB |
226 | } |
227 | ||
b128c09f BB |
228 | static void |
229 | primary_cache_changed_cb(void *arg, uint64_t newval) | |
230 | { | |
428870ff | 231 | objset_t *os = arg; |
b128c09f BB |
232 | |
233 | /* | |
234 | * Inheritance and range checking should have been done by now. | |
235 | */ | |
236 | ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE || | |
237 | newval == ZFS_CACHE_METADATA); | |
238 | ||
428870ff | 239 | os->os_primary_cache = newval; |
b128c09f BB |
240 | } |
241 | ||
242 | static void | |
243 | secondary_cache_changed_cb(void *arg, uint64_t newval) | |
244 | { | |
428870ff | 245 | objset_t *os = arg; |
b128c09f BB |
246 | |
247 | /* | |
248 | * Inheritance and range checking should have been done by now. | |
249 | */ | |
250 | ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE || | |
251 | newval == ZFS_CACHE_METADATA); | |
252 | ||
428870ff BB |
253 | os->os_secondary_cache = newval; |
254 | } | |
255 | ||
256 | static void | |
257 | sync_changed_cb(void *arg, uint64_t newval) | |
258 | { | |
259 | objset_t *os = arg; | |
260 | ||
261 | /* | |
262 | * Inheritance and range checking should have been done by now. | |
263 | */ | |
264 | ASSERT(newval == ZFS_SYNC_STANDARD || newval == ZFS_SYNC_ALWAYS || | |
265 | newval == ZFS_SYNC_DISABLED); | |
266 | ||
267 | os->os_sync = newval; | |
268 | if (os->os_zil) | |
269 | zil_set_sync(os->os_zil, newval); | |
270 | } | |
271 | ||
faf0f58c MA |
272 | static void |
273 | redundant_metadata_changed_cb(void *arg, uint64_t newval) | |
274 | { | |
275 | objset_t *os = arg; | |
276 | ||
277 | /* | |
278 | * Inheritance and range checking should have been done by now. | |
279 | */ | |
280 | ASSERT(newval == ZFS_REDUNDANT_METADATA_ALL || | |
281 | newval == ZFS_REDUNDANT_METADATA_MOST); | |
282 | ||
283 | os->os_redundant_metadata = newval; | |
284 | } | |
285 | ||
50c957f7 NB |
286 | static void |
287 | dnodesize_changed_cb(void *arg, uint64_t newval) | |
288 | { | |
289 | objset_t *os = arg; | |
290 | ||
291 | switch (newval) { | |
292 | case ZFS_DNSIZE_LEGACY: | |
293 | os->os_dnodesize = DNODE_MIN_SIZE; | |
294 | break; | |
295 | case ZFS_DNSIZE_AUTO: | |
296 | /* | |
297 | * Choose a dnode size that will work well for most | |
298 | * workloads if the user specified "auto". Future code | |
299 | * improvements could dynamically select a dnode size | |
300 | * based on observed workload patterns. | |
301 | */ | |
302 | os->os_dnodesize = DNODE_MIN_SIZE * 2; | |
303 | break; | |
304 | case ZFS_DNSIZE_1K: | |
305 | case ZFS_DNSIZE_2K: | |
306 | case ZFS_DNSIZE_4K: | |
307 | case ZFS_DNSIZE_8K: | |
308 | case ZFS_DNSIZE_16K: | |
309 | os->os_dnodesize = newval; | |
310 | break; | |
311 | } | |
312 | } | |
313 | ||
428870ff BB |
314 | static void |
315 | logbias_changed_cb(void *arg, uint64_t newval) | |
316 | { | |
317 | objset_t *os = arg; | |
318 | ||
319 | ASSERT(newval == ZFS_LOGBIAS_LATENCY || | |
320 | newval == ZFS_LOGBIAS_THROUGHPUT); | |
321 | os->os_logbias = newval; | |
322 | if (os->os_zil) | |
323 | zil_set_logbias(os->os_zil, newval); | |
b128c09f BB |
324 | } |
325 | ||
f1512ee6 MA |
326 | static void |
327 | recordsize_changed_cb(void *arg, uint64_t newval) | |
328 | { | |
329 | objset_t *os = arg; | |
330 | ||
331 | os->os_recordsize = newval; | |
332 | } | |
333 | ||
34dc7c2f BB |
334 | void |
335 | dmu_objset_byteswap(void *buf, size_t size) | |
336 | { | |
337 | objset_phys_t *osp = buf; | |
338 | ||
9babb374 | 339 | ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t)); |
34dc7c2f BB |
340 | dnode_byteswap(&osp->os_meta_dnode); |
341 | byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t)); | |
342 | osp->os_type = BSWAP_64(osp->os_type); | |
9babb374 BB |
343 | osp->os_flags = BSWAP_64(osp->os_flags); |
344 | if (size == sizeof (objset_phys_t)) { | |
345 | dnode_byteswap(&osp->os_userused_dnode); | |
346 | dnode_byteswap(&osp->os_groupused_dnode); | |
347 | } | |
34dc7c2f BB |
348 | } |
349 | ||
64fc7762 MA |
350 | /* |
351 | * The hash is a CRC-based hash of the objset_t pointer and the object number. | |
352 | */ | |
353 | static uint64_t | |
354 | dnode_hash(const objset_t *os, uint64_t obj) | |
355 | { | |
356 | uintptr_t osv = (uintptr_t)os; | |
357 | uint64_t crc = -1ULL; | |
358 | ||
359 | ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY); | |
360 | /* | |
361 | * The low 6 bits of the pointer don't have much entropy, because | |
362 | * the objset_t is larger than 2^6 bytes long. | |
363 | */ | |
364 | crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (osv >> 6)) & 0xFF]; | |
365 | crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 0)) & 0xFF]; | |
366 | crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 8)) & 0xFF]; | |
367 | crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 16)) & 0xFF]; | |
368 | ||
369 | crc ^= (osv>>14) ^ (obj>>24); | |
370 | ||
371 | return (crc); | |
372 | } | |
373 | ||
374 | unsigned int | |
375 | dnode_multilist_index_func(multilist_t *ml, void *obj) | |
376 | { | |
377 | dnode_t *dn = obj; | |
378 | return (dnode_hash(dn->dn_objset, dn->dn_object) % | |
379 | multilist_get_num_sublists(ml)); | |
380 | } | |
381 | ||
34dc7c2f BB |
382 | int |
383 | dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, | |
428870ff | 384 | objset_t **osp) |
34dc7c2f | 385 | { |
428870ff | 386 | objset_t *os; |
b128c09f | 387 | int i, err; |
34dc7c2f BB |
388 | |
389 | ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock)); | |
390 | ||
79c76d5b | 391 | os = kmem_zalloc(sizeof (objset_t), KM_SLEEP); |
428870ff BB |
392 | os->os_dsl_dataset = ds; |
393 | os->os_spa = spa; | |
394 | os->os_rootbp = bp; | |
395 | if (!BP_IS_HOLE(os->os_rootbp)) { | |
2a432414 | 396 | arc_flags_t aflags = ARC_FLAG_WAIT; |
5dbd68a3 | 397 | zbookmark_phys_t zb; |
b5256303 | 398 | enum zio_flag zio_flags = ZIO_FLAG_CANFAIL; |
428870ff BB |
399 | SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET, |
400 | ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID); | |
401 | ||
402 | if (DMU_OS_IS_L2CACHEABLE(os)) | |
2a432414 | 403 | aflags |= ARC_FLAG_L2CACHE; |
34dc7c2f | 404 | |
b5256303 TC |
405 | if (ds != NULL && ds->ds_dir->dd_crypto_obj != 0) { |
406 | ASSERT3U(BP_GET_COMPRESS(bp), ==, ZIO_COMPRESS_OFF); | |
407 | ASSERT(BP_IS_AUTHENTICATED(bp)); | |
408 | zio_flags |= ZIO_FLAG_RAW; | |
409 | } | |
410 | ||
428870ff | 411 | dprintf_bp(os->os_rootbp, "reading %s", ""); |
294f6806 | 412 | err = arc_read(NULL, spa, os->os_rootbp, |
428870ff | 413 | arc_getbuf_func, &os->os_phys_buf, |
b5256303 | 414 | ZIO_PRIORITY_SYNC_READ, zio_flags, &aflags, &zb); |
13fe0198 | 415 | if (err != 0) { |
428870ff | 416 | kmem_free(os, sizeof (objset_t)); |
b128c09f BB |
417 | /* convert checksum errors into IO errors */ |
418 | if (err == ECKSUM) | |
2e528b49 | 419 | err = SET_ERROR(EIO); |
34dc7c2f BB |
420 | return (err); |
421 | } | |
9babb374 BB |
422 | |
423 | /* Increase the blocksize if we are permitted. */ | |
424 | if (spa_version(spa) >= SPA_VERSION_USERSPACE && | |
428870ff | 425 | arc_buf_size(os->os_phys_buf) < sizeof (objset_phys_t)) { |
2aa34383 DK |
426 | arc_buf_t *buf = arc_alloc_buf(spa, &os->os_phys_buf, |
427 | ARC_BUFC_METADATA, sizeof (objset_phys_t)); | |
9babb374 | 428 | bzero(buf->b_data, sizeof (objset_phys_t)); |
428870ff BB |
429 | bcopy(os->os_phys_buf->b_data, buf->b_data, |
430 | arc_buf_size(os->os_phys_buf)); | |
d3c2ae1c | 431 | arc_buf_destroy(os->os_phys_buf, &os->os_phys_buf); |
428870ff | 432 | os->os_phys_buf = buf; |
9babb374 BB |
433 | } |
434 | ||
428870ff BB |
435 | os->os_phys = os->os_phys_buf->b_data; |
436 | os->os_flags = os->os_phys->os_flags; | |
34dc7c2f | 437 | } else { |
9babb374 BB |
438 | int size = spa_version(spa) >= SPA_VERSION_USERSPACE ? |
439 | sizeof (objset_phys_t) : OBJSET_OLD_PHYS_SIZE; | |
2aa34383 DK |
440 | os->os_phys_buf = arc_alloc_buf(spa, &os->os_phys_buf, |
441 | ARC_BUFC_METADATA, size); | |
428870ff BB |
442 | os->os_phys = os->os_phys_buf->b_data; |
443 | bzero(os->os_phys, size); | |
34dc7c2f BB |
444 | } |
445 | ||
446 | /* | |
447 | * Note: the changed_cb will be called once before the register | |
448 | * func returns, thus changing the checksum/compression from the | |
b128c09f BB |
449 | * default (fletcher2/off). Snapshots don't need to know about |
450 | * checksum/compression/copies. | |
34dc7c2f | 451 | */ |
9b67f605 | 452 | if (ds != NULL) { |
47dfff3b MA |
453 | boolean_t needlock = B_FALSE; |
454 | ||
b5256303 TC |
455 | os->os_encrypted = (ds->ds_dir->dd_crypto_obj != 0); |
456 | ||
47dfff3b MA |
457 | /* |
458 | * Note: it's valid to open the objset if the dataset is | |
459 | * long-held, in which case the pool_config lock will not | |
460 | * be held. | |
461 | */ | |
462 | if (!dsl_pool_config_held(dmu_objset_pool(os))) { | |
463 | needlock = B_TRUE; | |
464 | dsl_pool_config_enter(dmu_objset_pool(os), FTAG); | |
465 | } | |
b5256303 | 466 | |
13fe0198 MA |
467 | err = dsl_prop_register(ds, |
468 | zfs_prop_to_name(ZFS_PROP_PRIMARYCACHE), | |
428870ff | 469 | primary_cache_changed_cb, os); |
13fe0198 MA |
470 | if (err == 0) { |
471 | err = dsl_prop_register(ds, | |
472 | zfs_prop_to_name(ZFS_PROP_SECONDARYCACHE), | |
428870ff | 473 | secondary_cache_changed_cb, os); |
13fe0198 | 474 | } |
0c66c32d | 475 | if (!ds->ds_is_snapshot) { |
13fe0198 MA |
476 | if (err == 0) { |
477 | err = dsl_prop_register(ds, | |
478 | zfs_prop_to_name(ZFS_PROP_CHECKSUM), | |
428870ff | 479 | checksum_changed_cb, os); |
13fe0198 MA |
480 | } |
481 | if (err == 0) { | |
482 | err = dsl_prop_register(ds, | |
483 | zfs_prop_to_name(ZFS_PROP_COMPRESSION), | |
428870ff | 484 | compression_changed_cb, os); |
13fe0198 MA |
485 | } |
486 | if (err == 0) { | |
487 | err = dsl_prop_register(ds, | |
488 | zfs_prop_to_name(ZFS_PROP_COPIES), | |
428870ff | 489 | copies_changed_cb, os); |
13fe0198 MA |
490 | } |
491 | if (err == 0) { | |
492 | err = dsl_prop_register(ds, | |
493 | zfs_prop_to_name(ZFS_PROP_DEDUP), | |
428870ff | 494 | dedup_changed_cb, os); |
13fe0198 MA |
495 | } |
496 | if (err == 0) { | |
497 | err = dsl_prop_register(ds, | |
498 | zfs_prop_to_name(ZFS_PROP_LOGBIAS), | |
428870ff | 499 | logbias_changed_cb, os); |
13fe0198 MA |
500 | } |
501 | if (err == 0) { | |
502 | err = dsl_prop_register(ds, | |
503 | zfs_prop_to_name(ZFS_PROP_SYNC), | |
428870ff | 504 | sync_changed_cb, os); |
13fe0198 | 505 | } |
faf0f58c MA |
506 | if (err == 0) { |
507 | err = dsl_prop_register(ds, | |
508 | zfs_prop_to_name( | |
509 | ZFS_PROP_REDUNDANT_METADATA), | |
510 | redundant_metadata_changed_cb, os); | |
511 | } | |
f1512ee6 MA |
512 | if (err == 0) { |
513 | err = dsl_prop_register(ds, | |
514 | zfs_prop_to_name(ZFS_PROP_RECORDSIZE), | |
515 | recordsize_changed_cb, os); | |
516 | } | |
50c957f7 NB |
517 | if (err == 0) { |
518 | err = dsl_prop_register(ds, | |
519 | zfs_prop_to_name(ZFS_PROP_DNODESIZE), | |
520 | dnodesize_changed_cb, os); | |
521 | } | |
b128c09f | 522 | } |
47dfff3b MA |
523 | if (needlock) |
524 | dsl_pool_config_exit(dmu_objset_pool(os), FTAG); | |
13fe0198 | 525 | if (err != 0) { |
d3c2ae1c | 526 | arc_buf_destroy(os->os_phys_buf, &os->os_phys_buf); |
428870ff | 527 | kmem_free(os, sizeof (objset_t)); |
34dc7c2f BB |
528 | return (err); |
529 | } | |
9b67f605 | 530 | } else { |
34dc7c2f | 531 | /* It's the meta-objset. */ |
428870ff | 532 | os->os_checksum = ZIO_CHECKSUM_FLETCHER_4; |
99197f03 | 533 | os->os_compress = ZIO_COMPRESS_ON; |
b5256303 | 534 | os->os_encrypted = B_FALSE; |
428870ff BB |
535 | os->os_copies = spa_max_replication(spa); |
536 | os->os_dedup_checksum = ZIO_CHECKSUM_OFF; | |
faf0f58c MA |
537 | os->os_dedup_verify = B_FALSE; |
538 | os->os_logbias = ZFS_LOGBIAS_LATENCY; | |
539 | os->os_sync = ZFS_SYNC_STANDARD; | |
428870ff BB |
540 | os->os_primary_cache = ZFS_CACHE_ALL; |
541 | os->os_secondary_cache = ZFS_CACHE_ALL; | |
50c957f7 | 542 | os->os_dnodesize = DNODE_MIN_SIZE; |
34dc7c2f BB |
543 | } |
544 | ||
0c66c32d | 545 | if (ds == NULL || !ds->ds_is_snapshot) |
572e2857 | 546 | os->os_zil_header = os->os_phys->os_zil_header; |
428870ff | 547 | os->os_zil = zil_alloc(os, &os->os_zil_header); |
34dc7c2f BB |
548 | |
549 | for (i = 0; i < TXG_SIZE; i++) { | |
64fc7762 MA |
550 | os->os_dirty_dnodes[i] = multilist_create(sizeof (dnode_t), |
551 | offsetof(dnode_t, dn_dirty_link[i]), | |
552 | dnode_multilist_index_func); | |
34dc7c2f | 553 | } |
428870ff | 554 | list_create(&os->os_dnodes, sizeof (dnode_t), |
34dc7c2f | 555 | offsetof(dnode_t, dn_link)); |
428870ff | 556 | list_create(&os->os_downgraded_dbufs, sizeof (dmu_buf_impl_t), |
34dc7c2f BB |
557 | offsetof(dmu_buf_impl_t, db_link)); |
558 | ||
0c66c32d JG |
559 | list_link_init(&os->os_evicting_node); |
560 | ||
428870ff | 561 | mutex_init(&os->os_lock, NULL, MUTEX_DEFAULT, NULL); |
64fc7762 | 562 | mutex_init(&os->os_userused_lock, NULL, MUTEX_DEFAULT, NULL); |
428870ff BB |
563 | mutex_init(&os->os_obj_lock, NULL, MUTEX_DEFAULT, NULL); |
564 | mutex_init(&os->os_user_ptr_lock, NULL, MUTEX_DEFAULT, NULL); | |
dbeb8796 MA |
565 | os->os_obj_next_percpu_len = boot_ncpus; |
566 | os->os_obj_next_percpu = kmem_zalloc(os->os_obj_next_percpu_len * | |
567 | sizeof (os->os_obj_next_percpu[0]), KM_SLEEP); | |
428870ff | 568 | |
0c66c32d JG |
569 | dnode_special_open(os, &os->os_phys->os_meta_dnode, |
570 | DMU_META_DNODE_OBJECT, &os->os_meta_dnode); | |
428870ff | 571 | if (arc_buf_size(os->os_phys_buf) >= sizeof (objset_phys_t)) { |
0c66c32d JG |
572 | dnode_special_open(os, &os->os_phys->os_userused_dnode, |
573 | DMU_USERUSED_OBJECT, &os->os_userused_dnode); | |
574 | dnode_special_open(os, &os->os_phys->os_groupused_dnode, | |
575 | DMU_GROUPUSED_OBJECT, &os->os_groupused_dnode); | |
9babb374 | 576 | } |
34dc7c2f | 577 | |
1de321e6 JX |
578 | mutex_init(&os->os_upgrade_lock, NULL, MUTEX_DEFAULT, NULL); |
579 | ||
428870ff | 580 | *osp = os; |
34dc7c2f BB |
581 | return (0); |
582 | } | |
583 | ||
428870ff BB |
584 | int |
585 | dmu_objset_from_ds(dsl_dataset_t *ds, objset_t **osp) | |
34dc7c2f | 586 | { |
428870ff | 587 | int err = 0; |
34dc7c2f | 588 | |
47dfff3b MA |
589 | /* |
590 | * We shouldn't be doing anything with dsl_dataset_t's unless the | |
591 | * pool_config lock is held, or the dataset is long-held. | |
592 | */ | |
593 | ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool) || | |
594 | dsl_dataset_long_held(ds)); | |
595 | ||
34dc7c2f | 596 | mutex_enter(&ds->ds_opening_lock); |
9b67f605 MA |
597 | if (ds->ds_objset == NULL) { |
598 | objset_t *os; | |
cc9bb3e5 | 599 | rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG); |
34dc7c2f | 600 | err = dmu_objset_open_impl(dsl_dataset_get_spa(ds), |
9b67f605 | 601 | ds, dsl_dataset_get_blkptr(ds), &os); |
cc9bb3e5 | 602 | rrw_exit(&ds->ds_bp_rwlock, FTAG); |
9b67f605 MA |
603 | |
604 | if (err == 0) { | |
605 | mutex_enter(&ds->ds_lock); | |
606 | ASSERT(ds->ds_objset == NULL); | |
607 | ds->ds_objset = os; | |
608 | mutex_exit(&ds->ds_lock); | |
609 | } | |
34dc7c2f | 610 | } |
9b67f605 | 611 | *osp = ds->ds_objset; |
34dc7c2f | 612 | mutex_exit(&ds->ds_opening_lock); |
428870ff | 613 | return (err); |
34dc7c2f BB |
614 | } |
615 | ||
13fe0198 MA |
616 | /* |
617 | * Holds the pool while the objset is held. Therefore only one objset | |
618 | * can be held at a time. | |
619 | */ | |
34dc7c2f | 620 | int |
b5256303 TC |
621 | dmu_objset_hold_flags(const char *name, boolean_t decrypt, void *tag, |
622 | objset_t **osp) | |
34dc7c2f | 623 | { |
13fe0198 | 624 | dsl_pool_t *dp; |
428870ff | 625 | dsl_dataset_t *ds; |
34dc7c2f | 626 | int err; |
b5256303 | 627 | ds_hold_flags_t flags = (decrypt) ? DS_HOLD_FLAG_DECRYPT : 0; |
34dc7c2f | 628 | |
13fe0198 MA |
629 | err = dsl_pool_hold(name, tag, &dp); |
630 | if (err != 0) | |
631 | return (err); | |
b5256303 | 632 | err = dsl_dataset_hold_flags(dp, name, flags, tag, &ds); |
13fe0198 MA |
633 | if (err != 0) { |
634 | dsl_pool_rele(dp, tag); | |
428870ff | 635 | return (err); |
13fe0198 | 636 | } |
428870ff BB |
637 | |
638 | err = dmu_objset_from_ds(ds, osp); | |
13fe0198 | 639 | if (err != 0) { |
428870ff | 640 | dsl_dataset_rele(ds, tag); |
13fe0198 MA |
641 | dsl_pool_rele(dp, tag); |
642 | } | |
428870ff | 643 | |
34dc7c2f BB |
644 | return (err); |
645 | } | |
646 | ||
b5256303 TC |
647 | int |
648 | dmu_objset_hold(const char *name, void *tag, objset_t **osp) | |
649 | { | |
650 | return (dmu_objset_hold_flags(name, B_FALSE, tag, osp)); | |
651 | } | |
652 | ||
9c43027b AJ |
653 | static int |
654 | dmu_objset_own_impl(dsl_dataset_t *ds, dmu_objset_type_t type, | |
b5256303 | 655 | boolean_t readonly, boolean_t decrypt, void *tag, objset_t **osp) |
9c43027b AJ |
656 | { |
657 | int err; | |
658 | ||
659 | err = dmu_objset_from_ds(ds, osp); | |
660 | if (err != 0) { | |
b5256303 | 661 | return (err); |
9c43027b | 662 | } else if (type != DMU_OST_ANY && type != (*osp)->os_phys->os_type) { |
9c43027b AJ |
663 | return (SET_ERROR(EINVAL)); |
664 | } else if (!readonly && dsl_dataset_is_snapshot(ds)) { | |
9c43027b | 665 | return (SET_ERROR(EROFS)); |
ae76f45c TC |
666 | } else if (!readonly && decrypt && |
667 | dsl_dir_incompatible_encryption_version(ds->ds_dir)) { | |
668 | return (SET_ERROR(EROFS)); | |
9c43027b | 669 | } |
b5256303 TC |
670 | |
671 | /* if we are decrypting, we can now check MACs in os->os_phys_buf */ | |
672 | if (decrypt && arc_is_unauthenticated((*osp)->os_phys_buf)) { | |
673 | err = arc_untransform((*osp)->os_phys_buf, (*osp)->os_spa, | |
674 | ds->ds_object, B_FALSE); | |
675 | if (err != 0) | |
676 | return (err); | |
677 | ||
678 | ASSERT0(arc_is_unauthenticated((*osp)->os_phys_buf)); | |
679 | } | |
680 | ||
681 | return (0); | |
9c43027b AJ |
682 | } |
683 | ||
13fe0198 MA |
684 | /* |
685 | * dsl_pool must not be held when this is called. | |
686 | * Upon successful return, there will be a longhold on the dataset, | |
687 | * and the dsl_pool will not be held. | |
688 | */ | |
34dc7c2f | 689 | int |
428870ff | 690 | dmu_objset_own(const char *name, dmu_objset_type_t type, |
b5256303 | 691 | boolean_t readonly, boolean_t decrypt, void *tag, objset_t **osp) |
34dc7c2f | 692 | { |
13fe0198 | 693 | dsl_pool_t *dp; |
34dc7c2f BB |
694 | dsl_dataset_t *ds; |
695 | int err; | |
b5256303 | 696 | ds_hold_flags_t flags = (decrypt) ? DS_HOLD_FLAG_DECRYPT : 0; |
34dc7c2f | 697 | |
13fe0198 MA |
698 | err = dsl_pool_hold(name, FTAG, &dp); |
699 | if (err != 0) | |
700 | return (err); | |
b5256303 | 701 | err = dsl_dataset_own(dp, name, flags, tag, &ds); |
13fe0198 MA |
702 | if (err != 0) { |
703 | dsl_pool_rele(dp, FTAG); | |
34dc7c2f | 704 | return (err); |
13fe0198 | 705 | } |
b5256303 TC |
706 | err = dmu_objset_own_impl(ds, type, readonly, decrypt, tag, osp); |
707 | if (err != 0) { | |
708 | dsl_dataset_disown(ds, flags, tag); | |
709 | dsl_pool_rele(dp, FTAG); | |
710 | return (err); | |
711 | } | |
712 | ||
4807c0ba TC |
713 | /* user accounting requires the dataset to be decrypted */ |
714 | if (dmu_objset_userobjspace_upgradable(*osp) && | |
715 | (ds->ds_dir->dd_crypto_obj == 0 || decrypt)) | |
1de321e6 JX |
716 | dmu_objset_userobjspace_upgrade(*osp); |
717 | ||
c0daec32 | 718 | dsl_pool_rele(dp, FTAG); |
b5256303 | 719 | return (0); |
34dc7c2f BB |
720 | } |
721 | ||
9c43027b AJ |
722 | int |
723 | dmu_objset_own_obj(dsl_pool_t *dp, uint64_t obj, dmu_objset_type_t type, | |
b5256303 | 724 | boolean_t readonly, boolean_t decrypt, void *tag, objset_t **osp) |
9c43027b AJ |
725 | { |
726 | dsl_dataset_t *ds; | |
727 | int err; | |
b5256303 | 728 | ds_hold_flags_t flags = (decrypt) ? DS_HOLD_FLAG_DECRYPT : 0; |
9c43027b | 729 | |
b5256303 | 730 | err = dsl_dataset_own_obj(dp, obj, flags, tag, &ds); |
9c43027b AJ |
731 | if (err != 0) |
732 | return (err); | |
733 | ||
b5256303 TC |
734 | err = dmu_objset_own_impl(ds, type, readonly, decrypt, tag, osp); |
735 | if (err != 0) { | |
736 | dsl_dataset_disown(ds, flags, tag); | |
737 | return (err); | |
738 | } | |
739 | ||
740 | return (0); | |
9c43027b AJ |
741 | } |
742 | ||
34dc7c2f | 743 | void |
b5256303 | 744 | dmu_objset_rele_flags(objset_t *os, boolean_t decrypt, void *tag) |
34dc7c2f | 745 | { |
b5256303 TC |
746 | ds_hold_flags_t flags = (decrypt) ? DS_HOLD_FLAG_DECRYPT : 0; |
747 | ||
13fe0198 | 748 | dsl_pool_t *dp = dmu_objset_pool(os); |
b5256303 | 749 | dsl_dataset_rele_flags(os->os_dsl_dataset, flags, tag); |
13fe0198 | 750 | dsl_pool_rele(dp, tag); |
428870ff | 751 | } |
b128c09f | 752 | |
b5256303 TC |
753 | void |
754 | dmu_objset_rele(objset_t *os, void *tag) | |
755 | { | |
756 | dmu_objset_rele_flags(os, B_FALSE, tag); | |
757 | } | |
758 | ||
831baf06 KW |
759 | /* |
760 | * When we are called, os MUST refer to an objset associated with a dataset | |
761 | * that is owned by 'tag'; that is, is held and long held by 'tag' and ds_owner | |
762 | * == tag. We will then release and reacquire ownership of the dataset while | |
763 | * holding the pool config_rwlock to avoid intervening namespace or ownership | |
764 | * changes may occur. | |
765 | * | |
766 | * This exists solely to accommodate zfs_ioc_userspace_upgrade()'s desire to | |
767 | * release the hold on its dataset and acquire a new one on the dataset of the | |
768 | * same name so that it can be partially torn down and reconstructed. | |
769 | */ | |
770 | void | |
b5256303 | 771 | dmu_objset_refresh_ownership(objset_t *os, boolean_t decrypt, void *tag) |
831baf06 KW |
772 | { |
773 | dsl_pool_t *dp; | |
774 | dsl_dataset_t *ds, *newds; | |
eca7b760 | 775 | char name[ZFS_MAX_DATASET_NAME_LEN]; |
831baf06 KW |
776 | |
777 | ds = os->os_dsl_dataset; | |
778 | VERIFY3P(ds, !=, NULL); | |
779 | VERIFY3P(ds->ds_owner, ==, tag); | |
780 | VERIFY(dsl_dataset_long_held(ds)); | |
781 | ||
782 | dsl_dataset_name(ds, name); | |
783 | dp = dmu_objset_pool(os); | |
784 | dsl_pool_config_enter(dp, FTAG); | |
b5256303 TC |
785 | dmu_objset_disown(os, decrypt, tag); |
786 | VERIFY0(dsl_dataset_own(dp, name, | |
787 | (decrypt) ? DS_HOLD_FLAG_DECRYPT : 0, tag, &newds)); | |
831baf06 KW |
788 | VERIFY3P(newds, ==, os->os_dsl_dataset); |
789 | dsl_pool_config_exit(dp, FTAG); | |
790 | } | |
791 | ||
428870ff | 792 | void |
b5256303 | 793 | dmu_objset_disown(objset_t *os, boolean_t decrypt, void *tag) |
428870ff | 794 | { |
1de321e6 JX |
795 | /* |
796 | * Stop upgrading thread | |
797 | */ | |
798 | dmu_objset_upgrade_stop(os); | |
b5256303 TC |
799 | dsl_dataset_disown(os->os_dsl_dataset, |
800 | (decrypt) ? DS_HOLD_FLAG_DECRYPT : 0, tag); | |
34dc7c2f BB |
801 | } |
802 | ||
13fe0198 | 803 | void |
34dc7c2f BB |
804 | dmu_objset_evict_dbufs(objset_t *os) |
805 | { | |
0c66c32d | 806 | dnode_t *dn_marker; |
34dc7c2f BB |
807 | dnode_t *dn; |
808 | ||
0c66c32d | 809 | dn_marker = kmem_alloc(sizeof (dnode_t), KM_SLEEP); |
34dc7c2f | 810 | |
0c66c32d JG |
811 | mutex_enter(&os->os_lock); |
812 | dn = list_head(&os->os_dnodes); | |
813 | while (dn != NULL) { | |
814 | /* | |
815 | * Skip dnodes without holds. We have to do this dance | |
816 | * because dnode_add_ref() only works if there is already a | |
817 | * hold. If the dnode has no holds, then it has no dbufs. | |
818 | */ | |
819 | if (dnode_add_ref(dn, FTAG)) { | |
820 | list_insert_after(&os->os_dnodes, dn, dn_marker); | |
821 | mutex_exit(&os->os_lock); | |
34dc7c2f | 822 | |
0c66c32d JG |
823 | dnode_evict_dbufs(dn); |
824 | dnode_rele(dn, FTAG); | |
34dc7c2f | 825 | |
0c66c32d JG |
826 | mutex_enter(&os->os_lock); |
827 | dn = list_next(&os->os_dnodes, dn_marker); | |
828 | list_remove(&os->os_dnodes, dn_marker); | |
829 | } else { | |
830 | dn = list_next(&os->os_dnodes, dn); | |
831 | } | |
832 | } | |
833 | mutex_exit(&os->os_lock); | |
34dc7c2f | 834 | |
0c66c32d | 835 | kmem_free(dn_marker, sizeof (dnode_t)); |
34dc7c2f | 836 | |
0c66c32d JG |
837 | if (DMU_USERUSED_DNODE(os) != NULL) { |
838 | dnode_evict_dbufs(DMU_GROUPUSED_DNODE(os)); | |
839 | dnode_evict_dbufs(DMU_USERUSED_DNODE(os)); | |
34dc7c2f | 840 | } |
0c66c32d | 841 | dnode_evict_dbufs(DMU_META_DNODE(os)); |
34dc7c2f BB |
842 | } |
843 | ||
0c66c32d JG |
844 | /* |
845 | * Objset eviction processing is split into into two pieces. | |
846 | * The first marks the objset as evicting, evicts any dbufs that | |
847 | * have a refcount of zero, and then queues up the objset for the | |
848 | * second phase of eviction. Once os->os_dnodes has been cleared by | |
849 | * dnode_buf_pageout()->dnode_destroy(), the second phase is executed. | |
850 | * The second phase closes the special dnodes, dequeues the objset from | |
851 | * the list of those undergoing eviction, and finally frees the objset. | |
852 | * | |
853 | * NOTE: Due to asynchronous eviction processing (invocation of | |
854 | * dnode_buf_pageout()), it is possible for the meta dnode for the | |
855 | * objset to have no holds even though os->os_dnodes is not empty. | |
856 | */ | |
34dc7c2f | 857 | void |
428870ff | 858 | dmu_objset_evict(objset_t *os) |
34dc7c2f | 859 | { |
6f1ffb06 MA |
860 | dsl_dataset_t *ds = os->os_dsl_dataset; |
861 | ||
1c27024e | 862 | for (int t = 0; t < TXG_SIZE; t++) |
428870ff | 863 | ASSERT(!dmu_objset_is_dirty(os, t)); |
34dc7c2f | 864 | |
0eb21616 JG |
865 | if (ds) |
866 | dsl_prop_unregister_all(ds, os); | |
34dc7c2f | 867 | |
428870ff BB |
868 | if (os->os_sa) |
869 | sa_tear_down(os); | |
870 | ||
13fe0198 | 871 | dmu_objset_evict_dbufs(os); |
34dc7c2f | 872 | |
0c66c32d JG |
873 | mutex_enter(&os->os_lock); |
874 | spa_evicting_os_register(os->os_spa, os); | |
875 | if (list_is_empty(&os->os_dnodes)) { | |
876 | mutex_exit(&os->os_lock); | |
877 | dmu_objset_evict_done(os); | |
878 | } else { | |
879 | mutex_exit(&os->os_lock); | |
880 | } | |
b5256303 TC |
881 | |
882 | ||
0c66c32d JG |
883 | } |
884 | ||
885 | void | |
886 | dmu_objset_evict_done(objset_t *os) | |
887 | { | |
888 | ASSERT3P(list_head(&os->os_dnodes), ==, NULL); | |
889 | ||
572e2857 BB |
890 | dnode_special_close(&os->os_meta_dnode); |
891 | if (DMU_USERUSED_DNODE(os)) { | |
892 | dnode_special_close(&os->os_userused_dnode); | |
893 | dnode_special_close(&os->os_groupused_dnode); | |
9babb374 | 894 | } |
428870ff BB |
895 | zil_free(os->os_zil); |
896 | ||
d3c2ae1c | 897 | arc_buf_destroy(os->os_phys_buf, &os->os_phys_buf); |
572e2857 BB |
898 | |
899 | /* | |
900 | * This is a barrier to prevent the objset from going away in | |
901 | * dnode_move() until we can safely ensure that the objset is still in | |
902 | * use. We consider the objset valid before the barrier and invalid | |
903 | * after the barrier. | |
904 | */ | |
905 | rw_enter(&os_lock, RW_READER); | |
906 | rw_exit(&os_lock); | |
907 | ||
dbeb8796 MA |
908 | kmem_free(os->os_obj_next_percpu, |
909 | os->os_obj_next_percpu_len * sizeof (os->os_obj_next_percpu[0])); | |
910 | ||
428870ff | 911 | mutex_destroy(&os->os_lock); |
64fc7762 | 912 | mutex_destroy(&os->os_userused_lock); |
428870ff BB |
913 | mutex_destroy(&os->os_obj_lock); |
914 | mutex_destroy(&os->os_user_ptr_lock); | |
c17486b2 | 915 | mutex_destroy(&os->os_upgrade_lock); |
64fc7762 MA |
916 | for (int i = 0; i < TXG_SIZE; i++) { |
917 | multilist_destroy(os->os_dirty_dnodes[i]); | |
918 | } | |
0c66c32d | 919 | spa_evicting_os_deregister(os->os_spa, os); |
428870ff BB |
920 | kmem_free(os, sizeof (objset_t)); |
921 | } | |
9babb374 | 922 | |
428870ff BB |
923 | timestruc_t |
924 | dmu_objset_snap_cmtime(objset_t *os) | |
925 | { | |
926 | return (dsl_dir_snap_cmtime(os->os_dsl_dataset->ds_dir)); | |
34dc7c2f BB |
927 | } |
928 | ||
428870ff | 929 | objset_t * |
b5256303 TC |
930 | dmu_objset_create_impl_dnstats(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, |
931 | dmu_objset_type_t type, int levels, int blksz, int ibs, dmu_tx_t *tx) | |
34dc7c2f | 932 | { |
428870ff | 933 | objset_t *os; |
34dc7c2f BB |
934 | dnode_t *mdn; |
935 | ||
936 | ASSERT(dmu_tx_is_syncing(tx)); | |
13fe0198 | 937 | |
b5256303 TC |
938 | if (blksz == 0) |
939 | blksz = DNODE_BLOCK_SIZE; | |
4807c0ba | 940 | if (ibs == 0) |
b5256303 TC |
941 | ibs = DN_MAX_INDBLKSHIFT; |
942 | ||
572e2857 | 943 | if (ds != NULL) |
13fe0198 | 944 | VERIFY0(dmu_objset_from_ds(ds, &os)); |
572e2857 | 945 | else |
13fe0198 | 946 | VERIFY0(dmu_objset_open_impl(spa, NULL, bp, &os)); |
572e2857 BB |
947 | |
948 | mdn = DMU_META_DNODE(os); | |
34dc7c2f | 949 | |
b5256303 TC |
950 | dnode_allocate(mdn, DMU_OT_DNODE, blksz, ibs, DMU_OT_NONE, 0, |
951 | DNODE_MIN_SLOTS, tx); | |
34dc7c2f BB |
952 | |
953 | /* | |
954 | * We don't want to have to increase the meta-dnode's nlevels | |
955 | * later, because then we could do it in quescing context while | |
956 | * we are also accessing it in open context. | |
957 | * | |
958 | * This precaution is not necessary for the MOS (ds == NULL), | |
959 | * because the MOS is only updated in syncing context. | |
960 | * This is most fortunate: the MOS is the only objset that | |
961 | * needs to be synced multiple times as spa_sync() iterates | |
962 | * to convergence, so minimizing its dn_nlevels matters. | |
963 | */ | |
964 | if (ds != NULL) { | |
b5256303 TC |
965 | if (levels == 0) { |
966 | levels = 1; | |
967 | ||
968 | /* | |
969 | * Determine the number of levels necessary for the | |
970 | * meta-dnode to contain DN_MAX_OBJECT dnodes. Note | |
971 | * that in order to ensure that we do not overflow | |
972 | * 64 bits, there has to be a nlevels that gives us a | |
973 | * number of blocks > DN_MAX_OBJECT but < 2^64. | |
974 | * Therefore, (mdn->dn_indblkshift - SPA_BLKPTRSHIFT) | |
975 | * (10) must be less than (64 - log2(DN_MAX_OBJECT)) | |
976 | * (16). | |
977 | */ | |
978 | while ((uint64_t)mdn->dn_nblkptr << | |
979 | (mdn->dn_datablkshift - DNODE_SHIFT + (levels - 1) * | |
980 | (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) < | |
981 | DN_MAX_OBJECT) | |
982 | levels++; | |
983 | } | |
34dc7c2f BB |
984 | |
985 | mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] = | |
986 | mdn->dn_nlevels = levels; | |
987 | } | |
988 | ||
989 | ASSERT(type != DMU_OST_NONE); | |
990 | ASSERT(type != DMU_OST_ANY); | |
991 | ASSERT(type < DMU_OST_NUMTYPES); | |
428870ff | 992 | os->os_phys->os_type = type; |
b5256303 TC |
993 | |
994 | /* | |
995 | * Enable user accounting if it is enabled and this is not an | |
996 | * encrypted receive. | |
997 | */ | |
998 | if (dmu_objset_userused_enabled(os) && | |
999 | (!os->os_encrypted || !dmu_objset_is_receiving(os))) { | |
428870ff | 1000 | os->os_phys->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE; |
1de321e6 JX |
1001 | if (dmu_objset_userobjused_enabled(os)) { |
1002 | ds->ds_feature_activation_needed[ | |
1003 | SPA_FEATURE_USEROBJ_ACCOUNTING] = B_TRUE; | |
1004 | os->os_phys->os_flags |= | |
1005 | OBJSET_FLAG_USEROBJACCOUNTING_COMPLETE; | |
1006 | } | |
428870ff | 1007 | os->os_flags = os->os_phys->os_flags; |
9babb374 | 1008 | } |
34dc7c2f BB |
1009 | |
1010 | dsl_dataset_dirty(ds, tx); | |
1011 | ||
428870ff | 1012 | return (os); |
34dc7c2f BB |
1013 | } |
1014 | ||
b5256303 TC |
1015 | /* called from dsl for meta-objset */ |
1016 | objset_t * | |
1017 | dmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, | |
1018 | dmu_objset_type_t type, dmu_tx_t *tx) | |
1019 | { | |
1020 | return (dmu_objset_create_impl_dnstats(spa, ds, bp, type, 0, 0, 0, tx)); | |
1021 | } | |
1022 | ||
13fe0198 MA |
1023 | typedef struct dmu_objset_create_arg { |
1024 | const char *doca_name; | |
1025 | cred_t *doca_cred; | |
1026 | void (*doca_userfunc)(objset_t *os, void *arg, | |
1027 | cred_t *cr, dmu_tx_t *tx); | |
1028 | void *doca_userarg; | |
1029 | dmu_objset_type_t doca_type; | |
1030 | uint64_t doca_flags; | |
b5256303 | 1031 | dsl_crypto_params_t *doca_dcp; |
13fe0198 | 1032 | } dmu_objset_create_arg_t; |
34dc7c2f BB |
1033 | |
1034 | /*ARGSUSED*/ | |
1035 | static int | |
13fe0198 | 1036 | dmu_objset_create_check(void *arg, dmu_tx_t *tx) |
34dc7c2f | 1037 | { |
13fe0198 MA |
1038 | dmu_objset_create_arg_t *doca = arg; |
1039 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1040 | dsl_dir_t *pdd; | |
1041 | const char *tail; | |
1042 | int error; | |
34dc7c2f | 1043 | |
13fe0198 | 1044 | if (strchr(doca->doca_name, '@') != NULL) |
2e528b49 | 1045 | return (SET_ERROR(EINVAL)); |
34dc7c2f | 1046 | |
eca7b760 IK |
1047 | if (strlen(doca->doca_name) >= ZFS_MAX_DATASET_NAME_LEN) |
1048 | return (SET_ERROR(ENAMETOOLONG)); | |
1049 | ||
13fe0198 MA |
1050 | error = dsl_dir_hold(dp, doca->doca_name, FTAG, &pdd, &tail); |
1051 | if (error != 0) | |
1052 | return (error); | |
1053 | if (tail == NULL) { | |
1054 | dsl_dir_rele(pdd, FTAG); | |
2e528b49 | 1055 | return (SET_ERROR(EEXIST)); |
34dc7c2f | 1056 | } |
b5256303 TC |
1057 | |
1058 | error = dmu_objset_create_crypt_check(pdd, doca->doca_dcp); | |
1059 | if (error != 0) { | |
1060 | dsl_dir_rele(pdd, FTAG); | |
1061 | return (error); | |
1062 | } | |
1063 | ||
788eb90c JJ |
1064 | error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL, |
1065 | doca->doca_cred); | |
b5256303 | 1066 | |
13fe0198 | 1067 | dsl_dir_rele(pdd, FTAG); |
34dc7c2f | 1068 | |
788eb90c | 1069 | return (error); |
34dc7c2f BB |
1070 | } |
1071 | ||
1072 | static void | |
13fe0198 | 1073 | dmu_objset_create_sync(void *arg, dmu_tx_t *tx) |
34dc7c2f | 1074 | { |
13fe0198 MA |
1075 | dmu_objset_create_arg_t *doca = arg; |
1076 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1077 | dsl_dir_t *pdd; | |
1078 | const char *tail; | |
6f1ffb06 | 1079 | dsl_dataset_t *ds; |
13fe0198 | 1080 | uint64_t obj; |
6f1ffb06 | 1081 | blkptr_t *bp; |
13fe0198 | 1082 | objset_t *os; |
b5256303 | 1083 | zio_t *rzio; |
34dc7c2f | 1084 | |
13fe0198 | 1085 | VERIFY0(dsl_dir_hold(dp, doca->doca_name, FTAG, &pdd, &tail)); |
34dc7c2f | 1086 | |
13fe0198 | 1087 | obj = dsl_dataset_create_sync(pdd, tail, NULL, doca->doca_flags, |
b5256303 | 1088 | doca->doca_cred, doca->doca_dcp, tx); |
34dc7c2f | 1089 | |
b5256303 TC |
1090 | VERIFY0(dsl_dataset_hold_obj_flags(pdd->dd_pool, obj, |
1091 | DS_HOLD_FLAG_DECRYPT, FTAG, &ds)); | |
cc9bb3e5 | 1092 | rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG); |
6f1ffb06 | 1093 | bp = dsl_dataset_get_blkptr(ds); |
13fe0198 MA |
1094 | os = dmu_objset_create_impl(pdd->dd_pool->dp_spa, |
1095 | ds, bp, doca->doca_type, tx); | |
cc9bb3e5 | 1096 | rrw_exit(&ds->ds_bp_rwlock, FTAG); |
34dc7c2f | 1097 | |
13fe0198 MA |
1098 | if (doca->doca_userfunc != NULL) { |
1099 | doca->doca_userfunc(os, doca->doca_userarg, | |
1100 | doca->doca_cred, tx); | |
34dc7c2f BB |
1101 | } |
1102 | ||
b5256303 | 1103 | /* |
4807c0ba | 1104 | * The doca_userfunc() may write out some data that needs to be |
b5256303 TC |
1105 | * encrypted if the dataset is encrypted (specifically the root |
1106 | * directory). This data must be written out before the encryption | |
1107 | * key mapping is removed by dsl_dataset_rele_flags(). Force the | |
1108 | * I/O to occur immediately by invoking the relevant sections of | |
1109 | * dsl_pool_sync(). | |
1110 | */ | |
1111 | if (os->os_encrypted) { | |
1112 | dsl_dataset_t *tmpds = NULL; | |
1113 | boolean_t need_sync_done = B_FALSE; | |
1114 | ||
4807c0ba TC |
1115 | mutex_enter(&ds->ds_lock); |
1116 | ds->ds_owner = FTAG; | |
1117 | mutex_exit(&ds->ds_lock); | |
1118 | ||
b5256303 | 1119 | rzio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); |
4807c0ba TC |
1120 | tmpds = txg_list_remove_this(&dp->dp_dirty_datasets, ds, |
1121 | tx->tx_txg); | |
b5256303 | 1122 | if (tmpds != NULL) { |
b5256303 TC |
1123 | dsl_dataset_sync(ds, rzio, tx); |
1124 | need_sync_done = B_TRUE; | |
1125 | } | |
1126 | VERIFY0(zio_wait(rzio)); | |
1127 | ||
1128 | dmu_objset_do_userquota_updates(os, tx); | |
1129 | taskq_wait(dp->dp_sync_taskq); | |
1130 | ||
1131 | rzio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); | |
4807c0ba TC |
1132 | tmpds = txg_list_remove_this(&dp->dp_dirty_datasets, ds, |
1133 | tx->tx_txg); | |
b5256303 | 1134 | if (tmpds != NULL) { |
b5256303 TC |
1135 | dmu_buf_rele(ds->ds_dbuf, ds); |
1136 | dsl_dataset_sync(ds, rzio, tx); | |
1137 | } | |
1138 | VERIFY0(zio_wait(rzio)); | |
1139 | ||
1140 | if (need_sync_done) | |
1141 | dsl_dataset_sync_done(ds, tx); | |
4807c0ba TC |
1142 | |
1143 | mutex_enter(&ds->ds_lock); | |
1144 | ds->ds_owner = NULL; | |
1145 | mutex_exit(&ds->ds_lock); | |
b5256303 TC |
1146 | } |
1147 | ||
13fe0198 | 1148 | spa_history_log_internal_ds(ds, "create", tx, ""); |
a0bd735a BP |
1149 | zvol_create_minors(dp->dp_spa, doca->doca_name, B_TRUE); |
1150 | ||
b5256303 | 1151 | dsl_dataset_rele_flags(ds, DS_HOLD_FLAG_DECRYPT, FTAG); |
13fe0198 | 1152 | dsl_dir_rele(pdd, FTAG); |
34dc7c2f BB |
1153 | } |
1154 | ||
1155 | int | |
428870ff | 1156 | dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags, |
b5256303 | 1157 | dsl_crypto_params_t *dcp, dmu_objset_create_sync_func_t func, void *arg) |
34dc7c2f | 1158 | { |
13fe0198 | 1159 | dmu_objset_create_arg_t doca; |
b5256303 | 1160 | dsl_crypto_params_t tmp_dcp = { 0 }; |
34dc7c2f | 1161 | |
13fe0198 MA |
1162 | doca.doca_name = name; |
1163 | doca.doca_cred = CRED(); | |
1164 | doca.doca_flags = flags; | |
1165 | doca.doca_userfunc = func; | |
1166 | doca.doca_userarg = arg; | |
1167 | doca.doca_type = type; | |
34dc7c2f | 1168 | |
b5256303 TC |
1169 | /* |
1170 | * Some callers (mostly for testing) do not provide a dcp on their | |
1171 | * own but various code inside the sync task will require it to be | |
1172 | * allocated. Rather than adding NULL checks throughout this code | |
1173 | * or adding dummy dcp's to all of the callers we simply create a | |
1174 | * dummy one here and use that. This zero dcp will have the same | |
1175 | * effect as asking for inheritence of all encryption params. | |
1176 | */ | |
1177 | doca.doca_dcp = (dcp != NULL) ? dcp : &tmp_dcp; | |
1178 | ||
13fe0198 | 1179 | return (dsl_sync_task(name, |
3d45fdd6 | 1180 | dmu_objset_create_check, dmu_objset_create_sync, &doca, |
b5256303 | 1181 | 6, ZFS_SPACE_CHECK_NORMAL)); |
34dc7c2f BB |
1182 | } |
1183 | ||
13fe0198 MA |
1184 | typedef struct dmu_objset_clone_arg { |
1185 | const char *doca_clone; | |
1186 | const char *doca_origin; | |
1187 | cred_t *doca_cred; | |
1188 | } dmu_objset_clone_arg_t; | |
1189 | ||
1190 | /*ARGSUSED*/ | |
1191 | static int | |
1192 | dmu_objset_clone_check(void *arg, dmu_tx_t *tx) | |
34dc7c2f | 1193 | { |
13fe0198 | 1194 | dmu_objset_clone_arg_t *doca = arg; |
428870ff BB |
1195 | dsl_dir_t *pdd; |
1196 | const char *tail; | |
13fe0198 MA |
1197 | int error; |
1198 | dsl_dataset_t *origin; | |
1199 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
34dc7c2f | 1200 | |
13fe0198 | 1201 | if (strchr(doca->doca_clone, '@') != NULL) |
2e528b49 | 1202 | return (SET_ERROR(EINVAL)); |
13fe0198 | 1203 | |
eca7b760 IK |
1204 | if (strlen(doca->doca_clone) >= ZFS_MAX_DATASET_NAME_LEN) |
1205 | return (SET_ERROR(ENAMETOOLONG)); | |
1206 | ||
13fe0198 MA |
1207 | error = dsl_dir_hold(dp, doca->doca_clone, FTAG, &pdd, &tail); |
1208 | if (error != 0) | |
1209 | return (error); | |
428870ff | 1210 | if (tail == NULL) { |
13fe0198 | 1211 | dsl_dir_rele(pdd, FTAG); |
2e528b49 | 1212 | return (SET_ERROR(EEXIST)); |
34dc7c2f | 1213 | } |
1cddb8c9 | 1214 | |
788eb90c JJ |
1215 | error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL, |
1216 | doca->doca_cred); | |
1217 | if (error != 0) { | |
1218 | dsl_dir_rele(pdd, FTAG); | |
1219 | return (SET_ERROR(EDQUOT)); | |
1220 | } | |
428870ff | 1221 | |
13fe0198 | 1222 | error = dsl_dataset_hold(dp, doca->doca_origin, FTAG, &origin); |
b5256303 TC |
1223 | if (error != 0) { |
1224 | dsl_dir_rele(pdd, FTAG); | |
572e2857 | 1225 | return (error); |
b5256303 | 1226 | } |
572e2857 | 1227 | |
13fe0198 | 1228 | /* You can only clone snapshots, not the head datasets. */ |
0c66c32d | 1229 | if (!origin->ds_is_snapshot) { |
13fe0198 | 1230 | dsl_dataset_rele(origin, FTAG); |
b5256303 | 1231 | dsl_dir_rele(pdd, FTAG); |
2e528b49 | 1232 | return (SET_ERROR(EINVAL)); |
428870ff | 1233 | } |
b5256303 TC |
1234 | |
1235 | error = dmu_objset_clone_crypt_check(pdd, origin->ds_dir); | |
1236 | if (error != 0) { | |
1237 | dsl_dataset_rele(origin, FTAG); | |
1238 | dsl_dir_rele(pdd, FTAG); | |
1239 | return (error); | |
1240 | } | |
1241 | ||
13fe0198 | 1242 | dsl_dataset_rele(origin, FTAG); |
b5256303 | 1243 | dsl_dir_rele(pdd, FTAG); |
572e2857 | 1244 | |
13fe0198 | 1245 | return (0); |
9babb374 | 1246 | } |
34dc7c2f | 1247 | |
13fe0198 MA |
1248 | static void |
1249 | dmu_objset_clone_sync(void *arg, dmu_tx_t *tx) | |
34dc7c2f | 1250 | { |
13fe0198 MA |
1251 | dmu_objset_clone_arg_t *doca = arg; |
1252 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1253 | dsl_dir_t *pdd; | |
1254 | const char *tail; | |
1255 | dsl_dataset_t *origin, *ds; | |
1256 | uint64_t obj; | |
eca7b760 | 1257 | char namebuf[ZFS_MAX_DATASET_NAME_LEN]; |
6f1ffb06 | 1258 | |
13fe0198 MA |
1259 | VERIFY0(dsl_dir_hold(dp, doca->doca_clone, FTAG, &pdd, &tail)); |
1260 | VERIFY0(dsl_dataset_hold(dp, doca->doca_origin, FTAG, &origin)); | |
6f1ffb06 | 1261 | |
13fe0198 | 1262 | obj = dsl_dataset_create_sync(pdd, tail, origin, 0, |
b5256303 | 1263 | doca->doca_cred, NULL, tx); |
34dc7c2f | 1264 | |
13fe0198 MA |
1265 | VERIFY0(dsl_dataset_hold_obj(pdd->dd_pool, obj, FTAG, &ds)); |
1266 | dsl_dataset_name(origin, namebuf); | |
1267 | spa_history_log_internal_ds(ds, "clone", tx, | |
1268 | "origin=%s (%llu)", namebuf, origin->ds_object); | |
a0bd735a | 1269 | zvol_create_minors(dp->dp_spa, doca->doca_clone, B_TRUE); |
13fe0198 MA |
1270 | dsl_dataset_rele(ds, FTAG); |
1271 | dsl_dataset_rele(origin, FTAG); | |
1272 | dsl_dir_rele(pdd, FTAG); | |
34dc7c2f BB |
1273 | } |
1274 | ||
1275 | int | |
13fe0198 | 1276 | dmu_objset_clone(const char *clone, const char *origin) |
34dc7c2f | 1277 | { |
13fe0198 | 1278 | dmu_objset_clone_arg_t doca; |
34dc7c2f | 1279 | |
13fe0198 MA |
1280 | doca.doca_clone = clone; |
1281 | doca.doca_origin = origin; | |
1282 | doca.doca_cred = CRED(); | |
572e2857 | 1283 | |
13fe0198 | 1284 | return (dsl_sync_task(clone, |
3d45fdd6 | 1285 | dmu_objset_clone_check, dmu_objset_clone_sync, &doca, |
b5256303 | 1286 | 6, ZFS_SPACE_CHECK_NORMAL)); |
6f1ffb06 MA |
1287 | } |
1288 | ||
1289 | int | |
1290 | dmu_objset_snapshot_one(const char *fsname, const char *snapname) | |
1291 | { | |
1292 | int err; | |
1293 | char *longsnap = kmem_asprintf("%s@%s", fsname, snapname); | |
1294 | nvlist_t *snaps = fnvlist_alloc(); | |
1295 | ||
1296 | fnvlist_add_boolean(snaps, longsnap); | |
6f1ffb06 | 1297 | strfree(longsnap); |
13fe0198 MA |
1298 | err = dsl_dataset_snapshot(snaps, NULL, NULL); |
1299 | fnvlist_free(snaps); | |
6f1ffb06 MA |
1300 | return (err); |
1301 | } | |
1302 | ||
1de321e6 JX |
1303 | static void |
1304 | dmu_objset_upgrade_task_cb(void *data) | |
1305 | { | |
1306 | objset_t *os = data; | |
1307 | ||
1308 | mutex_enter(&os->os_upgrade_lock); | |
1309 | os->os_upgrade_status = EINTR; | |
1310 | if (!os->os_upgrade_exit) { | |
1311 | mutex_exit(&os->os_upgrade_lock); | |
1312 | ||
1313 | os->os_upgrade_status = os->os_upgrade_cb(os); | |
1314 | mutex_enter(&os->os_upgrade_lock); | |
1315 | } | |
1316 | os->os_upgrade_exit = B_TRUE; | |
1317 | os->os_upgrade_id = 0; | |
1318 | mutex_exit(&os->os_upgrade_lock); | |
c0daec32 | 1319 | dsl_dataset_long_rele(dmu_objset_ds(os), upgrade_tag); |
1de321e6 JX |
1320 | } |
1321 | ||
1322 | static void | |
1323 | dmu_objset_upgrade(objset_t *os, dmu_objset_upgrade_cb_t cb) | |
1324 | { | |
1325 | if (os->os_upgrade_id != 0) | |
1326 | return; | |
1327 | ||
c0daec32 AB |
1328 | ASSERT(dsl_pool_config_held(dmu_objset_pool(os))); |
1329 | dsl_dataset_long_hold(dmu_objset_ds(os), upgrade_tag); | |
1330 | ||
1de321e6 JX |
1331 | mutex_enter(&os->os_upgrade_lock); |
1332 | if (os->os_upgrade_id == 0 && os->os_upgrade_status == 0) { | |
1333 | os->os_upgrade_exit = B_FALSE; | |
1334 | os->os_upgrade_cb = cb; | |
1335 | os->os_upgrade_id = taskq_dispatch( | |
1336 | os->os_spa->spa_upgrade_taskq, | |
1337 | dmu_objset_upgrade_task_cb, os, TQ_SLEEP); | |
c0daec32 AB |
1338 | if (os->os_upgrade_id == TASKQID_INVALID) { |
1339 | dsl_dataset_long_rele(dmu_objset_ds(os), upgrade_tag); | |
1de321e6 | 1340 | os->os_upgrade_status = ENOMEM; |
c0daec32 | 1341 | } |
1de321e6 JX |
1342 | } |
1343 | mutex_exit(&os->os_upgrade_lock); | |
1344 | } | |
1345 | ||
1346 | static void | |
1347 | dmu_objset_upgrade_stop(objset_t *os) | |
1348 | { | |
1349 | mutex_enter(&os->os_upgrade_lock); | |
1350 | os->os_upgrade_exit = B_TRUE; | |
1351 | if (os->os_upgrade_id != 0) { | |
1352 | taskqid_t id = os->os_upgrade_id; | |
1353 | ||
1354 | os->os_upgrade_id = 0; | |
1355 | mutex_exit(&os->os_upgrade_lock); | |
1356 | ||
c0daec32 AB |
1357 | if ((taskq_cancel_id(os->os_spa->spa_upgrade_taskq, id)) == 0) { |
1358 | dsl_dataset_long_rele(dmu_objset_ds(os), upgrade_tag); | |
1359 | } | |
4807c0ba | 1360 | txg_wait_synced(os->os_spa->spa_dsl_pool, 0); |
1de321e6 JX |
1361 | } else { |
1362 | mutex_exit(&os->os_upgrade_lock); | |
1363 | } | |
1364 | } | |
1365 | ||
34dc7c2f | 1366 | static void |
64fc7762 | 1367 | dmu_objset_sync_dnodes(multilist_sublist_t *list, dmu_tx_t *tx) |
34dc7c2f BB |
1368 | { |
1369 | dnode_t *dn; | |
1370 | ||
64fc7762 | 1371 | while ((dn = multilist_sublist_head(list)) != NULL) { |
34dc7c2f BB |
1372 | ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT); |
1373 | ASSERT(dn->dn_dbuf->db_data_pending); | |
1374 | /* | |
9babb374 BB |
1375 | * Initialize dn_zio outside dnode_sync() because the |
1376 | * meta-dnode needs to set it ouside dnode_sync(). | |
34dc7c2f BB |
1377 | */ |
1378 | dn->dn_zio = dn->dn_dbuf->db_data_pending->dr_zio; | |
1379 | ASSERT(dn->dn_zio); | |
1380 | ||
1381 | ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS); | |
64fc7762 | 1382 | multilist_sublist_remove(list, dn); |
9babb374 | 1383 | |
64fc7762 MA |
1384 | multilist_t *newlist = dn->dn_objset->os_synced_dnodes; |
1385 | if (newlist != NULL) { | |
9babb374 | 1386 | (void) dnode_add_ref(dn, newlist); |
64fc7762 | 1387 | multilist_insert(newlist, dn); |
9babb374 BB |
1388 | } |
1389 | ||
34dc7c2f BB |
1390 | dnode_sync(dn, tx); |
1391 | } | |
1392 | } | |
1393 | ||
1394 | /* ARGSUSED */ | |
1395 | static void | |
428870ff | 1396 | dmu_objset_write_ready(zio_t *zio, arc_buf_t *abuf, void *arg) |
34dc7c2f | 1397 | { |
b128c09f | 1398 | blkptr_t *bp = zio->io_bp; |
428870ff | 1399 | objset_t *os = arg; |
34dc7c2f | 1400 | dnode_phys_t *dnp = &os->os_phys->os_meta_dnode; |
b5256303 | 1401 | uint64_t fill = 0; |
34dc7c2f | 1402 | |
9b67f605 | 1403 | ASSERT(!BP_IS_EMBEDDED(bp)); |
13fe0198 MA |
1404 | ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_OBJSET); |
1405 | ASSERT0(BP_GET_LEVEL(bp)); | |
34dc7c2f BB |
1406 | |
1407 | /* | |
9babb374 BB |
1408 | * Update rootbp fill count: it should be the number of objects |
1409 | * allocated in the object set (not counting the "special" | |
1410 | * objects that are stored in the objset_phys_t -- the meta | |
1411 | * dnode and user/group accounting objects). | |
34dc7c2f | 1412 | */ |
1c27024e | 1413 | for (int i = 0; i < dnp->dn_nblkptr; i++) |
b5256303 TC |
1414 | fill += BP_GET_FILL(&dnp->dn_blkptr[i]); |
1415 | ||
1416 | BP_SET_FILL(bp, fill); | |
1417 | ||
cc9bb3e5 GM |
1418 | if (os->os_dsl_dataset != NULL) |
1419 | rrw_enter(&os->os_dsl_dataset->ds_bp_rwlock, RW_WRITER, FTAG); | |
1420 | *os->os_rootbp = *bp; | |
1421 | if (os->os_dsl_dataset != NULL) | |
1422 | rrw_exit(&os->os_dsl_dataset->ds_bp_rwlock, FTAG); | |
428870ff BB |
1423 | } |
1424 | ||
1425 | /* ARGSUSED */ | |
1426 | static void | |
1427 | dmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg) | |
1428 | { | |
1429 | blkptr_t *bp = zio->io_bp; | |
1430 | blkptr_t *bp_orig = &zio->io_bp_orig; | |
1431 | objset_t *os = arg; | |
34dc7c2f | 1432 | |
b128c09f | 1433 | if (zio->io_flags & ZIO_FLAG_IO_REWRITE) { |
428870ff | 1434 | ASSERT(BP_EQUAL(bp, bp_orig)); |
b128c09f | 1435 | } else { |
428870ff BB |
1436 | dsl_dataset_t *ds = os->os_dsl_dataset; |
1437 | dmu_tx_t *tx = os->os_synctx; | |
1438 | ||
1439 | (void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE); | |
1440 | dsl_dataset_block_born(ds, bp, tx); | |
34dc7c2f | 1441 | } |
cc9bb3e5 | 1442 | kmem_free(bp, sizeof (*bp)); |
34dc7c2f BB |
1443 | } |
1444 | ||
64fc7762 MA |
1445 | typedef struct sync_dnodes_arg { |
1446 | multilist_t *sda_list; | |
1447 | int sda_sublist_idx; | |
1448 | multilist_t *sda_newlist; | |
1449 | dmu_tx_t *sda_tx; | |
1450 | } sync_dnodes_arg_t; | |
1451 | ||
1452 | static void | |
1453 | sync_dnodes_task(void *arg) | |
1454 | { | |
1455 | sync_dnodes_arg_t *sda = arg; | |
1456 | ||
1457 | multilist_sublist_t *ms = | |
1458 | multilist_sublist_lock(sda->sda_list, sda->sda_sublist_idx); | |
1459 | ||
1460 | dmu_objset_sync_dnodes(ms, sda->sda_tx); | |
1461 | ||
1462 | multilist_sublist_unlock(ms); | |
1463 | ||
1464 | kmem_free(sda, sizeof (*sda)); | |
1465 | } | |
1466 | ||
1467 | ||
34dc7c2f BB |
1468 | /* called from dsl */ |
1469 | void | |
428870ff | 1470 | dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx) |
34dc7c2f BB |
1471 | { |
1472 | int txgoff; | |
5dbd68a3 | 1473 | zbookmark_phys_t zb; |
428870ff | 1474 | zio_prop_t zp; |
34dc7c2f BB |
1475 | zio_t *zio; |
1476 | list_t *list; | |
1477 | dbuf_dirty_record_t *dr; | |
cc9bb3e5 GM |
1478 | blkptr_t *blkptr_copy = kmem_alloc(sizeof (*os->os_rootbp), KM_SLEEP); |
1479 | *blkptr_copy = *os->os_rootbp; | |
34dc7c2f BB |
1480 | |
1481 | dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg); | |
1482 | ||
1483 | ASSERT(dmu_tx_is_syncing(tx)); | |
1484 | /* XXX the write_done callback should really give us the tx... */ | |
1485 | os->os_synctx = tx; | |
1486 | ||
1487 | if (os->os_dsl_dataset == NULL) { | |
1488 | /* | |
1489 | * This is the MOS. If we have upgraded, | |
1490 | * spa_max_replication() could change, so reset | |
1491 | * os_copies here. | |
1492 | */ | |
1493 | os->os_copies = spa_max_replication(os->os_spa); | |
1494 | } | |
1495 | ||
1496 | /* | |
1497 | * Create the root block IO | |
1498 | */ | |
428870ff BB |
1499 | SET_BOOKMARK(&zb, os->os_dsl_dataset ? |
1500 | os->os_dsl_dataset->ds_object : DMU_META_OBJSET, | |
1501 | ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID); | |
294f6806 | 1502 | arc_release(os->os_phys_buf, &os->os_phys_buf); |
b128c09f | 1503 | |
82644107 | 1504 | dmu_write_policy(os, NULL, 0, 0, &zp); |
9babb374 | 1505 | |
b5256303 TC |
1506 | /* |
1507 | * If we are either claiming the ZIL or doing a raw receive write out | |
1508 | * the os_phys_buf raw. Neither of these actions will effect the MAC | |
1509 | * at this point. | |
1510 | */ | |
1511 | if (arc_is_unauthenticated(os->os_phys_buf) || os->os_next_write_raw) { | |
1512 | ASSERT(os->os_encrypted); | |
1513 | os->os_next_write_raw = B_FALSE; | |
1514 | arc_convert_to_raw(os->os_phys_buf, | |
1515 | os->os_dsl_dataset->ds_object, ZFS_HOST_BYTEORDER, | |
1516 | DMU_OT_OBJSET, NULL, NULL, NULL); | |
1517 | } | |
1518 | ||
428870ff | 1519 | zio = arc_write(pio, os->os_spa, tx->tx_txg, |
cc9bb3e5 | 1520 | blkptr_copy, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os), |
bc77ba73 PD |
1521 | &zp, dmu_objset_write_ready, NULL, NULL, dmu_objset_write_done, |
1522 | os, ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb); | |
34dc7c2f BB |
1523 | |
1524 | /* | |
9babb374 | 1525 | * Sync special dnodes - the parent IO for the sync is the root block |
34dc7c2f | 1526 | */ |
572e2857 BB |
1527 | DMU_META_DNODE(os)->dn_zio = zio; |
1528 | dnode_sync(DMU_META_DNODE(os), tx); | |
34dc7c2f | 1529 | |
9babb374 BB |
1530 | os->os_phys->os_flags = os->os_flags; |
1531 | ||
572e2857 BB |
1532 | if (DMU_USERUSED_DNODE(os) && |
1533 | DMU_USERUSED_DNODE(os)->dn_type != DMU_OT_NONE) { | |
1534 | DMU_USERUSED_DNODE(os)->dn_zio = zio; | |
1535 | dnode_sync(DMU_USERUSED_DNODE(os), tx); | |
1536 | DMU_GROUPUSED_DNODE(os)->dn_zio = zio; | |
1537 | dnode_sync(DMU_GROUPUSED_DNODE(os), tx); | |
9babb374 BB |
1538 | } |
1539 | ||
34dc7c2f BB |
1540 | txgoff = tx->tx_txg & TXG_MASK; |
1541 | ||
b5256303 TC |
1542 | if (dmu_objset_userused_enabled(os) && |
1543 | (!os->os_encrypted || !dmu_objset_is_receiving(os))) { | |
9babb374 BB |
1544 | /* |
1545 | * We must create the list here because it uses the | |
64fc7762 MA |
1546 | * dn_dirty_link[] of this txg. But it may already |
1547 | * exist because we call dsl_dataset_sync() twice per txg. | |
9babb374 | 1548 | */ |
64fc7762 MA |
1549 | if (os->os_synced_dnodes == NULL) { |
1550 | os->os_synced_dnodes = | |
1551 | multilist_create(sizeof (dnode_t), | |
1552 | offsetof(dnode_t, dn_dirty_link[txgoff]), | |
1553 | dnode_multilist_index_func); | |
1554 | } else { | |
1555 | ASSERT3U(os->os_synced_dnodes->ml_offset, ==, | |
1556 | offsetof(dnode_t, dn_dirty_link[txgoff])); | |
1557 | } | |
9babb374 BB |
1558 | } |
1559 | ||
64fc7762 MA |
1560 | for (int i = 0; |
1561 | i < multilist_get_num_sublists(os->os_dirty_dnodes[txgoff]); i++) { | |
1562 | sync_dnodes_arg_t *sda = kmem_alloc(sizeof (*sda), KM_SLEEP); | |
1563 | sda->sda_list = os->os_dirty_dnodes[txgoff]; | |
1564 | sda->sda_sublist_idx = i; | |
1565 | sda->sda_tx = tx; | |
1566 | (void) taskq_dispatch(dmu_objset_pool(os)->dp_sync_taskq, | |
1567 | sync_dnodes_task, sda, 0); | |
1568 | /* callback frees sda */ | |
1569 | } | |
1570 | taskq_wait(dmu_objset_pool(os)->dp_sync_taskq); | |
34dc7c2f | 1571 | |
572e2857 | 1572 | list = &DMU_META_DNODE(os)->dn_dirty_records[txgoff]; |
64fc7762 | 1573 | while ((dr = list_head(list)) != NULL) { |
13fe0198 | 1574 | ASSERT0(dr->dr_dbuf->db_level); |
34dc7c2f BB |
1575 | list_remove(list, dr); |
1576 | if (dr->dr_zio) | |
1577 | zio_nowait(dr->dr_zio); | |
1578 | } | |
68cbd56e NB |
1579 | |
1580 | /* Enable dnode backfill if enough objects have been freed. */ | |
1581 | if (os->os_freed_dnodes >= dmu_rescan_dnode_threshold) { | |
1582 | os->os_rescan_dnodes = B_TRUE; | |
1583 | os->os_freed_dnodes = 0; | |
1584 | } | |
1585 | ||
34dc7c2f BB |
1586 | /* |
1587 | * Free intent log blocks up to this tx. | |
1588 | */ | |
1589 | zil_sync(os->os_zil, tx); | |
b128c09f | 1590 | os->os_phys->os_zil_header = os->os_zil_header; |
34dc7c2f BB |
1591 | zio_nowait(zio); |
1592 | } | |
1593 | ||
428870ff BB |
1594 | boolean_t |
1595 | dmu_objset_is_dirty(objset_t *os, uint64_t txg) | |
1596 | { | |
64fc7762 | 1597 | return (!multilist_is_empty(os->os_dirty_dnodes[txg & TXG_MASK])); |
428870ff BB |
1598 | } |
1599 | ||
572e2857 | 1600 | static objset_used_cb_t *used_cbs[DMU_OST_NUMTYPES]; |
9babb374 BB |
1601 | |
1602 | void | |
1603 | dmu_objset_register_type(dmu_objset_type_t ost, objset_used_cb_t *cb) | |
1604 | { | |
1605 | used_cbs[ost] = cb; | |
1606 | } | |
1607 | ||
1608 | boolean_t | |
428870ff | 1609 | dmu_objset_userused_enabled(objset_t *os) |
9babb374 BB |
1610 | { |
1611 | return (spa_version(os->os_spa) >= SPA_VERSION_USERSPACE && | |
572e2857 BB |
1612 | used_cbs[os->os_phys->os_type] != NULL && |
1613 | DMU_USERUSED_DNODE(os) != NULL); | |
9babb374 BB |
1614 | } |
1615 | ||
1de321e6 JX |
1616 | boolean_t |
1617 | dmu_objset_userobjused_enabled(objset_t *os) | |
1618 | { | |
1619 | return (dmu_objset_userused_enabled(os) && | |
1620 | spa_feature_is_enabled(os->os_spa, SPA_FEATURE_USEROBJ_ACCOUNTING)); | |
1621 | } | |
1622 | ||
9b7a83cb JX |
1623 | typedef struct userquota_node { |
1624 | /* must be in the first filed, see userquota_update_cache() */ | |
1625 | char uqn_id[20 + DMU_OBJACCT_PREFIX_LEN]; | |
1626 | int64_t uqn_delta; | |
1627 | avl_node_t uqn_node; | |
1628 | } userquota_node_t; | |
1629 | ||
1630 | typedef struct userquota_cache { | |
1631 | avl_tree_t uqc_user_deltas; | |
1632 | avl_tree_t uqc_group_deltas; | |
1633 | } userquota_cache_t; | |
1634 | ||
1635 | static int | |
1636 | userquota_compare(const void *l, const void *r) | |
1637 | { | |
1638 | const userquota_node_t *luqn = l; | |
1639 | const userquota_node_t *ruqn = r; | |
e4ffa98d | 1640 | int rv; |
9b7a83cb JX |
1641 | |
1642 | /* | |
1643 | * NB: can only access uqn_id because userquota_update_cache() doesn't | |
1644 | * pass in an entire userquota_node_t. | |
1645 | */ | |
e4ffa98d BB |
1646 | rv = strcmp(luqn->uqn_id, ruqn->uqn_id); |
1647 | ||
1648 | return (AVL_ISIGN(rv)); | |
9b7a83cb JX |
1649 | } |
1650 | ||
1651 | static void | |
1652 | do_userquota_cacheflush(objset_t *os, userquota_cache_t *cache, dmu_tx_t *tx) | |
1653 | { | |
1654 | void *cookie; | |
1655 | userquota_node_t *uqn; | |
1656 | ||
1657 | ASSERT(dmu_tx_is_syncing(tx)); | |
1658 | ||
1659 | cookie = NULL; | |
1660 | while ((uqn = avl_destroy_nodes(&cache->uqc_user_deltas, | |
1661 | &cookie)) != NULL) { | |
64fc7762 MA |
1662 | /* |
1663 | * os_userused_lock protects against concurrent calls to | |
1664 | * zap_increment_int(). It's needed because zap_increment_int() | |
1665 | * is not thread-safe (i.e. not atomic). | |
1666 | */ | |
1667 | mutex_enter(&os->os_userused_lock); | |
9b7a83cb JX |
1668 | VERIFY0(zap_increment(os, DMU_USERUSED_OBJECT, |
1669 | uqn->uqn_id, uqn->uqn_delta, tx)); | |
64fc7762 | 1670 | mutex_exit(&os->os_userused_lock); |
9b7a83cb JX |
1671 | kmem_free(uqn, sizeof (*uqn)); |
1672 | } | |
1673 | avl_destroy(&cache->uqc_user_deltas); | |
1674 | ||
1675 | cookie = NULL; | |
1676 | while ((uqn = avl_destroy_nodes(&cache->uqc_group_deltas, | |
1677 | &cookie)) != NULL) { | |
64fc7762 | 1678 | mutex_enter(&os->os_userused_lock); |
9b7a83cb JX |
1679 | VERIFY0(zap_increment(os, DMU_GROUPUSED_OBJECT, |
1680 | uqn->uqn_id, uqn->uqn_delta, tx)); | |
64fc7762 | 1681 | mutex_exit(&os->os_userused_lock); |
9b7a83cb JX |
1682 | kmem_free(uqn, sizeof (*uqn)); |
1683 | } | |
1684 | avl_destroy(&cache->uqc_group_deltas); | |
1685 | } | |
1686 | ||
1687 | static void | |
1688 | userquota_update_cache(avl_tree_t *avl, const char *id, int64_t delta) | |
1689 | { | |
1690 | userquota_node_t *uqn; | |
1691 | avl_index_t idx; | |
1692 | ||
1693 | ASSERT(strlen(id) < sizeof (uqn->uqn_id)); | |
1694 | /* | |
1695 | * Use id directly for searching because uqn_id is the first field of | |
1696 | * userquota_node_t and fields after uqn_id won't be accessed in | |
1697 | * avl_find(). | |
1698 | */ | |
1699 | uqn = avl_find(avl, (const void *)id, &idx); | |
1700 | if (uqn == NULL) { | |
1701 | uqn = kmem_zalloc(sizeof (*uqn), KM_SLEEP); | |
1f51b525 | 1702 | strlcpy(uqn->uqn_id, id, sizeof (uqn->uqn_id)); |
9b7a83cb JX |
1703 | avl_insert(avl, uqn, idx); |
1704 | } | |
1705 | uqn->uqn_delta += delta; | |
1706 | } | |
1707 | ||
428870ff | 1708 | static void |
9b7a83cb JX |
1709 | do_userquota_update(userquota_cache_t *cache, uint64_t used, uint64_t flags, |
1710 | uint64_t user, uint64_t group, boolean_t subtract) | |
428870ff BB |
1711 | { |
1712 | if ((flags & DNODE_FLAG_USERUSED_ACCOUNTED)) { | |
50c957f7 | 1713 | int64_t delta = DNODE_MIN_SIZE + used; |
9b7a83cb JX |
1714 | char name[20]; |
1715 | ||
428870ff BB |
1716 | if (subtract) |
1717 | delta = -delta; | |
9b7a83cb JX |
1718 | |
1719 | (void) sprintf(name, "%llx", (longlong_t)user); | |
1720 | userquota_update_cache(&cache->uqc_user_deltas, name, delta); | |
1721 | ||
1722 | (void) sprintf(name, "%llx", (longlong_t)group); | |
1723 | userquota_update_cache(&cache->uqc_group_deltas, name, delta); | |
428870ff BB |
1724 | } |
1725 | } | |
1726 | ||
1de321e6 | 1727 | static void |
9b7a83cb JX |
1728 | do_userobjquota_update(userquota_cache_t *cache, uint64_t flags, |
1729 | uint64_t user, uint64_t group, boolean_t subtract) | |
1de321e6 JX |
1730 | { |
1731 | if (flags & DNODE_FLAG_USEROBJUSED_ACCOUNTED) { | |
1732 | char name[20 + DMU_OBJACCT_PREFIX_LEN]; | |
9b7a83cb | 1733 | int delta = subtract ? -1 : 1; |
1de321e6 JX |
1734 | |
1735 | (void) snprintf(name, sizeof (name), DMU_OBJACCT_PREFIX "%llx", | |
1736 | (longlong_t)user); | |
9b7a83cb | 1737 | userquota_update_cache(&cache->uqc_user_deltas, name, delta); |
1de321e6 JX |
1738 | |
1739 | (void) snprintf(name, sizeof (name), DMU_OBJACCT_PREFIX "%llx", | |
1740 | (longlong_t)group); | |
9b7a83cb | 1741 | userquota_update_cache(&cache->uqc_group_deltas, name, delta); |
1de321e6 JX |
1742 | } |
1743 | } | |
1744 | ||
64fc7762 MA |
1745 | typedef struct userquota_updates_arg { |
1746 | objset_t *uua_os; | |
1747 | int uua_sublist_idx; | |
1748 | dmu_tx_t *uua_tx; | |
1749 | } userquota_updates_arg_t; | |
1750 | ||
1751 | static void | |
1752 | userquota_updates_task(void *arg) | |
9babb374 | 1753 | { |
64fc7762 MA |
1754 | userquota_updates_arg_t *uua = arg; |
1755 | objset_t *os = uua->uua_os; | |
1756 | dmu_tx_t *tx = uua->uua_tx; | |
9babb374 | 1757 | dnode_t *dn; |
9b7a83cb | 1758 | userquota_cache_t cache = { { 0 } }; |
9babb374 | 1759 | |
64fc7762 MA |
1760 | multilist_sublist_t *list = |
1761 | multilist_sublist_lock(os->os_synced_dnodes, uua->uua_sublist_idx); | |
9babb374 | 1762 | |
64fc7762 MA |
1763 | ASSERT(multilist_sublist_head(list) == NULL || |
1764 | dmu_objset_userused_enabled(os)); | |
9b7a83cb JX |
1765 | avl_create(&cache.uqc_user_deltas, userquota_compare, |
1766 | sizeof (userquota_node_t), offsetof(userquota_node_t, uqn_node)); | |
1767 | avl_create(&cache.uqc_group_deltas, userquota_compare, | |
1768 | sizeof (userquota_node_t), offsetof(userquota_node_t, uqn_node)); | |
1769 | ||
64fc7762 | 1770 | while ((dn = multilist_sublist_head(list)) != NULL) { |
572e2857 | 1771 | int flags; |
9babb374 | 1772 | ASSERT(!DMU_OBJECT_IS_SPECIAL(dn->dn_object)); |
9babb374 BB |
1773 | ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE || |
1774 | dn->dn_phys->dn_flags & | |
1775 | DNODE_FLAG_USERUSED_ACCOUNTED); | |
1776 | ||
572e2857 BB |
1777 | flags = dn->dn_id_flags; |
1778 | ASSERT(flags); | |
1779 | if (flags & DN_ID_OLD_EXIST) { | |
9b7a83cb JX |
1780 | do_userquota_update(&cache, |
1781 | dn->dn_oldused, dn->dn_oldflags, | |
1782 | dn->dn_olduid, dn->dn_oldgid, B_TRUE); | |
1783 | do_userobjquota_update(&cache, dn->dn_oldflags, | |
1784 | dn->dn_olduid, dn->dn_oldgid, B_TRUE); | |
428870ff | 1785 | } |
572e2857 | 1786 | if (flags & DN_ID_NEW_EXIST) { |
9b7a83cb JX |
1787 | do_userquota_update(&cache, |
1788 | DN_USED_BYTES(dn->dn_phys), dn->dn_phys->dn_flags, | |
1789 | dn->dn_newuid, dn->dn_newgid, B_FALSE); | |
1790 | do_userobjquota_update(&cache, dn->dn_phys->dn_flags, | |
1791 | dn->dn_newuid, dn->dn_newgid, B_FALSE); | |
428870ff BB |
1792 | } |
1793 | ||
572e2857 | 1794 | mutex_enter(&dn->dn_mtx); |
428870ff BB |
1795 | dn->dn_oldused = 0; |
1796 | dn->dn_oldflags = 0; | |
1797 | if (dn->dn_id_flags & DN_ID_NEW_EXIST) { | |
1798 | dn->dn_olduid = dn->dn_newuid; | |
1799 | dn->dn_oldgid = dn->dn_newgid; | |
1800 | dn->dn_id_flags |= DN_ID_OLD_EXIST; | |
1801 | if (dn->dn_bonuslen == 0) | |
1802 | dn->dn_id_flags |= DN_ID_CHKED_SPILL; | |
1803 | else | |
1804 | dn->dn_id_flags |= DN_ID_CHKED_BONUS; | |
1805 | } | |
1806 | dn->dn_id_flags &= ~(DN_ID_NEW_EXIST); | |
9babb374 BB |
1807 | mutex_exit(&dn->dn_mtx); |
1808 | ||
64fc7762 MA |
1809 | multilist_sublist_remove(list, dn); |
1810 | dnode_rele(dn, os->os_synced_dnodes); | |
9babb374 | 1811 | } |
9b7a83cb | 1812 | do_userquota_cacheflush(os, &cache, tx); |
64fc7762 MA |
1813 | multilist_sublist_unlock(list); |
1814 | kmem_free(uua, sizeof (*uua)); | |
1815 | } | |
1816 | ||
1817 | void | |
1818 | dmu_objset_do_userquota_updates(objset_t *os, dmu_tx_t *tx) | |
1819 | { | |
1820 | if (!dmu_objset_userused_enabled(os)) | |
1821 | return; | |
1822 | ||
b5256303 TC |
1823 | /* if this is a raw receive just return and handle accounting later */ |
1824 | if (os->os_encrypted && dmu_objset_is_receiving(os)) | |
1825 | return; | |
1826 | ||
64fc7762 MA |
1827 | /* Allocate the user/groupused objects if necessary. */ |
1828 | if (DMU_USERUSED_DNODE(os)->dn_type == DMU_OT_NONE) { | |
1829 | VERIFY0(zap_create_claim(os, | |
1830 | DMU_USERUSED_OBJECT, | |
1831 | DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx)); | |
1832 | VERIFY0(zap_create_claim(os, | |
1833 | DMU_GROUPUSED_OBJECT, | |
1834 | DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx)); | |
1835 | } | |
1836 | ||
1837 | for (int i = 0; | |
1838 | i < multilist_get_num_sublists(os->os_synced_dnodes); i++) { | |
1839 | userquota_updates_arg_t *uua = | |
1840 | kmem_alloc(sizeof (*uua), KM_SLEEP); | |
1841 | uua->uua_os = os; | |
1842 | uua->uua_sublist_idx = i; | |
1843 | uua->uua_tx = tx; | |
1844 | /* note: caller does taskq_wait() */ | |
1845 | (void) taskq_dispatch(dmu_objset_pool(os)->dp_sync_taskq, | |
1846 | userquota_updates_task, uua, 0); | |
1847 | /* callback frees uua */ | |
1848 | } | |
9babb374 BB |
1849 | } |
1850 | ||
428870ff BB |
1851 | /* |
1852 | * Returns a pointer to data to find uid/gid from | |
1853 | * | |
1854 | * If a dirty record for transaction group that is syncing can't | |
1855 | * be found then NULL is returned. In the NULL case it is assumed | |
1856 | * the uid/gid aren't changing. | |
1857 | */ | |
1858 | static void * | |
1859 | dmu_objset_userquota_find_data(dmu_buf_impl_t *db, dmu_tx_t *tx) | |
1860 | { | |
1861 | dbuf_dirty_record_t *dr, **drp; | |
1862 | void *data; | |
1863 | ||
1864 | if (db->db_dirtycnt == 0) | |
1865 | return (db->db.db_data); /* Nothing is changing */ | |
1866 | ||
1867 | for (drp = &db->db_last_dirty; (dr = *drp) != NULL; drp = &dr->dr_next) | |
1868 | if (dr->dr_txg == tx->tx_txg) | |
1869 | break; | |
1870 | ||
572e2857 | 1871 | if (dr == NULL) { |
428870ff | 1872 | data = NULL; |
572e2857 BB |
1873 | } else { |
1874 | dnode_t *dn; | |
1875 | ||
1876 | DB_DNODE_ENTER(dr->dr_dbuf); | |
1877 | dn = DB_DNODE(dr->dr_dbuf); | |
1878 | ||
1879 | if (dn->dn_bonuslen == 0 && | |
1880 | dr->dr_dbuf->db_blkid == DMU_SPILL_BLKID) | |
1881 | data = dr->dt.dl.dr_data->b_data; | |
1882 | else | |
1883 | data = dr->dt.dl.dr_data; | |
1884 | ||
1885 | DB_DNODE_EXIT(dr->dr_dbuf); | |
1886 | } | |
1887 | ||
428870ff BB |
1888 | return (data); |
1889 | } | |
1890 | ||
1891 | void | |
1892 | dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx) | |
1893 | { | |
1894 | objset_t *os = dn->dn_objset; | |
1895 | void *data = NULL; | |
1896 | dmu_buf_impl_t *db = NULL; | |
a117a6d6 GW |
1897 | uint64_t *user = NULL; |
1898 | uint64_t *group = NULL; | |
428870ff BB |
1899 | int flags = dn->dn_id_flags; |
1900 | int error; | |
1901 | boolean_t have_spill = B_FALSE; | |
1902 | ||
1903 | if (!dmu_objset_userused_enabled(dn->dn_objset)) | |
1904 | return; | |
1905 | ||
b5256303 TC |
1906 | /* |
1907 | * Raw receives introduce a problem with user accounting. Raw | |
1908 | * receives cannot update the user accounting info because the | |
1909 | * user ids and the sizes are encrypted. To guarantee that we | |
1910 | * never end up with bad user accounting, we simply disable it | |
1911 | * during raw receives. We also disable this for normal receives | |
1912 | * so that an incremental raw receive may be done on top of an | |
1913 | * existing non-raw receive. | |
1914 | */ | |
1915 | if (os->os_encrypted && dmu_objset_is_receiving(os)) | |
1916 | return; | |
1917 | ||
428870ff BB |
1918 | if (before && (flags & (DN_ID_CHKED_BONUS|DN_ID_OLD_EXIST| |
1919 | DN_ID_CHKED_SPILL))) | |
1920 | return; | |
1921 | ||
1922 | if (before && dn->dn_bonuslen != 0) | |
1923 | data = DN_BONUS(dn->dn_phys); | |
1924 | else if (!before && dn->dn_bonuslen != 0) { | |
a3000f93 BB |
1925 | if (dn->dn_bonus) { |
1926 | db = dn->dn_bonus; | |
428870ff BB |
1927 | mutex_enter(&db->db_mtx); |
1928 | data = dmu_objset_userquota_find_data(db, tx); | |
1929 | } else { | |
1930 | data = DN_BONUS(dn->dn_phys); | |
1931 | } | |
1932 | } else if (dn->dn_bonuslen == 0 && dn->dn_bonustype == DMU_OT_SA) { | |
1933 | int rf = 0; | |
1934 | ||
1935 | if (RW_WRITE_HELD(&dn->dn_struct_rwlock)) | |
1936 | rf |= DB_RF_HAVESTRUCT; | |
572e2857 BB |
1937 | error = dmu_spill_hold_by_dnode(dn, |
1938 | rf | DB_RF_MUST_SUCCEED, | |
428870ff BB |
1939 | FTAG, (dmu_buf_t **)&db); |
1940 | ASSERT(error == 0); | |
1941 | mutex_enter(&db->db_mtx); | |
1942 | data = (before) ? db->db.db_data : | |
1943 | dmu_objset_userquota_find_data(db, tx); | |
1944 | have_spill = B_TRUE; | |
1945 | } else { | |
1946 | mutex_enter(&dn->dn_mtx); | |
1947 | dn->dn_id_flags |= DN_ID_CHKED_BONUS; | |
1948 | mutex_exit(&dn->dn_mtx); | |
1949 | return; | |
1950 | } | |
1951 | ||
1952 | if (before) { | |
1953 | ASSERT(data); | |
1954 | user = &dn->dn_olduid; | |
1955 | group = &dn->dn_oldgid; | |
1956 | } else if (data) { | |
1957 | user = &dn->dn_newuid; | |
1958 | group = &dn->dn_newgid; | |
1959 | } | |
1960 | ||
1961 | /* | |
1962 | * Must always call the callback in case the object | |
1963 | * type has changed and that type isn't an object type to track | |
1964 | */ | |
1965 | error = used_cbs[os->os_phys->os_type](dn->dn_bonustype, data, | |
1966 | user, group); | |
1967 | ||
1968 | /* | |
1969 | * Preserve existing uid/gid when the callback can't determine | |
1970 | * what the new uid/gid are and the callback returned EEXIST. | |
1971 | * The EEXIST error tells us to just use the existing uid/gid. | |
1972 | * If we don't know what the old values are then just assign | |
1973 | * them to 0, since that is a new file being created. | |
1974 | */ | |
1975 | if (!before && data == NULL && error == EEXIST) { | |
1976 | if (flags & DN_ID_OLD_EXIST) { | |
1977 | dn->dn_newuid = dn->dn_olduid; | |
1978 | dn->dn_newgid = dn->dn_oldgid; | |
1979 | } else { | |
1980 | dn->dn_newuid = 0; | |
1981 | dn->dn_newgid = 0; | |
1982 | } | |
1983 | error = 0; | |
1984 | } | |
1985 | ||
1986 | if (db) | |
1987 | mutex_exit(&db->db_mtx); | |
1988 | ||
1989 | mutex_enter(&dn->dn_mtx); | |
1990 | if (error == 0 && before) | |
1991 | dn->dn_id_flags |= DN_ID_OLD_EXIST; | |
1992 | if (error == 0 && !before) | |
1993 | dn->dn_id_flags |= DN_ID_NEW_EXIST; | |
1994 | ||
1995 | if (have_spill) { | |
1996 | dn->dn_id_flags |= DN_ID_CHKED_SPILL; | |
1997 | } else { | |
1998 | dn->dn_id_flags |= DN_ID_CHKED_BONUS; | |
1999 | } | |
2000 | mutex_exit(&dn->dn_mtx); | |
a3000f93 | 2001 | if (have_spill) |
428870ff BB |
2002 | dmu_buf_rele((dmu_buf_t *)db, FTAG); |
2003 | } | |
2004 | ||
9babb374 BB |
2005 | boolean_t |
2006 | dmu_objset_userspace_present(objset_t *os) | |
2007 | { | |
428870ff | 2008 | return (os->os_phys->os_flags & |
9babb374 BB |
2009 | OBJSET_FLAG_USERACCOUNTING_COMPLETE); |
2010 | } | |
2011 | ||
1de321e6 JX |
2012 | boolean_t |
2013 | dmu_objset_userobjspace_present(objset_t *os) | |
2014 | { | |
2015 | return (os->os_phys->os_flags & | |
2016 | OBJSET_FLAG_USEROBJACCOUNTING_COMPLETE); | |
2017 | } | |
2018 | ||
2019 | static int | |
2020 | dmu_objset_space_upgrade(objset_t *os) | |
9babb374 BB |
2021 | { |
2022 | uint64_t obj; | |
2023 | int err = 0; | |
2024 | ||
9babb374 BB |
2025 | /* |
2026 | * We simply need to mark every object dirty, so that it will be | |
2027 | * synced out and now accounted. If this is called | |
2028 | * concurrently, or if we already did some work before crashing, | |
2029 | * that's fine, since we track each object's accounted state | |
2030 | * independently. | |
2031 | */ | |
2032 | ||
2033 | for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE, 0)) { | |
45d1cae3 | 2034 | dmu_tx_t *tx; |
9babb374 BB |
2035 | dmu_buf_t *db; |
2036 | int objerr; | |
2037 | ||
1de321e6 JX |
2038 | mutex_enter(&os->os_upgrade_lock); |
2039 | if (os->os_upgrade_exit) | |
2040 | err = SET_ERROR(EINTR); | |
2041 | mutex_exit(&os->os_upgrade_lock); | |
2042 | if (err != 0) | |
2043 | return (err); | |
2044 | ||
9babb374 | 2045 | if (issig(JUSTLOOKING) && issig(FORREAL)) |
2e528b49 | 2046 | return (SET_ERROR(EINTR)); |
9babb374 BB |
2047 | |
2048 | objerr = dmu_bonus_hold(os, obj, FTAG, &db); | |
13fe0198 | 2049 | if (objerr != 0) |
9babb374 | 2050 | continue; |
45d1cae3 | 2051 | tx = dmu_tx_create(os); |
9babb374 BB |
2052 | dmu_tx_hold_bonus(tx, obj); |
2053 | objerr = dmu_tx_assign(tx, TXG_WAIT); | |
13fe0198 | 2054 | if (objerr != 0) { |
d22323e8 | 2055 | dmu_buf_rele(db, FTAG); |
9babb374 BB |
2056 | dmu_tx_abort(tx); |
2057 | continue; | |
2058 | } | |
2059 | dmu_buf_will_dirty(db, tx); | |
2060 | dmu_buf_rele(db, FTAG); | |
2061 | dmu_tx_commit(tx); | |
2062 | } | |
1de321e6 JX |
2063 | return (0); |
2064 | } | |
2065 | ||
2066 | int | |
2067 | dmu_objset_userspace_upgrade(objset_t *os) | |
2068 | { | |
2069 | int err = 0; | |
2070 | ||
2071 | if (dmu_objset_userspace_present(os)) | |
2072 | return (0); | |
2073 | if (dmu_objset_is_snapshot(os)) | |
2074 | return (SET_ERROR(EINVAL)); | |
2075 | if (!dmu_objset_userused_enabled(os)) | |
2076 | return (SET_ERROR(ENOTSUP)); | |
2077 | ||
2078 | err = dmu_objset_space_upgrade(os); | |
2079 | if (err) | |
2080 | return (err); | |
9babb374 | 2081 | |
428870ff | 2082 | os->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE; |
9babb374 BB |
2083 | txg_wait_synced(dmu_objset_pool(os), 0); |
2084 | return (0); | |
2085 | } | |
2086 | ||
1de321e6 JX |
2087 | static int |
2088 | dmu_objset_userobjspace_upgrade_cb(objset_t *os) | |
2089 | { | |
2090 | int err = 0; | |
2091 | ||
2092 | if (dmu_objset_userobjspace_present(os)) | |
2093 | return (0); | |
2094 | if (dmu_objset_is_snapshot(os)) | |
2095 | return (SET_ERROR(EINVAL)); | |
2096 | if (!dmu_objset_userobjused_enabled(os)) | |
2097 | return (SET_ERROR(ENOTSUP)); | |
2098 | ||
2099 | dmu_objset_ds(os)->ds_feature_activation_needed[ | |
2100 | SPA_FEATURE_USEROBJ_ACCOUNTING] = B_TRUE; | |
2101 | ||
2102 | err = dmu_objset_space_upgrade(os); | |
2103 | if (err) | |
2104 | return (err); | |
2105 | ||
2106 | os->os_flags |= OBJSET_FLAG_USEROBJACCOUNTING_COMPLETE; | |
2107 | txg_wait_synced(dmu_objset_pool(os), 0); | |
2108 | return (0); | |
2109 | } | |
2110 | ||
2111 | void | |
2112 | dmu_objset_userobjspace_upgrade(objset_t *os) | |
2113 | { | |
2114 | dmu_objset_upgrade(os, dmu_objset_userobjspace_upgrade_cb); | |
2115 | } | |
2116 | ||
126ae9f4 JX |
2117 | boolean_t |
2118 | dmu_objset_userobjspace_upgradable(objset_t *os) | |
2119 | { | |
2120 | return (dmu_objset_type(os) == DMU_OST_ZFS && | |
2121 | !dmu_objset_is_snapshot(os) && | |
2122 | dmu_objset_userobjused_enabled(os) && | |
2123 | !dmu_objset_userobjspace_present(os)); | |
2124 | } | |
2125 | ||
34dc7c2f BB |
2126 | void |
2127 | dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp, | |
2128 | uint64_t *usedobjsp, uint64_t *availobjsp) | |
2129 | { | |
428870ff | 2130 | dsl_dataset_space(os->os_dsl_dataset, refdbytesp, availbytesp, |
34dc7c2f BB |
2131 | usedobjsp, availobjsp); |
2132 | } | |
2133 | ||
2134 | uint64_t | |
2135 | dmu_objset_fsid_guid(objset_t *os) | |
2136 | { | |
428870ff | 2137 | return (dsl_dataset_fsid_guid(os->os_dsl_dataset)); |
34dc7c2f BB |
2138 | } |
2139 | ||
2140 | void | |
2141 | dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat) | |
2142 | { | |
428870ff BB |
2143 | stat->dds_type = os->os_phys->os_type; |
2144 | if (os->os_dsl_dataset) | |
2145 | dsl_dataset_fast_stat(os->os_dsl_dataset, stat); | |
34dc7c2f BB |
2146 | } |
2147 | ||
2148 | void | |
2149 | dmu_objset_stats(objset_t *os, nvlist_t *nv) | |
2150 | { | |
428870ff BB |
2151 | ASSERT(os->os_dsl_dataset || |
2152 | os->os_phys->os_type == DMU_OST_META); | |
34dc7c2f | 2153 | |
428870ff BB |
2154 | if (os->os_dsl_dataset != NULL) |
2155 | dsl_dataset_stats(os->os_dsl_dataset, nv); | |
34dc7c2f BB |
2156 | |
2157 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_TYPE, | |
428870ff | 2158 | os->os_phys->os_type); |
9babb374 BB |
2159 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERACCOUNTING, |
2160 | dmu_objset_userspace_present(os)); | |
34dc7c2f BB |
2161 | } |
2162 | ||
2163 | int | |
2164 | dmu_objset_is_snapshot(objset_t *os) | |
2165 | { | |
428870ff | 2166 | if (os->os_dsl_dataset != NULL) |
0c66c32d | 2167 | return (os->os_dsl_dataset->ds_is_snapshot); |
34dc7c2f BB |
2168 | else |
2169 | return (B_FALSE); | |
2170 | } | |
2171 | ||
2172 | int | |
2173 | dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen, | |
2174 | boolean_t *conflict) | |
2175 | { | |
428870ff | 2176 | dsl_dataset_t *ds = os->os_dsl_dataset; |
34dc7c2f BB |
2177 | uint64_t ignored; |
2178 | ||
d683ddbb | 2179 | if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0) |
2e528b49 | 2180 | return (SET_ERROR(ENOENT)); |
34dc7c2f BB |
2181 | |
2182 | return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset, | |
d683ddbb | 2183 | dsl_dataset_phys(ds)->ds_snapnames_zapobj, name, 8, 1, &ignored, |
9b7b9cd3 | 2184 | MT_NORMALIZE, real, maxlen, conflict)); |
34dc7c2f BB |
2185 | } |
2186 | ||
2187 | int | |
2188 | dmu_snapshot_list_next(objset_t *os, int namelen, char *name, | |
2189 | uint64_t *idp, uint64_t *offp, boolean_t *case_conflict) | |
2190 | { | |
428870ff | 2191 | dsl_dataset_t *ds = os->os_dsl_dataset; |
34dc7c2f BB |
2192 | zap_cursor_t cursor; |
2193 | zap_attribute_t attr; | |
2194 | ||
13fe0198 MA |
2195 | ASSERT(dsl_pool_config_held(dmu_objset_pool(os))); |
2196 | ||
d683ddbb | 2197 | if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0) |
2e528b49 | 2198 | return (SET_ERROR(ENOENT)); |
34dc7c2f BB |
2199 | |
2200 | zap_cursor_init_serialized(&cursor, | |
2201 | ds->ds_dir->dd_pool->dp_meta_objset, | |
d683ddbb | 2202 | dsl_dataset_phys(ds)->ds_snapnames_zapobj, *offp); |
34dc7c2f BB |
2203 | |
2204 | if (zap_cursor_retrieve(&cursor, &attr) != 0) { | |
2205 | zap_cursor_fini(&cursor); | |
2e528b49 | 2206 | return (SET_ERROR(ENOENT)); |
34dc7c2f BB |
2207 | } |
2208 | ||
2209 | if (strlen(attr.za_name) + 1 > namelen) { | |
2210 | zap_cursor_fini(&cursor); | |
2e528b49 | 2211 | return (SET_ERROR(ENAMETOOLONG)); |
34dc7c2f BB |
2212 | } |
2213 | ||
2214 | (void) strcpy(name, attr.za_name); | |
2215 | if (idp) | |
2216 | *idp = attr.za_first_integer; | |
2217 | if (case_conflict) | |
2218 | *case_conflict = attr.za_normalization_conflict; | |
2219 | zap_cursor_advance(&cursor); | |
2220 | *offp = zap_cursor_serialize(&cursor); | |
2221 | zap_cursor_fini(&cursor); | |
2222 | ||
2223 | return (0); | |
2224 | } | |
2225 | ||
ebe7e575 | 2226 | int |
6772fb67 | 2227 | dmu_snapshot_lookup(objset_t *os, const char *name, uint64_t *value) |
ebe7e575 | 2228 | { |
d1d7e268 | 2229 | return (dsl_dataset_snap_lookup(os->os_dsl_dataset, name, value)); |
ebe7e575 BB |
2230 | } |
2231 | ||
34dc7c2f BB |
2232 | int |
2233 | dmu_dir_list_next(objset_t *os, int namelen, char *name, | |
2234 | uint64_t *idp, uint64_t *offp) | |
2235 | { | |
428870ff | 2236 | dsl_dir_t *dd = os->os_dsl_dataset->ds_dir; |
34dc7c2f BB |
2237 | zap_cursor_t cursor; |
2238 | zap_attribute_t attr; | |
2239 | ||
2240 | /* there is no next dir on a snapshot! */ | |
428870ff | 2241 | if (os->os_dsl_dataset->ds_object != |
d683ddbb | 2242 | dsl_dir_phys(dd)->dd_head_dataset_obj) |
2e528b49 | 2243 | return (SET_ERROR(ENOENT)); |
34dc7c2f BB |
2244 | |
2245 | zap_cursor_init_serialized(&cursor, | |
2246 | dd->dd_pool->dp_meta_objset, | |
d683ddbb | 2247 | dsl_dir_phys(dd)->dd_child_dir_zapobj, *offp); |
34dc7c2f BB |
2248 | |
2249 | if (zap_cursor_retrieve(&cursor, &attr) != 0) { | |
2250 | zap_cursor_fini(&cursor); | |
2e528b49 | 2251 | return (SET_ERROR(ENOENT)); |
34dc7c2f BB |
2252 | } |
2253 | ||
2254 | if (strlen(attr.za_name) + 1 > namelen) { | |
2255 | zap_cursor_fini(&cursor); | |
2e528b49 | 2256 | return (SET_ERROR(ENAMETOOLONG)); |
34dc7c2f BB |
2257 | } |
2258 | ||
2259 | (void) strcpy(name, attr.za_name); | |
2260 | if (idp) | |
2261 | *idp = attr.za_first_integer; | |
2262 | zap_cursor_advance(&cursor); | |
2263 | *offp = zap_cursor_serialize(&cursor); | |
2264 | zap_cursor_fini(&cursor); | |
2265 | ||
2266 | return (0); | |
2267 | } | |
2268 | ||
9c43027b AJ |
2269 | typedef struct dmu_objset_find_ctx { |
2270 | taskq_t *dc_tq; | |
2271 | dsl_pool_t *dc_dp; | |
2272 | uint64_t dc_ddobj; | |
1149ba64 | 2273 | char *dc_ddname; /* last component of ddobj's name */ |
9c43027b AJ |
2274 | int (*dc_func)(dsl_pool_t *, dsl_dataset_t *, void *); |
2275 | void *dc_arg; | |
2276 | int dc_flags; | |
2277 | kmutex_t *dc_error_lock; | |
2278 | int *dc_error; | |
2279 | } dmu_objset_find_ctx_t; | |
2280 | ||
2281 | static void | |
2282 | dmu_objset_find_dp_impl(dmu_objset_find_ctx_t *dcp) | |
b128c09f | 2283 | { |
9c43027b | 2284 | dsl_pool_t *dp = dcp->dc_dp; |
13fe0198 MA |
2285 | dsl_dir_t *dd; |
2286 | dsl_dataset_t *ds; | |
2287 | zap_cursor_t zc; | |
2288 | zap_attribute_t *attr; | |
2289 | uint64_t thisobj; | |
9c43027b | 2290 | int err = 0; |
13fe0198 | 2291 | |
9c43027b AJ |
2292 | /* don't process if there already was an error */ |
2293 | if (*dcp->dc_error != 0) | |
2294 | goto out; | |
13fe0198 | 2295 | |
1149ba64 GM |
2296 | /* |
2297 | * Note: passing the name (dc_ddname) here is optional, but it | |
2298 | * improves performance because we don't need to call | |
2299 | * zap_value_search() to determine the name. | |
2300 | */ | |
2301 | err = dsl_dir_hold_obj(dp, dcp->dc_ddobj, dcp->dc_ddname, FTAG, &dd); | |
13fe0198 | 2302 | if (err != 0) |
9c43027b | 2303 | goto out; |
13fe0198 MA |
2304 | |
2305 | /* Don't visit hidden ($MOS & $ORIGIN) objsets. */ | |
2306 | if (dd->dd_myname[0] == '$') { | |
2307 | dsl_dir_rele(dd, FTAG); | |
9c43027b | 2308 | goto out; |
13fe0198 MA |
2309 | } |
2310 | ||
d683ddbb | 2311 | thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj; |
79c76d5b | 2312 | attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP); |
13fe0198 MA |
2313 | |
2314 | /* | |
2315 | * Iterate over all children. | |
2316 | */ | |
9c43027b | 2317 | if (dcp->dc_flags & DS_FIND_CHILDREN) { |
13fe0198 | 2318 | for (zap_cursor_init(&zc, dp->dp_meta_objset, |
d683ddbb | 2319 | dsl_dir_phys(dd)->dd_child_dir_zapobj); |
13fe0198 MA |
2320 | zap_cursor_retrieve(&zc, attr) == 0; |
2321 | (void) zap_cursor_advance(&zc)) { | |
2322 | ASSERT3U(attr->za_integer_length, ==, | |
2323 | sizeof (uint64_t)); | |
2324 | ASSERT3U(attr->za_num_integers, ==, 1); | |
2325 | ||
1c27024e | 2326 | dmu_objset_find_ctx_t *child_dcp = |
1149ba64 | 2327 | kmem_alloc(sizeof (*child_dcp), KM_SLEEP); |
9c43027b AJ |
2328 | *child_dcp = *dcp; |
2329 | child_dcp->dc_ddobj = attr->za_first_integer; | |
1149ba64 | 2330 | child_dcp->dc_ddname = spa_strdup(attr->za_name); |
9c43027b AJ |
2331 | if (dcp->dc_tq != NULL) |
2332 | (void) taskq_dispatch(dcp->dc_tq, | |
2333 | dmu_objset_find_dp_cb, child_dcp, TQ_SLEEP); | |
2334 | else | |
2335 | dmu_objset_find_dp_impl(child_dcp); | |
13fe0198 MA |
2336 | } |
2337 | zap_cursor_fini(&zc); | |
13fe0198 MA |
2338 | } |
2339 | ||
2340 | /* | |
2341 | * Iterate over all snapshots. | |
2342 | */ | |
9c43027b | 2343 | if (dcp->dc_flags & DS_FIND_SNAPSHOTS) { |
13fe0198 MA |
2344 | dsl_dataset_t *ds; |
2345 | err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds); | |
2346 | ||
2347 | if (err == 0) { | |
d683ddbb JG |
2348 | uint64_t snapobj; |
2349 | ||
2350 | snapobj = dsl_dataset_phys(ds)->ds_snapnames_zapobj; | |
13fe0198 MA |
2351 | dsl_dataset_rele(ds, FTAG); |
2352 | ||
2353 | for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj); | |
2354 | zap_cursor_retrieve(&zc, attr) == 0; | |
2355 | (void) zap_cursor_advance(&zc)) { | |
2356 | ASSERT3U(attr->za_integer_length, ==, | |
2357 | sizeof (uint64_t)); | |
2358 | ASSERT3U(attr->za_num_integers, ==, 1); | |
2359 | ||
2360 | err = dsl_dataset_hold_obj(dp, | |
2361 | attr->za_first_integer, FTAG, &ds); | |
2362 | if (err != 0) | |
2363 | break; | |
9c43027b | 2364 | err = dcp->dc_func(dp, ds, dcp->dc_arg); |
13fe0198 MA |
2365 | dsl_dataset_rele(ds, FTAG); |
2366 | if (err != 0) | |
2367 | break; | |
2368 | } | |
2369 | zap_cursor_fini(&zc); | |
2370 | } | |
2371 | } | |
2372 | ||
13fe0198 MA |
2373 | kmem_free(attr, sizeof (zap_attribute_t)); |
2374 | ||
1149ba64 GM |
2375 | if (err != 0) { |
2376 | dsl_dir_rele(dd, FTAG); | |
9c43027b | 2377 | goto out; |
1149ba64 | 2378 | } |
13fe0198 MA |
2379 | |
2380 | /* | |
2381 | * Apply to self. | |
2382 | */ | |
2383 | err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds); | |
1149ba64 GM |
2384 | |
2385 | /* | |
2386 | * Note: we hold the dir while calling dsl_dataset_hold_obj() so | |
2387 | * that the dir will remain cached, and we won't have to re-instantiate | |
2388 | * it (which could be expensive due to finding its name via | |
2389 | * zap_value_search()). | |
2390 | */ | |
2391 | dsl_dir_rele(dd, FTAG); | |
13fe0198 | 2392 | if (err != 0) |
9c43027b AJ |
2393 | goto out; |
2394 | err = dcp->dc_func(dp, ds, dcp->dc_arg); | |
13fe0198 | 2395 | dsl_dataset_rele(ds, FTAG); |
9c43027b AJ |
2396 | |
2397 | out: | |
2398 | if (err != 0) { | |
2399 | mutex_enter(dcp->dc_error_lock); | |
2400 | /* only keep first error */ | |
2401 | if (*dcp->dc_error == 0) | |
2402 | *dcp->dc_error = err; | |
2403 | mutex_exit(dcp->dc_error_lock); | |
2404 | } | |
2405 | ||
1149ba64 GM |
2406 | if (dcp->dc_ddname != NULL) |
2407 | spa_strfree(dcp->dc_ddname); | |
9c43027b AJ |
2408 | kmem_free(dcp, sizeof (*dcp)); |
2409 | } | |
2410 | ||
2411 | static void | |
2412 | dmu_objset_find_dp_cb(void *arg) | |
2413 | { | |
2414 | dmu_objset_find_ctx_t *dcp = arg; | |
2415 | dsl_pool_t *dp = dcp->dc_dp; | |
2416 | ||
5e8cd5d1 AJ |
2417 | /* |
2418 | * We need to get a pool_config_lock here, as there are several | |
2419 | * asssert(pool_config_held) down the stack. Getting a lock via | |
2420 | * dsl_pool_config_enter is risky, as it might be stalled by a | |
2421 | * pending writer. This would deadlock, as the write lock can | |
2422 | * only be granted when our parent thread gives up the lock. | |
2423 | * The _prio interface gives us priority over a pending writer. | |
2424 | */ | |
2425 | dsl_pool_config_enter_prio(dp, FTAG); | |
9c43027b AJ |
2426 | |
2427 | dmu_objset_find_dp_impl(dcp); | |
2428 | ||
2429 | dsl_pool_config_exit(dp, FTAG); | |
2430 | } | |
2431 | ||
2432 | /* | |
2433 | * Find objsets under and including ddobj, call func(ds) on each. | |
2434 | * The order for the enumeration is completely undefined. | |
2435 | * func is called with dsl_pool_config held. | |
2436 | */ | |
2437 | int | |
2438 | dmu_objset_find_dp(dsl_pool_t *dp, uint64_t ddobj, | |
2439 | int func(dsl_pool_t *, dsl_dataset_t *, void *), void *arg, int flags) | |
2440 | { | |
2441 | int error = 0; | |
2442 | taskq_t *tq = NULL; | |
2443 | int ntasks; | |
2444 | dmu_objset_find_ctx_t *dcp; | |
2445 | kmutex_t err_lock; | |
2446 | ||
2447 | mutex_init(&err_lock, NULL, MUTEX_DEFAULT, NULL); | |
2448 | dcp = kmem_alloc(sizeof (*dcp), KM_SLEEP); | |
2449 | dcp->dc_tq = NULL; | |
2450 | dcp->dc_dp = dp; | |
2451 | dcp->dc_ddobj = ddobj; | |
1149ba64 | 2452 | dcp->dc_ddname = NULL; |
9c43027b AJ |
2453 | dcp->dc_func = func; |
2454 | dcp->dc_arg = arg; | |
2455 | dcp->dc_flags = flags; | |
2456 | dcp->dc_error_lock = &err_lock; | |
2457 | dcp->dc_error = &error; | |
2458 | ||
2459 | if ((flags & DS_FIND_SERIALIZE) || dsl_pool_config_held_writer(dp)) { | |
2460 | /* | |
2461 | * In case a write lock is held we can't make use of | |
2462 | * parallelism, as down the stack of the worker threads | |
2463 | * the lock is asserted via dsl_pool_config_held. | |
2464 | * In case of a read lock this is solved by getting a read | |
2465 | * lock in each worker thread, which isn't possible in case | |
2466 | * of a writer lock. So we fall back to the synchronous path | |
2467 | * here. | |
2468 | * In the future it might be possible to get some magic into | |
2469 | * dsl_pool_config_held in a way that it returns true for | |
2470 | * the worker threads so that a single lock held from this | |
2471 | * thread suffices. For now, stay single threaded. | |
2472 | */ | |
2473 | dmu_objset_find_dp_impl(dcp); | |
e5676636 | 2474 | mutex_destroy(&err_lock); |
9c43027b AJ |
2475 | |
2476 | return (error); | |
2477 | } | |
2478 | ||
2479 | ntasks = dmu_find_threads; | |
2480 | if (ntasks == 0) | |
2481 | ntasks = vdev_count_leaves(dp->dp_spa) * 4; | |
1229323d | 2482 | tq = taskq_create("dmu_objset_find", ntasks, maxclsyspri, ntasks, |
9c43027b AJ |
2483 | INT_MAX, 0); |
2484 | if (tq == NULL) { | |
2485 | kmem_free(dcp, sizeof (*dcp)); | |
e5676636 BB |
2486 | mutex_destroy(&err_lock); |
2487 | ||
9c43027b AJ |
2488 | return (SET_ERROR(ENOMEM)); |
2489 | } | |
2490 | dcp->dc_tq = tq; | |
2491 | ||
2492 | /* dcp will be freed by task */ | |
2493 | (void) taskq_dispatch(tq, dmu_objset_find_dp_cb, dcp, TQ_SLEEP); | |
2494 | ||
2495 | /* | |
2496 | * PORTING: this code relies on the property of taskq_wait to wait | |
2497 | * until no more tasks are queued and no more tasks are active. As | |
2498 | * we always queue new tasks from within other tasks, task_wait | |
2499 | * reliably waits for the full recursion to finish, even though we | |
2500 | * enqueue new tasks after taskq_wait has been called. | |
2501 | * On platforms other than illumos, taskq_wait may not have this | |
2502 | * property. | |
2503 | */ | |
2504 | taskq_wait(tq); | |
2505 | taskq_destroy(tq); | |
2506 | mutex_destroy(&err_lock); | |
2507 | ||
2508 | return (error); | |
b128c09f BB |
2509 | } |
2510 | ||
2511 | /* | |
13fe0198 MA |
2512 | * Find all objsets under name, and for each, call 'func(child_name, arg)'. |
2513 | * The dp_config_rwlock must not be held when this is called, and it | |
2514 | * will not be held when the callback is called. | |
2515 | * Therefore this function should only be used when the pool is not changing | |
2516 | * (e.g. in syncing context), or the callback can deal with the possible races. | |
b128c09f | 2517 | */ |
13fe0198 MA |
2518 | static int |
2519 | dmu_objset_find_impl(spa_t *spa, const char *name, | |
2520 | int func(const char *, void *), void *arg, int flags) | |
34dc7c2f BB |
2521 | { |
2522 | dsl_dir_t *dd; | |
13fe0198 | 2523 | dsl_pool_t *dp = spa_get_dsl(spa); |
b128c09f | 2524 | dsl_dataset_t *ds; |
34dc7c2f BB |
2525 | zap_cursor_t zc; |
2526 | zap_attribute_t *attr; | |
2527 | char *child; | |
b128c09f BB |
2528 | uint64_t thisobj; |
2529 | int err; | |
34dc7c2f | 2530 | |
13fe0198 MA |
2531 | dsl_pool_config_enter(dp, FTAG); |
2532 | ||
2533 | err = dsl_dir_hold(dp, name, FTAG, &dd, NULL); | |
2534 | if (err != 0) { | |
2535 | dsl_pool_config_exit(dp, FTAG); | |
34dc7c2f | 2536 | return (err); |
13fe0198 | 2537 | } |
34dc7c2f | 2538 | |
b128c09f BB |
2539 | /* Don't visit hidden ($MOS & $ORIGIN) objsets. */ |
2540 | if (dd->dd_myname[0] == '$') { | |
13fe0198 MA |
2541 | dsl_dir_rele(dd, FTAG); |
2542 | dsl_pool_config_exit(dp, FTAG); | |
b128c09f BB |
2543 | return (0); |
2544 | } | |
2545 | ||
d683ddbb | 2546 | thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj; |
79c76d5b | 2547 | attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP); |
34dc7c2f BB |
2548 | |
2549 | /* | |
2550 | * Iterate over all children. | |
2551 | */ | |
2552 | if (flags & DS_FIND_CHILDREN) { | |
b128c09f | 2553 | for (zap_cursor_init(&zc, dp->dp_meta_objset, |
d683ddbb | 2554 | dsl_dir_phys(dd)->dd_child_dir_zapobj); |
34dc7c2f BB |
2555 | zap_cursor_retrieve(&zc, attr) == 0; |
2556 | (void) zap_cursor_advance(&zc)) { | |
13fe0198 MA |
2557 | ASSERT3U(attr->za_integer_length, ==, |
2558 | sizeof (uint64_t)); | |
2559 | ASSERT3U(attr->za_num_integers, ==, 1); | |
34dc7c2f | 2560 | |
428870ff | 2561 | child = kmem_asprintf("%s/%s", name, attr->za_name); |
13fe0198 MA |
2562 | dsl_pool_config_exit(dp, FTAG); |
2563 | err = dmu_objset_find_impl(spa, child, | |
2564 | func, arg, flags); | |
2565 | dsl_pool_config_enter(dp, FTAG); | |
428870ff | 2566 | strfree(child); |
13fe0198 | 2567 | if (err != 0) |
34dc7c2f BB |
2568 | break; |
2569 | } | |
2570 | zap_cursor_fini(&zc); | |
2571 | ||
13fe0198 MA |
2572 | if (err != 0) { |
2573 | dsl_dir_rele(dd, FTAG); | |
2574 | dsl_pool_config_exit(dp, FTAG); | |
34dc7c2f BB |
2575 | kmem_free(attr, sizeof (zap_attribute_t)); |
2576 | return (err); | |
2577 | } | |
2578 | } | |
2579 | ||
2580 | /* | |
2581 | * Iterate over all snapshots. | |
2582 | */ | |
b128c09f | 2583 | if (flags & DS_FIND_SNAPSHOTS) { |
b128c09f | 2584 | err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds); |
b128c09f BB |
2585 | |
2586 | if (err == 0) { | |
d683ddbb JG |
2587 | uint64_t snapobj; |
2588 | ||
2589 | snapobj = dsl_dataset_phys(ds)->ds_snapnames_zapobj; | |
b128c09f BB |
2590 | dsl_dataset_rele(ds, FTAG); |
2591 | ||
2592 | for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj); | |
2593 | zap_cursor_retrieve(&zc, attr) == 0; | |
2594 | (void) zap_cursor_advance(&zc)) { | |
13fe0198 | 2595 | ASSERT3U(attr->za_integer_length, ==, |
b128c09f | 2596 | sizeof (uint64_t)); |
13fe0198 | 2597 | ASSERT3U(attr->za_num_integers, ==, 1); |
b128c09f | 2598 | |
428870ff BB |
2599 | child = kmem_asprintf("%s@%s", |
2600 | name, attr->za_name); | |
13fe0198 MA |
2601 | dsl_pool_config_exit(dp, FTAG); |
2602 | err = func(child, arg); | |
2603 | dsl_pool_config_enter(dp, FTAG); | |
428870ff | 2604 | strfree(child); |
13fe0198 | 2605 | if (err != 0) |
b128c09f BB |
2606 | break; |
2607 | } | |
2608 | zap_cursor_fini(&zc); | |
34dc7c2f | 2609 | } |
34dc7c2f BB |
2610 | } |
2611 | ||
13fe0198 | 2612 | dsl_dir_rele(dd, FTAG); |
34dc7c2f | 2613 | kmem_free(attr, sizeof (zap_attribute_t)); |
13fe0198 | 2614 | dsl_pool_config_exit(dp, FTAG); |
34dc7c2f | 2615 | |
13fe0198 | 2616 | if (err != 0) |
34dc7c2f BB |
2617 | return (err); |
2618 | ||
13fe0198 MA |
2619 | /* Apply to self. */ |
2620 | return (func(name, arg)); | |
34dc7c2f BB |
2621 | } |
2622 | ||
13fe0198 MA |
2623 | /* |
2624 | * See comment above dmu_objset_find_impl(). | |
2625 | */ | |
d164b209 | 2626 | int |
13fe0198 MA |
2627 | dmu_objset_find(char *name, int func(const char *, void *), void *arg, |
2628 | int flags) | |
d164b209 | 2629 | { |
13fe0198 MA |
2630 | spa_t *spa; |
2631 | int error; | |
d164b209 | 2632 | |
13fe0198 MA |
2633 | error = spa_open(name, &spa, FTAG); |
2634 | if (error != 0) | |
2635 | return (error); | |
2636 | error = dmu_objset_find_impl(spa, name, func, arg, flags); | |
2637 | spa_close(spa, FTAG); | |
2638 | return (error); | |
d164b209 BB |
2639 | } |
2640 | ||
ae76f45c TC |
2641 | boolean_t |
2642 | dmu_objset_incompatible_encryption_version(objset_t *os) | |
2643 | { | |
2644 | return (dsl_dir_incompatible_encryption_version( | |
2645 | os->os_dsl_dataset->ds_dir)); | |
2646 | } | |
2647 | ||
34dc7c2f BB |
2648 | void |
2649 | dmu_objset_set_user(objset_t *os, void *user_ptr) | |
2650 | { | |
428870ff BB |
2651 | ASSERT(MUTEX_HELD(&os->os_user_ptr_lock)); |
2652 | os->os_user_ptr = user_ptr; | |
34dc7c2f BB |
2653 | } |
2654 | ||
2655 | void * | |
2656 | dmu_objset_get_user(objset_t *os) | |
2657 | { | |
428870ff BB |
2658 | ASSERT(MUTEX_HELD(&os->os_user_ptr_lock)); |
2659 | return (os->os_user_ptr); | |
34dc7c2f | 2660 | } |
c28b2279 | 2661 | |
13fe0198 MA |
2662 | /* |
2663 | * Determine name of filesystem, given name of snapshot. | |
eca7b760 | 2664 | * buf must be at least ZFS_MAX_DATASET_NAME_LEN bytes |
13fe0198 MA |
2665 | */ |
2666 | int | |
2667 | dmu_fsname(const char *snapname, char *buf) | |
2668 | { | |
2669 | char *atp = strchr(snapname, '@'); | |
2670 | if (atp == NULL) | |
2e528b49 | 2671 | return (SET_ERROR(EINVAL)); |
eca7b760 | 2672 | if (atp - snapname >= ZFS_MAX_DATASET_NAME_LEN) |
2e528b49 | 2673 | return (SET_ERROR(ENAMETOOLONG)); |
13fe0198 MA |
2674 | (void) strlcpy(buf, snapname, atp - snapname + 1); |
2675 | return (0); | |
2676 | } | |
2677 | ||
3ec3bc21 BB |
2678 | /* |
2679 | * Call when we think we're going to write/free space in open context to track | |
2680 | * the amount of dirty data in the open txg, which is also the amount | |
2681 | * of memory that can not be evicted until this txg syncs. | |
2682 | */ | |
2683 | void | |
2684 | dmu_objset_willuse_space(objset_t *os, int64_t space, dmu_tx_t *tx) | |
2685 | { | |
2686 | dsl_dataset_t *ds = os->os_dsl_dataset; | |
2687 | int64_t aspace = spa_get_worst_case_asize(os->os_spa, space); | |
2688 | ||
2689 | if (ds != NULL) { | |
2690 | dsl_dir_willuse_space(ds->ds_dir, aspace, tx); | |
2691 | dsl_pool_dirty_space(dmu_tx_pool(tx), space, tx); | |
2692 | } | |
2693 | } | |
2694 | ||
c28b2279 | 2695 | #if defined(_KERNEL) && defined(HAVE_SPL) |
f0fd83be | 2696 | EXPORT_SYMBOL(dmu_objset_zil); |
c28b2279 | 2697 | EXPORT_SYMBOL(dmu_objset_pool); |
f0fd83be BB |
2698 | EXPORT_SYMBOL(dmu_objset_ds); |
2699 | EXPORT_SYMBOL(dmu_objset_type); | |
c28b2279 BB |
2700 | EXPORT_SYMBOL(dmu_objset_name); |
2701 | EXPORT_SYMBOL(dmu_objset_hold); | |
b5256303 | 2702 | EXPORT_SYMBOL(dmu_objset_hold_flags); |
c28b2279 BB |
2703 | EXPORT_SYMBOL(dmu_objset_own); |
2704 | EXPORT_SYMBOL(dmu_objset_rele); | |
b5256303 | 2705 | EXPORT_SYMBOL(dmu_objset_rele_flags); |
c28b2279 BB |
2706 | EXPORT_SYMBOL(dmu_objset_disown); |
2707 | EXPORT_SYMBOL(dmu_objset_from_ds); | |
2708 | EXPORT_SYMBOL(dmu_objset_create); | |
2709 | EXPORT_SYMBOL(dmu_objset_clone); | |
c28b2279 BB |
2710 | EXPORT_SYMBOL(dmu_objset_stats); |
2711 | EXPORT_SYMBOL(dmu_objset_fast_stat); | |
54a179e7 | 2712 | EXPORT_SYMBOL(dmu_objset_spa); |
c28b2279 BB |
2713 | EXPORT_SYMBOL(dmu_objset_space); |
2714 | EXPORT_SYMBOL(dmu_objset_fsid_guid); | |
2715 | EXPORT_SYMBOL(dmu_objset_find); | |
c28b2279 BB |
2716 | EXPORT_SYMBOL(dmu_objset_byteswap); |
2717 | EXPORT_SYMBOL(dmu_objset_evict_dbufs); | |
2718 | EXPORT_SYMBOL(dmu_objset_snap_cmtime); | |
50c957f7 | 2719 | EXPORT_SYMBOL(dmu_objset_dnodesize); |
c28b2279 BB |
2720 | |
2721 | EXPORT_SYMBOL(dmu_objset_sync); | |
2722 | EXPORT_SYMBOL(dmu_objset_is_dirty); | |
b5256303 | 2723 | EXPORT_SYMBOL(dmu_objset_create_impl_dnstats); |
c28b2279 BB |
2724 | EXPORT_SYMBOL(dmu_objset_create_impl); |
2725 | EXPORT_SYMBOL(dmu_objset_open_impl); | |
2726 | EXPORT_SYMBOL(dmu_objset_evict); | |
2727 | EXPORT_SYMBOL(dmu_objset_register_type); | |
2728 | EXPORT_SYMBOL(dmu_objset_do_userquota_updates); | |
2729 | EXPORT_SYMBOL(dmu_objset_userquota_get_ids); | |
2730 | EXPORT_SYMBOL(dmu_objset_userused_enabled); | |
2731 | EXPORT_SYMBOL(dmu_objset_userspace_upgrade); | |
2732 | EXPORT_SYMBOL(dmu_objset_userspace_present); | |
1de321e6 JX |
2733 | EXPORT_SYMBOL(dmu_objset_userobjused_enabled); |
2734 | EXPORT_SYMBOL(dmu_objset_userobjspace_upgrade); | |
126ae9f4 | 2735 | EXPORT_SYMBOL(dmu_objset_userobjspace_upgradable); |
1de321e6 | 2736 | EXPORT_SYMBOL(dmu_objset_userobjspace_present); |
c28b2279 | 2737 | #endif |