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.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Portions Copyright 2010 Robert Milkowski */
28 #include <sys/zfs_context.h>
29 #include <sys/dmu_objset.h>
30 #include <sys/dsl_dir.h>
31 #include <sys/dsl_dataset.h>
32 #include <sys/dsl_prop.h>
33 #include <sys/dsl_pool.h>
34 #include <sys/dsl_synctask.h>
35 #include <sys/dsl_deleg.h>
36 #include <sys/dnode.h>
39 #include <sys/dmu_tx.h>
42 #include <sys/dmu_impl.h>
43 #include <sys/zfs_ioctl.h>
44 #include <sys/sunddi.h>
48 dmu_objset_spa(objset_t *os)
54 dmu_objset_zil(objset_t *os)
60 dmu_objset_pool(objset_t *os)
64 if ((ds = os->os_dsl_dataset) != NULL && ds->ds_dir)
65 return (ds->ds_dir->dd_pool);
67 return (spa_get_dsl(os->os_spa));
71 dmu_objset_ds(objset_t *os)
73 return (os->os_dsl_dataset);
77 dmu_objset_type(objset_t *os)
79 return (os->os_phys->os_type);
83 dmu_objset_name(objset_t *os, char *buf)
85 dsl_dataset_name(os->os_dsl_dataset, buf);
89 dmu_objset_id(objset_t *os)
91 dsl_dataset_t *ds = os->os_dsl_dataset;
93 return (ds ? ds->ds_object : 0);
97 dmu_objset_syncprop(objset_t *os)
103 dmu_objset_logbias(objset_t *os)
105 return (os->os_logbias);
109 checksum_changed_cb(void *arg, uint64_t newval)
114 * Inheritance should have been done by now.
116 ASSERT(newval != ZIO_CHECKSUM_INHERIT);
118 os->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE);
122 compression_changed_cb(void *arg, uint64_t newval)
127 * Inheritance and range checking should have been done by now.
129 ASSERT(newval != ZIO_COMPRESS_INHERIT);
131 os->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE);
135 copies_changed_cb(void *arg, uint64_t newval)
140 * Inheritance and range checking should have been done by now.
143 ASSERT(newval <= spa_max_replication(os->os_spa));
145 os->os_copies = newval;
149 dedup_changed_cb(void *arg, uint64_t newval)
152 spa_t *spa = os->os_spa;
153 enum zio_checksum checksum;
156 * Inheritance should have been done by now.
158 ASSERT(newval != ZIO_CHECKSUM_INHERIT);
160 checksum = zio_checksum_dedup_select(spa, newval, ZIO_CHECKSUM_OFF);
162 os->os_dedup_checksum = checksum & ZIO_CHECKSUM_MASK;
163 os->os_dedup_verify = !!(checksum & ZIO_CHECKSUM_VERIFY);
167 primary_cache_changed_cb(void *arg, uint64_t newval)
172 * Inheritance and range checking should have been done by now.
174 ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
175 newval == ZFS_CACHE_METADATA);
177 os->os_primary_cache = newval;
181 secondary_cache_changed_cb(void *arg, uint64_t newval)
186 * Inheritance and range checking should have been done by now.
188 ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
189 newval == ZFS_CACHE_METADATA);
191 os->os_secondary_cache = newval;
195 sync_changed_cb(void *arg, uint64_t newval)
200 * Inheritance and range checking should have been done by now.
202 ASSERT(newval == ZFS_SYNC_STANDARD || newval == ZFS_SYNC_ALWAYS ||
203 newval == ZFS_SYNC_DISABLED);
205 os->os_sync = newval;
207 zil_set_sync(os->os_zil, newval);
211 logbias_changed_cb(void *arg, uint64_t newval)
215 ASSERT(newval == ZFS_LOGBIAS_LATENCY ||
216 newval == ZFS_LOGBIAS_THROUGHPUT);
217 os->os_logbias = newval;
219 zil_set_logbias(os->os_zil, newval);
223 dmu_objset_byteswap(void *buf, size_t size)
225 objset_phys_t *osp = buf;
227 ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t));
228 dnode_byteswap(&osp->os_meta_dnode);
229 byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
230 osp->os_type = BSWAP_64(osp->os_type);
231 osp->os_flags = BSWAP_64(osp->os_flags);
232 if (size == sizeof (objset_phys_t)) {
233 dnode_byteswap(&osp->os_userused_dnode);
234 dnode_byteswap(&osp->os_groupused_dnode);
239 dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
245 ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock));
247 os = kmem_zalloc(sizeof (objset_t), KM_SLEEP);
248 os->os_dsl_dataset = ds;
251 if (!BP_IS_HOLE(os->os_rootbp)) {
252 uint32_t aflags = ARC_WAIT;
254 SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET,
255 ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
257 if (DMU_OS_IS_L2CACHEABLE(os))
258 aflags |= ARC_L2CACHE;
260 dprintf_bp(os->os_rootbp, "reading %s", "");
262 * XXX when bprewrite scrub can change the bp,
263 * and this is called from dmu_objset_open_ds_os, the bp
264 * could change, and we'll need a lock.
266 err = dsl_read_nolock(NULL, spa, os->os_rootbp,
267 arc_getbuf_func, &os->os_phys_buf,
268 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb);
270 kmem_free(os, sizeof (objset_t));
271 /* convert checksum errors into IO errors */
277 /* Increase the blocksize if we are permitted. */
278 if (spa_version(spa) >= SPA_VERSION_USERSPACE &&
279 arc_buf_size(os->os_phys_buf) < sizeof (objset_phys_t)) {
280 arc_buf_t *buf = arc_buf_alloc(spa,
281 sizeof (objset_phys_t), &os->os_phys_buf,
283 bzero(buf->b_data, sizeof (objset_phys_t));
284 bcopy(os->os_phys_buf->b_data, buf->b_data,
285 arc_buf_size(os->os_phys_buf));
286 (void) arc_buf_remove_ref(os->os_phys_buf,
288 os->os_phys_buf = buf;
291 os->os_phys = os->os_phys_buf->b_data;
292 os->os_flags = os->os_phys->os_flags;
294 int size = spa_version(spa) >= SPA_VERSION_USERSPACE ?
295 sizeof (objset_phys_t) : OBJSET_OLD_PHYS_SIZE;
296 os->os_phys_buf = arc_buf_alloc(spa, size,
297 &os->os_phys_buf, ARC_BUFC_METADATA);
298 os->os_phys = os->os_phys_buf->b_data;
299 bzero(os->os_phys, size);
303 * Note: the changed_cb will be called once before the register
304 * func returns, thus changing the checksum/compression from the
305 * default (fletcher2/off). Snapshots don't need to know about
306 * checksum/compression/copies.
309 err = dsl_prop_register(ds, "primarycache",
310 primary_cache_changed_cb, os);
312 err = dsl_prop_register(ds, "secondarycache",
313 secondary_cache_changed_cb, os);
314 if (!dsl_dataset_is_snapshot(ds)) {
316 err = dsl_prop_register(ds, "checksum",
317 checksum_changed_cb, os);
319 err = dsl_prop_register(ds, "compression",
320 compression_changed_cb, os);
322 err = dsl_prop_register(ds, "copies",
323 copies_changed_cb, os);
325 err = dsl_prop_register(ds, "dedup",
326 dedup_changed_cb, os);
328 err = dsl_prop_register(ds, "logbias",
329 logbias_changed_cb, os);
331 err = dsl_prop_register(ds, "sync",
332 sync_changed_cb, os);
335 VERIFY(arc_buf_remove_ref(os->os_phys_buf,
336 &os->os_phys_buf) == 1);
337 kmem_free(os, sizeof (objset_t));
340 } else if (ds == NULL) {
341 /* It's the meta-objset. */
342 os->os_checksum = ZIO_CHECKSUM_FLETCHER_4;
343 os->os_compress = ZIO_COMPRESS_LZJB;
344 os->os_copies = spa_max_replication(spa);
345 os->os_dedup_checksum = ZIO_CHECKSUM_OFF;
346 os->os_dedup_verify = 0;
349 os->os_primary_cache = ZFS_CACHE_ALL;
350 os->os_secondary_cache = ZFS_CACHE_ALL;
353 os->os_zil_header = os->os_phys->os_zil_header;
354 os->os_zil = zil_alloc(os, &os->os_zil_header);
356 for (i = 0; i < TXG_SIZE; i++) {
357 list_create(&os->os_dirty_dnodes[i], sizeof (dnode_t),
358 offsetof(dnode_t, dn_dirty_link[i]));
359 list_create(&os->os_free_dnodes[i], sizeof (dnode_t),
360 offsetof(dnode_t, dn_dirty_link[i]));
362 list_create(&os->os_dnodes, sizeof (dnode_t),
363 offsetof(dnode_t, dn_link));
364 list_create(&os->os_downgraded_dbufs, sizeof (dmu_buf_impl_t),
365 offsetof(dmu_buf_impl_t, db_link));
367 mutex_init(&os->os_lock, NULL, MUTEX_DEFAULT, NULL);
368 mutex_init(&os->os_obj_lock, NULL, MUTEX_DEFAULT, NULL);
369 mutex_init(&os->os_user_ptr_lock, NULL, MUTEX_DEFAULT, NULL);
371 os->os_meta_dnode = dnode_special_open(os,
372 &os->os_phys->os_meta_dnode, DMU_META_DNODE_OBJECT);
373 if (arc_buf_size(os->os_phys_buf) >= sizeof (objset_phys_t)) {
374 os->os_userused_dnode = dnode_special_open(os,
375 &os->os_phys->os_userused_dnode, DMU_USERUSED_OBJECT);
376 os->os_groupused_dnode = dnode_special_open(os,
377 &os->os_phys->os_groupused_dnode, DMU_GROUPUSED_OBJECT);
381 * We should be the only thread trying to do this because we
382 * have ds_opening_lock
385 mutex_enter(&ds->ds_lock);
386 ASSERT(ds->ds_objset == NULL);
388 mutex_exit(&ds->ds_lock);
396 dmu_objset_from_ds(dsl_dataset_t *ds, objset_t **osp)
400 mutex_enter(&ds->ds_opening_lock);
401 *osp = ds->ds_objset;
403 err = dmu_objset_open_impl(dsl_dataset_get_spa(ds),
404 ds, &ds->ds_phys->ds_bp, osp);
406 mutex_exit(&ds->ds_opening_lock);
410 /* called from zpl */
412 dmu_objset_hold(const char *name, void *tag, objset_t **osp)
417 err = dsl_dataset_hold(name, tag, &ds);
421 err = dmu_objset_from_ds(ds, osp);
423 dsl_dataset_rele(ds, tag);
428 /* called from zpl */
430 dmu_objset_own(const char *name, dmu_objset_type_t type,
431 boolean_t readonly, void *tag, objset_t **osp)
436 err = dsl_dataset_own(name, B_FALSE, tag, &ds);
440 err = dmu_objset_from_ds(ds, osp);
442 dsl_dataset_disown(ds, tag);
443 } else if (type != DMU_OST_ANY && type != (*osp)->os_phys->os_type) {
444 dmu_objset_disown(*osp, tag);
446 } else if (!readonly && dsl_dataset_is_snapshot(ds)) {
447 dmu_objset_disown(*osp, tag);
454 dmu_objset_rele(objset_t *os, void *tag)
456 dsl_dataset_rele(os->os_dsl_dataset, tag);
460 dmu_objset_disown(objset_t *os, void *tag)
462 dsl_dataset_disown(os->os_dsl_dataset, tag);
466 dmu_objset_evict_dbufs(objset_t *os)
470 mutex_enter(&os->os_lock);
472 /* process the mdn last, since the other dnodes have holds on it */
473 list_remove(&os->os_dnodes, os->os_meta_dnode);
474 list_insert_tail(&os->os_dnodes, os->os_meta_dnode);
477 * Find the first dnode with holds. We have to do this dance
478 * because dnode_add_ref() only works if you already have a
479 * hold. If there are no holds then it has no dbufs so OK to
482 for (dn = list_head(&os->os_dnodes);
483 dn && !dnode_add_ref(dn, FTAG);
484 dn = list_next(&os->os_dnodes, dn))
488 dnode_t *next_dn = dn;
491 next_dn = list_next(&os->os_dnodes, next_dn);
492 } while (next_dn && !dnode_add_ref(next_dn, FTAG));
494 mutex_exit(&os->os_lock);
495 dnode_evict_dbufs(dn);
496 dnode_rele(dn, FTAG);
497 mutex_enter(&os->os_lock);
500 mutex_exit(&os->os_lock);
501 return (list_head(&os->os_dnodes) != os->os_meta_dnode);
505 dmu_objset_evict(objset_t *os)
507 dsl_dataset_t *ds = os->os_dsl_dataset;
509 for (int t = 0; t < TXG_SIZE; t++)
510 ASSERT(!dmu_objset_is_dirty(os, t));
513 if (!dsl_dataset_is_snapshot(ds)) {
514 VERIFY(0 == dsl_prop_unregister(ds, "checksum",
515 checksum_changed_cb, os));
516 VERIFY(0 == dsl_prop_unregister(ds, "compression",
517 compression_changed_cb, os));
518 VERIFY(0 == dsl_prop_unregister(ds, "copies",
519 copies_changed_cb, os));
520 VERIFY(0 == dsl_prop_unregister(ds, "dedup",
521 dedup_changed_cb, os));
522 VERIFY(0 == dsl_prop_unregister(ds, "logbias",
523 logbias_changed_cb, os));
524 VERIFY(0 == dsl_prop_unregister(ds, "sync",
525 sync_changed_cb, os));
527 VERIFY(0 == dsl_prop_unregister(ds, "primarycache",
528 primary_cache_changed_cb, os));
529 VERIFY(0 == dsl_prop_unregister(ds, "secondarycache",
530 secondary_cache_changed_cb, os));
537 * We should need only a single pass over the dnode list, since
538 * nothing can be added to the list at this point.
540 (void) dmu_objset_evict_dbufs(os);
542 dnode_special_close(os->os_meta_dnode);
543 if (os->os_userused_dnode) {
544 dnode_special_close(os->os_userused_dnode);
545 dnode_special_close(os->os_groupused_dnode);
547 zil_free(os->os_zil);
549 ASSERT3P(list_head(&os->os_dnodes), ==, NULL);
551 VERIFY(arc_buf_remove_ref(os->os_phys_buf, &os->os_phys_buf) == 1);
552 mutex_destroy(&os->os_lock);
553 mutex_destroy(&os->os_obj_lock);
554 mutex_destroy(&os->os_user_ptr_lock);
555 kmem_free(os, sizeof (objset_t));
559 dmu_objset_snap_cmtime(objset_t *os)
561 return (dsl_dir_snap_cmtime(os->os_dsl_dataset->ds_dir));
564 /* called from dsl for meta-objset */
566 dmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
567 dmu_objset_type_t type, dmu_tx_t *tx)
572 ASSERT(dmu_tx_is_syncing(tx));
574 mutex_enter(&ds->ds_opening_lock);
575 VERIFY(0 == dmu_objset_open_impl(spa, ds, bp, &os));
577 mutex_exit(&ds->ds_opening_lock);
578 mdn = os->os_meta_dnode;
580 dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT,
581 DN_MAX_INDBLKSHIFT, DMU_OT_NONE, 0, tx);
584 * We don't want to have to increase the meta-dnode's nlevels
585 * later, because then we could do it in quescing context while
586 * we are also accessing it in open context.
588 * This precaution is not necessary for the MOS (ds == NULL),
589 * because the MOS is only updated in syncing context.
590 * This is most fortunate: the MOS is the only objset that
591 * needs to be synced multiple times as spa_sync() iterates
592 * to convergence, so minimizing its dn_nlevels matters.
598 * Determine the number of levels necessary for the meta-dnode
599 * to contain DN_MAX_OBJECT dnodes.
601 while ((uint64_t)mdn->dn_nblkptr << (mdn->dn_datablkshift +
602 (levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) <
603 DN_MAX_OBJECT * sizeof (dnode_phys_t))
606 mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] =
607 mdn->dn_nlevels = levels;
610 ASSERT(type != DMU_OST_NONE);
611 ASSERT(type != DMU_OST_ANY);
612 ASSERT(type < DMU_OST_NUMTYPES);
613 os->os_phys->os_type = type;
614 if (dmu_objset_userused_enabled(os)) {
615 os->os_phys->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
616 os->os_flags = os->os_phys->os_flags;
619 dsl_dataset_dirty(ds, tx);
625 void (*userfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
627 dsl_dataset_t *clone_origin;
628 const char *lastname;
629 dmu_objset_type_t type;
636 dmu_objset_create_check(void *arg1, void *arg2, dmu_tx_t *tx)
638 dsl_dir_t *dd = arg1;
639 struct oscarg *oa = arg2;
640 objset_t *mos = dd->dd_pool->dp_meta_objset;
644 err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj,
645 oa->lastname, sizeof (uint64_t), 1, &ddobj);
647 return (err ? err : EEXIST);
649 if (oa->clone_origin != NULL) {
650 /* You can't clone across pools. */
651 if (oa->clone_origin->ds_dir->dd_pool != dd->dd_pool)
654 /* You can only clone snapshots, not the head datasets. */
655 if (!dsl_dataset_is_snapshot(oa->clone_origin))
663 dmu_objset_create_sync(void *arg1, void *arg2, dmu_tx_t *tx)
665 dsl_dir_t *dd = arg1;
666 struct oscarg *oa = arg2;
669 ASSERT(dmu_tx_is_syncing(tx));
671 dsobj = dsl_dataset_create_sync(dd, oa->lastname,
672 oa->clone_origin, oa->flags, oa->cr, tx);
674 if (oa->clone_origin == NULL) {
679 VERIFY(0 == dsl_dataset_hold_obj(dd->dd_pool, dsobj,
681 bp = dsl_dataset_get_blkptr(ds);
682 ASSERT(BP_IS_HOLE(bp));
684 os = dmu_objset_create_impl(dsl_dataset_get_spa(ds),
685 ds, bp, oa->type, tx);
688 oa->userfunc(os, oa->userarg, oa->cr, tx);
689 dsl_dataset_rele(ds, FTAG);
692 spa_history_log_internal(LOG_DS_CREATE, dd->dd_pool->dp_spa,
693 tx, "dataset = %llu", dsobj);
697 dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
698 void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg)
703 struct oscarg oa = { 0 };
705 ASSERT(strchr(name, '@') == NULL);
706 err = dsl_dir_open(name, FTAG, &pdd, &tail);
710 dsl_dir_close(pdd, FTAG);
721 err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
722 dmu_objset_create_sync, pdd, &oa, 5);
723 dsl_dir_close(pdd, FTAG);
728 dmu_objset_clone(const char *name, dsl_dataset_t *clone_origin, uint64_t flags)
733 struct oscarg oa = { 0 };
735 ASSERT(strchr(name, '@') == NULL);
736 err = dsl_dir_open(name, FTAG, &pdd, &tail);
740 dsl_dir_close(pdd, FTAG);
745 oa.clone_origin = clone_origin;
749 err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
750 dmu_objset_create_sync, pdd, &oa, 5);
751 dsl_dir_close(pdd, FTAG);
756 dmu_objset_destroy(const char *name, boolean_t defer)
762 * dsl_dataset_destroy() can free any claimed-but-unplayed
763 * intent log, but if there is an active log, it has blocks that
764 * are allocated, but may not yet be reflected in the on-disk
765 * structure. Only the ZIL knows how to free them, so we have
766 * to call into it here.
768 error = dsl_dataset_own(name, B_TRUE, FTAG, &ds);
771 if (dmu_objset_from_ds(ds, &os) == 0)
772 zil_destroy(dmu_objset_zil(os), B_FALSE);
773 error = dsl_dataset_destroy(ds, FTAG, defer);
774 /* dsl_dataset_destroy() closes the ds. */
781 dsl_sync_task_group_t *dstg;
783 char failed[MAXPATHLEN];
789 snapshot_check(void *arg1, void *arg2, dmu_tx_t *tx)
792 struct snaparg *sn = arg2;
794 /* The props have already been checked by zfs_check_userprops(). */
796 return (dsl_dataset_snapshot_check(os->os_dsl_dataset,
801 snapshot_sync(void *arg1, void *arg2, dmu_tx_t *tx)
804 dsl_dataset_t *ds = os->os_dsl_dataset;
805 struct snaparg *sn = arg2;
807 dsl_dataset_snapshot_sync(ds, sn->snapname, tx);
811 pa.pa_props = sn->props;
812 pa.pa_source = ZPROP_SRC_LOCAL;
813 dsl_props_set_sync(ds->ds_prev, &pa, tx);
818 dmu_objset_snapshot_one(const char *name, void *arg)
820 struct snaparg *sn = arg;
826 * If the objset starts with a '%', then ignore it unless it was
827 * explicitly named (ie, not recursive). These hidden datasets
828 * are always inconsistent, and by not opening them here, we can
829 * avoid a race with dsl_dir_destroy_check().
831 cp = strrchr(name, '/');
832 if (cp && cp[1] == '%' && sn->recursive)
835 (void) strcpy(sn->failed, name);
838 * Check permissions if we are doing a recursive snapshot. The
839 * permission checks for the starting dataset have already been
840 * performed in zfs_secpolicy_snapshot()
842 if (sn->recursive && (err = zfs_secpolicy_snapshot_perms(name, CRED())))
845 err = dmu_objset_hold(name, sn, &os);
850 * If the objset is in an inconsistent state (eg, in the process
851 * of being destroyed), don't snapshot it. As with %hidden
852 * datasets, we return EBUSY if this name was explicitly
853 * requested (ie, not recursive), and otherwise ignore it.
855 if (os->os_dsl_dataset->ds_phys->ds_flags & DS_FLAG_INCONSISTENT) {
856 dmu_objset_rele(os, sn);
857 return (sn->recursive ? 0 : EBUSY);
861 * NB: we need to wait for all in-flight changes to get to disk,
862 * so that we snapshot those changes. zil_suspend does this as
865 err = zil_suspend(dmu_objset_zil(os));
867 dsl_sync_task_create(sn->dstg, snapshot_check,
868 snapshot_sync, os, sn, 3);
870 dmu_objset_rele(os, sn);
877 dmu_objset_snapshot(char *fsname, char *snapname,
878 nvlist_t *props, boolean_t recursive)
880 dsl_sync_task_t *dst;
885 (void) strcpy(sn.failed, fsname);
887 err = spa_open(fsname, &spa, FTAG);
891 sn.dstg = dsl_sync_task_group_create(spa_get_dsl(spa));
892 sn.snapname = snapname;
894 sn.recursive = recursive;
897 err = dmu_objset_find(fsname,
898 dmu_objset_snapshot_one, &sn, DS_FIND_CHILDREN);
900 err = dmu_objset_snapshot_one(fsname, &sn);
904 err = dsl_sync_task_group_wait(sn.dstg);
906 for (dst = list_head(&sn.dstg->dstg_tasks); dst;
907 dst = list_next(&sn.dstg->dstg_tasks, dst)) {
908 objset_t *os = dst->dst_arg1;
909 dsl_dataset_t *ds = os->os_dsl_dataset;
911 dsl_dataset_name(ds, sn.failed);
912 zil_resume(dmu_objset_zil(os));
913 dmu_objset_rele(os, &sn);
917 (void) strcpy(fsname, sn.failed);
918 dsl_sync_task_group_destroy(sn.dstg);
919 spa_close(spa, FTAG);
924 dmu_objset_sync_dnodes(list_t *list, list_t *newlist, dmu_tx_t *tx)
928 while (dn = list_head(list)) {
929 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
930 ASSERT(dn->dn_dbuf->db_data_pending);
932 * Initialize dn_zio outside dnode_sync() because the
933 * meta-dnode needs to set it ouside dnode_sync().
935 dn->dn_zio = dn->dn_dbuf->db_data_pending->dr_zio;
938 ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS);
939 list_remove(list, dn);
942 (void) dnode_add_ref(dn, newlist);
943 list_insert_tail(newlist, dn);
952 dmu_objset_write_ready(zio_t *zio, arc_buf_t *abuf, void *arg)
954 blkptr_t *bp = zio->io_bp;
956 dnode_phys_t *dnp = &os->os_phys->os_meta_dnode;
958 ASSERT(bp == os->os_rootbp);
959 ASSERT(BP_GET_TYPE(bp) == DMU_OT_OBJSET);
960 ASSERT(BP_GET_LEVEL(bp) == 0);
963 * Update rootbp fill count: it should be the number of objects
964 * allocated in the object set (not counting the "special"
965 * objects that are stored in the objset_phys_t -- the meta
966 * dnode and user/group accounting objects).
969 for (int i = 0; i < dnp->dn_nblkptr; i++)
970 bp->blk_fill += dnp->dn_blkptr[i].blk_fill;
975 dmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg)
977 blkptr_t *bp = zio->io_bp;
978 blkptr_t *bp_orig = &zio->io_bp_orig;
981 if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {
982 ASSERT(BP_EQUAL(bp, bp_orig));
984 dsl_dataset_t *ds = os->os_dsl_dataset;
985 dmu_tx_t *tx = os->os_synctx;
987 (void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE);
988 dsl_dataset_block_born(ds, bp, tx);
992 /* called from dsl */
994 dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx)
1001 list_t *newlist = NULL;
1002 dbuf_dirty_record_t *dr;
1004 dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg);
1006 ASSERT(dmu_tx_is_syncing(tx));
1007 /* XXX the write_done callback should really give us the tx... */
1010 if (os->os_dsl_dataset == NULL) {
1012 * This is the MOS. If we have upgraded,
1013 * spa_max_replication() could change, so reset
1016 os->os_copies = spa_max_replication(os->os_spa);
1020 * Create the root block IO
1022 SET_BOOKMARK(&zb, os->os_dsl_dataset ?
1023 os->os_dsl_dataset->ds_object : DMU_META_OBJSET,
1024 ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
1025 VERIFY3U(0, ==, arc_release_bp(os->os_phys_buf, &os->os_phys_buf,
1026 os->os_rootbp, os->os_spa, &zb));
1028 dmu_write_policy(os, NULL, 0, 0, &zp);
1030 zio = arc_write(pio, os->os_spa, tx->tx_txg,
1031 os->os_rootbp, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os), &zp,
1032 dmu_objset_write_ready, dmu_objset_write_done, os,
1033 ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb);
1036 * Sync special dnodes - the parent IO for the sync is the root block
1038 os->os_meta_dnode->dn_zio = zio;
1039 dnode_sync(os->os_meta_dnode, tx);
1041 os->os_phys->os_flags = os->os_flags;
1043 if (os->os_userused_dnode &&
1044 os->os_userused_dnode->dn_type != DMU_OT_NONE) {
1045 os->os_userused_dnode->dn_zio = zio;
1046 dnode_sync(os->os_userused_dnode, tx);
1047 os->os_groupused_dnode->dn_zio = zio;
1048 dnode_sync(os->os_groupused_dnode, tx);
1051 txgoff = tx->tx_txg & TXG_MASK;
1053 if (dmu_objset_userused_enabled(os)) {
1054 newlist = &os->os_synced_dnodes;
1056 * We must create the list here because it uses the
1057 * dn_dirty_link[] of this txg.
1059 list_create(newlist, sizeof (dnode_t),
1060 offsetof(dnode_t, dn_dirty_link[txgoff]));
1063 dmu_objset_sync_dnodes(&os->os_free_dnodes[txgoff], newlist, tx);
1064 dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], newlist, tx);
1066 list = &os->os_meta_dnode->dn_dirty_records[txgoff];
1067 while (dr = list_head(list)) {
1068 ASSERT(dr->dr_dbuf->db_level == 0);
1069 list_remove(list, dr);
1071 zio_nowait(dr->dr_zio);
1074 * Free intent log blocks up to this tx.
1076 zil_sync(os->os_zil, tx);
1077 os->os_phys->os_zil_header = os->os_zil_header;
1082 dmu_objset_is_dirty(objset_t *os, uint64_t txg)
1084 return (!list_is_empty(&os->os_dirty_dnodes[txg & TXG_MASK]) ||
1085 !list_is_empty(&os->os_free_dnodes[txg & TXG_MASK]));
1088 objset_used_cb_t *used_cbs[DMU_OST_NUMTYPES];
1091 dmu_objset_register_type(dmu_objset_type_t ost, objset_used_cb_t *cb)
1097 dmu_objset_userused_enabled(objset_t *os)
1099 return (spa_version(os->os_spa) >= SPA_VERSION_USERSPACE &&
1100 used_cbs[os->os_phys->os_type] &&
1101 os->os_userused_dnode);
1105 do_userquota_update(objset_t *os, uint64_t used, uint64_t flags,
1106 uint64_t user, uint64_t group, boolean_t subtract, dmu_tx_t *tx)
1108 if ((flags & DNODE_FLAG_USERUSED_ACCOUNTED)) {
1109 int64_t delta = DNODE_SIZE + used;
1112 VERIFY3U(0, ==, zap_increment_int(os, DMU_USERUSED_OBJECT,
1114 VERIFY3U(0, ==, zap_increment_int(os, DMU_GROUPUSED_OBJECT,
1120 dmu_objset_do_userquota_updates(objset_t *os, dmu_tx_t *tx)
1123 list_t *list = &os->os_synced_dnodes;
1125 ASSERT(list_head(list) == NULL || dmu_objset_userused_enabled(os));
1127 while (dn = list_head(list)) {
1128 ASSERT(!DMU_OBJECT_IS_SPECIAL(dn->dn_object));
1129 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE ||
1130 dn->dn_phys->dn_flags &
1131 DNODE_FLAG_USERUSED_ACCOUNTED);
1133 /* Allocate the user/groupused objects if necessary. */
1134 if (os->os_userused_dnode->dn_type == DMU_OT_NONE) {
1135 VERIFY(0 == zap_create_claim(os,
1136 DMU_USERUSED_OBJECT,
1137 DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx));
1138 VERIFY(0 == zap_create_claim(os,
1139 DMU_GROUPUSED_OBJECT,
1140 DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx));
1144 * We intentionally modify the zap object even if the
1145 * net delta is zero. Otherwise
1146 * the block of the zap obj could be shared between
1147 * datasets but need to be different between them after
1151 mutex_enter(&dn->dn_mtx);
1152 ASSERT(dn->dn_id_flags);
1153 if (dn->dn_id_flags & DN_ID_OLD_EXIST) {
1154 do_userquota_update(os, dn->dn_oldused, dn->dn_oldflags,
1155 dn->dn_olduid, dn->dn_oldgid, B_TRUE, tx);
1157 if (dn->dn_id_flags & DN_ID_NEW_EXIST) {
1158 do_userquota_update(os, DN_USED_BYTES(dn->dn_phys),
1159 dn->dn_phys->dn_flags, dn->dn_newuid,
1160 dn->dn_newgid, B_FALSE, tx);
1164 dn->dn_oldflags = 0;
1165 if (dn->dn_id_flags & DN_ID_NEW_EXIST) {
1166 dn->dn_olduid = dn->dn_newuid;
1167 dn->dn_oldgid = dn->dn_newgid;
1168 dn->dn_id_flags |= DN_ID_OLD_EXIST;
1169 if (dn->dn_bonuslen == 0)
1170 dn->dn_id_flags |= DN_ID_CHKED_SPILL;
1172 dn->dn_id_flags |= DN_ID_CHKED_BONUS;
1174 dn->dn_id_flags &= ~(DN_ID_NEW_EXIST);
1175 mutex_exit(&dn->dn_mtx);
1177 list_remove(list, dn);
1178 dnode_rele(dn, list);
1183 * Returns a pointer to data to find uid/gid from
1185 * If a dirty record for transaction group that is syncing can't
1186 * be found then NULL is returned. In the NULL case it is assumed
1187 * the uid/gid aren't changing.
1190 dmu_objset_userquota_find_data(dmu_buf_impl_t *db, dmu_tx_t *tx)
1192 dbuf_dirty_record_t *dr, **drp;
1195 if (db->db_dirtycnt == 0)
1196 return (db->db.db_data); /* Nothing is changing */
1198 for (drp = &db->db_last_dirty; (dr = *drp) != NULL; drp = &dr->dr_next)
1199 if (dr->dr_txg == tx->tx_txg)
1204 else if (dr->dr_dbuf->db_dnode->dn_bonuslen == 0 &&
1205 dr->dr_dbuf->db_blkid == DMU_SPILL_BLKID)
1206 data = dr->dt.dl.dr_data->b_data;
1208 data = dr->dt.dl.dr_data;
1213 dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
1215 objset_t *os = dn->dn_objset;
1217 dmu_buf_impl_t *db = NULL;
1218 uint64_t *user, *group;
1219 int flags = dn->dn_id_flags;
1221 boolean_t have_spill = B_FALSE;
1223 if (!dmu_objset_userused_enabled(dn->dn_objset))
1226 if (before && (flags & (DN_ID_CHKED_BONUS|DN_ID_OLD_EXIST|
1227 DN_ID_CHKED_SPILL)))
1230 if (before && dn->dn_bonuslen != 0)
1231 data = DN_BONUS(dn->dn_phys);
1232 else if (!before && dn->dn_bonuslen != 0) {
1235 mutex_enter(&db->db_mtx);
1236 data = dmu_objset_userquota_find_data(db, tx);
1238 data = DN_BONUS(dn->dn_phys);
1240 } else if (dn->dn_bonuslen == 0 && dn->dn_bonustype == DMU_OT_SA) {
1243 if (RW_WRITE_HELD(&dn->dn_struct_rwlock))
1244 rf |= DB_RF_HAVESTRUCT;
1245 error = dmu_spill_hold_by_dnode(dn, rf,
1246 FTAG, (dmu_buf_t **)&db);
1248 mutex_enter(&db->db_mtx);
1249 data = (before) ? db->db.db_data :
1250 dmu_objset_userquota_find_data(db, tx);
1251 have_spill = B_TRUE;
1253 mutex_enter(&dn->dn_mtx);
1254 dn->dn_id_flags |= DN_ID_CHKED_BONUS;
1255 mutex_exit(&dn->dn_mtx);
1261 user = &dn->dn_olduid;
1262 group = &dn->dn_oldgid;
1264 user = &dn->dn_newuid;
1265 group = &dn->dn_newgid;
1269 * Must always call the callback in case the object
1270 * type has changed and that type isn't an object type to track
1272 error = used_cbs[os->os_phys->os_type](dn->dn_bonustype, data,
1276 * Preserve existing uid/gid when the callback can't determine
1277 * what the new uid/gid are and the callback returned EEXIST.
1278 * The EEXIST error tells us to just use the existing uid/gid.
1279 * If we don't know what the old values are then just assign
1280 * them to 0, since that is a new file being created.
1282 if (!before && data == NULL && error == EEXIST) {
1283 if (flags & DN_ID_OLD_EXIST) {
1284 dn->dn_newuid = dn->dn_olduid;
1285 dn->dn_newgid = dn->dn_oldgid;
1294 mutex_exit(&db->db_mtx);
1296 mutex_enter(&dn->dn_mtx);
1297 if (error == 0 && before)
1298 dn->dn_id_flags |= DN_ID_OLD_EXIST;
1299 if (error == 0 && !before)
1300 dn->dn_id_flags |= DN_ID_NEW_EXIST;
1303 dn->dn_id_flags |= DN_ID_CHKED_SPILL;
1305 dn->dn_id_flags |= DN_ID_CHKED_BONUS;
1307 mutex_exit(&dn->dn_mtx);
1309 dmu_buf_rele((dmu_buf_t *)db, FTAG);
1313 dmu_objset_userspace_present(objset_t *os)
1315 return (os->os_phys->os_flags &
1316 OBJSET_FLAG_USERACCOUNTING_COMPLETE);
1320 dmu_objset_userspace_upgrade(objset_t *os)
1325 if (dmu_objset_userspace_present(os))
1327 if (!dmu_objset_userused_enabled(os))
1329 if (dmu_objset_is_snapshot(os))
1333 * We simply need to mark every object dirty, so that it will be
1334 * synced out and now accounted. If this is called
1335 * concurrently, or if we already did some work before crashing,
1336 * that's fine, since we track each object's accounted state
1340 for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE, 0)) {
1345 if (issig(JUSTLOOKING) && issig(FORREAL))
1348 objerr = dmu_bonus_hold(os, obj, FTAG, &db);
1351 tx = dmu_tx_create(os);
1352 dmu_tx_hold_bonus(tx, obj);
1353 objerr = dmu_tx_assign(tx, TXG_WAIT);
1358 dmu_buf_will_dirty(db, tx);
1359 dmu_buf_rele(db, FTAG);
1363 os->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
1364 txg_wait_synced(dmu_objset_pool(os), 0);
1369 dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
1370 uint64_t *usedobjsp, uint64_t *availobjsp)
1372 dsl_dataset_space(os->os_dsl_dataset, refdbytesp, availbytesp,
1373 usedobjsp, availobjsp);
1377 dmu_objset_fsid_guid(objset_t *os)
1379 return (dsl_dataset_fsid_guid(os->os_dsl_dataset));
1383 dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat)
1385 stat->dds_type = os->os_phys->os_type;
1386 if (os->os_dsl_dataset)
1387 dsl_dataset_fast_stat(os->os_dsl_dataset, stat);
1391 dmu_objset_stats(objset_t *os, nvlist_t *nv)
1393 ASSERT(os->os_dsl_dataset ||
1394 os->os_phys->os_type == DMU_OST_META);
1396 if (os->os_dsl_dataset != NULL)
1397 dsl_dataset_stats(os->os_dsl_dataset, nv);
1399 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_TYPE,
1400 os->os_phys->os_type);
1401 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERACCOUNTING,
1402 dmu_objset_userspace_present(os));
1406 dmu_objset_is_snapshot(objset_t *os)
1408 if (os->os_dsl_dataset != NULL)
1409 return (dsl_dataset_is_snapshot(os->os_dsl_dataset));
1415 dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen,
1416 boolean_t *conflict)
1418 dsl_dataset_t *ds = os->os_dsl_dataset;
1421 if (ds->ds_phys->ds_snapnames_zapobj == 0)
1424 return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset,
1425 ds->ds_phys->ds_snapnames_zapobj, name, 8, 1, &ignored, MT_FIRST,
1426 real, maxlen, conflict));
1430 dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
1431 uint64_t *idp, uint64_t *offp, boolean_t *case_conflict)
1433 dsl_dataset_t *ds = os->os_dsl_dataset;
1434 zap_cursor_t cursor;
1435 zap_attribute_t attr;
1437 if (ds->ds_phys->ds_snapnames_zapobj == 0)
1440 zap_cursor_init_serialized(&cursor,
1441 ds->ds_dir->dd_pool->dp_meta_objset,
1442 ds->ds_phys->ds_snapnames_zapobj, *offp);
1444 if (zap_cursor_retrieve(&cursor, &attr) != 0) {
1445 zap_cursor_fini(&cursor);
1449 if (strlen(attr.za_name) + 1 > namelen) {
1450 zap_cursor_fini(&cursor);
1451 return (ENAMETOOLONG);
1454 (void) strcpy(name, attr.za_name);
1456 *idp = attr.za_first_integer;
1458 *case_conflict = attr.za_normalization_conflict;
1459 zap_cursor_advance(&cursor);
1460 *offp = zap_cursor_serialize(&cursor);
1461 zap_cursor_fini(&cursor);
1467 dmu_dir_list_next(objset_t *os, int namelen, char *name,
1468 uint64_t *idp, uint64_t *offp)
1470 dsl_dir_t *dd = os->os_dsl_dataset->ds_dir;
1471 zap_cursor_t cursor;
1472 zap_attribute_t attr;
1474 /* there is no next dir on a snapshot! */
1475 if (os->os_dsl_dataset->ds_object !=
1476 dd->dd_phys->dd_head_dataset_obj)
1479 zap_cursor_init_serialized(&cursor,
1480 dd->dd_pool->dp_meta_objset,
1481 dd->dd_phys->dd_child_dir_zapobj, *offp);
1483 if (zap_cursor_retrieve(&cursor, &attr) != 0) {
1484 zap_cursor_fini(&cursor);
1488 if (strlen(attr.za_name) + 1 > namelen) {
1489 zap_cursor_fini(&cursor);
1490 return (ENAMETOOLONG);
1493 (void) strcpy(name, attr.za_name);
1495 *idp = attr.za_first_integer;
1496 zap_cursor_advance(&cursor);
1497 *offp = zap_cursor_serialize(&cursor);
1498 zap_cursor_fini(&cursor);
1504 int (*func)(const char *, void *);
1510 findfunc(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
1512 struct findarg *fa = arg;
1513 return (fa->func(dsname, fa->arg));
1517 * Find all objsets under name, and for each, call 'func(child_name, arg)'.
1518 * Perhaps change all callers to use dmu_objset_find_spa()?
1521 dmu_objset_find(char *name, int func(const char *, void *), void *arg,
1527 return (dmu_objset_find_spa(NULL, name, findfunc, &fa, flags));
1531 * Find all objsets under name, call func on each
1534 dmu_objset_find_spa(spa_t *spa, const char *name,
1535 int func(spa_t *, uint64_t, const char *, void *), void *arg, int flags)
1541 zap_attribute_t *attr;
1547 name = spa_name(spa);
1548 err = dsl_dir_open_spa(spa, name, FTAG, &dd, NULL);
1552 /* Don't visit hidden ($MOS & $ORIGIN) objsets. */
1553 if (dd->dd_myname[0] == '$') {
1554 dsl_dir_close(dd, FTAG);
1558 thisobj = dd->dd_phys->dd_head_dataset_obj;
1559 attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
1563 * Iterate over all children.
1565 if (flags & DS_FIND_CHILDREN) {
1566 for (zap_cursor_init(&zc, dp->dp_meta_objset,
1567 dd->dd_phys->dd_child_dir_zapobj);
1568 zap_cursor_retrieve(&zc, attr) == 0;
1569 (void) zap_cursor_advance(&zc)) {
1570 ASSERT(attr->za_integer_length == sizeof (uint64_t));
1571 ASSERT(attr->za_num_integers == 1);
1573 child = kmem_asprintf("%s/%s", name, attr->za_name);
1574 err = dmu_objset_find_spa(spa, child, func, arg, flags);
1579 zap_cursor_fini(&zc);
1582 dsl_dir_close(dd, FTAG);
1583 kmem_free(attr, sizeof (zap_attribute_t));
1589 * Iterate over all snapshots.
1591 if (flags & DS_FIND_SNAPSHOTS) {
1592 if (!dsl_pool_sync_context(dp))
1593 rw_enter(&dp->dp_config_rwlock, RW_READER);
1594 err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);
1595 if (!dsl_pool_sync_context(dp))
1596 rw_exit(&dp->dp_config_rwlock);
1599 uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj;
1600 dsl_dataset_rele(ds, FTAG);
1602 for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
1603 zap_cursor_retrieve(&zc, attr) == 0;
1604 (void) zap_cursor_advance(&zc)) {
1605 ASSERT(attr->za_integer_length ==
1607 ASSERT(attr->za_num_integers == 1);
1609 child = kmem_asprintf("%s@%s",
1610 name, attr->za_name);
1611 err = func(spa, attr->za_first_integer,
1617 zap_cursor_fini(&zc);
1621 dsl_dir_close(dd, FTAG);
1622 kmem_free(attr, sizeof (zap_attribute_t));
1628 * Apply to self if appropriate.
1630 err = func(spa, thisobj, name, arg);
1636 dmu_objset_prefetch(const char *name, void *arg)
1640 if (dsl_dataset_hold(name, FTAG, &ds))
1643 if (!BP_IS_HOLE(&ds->ds_phys->ds_bp)) {
1644 mutex_enter(&ds->ds_opening_lock);
1645 if (ds->ds_objset == NULL) {
1646 uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
1649 SET_BOOKMARK(&zb, ds->ds_object, ZB_ROOT_OBJECT,
1650 ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
1652 (void) dsl_read_nolock(NULL, dsl_dataset_get_spa(ds),
1653 &ds->ds_phys->ds_bp, NULL, NULL,
1654 ZIO_PRIORITY_ASYNC_READ,
1655 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE,
1658 mutex_exit(&ds->ds_opening_lock);
1661 dsl_dataset_rele(ds, FTAG);
1666 dmu_objset_set_user(objset_t *os, void *user_ptr)
1668 ASSERT(MUTEX_HELD(&os->os_user_ptr_lock));
1669 os->os_user_ptr = user_ptr;
1673 dmu_objset_get_user(objset_t *os)
1675 ASSERT(MUTEX_HELD(&os->os_user_ptr_lock));
1676 return (os->os_user_ptr);