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