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