fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
aad02571bc59671aa3103bb070ae365f531b0b62Saso Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Copyright (c) 2013, Joyent, Inc. All rights reserved.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
03b1c2971d24a9cd2c073d634f7e074fbd14e984Alexander Eremin * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * Copyright (c) 2015, STRATO AG, Inc. All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
55da60b91d96984f12de050ce428373ea25c7f35Mark J Musante/* Portions Copyright 2010 Robert Milkowski */
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Needed to close a window in dnode_move() that allows the objset to be freed
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * before it can be safely accessed.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * Tunable to overwrite the maximum number of threads for the parallization
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * of dmu_objset_find_dp, needed to speed up the import of pools with many
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * Default is 4 times the number of leaf vdevs.
af346df58864e8fe897b1ff1a3a4c12f9294391bNed Bass * Backfill lower metadnode objects after this many have been freed.
af346df58864e8fe897b1ff1a3a4c12f9294391bNed Bass * Backfilling negatively impacts object creation rates, so only do it
af346df58864e8fe897b1ff1a3a4c12f9294391bNed Bass * if there are enough holes to fill.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if ((ds = os->os_dsl_dataset) != NULL && ds->ds_dir)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Inheritance should have been done by now.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens os->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Inheritance and range checking should have been done by now.
db1741f555ec79def5e9846e6bfd132248514ffeJustin T. Gibbs os->os_compress = zio_compress_select(os->os_spa, newval,
d0ad202d2eff2cc0c70ee550686a703ddda7106cahrens * Inheritance and range checking should have been done by now.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens ASSERT(newval <= spa_max_replication(os->os_spa));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * Inheritance should have been done by now.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick checksum = zio_checksum_dedup_select(spa, newval, ZIO_CHECKSUM_OFF);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick os->os_dedup_checksum = checksum & ZIO_CHECKSUM_MASK;
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick os->os_dedup_verify = !!(checksum & ZIO_CHECKSUM_VERIFY);
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bekstatic void
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bek * Inheritance and range checking should have been done by now.
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bek ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bekstatic void
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bek * Inheritance and range checking should have been done by now.
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bek ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
55da60b91d96984f12de050ce428373ea25c7f35Mark J Musante * Inheritance and range checking should have been done by now.
55da60b91d96984f12de050ce428373ea25c7f35Mark J Musante ASSERT(newval == ZFS_SYNC_STANDARD || newval == ZFS_SYNC_ALWAYS ||
edf345e6b8342e8627ec20ce821a977a62cee19dMatthew Ahrensredundant_metadata_changed_cb(void *arg, uint64_t newval)
edf345e6b8342e8627ec20ce821a977a62cee19dMatthew Ahrens * Inheritance and range checking should have been done by now.
edf345e6b8342e8627ec20ce821a977a62cee19dMatthew Ahrens ASSERT(newval == ZFS_REDUNDANT_METADATA_ALL ||
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrensrecordsize_changed_cb(void *arg, uint64_t newval)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockdmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
91ebeef555ce7f899b6270a3c2df47b51f7ad59aahrens ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock));
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens os = kmem_zalloc(sizeof (objset_t), KM_SLEEP);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET,
13506d1eefbbc37e2f12a0528831d9f6d4c361d7maybee ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb);
b87f3af36bb994656da117319f5129ddfd05ed21perrin /* convert checksum errors into IO errors */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* Increase the blocksize if we are permitted. */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (spa_version(spa) >= SPA_VERSION_USERSPACE &&
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens arc_buf_size(os->os_phys_buf) < sizeof (objset_phys_t)) {
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel arc_buf_t *buf = arc_alloc_buf(spa, &os->os_phys_buf,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson arc_buf_destroy(os->os_phys_buf, &os->os_phys_buf);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens int size = spa_version(spa) >= SPA_VERSION_USERSPACE ?
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens sizeof (objset_phys_t) : OBJSET_OLD_PHYS_SIZE;
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel os->os_phys_buf = arc_alloc_buf(spa, &os->os_phys_buf,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Note: the changed_cb will be called once before the register
fa9e4066f08beec538e775443c5be79dd423fcabahrens * func returns, thus changing the checksum/compression from the
3baa08fc5b6bea08a475b0cfe3ad161d74c5864bek * default (fletcher2/off). Snapshots don't need to know about
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Note: it's valid to open the objset if the dataset is
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * long-held, in which case the pool_config lock will not
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (!dsl_pool_config_held(dmu_objset_pool(os))) {
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson arc_buf_destroy(os->os_phys_buf, &os->os_phys_buf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* It's the meta-objset. */
6e0cbcaa0c6f2bc34634a4cc17b099f9ecef03d1Matthew Ahrens os->os_zil_header = os->os_phys->os_zil_header;
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens os->os_zil = zil_alloc(os, &os->os_zil_header);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < TXG_SIZE; i++) {
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens list_create(&os->os_dirty_dnodes[i], sizeof (dnode_t),
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens list_create(&os->os_free_dnodes[i], sizeof (dnode_t),
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens list_create(&os->os_dnodes, sizeof (dnode_t),
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens list_create(&os->os_downgraded_dbufs, sizeof (dmu_buf_impl_t),
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens mutex_init(&os->os_lock, NULL, MUTEX_DEFAULT, NULL);
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens mutex_init(&os->os_obj_lock, NULL, MUTEX_DEFAULT, NULL);
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens mutex_init(&os->os_user_ptr_lock, NULL, MUTEX_DEFAULT, NULL);
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs dnode_special_open(os, &os->os_phys->os_meta_dnode,
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if (arc_buf_size(os->os_phys_buf) >= sizeof (objset_phys_t)) {
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs dnode_special_open(os, &os->os_phys->os_userused_dnode,
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs dnode_special_open(os, &os->os_phys->os_groupused_dnode,
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs DMU_GROUPUSED_OBJECT, &os->os_groupused_dnode);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrensdmu_objset_from_ds(dsl_dataset_t *ds, objset_t **osp)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * We shouldn't be doing anything with dsl_dataset_t's unless the
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * pool_config lock is held, or the dataset is long-held.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool) ||
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Holds the pool while the objset is held. Therefore only one objset
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * can be held at a time.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrensdmu_objset_hold(const char *name, void *tag, objset_t **osp)
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansendmu_objset_own_impl(dsl_dataset_t *ds, dmu_objset_type_t type,
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen } else if (type != DMU_OST_ANY && type != (*osp)->os_phys->os_type) {
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen } else if (!readonly && dsl_dataset_is_snapshot(ds)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_pool must not be held when this is called.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Upon successful return, there will be a longhold on the dataset,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * and the dsl_pool will not be held.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrensdmu_objset_own(const char *name, dmu_objset_type_t type,
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens boolean_t readonly, void *tag, objset_t **osp)
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen err = dmu_objset_own_impl(ds, type, readonly, tag, osp);
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansendmu_objset_own_obj(dsl_pool_t *dp, uint64_t obj, dmu_objset_type_t type,
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen return (dmu_objset_own_impl(ds, type, readonly, tag, osp));
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * When we are called, os MUST refer to an objset associated with a dataset
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * that is owned by 'tag'; that is, is held and long held by 'tag' and ds_owner
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * == tag. We will then release and reacquire ownership of the dataset while
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * holding the pool config_rwlock to avoid intervening namespace or ownership
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * changes may occur.
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * This exists solely to accommodate zfs_ioc_userspace_upgrade()'s desire to
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * release the hold on its dataset and acquire a new one on the dataset of the
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski * same name so that it can be partially torn down and reconstructed.
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowskidmu_objset_refresh_ownership(objset_t *os, void *tag)
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski VERIFY0(dsl_dataset_own(dp, name, tag, &newds));
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * Skip dnodes without holds. We have to do this dance
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * because dnode_add_ref() only works if there is already a
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * hold. If the dnode has no holds, then it has no dbufs.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs list_insert_after(&os->os_dnodes, dn, &dn_marker);
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * Objset eviction processing is split into into two pieces.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * The first marks the objset as evicting, evicts any dbufs that
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * have a refcount of zero, and then queues up the objset for the
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * second phase of eviction. Once os->os_dnodes has been cleared by
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * dnode_buf_pageout()->dnode_destroy(), the second phase is executed.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * The second phase closes the special dnodes, dequeues the objset from
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * the list of those undergoing eviction, and finally frees the objset.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * NOTE: Due to asynchronous eviction processing (invocation of
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * dnode_buf_pageout()), it is possible for the meta dnode for the
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * objset to have no holds even though os->os_dnodes is not empty.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick for (int t = 0; t < TXG_SIZE; t++)
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson arc_buf_destroy(os->os_phys_buf, &os->os_phys_buf);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * This is a barrier to prevent the objset from going away in
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * dnode_move() until we can safely ensure that the objset is still in
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * use. We consider the objset valid before the barrier and invalid
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * after the barrier.
71eb05381846ad14a2087631474e832d0f316654Chris Kirby return (dsl_dir_snap_cmtime(os->os_dsl_dataset->ds_dir));
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* called from dsl for meta-objset */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeedmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dmu_objset_open_impl(spa, NULL, bp, &os));
fa9e4066f08beec538e775443c5be79dd423fcabahrens dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We don't want to have to increase the meta-dnode's nlevels
fa9e4066f08beec538e775443c5be79dd423fcabahrens * later, because then we could do it in quescing context while
fa9e4066f08beec538e775443c5be79dd423fcabahrens * we are also accessing it in open context.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This precaution is not necessary for the MOS (ds == NULL),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * because the MOS is only updated in syncing context.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is most fortunate: the MOS is the only objset that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * needs to be synced multiple times as spa_sync() iterates
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to convergence, so minimizing its dn_nlevels matters.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Determine the number of levels necessary for the meta-dnode
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens * to contain DN_MAX_OBJECT dnodes. Note that in order to
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens * ensure that we do not overflow 64 bits, there has to be
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens * a nlevels that gives us a number of blocks > DN_MAX_OBJECT
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens * but < 2^64. Therefore,
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT) (10) must be
4b5c8e93cab28d3c65ba9d407fd8f46e3be1db1cMatthew Ahrens * less than (64 - log2(DN_MAX_OBJECT)) (16).
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) <
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens os->os_phys->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens void (*doca_userfunc)(objset_t *os, void *arg,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks/*ARGSUSED*/
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_create_check(void *arg, dmu_tx_t *tx)
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens if (strlen(doca->doca_name) >= ZFS_MAX_DATASET_NAME_LEN)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dir_hold(dp, doca->doca_name, FTAG, &pdd, &tail);
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_create_sync(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dir_hold(dp, doca->doca_name, FTAG, &pdd, &tail));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens obj = dsl_dataset_create_sync(pdd, tail, NULL, doca->doca_flags,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(pdd->dd_pool, obj, FTAG, &ds));
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens os = dmu_objset_create_impl(pdd->dd_pool->dp_spa,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(ds, "create", tx, "");
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrensdmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg)
7d46dc6ca63a6f3f0d51aa655bfcf10cf2405a9eMatthew Ahrens dmu_objset_create_check, dmu_objset_create_sync, &doca,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_clone_check(void *arg, dmu_tx_t *tx)
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens if (strlen(doca->doca_clone) >= ZFS_MAX_DATASET_NAME_LEN)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dir_hold(dp, doca->doca_clone, FTAG, &pdd, &tail);
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, doca->doca_origin, FTAG, &origin);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* You can only clone snapshots, not the head datasets. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_clone_sync(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dir_hold(dp, doca->doca_clone, FTAG, &pdd, &tail));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, doca->doca_origin, FTAG, &origin));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens obj = dsl_dataset_create_sync(pdd, tail, origin, 0,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(pdd->dd_pool, obj, FTAG, &ds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens "origin=%s (%llu)", namebuf, origin->ds_object);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_clone(const char *clone, const char *origin)
7d46dc6ca63a6f3f0d51aa655bfcf10cf2405a9eMatthew Ahrens dmu_objset_clone_check, dmu_objset_clone_sync, &doca,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrensdmu_objset_snapshot_one(const char *fsname, const char *snapname)
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens char *longsnap = kmem_asprintf("%s@%s", fsname, snapname);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_snapshot(snaps, NULL, NULL);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensdmu_objset_sync_dnodes(list_t *list, list_t *newlist, dmu_tx_t *tx)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Initialize dn_zio outside dnode_sync() because the
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * meta-dnode needs to set it ouside dnode_sync().
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickdmu_objset_write_ready(zio_t *zio, arc_buf_t *abuf, void *arg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_OBJSET);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Update rootbp fill count: it should be the number of objects
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * allocated in the object set (not counting the "special"
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * objects that are stored in the objset_phys_t -- the meta
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * dnode and user/group accounting objects).
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens bp->blk_fill += BP_GET_FILL(&dnp->dn_blkptr[i]);
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&os->os_dsl_dataset->ds_bp_rwlock, RW_WRITER, FTAG);
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_exit(&os->os_dsl_dataset->ds_bp_rwlock, FTAG);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick/* ARGSUSED */
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickdmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg)
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick (void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* called from dsl */
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrensdmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx)
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie blkptr_t *blkptr_copy = kmem_alloc(sizeof (*os->os_rootbp), KM_SLEEP);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXX the write_done callback should really give us the tx... */
87bd5c1ed737e21cdf359451c9715fae0ba4927eahrens * This is the MOS. If we have upgraded,
87bd5c1ed737e21cdf359451c9715fae0ba4927eahrens * spa_max_replication() could change, so reset
87bd5c1ed737e21cdf359451c9715fae0ba4927eahrens * os_copies here.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * Create the root block IO
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick os->os_dsl_dataset->ds_object : DMU_META_OBJSET,
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson arc_release(os->os_phys_buf, &os->os_phys_buf);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dmu_write_policy(os, NULL, 0, 0, ZIO_COMPRESS_INHERIT, &zp);
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie blkptr_copy, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os),
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie &zp, dmu_objset_write_ready, NULL, NULL, dmu_objset_write_done,
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie os, ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Sync special dnodes - the parent IO for the sync is the root block
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson DMU_USERUSED_DNODE(os)->dn_type != DMU_OT_NONE) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * We must create the list here because it uses the
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * dn_dirty_link[] of this txg.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens dmu_objset_sync_dnodes(&os->os_free_dnodes[txgoff], newlist, tx);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], newlist, tx);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson list = &DMU_META_DNODE(os)->dn_dirty_records[txgoff];
af346df58864e8fe897b1ff1a3a4c12f9294391bNed Bass /* Enable dnode backfill if enough objects have been freed. */
af346df58864e8fe897b1ff1a3a4c12f9294391bNed Bass if (os->os_freed_dnodes >= dmu_rescan_dnode_threshold) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * Free intent log blocks up to this tx.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick return (!list_is_empty(&os->os_dirty_dnodes[txg & TXG_MASK]) ||
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick !list_is_empty(&os->os_free_dnodes[txg & TXG_MASK]));
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonstatic objset_used_cb_t *used_cbs[DMU_OST_NUMTYPES];
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensdmu_objset_register_type(dmu_objset_type_t ost, objset_used_cb_t *cb)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens return (spa_version(os->os_spa) >= SPA_VERSION_USERSPACE &&
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrensuserquota_compare(const void *l, const void *r)
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrensdo_userquota_cacheflush(objset_t *os, userquota_cache_t *cache, dmu_tx_t *tx)
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens while ((uqn = avl_destroy_nodes(&cache->uqc_user_deltas,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens VERIFY0(zap_increment_int(os, DMU_USERUSED_OBJECT,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens while ((uqn = avl_destroy_nodes(&cache->uqc_group_deltas,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens VERIFY0(zap_increment_int(os, DMU_GROUPUSED_OBJECT,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrensuserquota_update_cache(avl_tree_t *avl, uint64_t id, int64_t delta)
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens userquota_node_t *uqn = avl_find(avl, &search, &idx);
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrensdo_userquota_update(userquota_cache_t *cache, uint64_t used, uint64_t flags,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens uint64_t user, uint64_t group, boolean_t subtract)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if ((flags & DNODE_FLAG_USERUSED_ACCOUNTED)) {
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens userquota_update_cache(&cache->uqc_user_deltas, user, delta);
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens userquota_update_cache(&cache->uqc_group_deltas, group, delta);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaumdmu_objset_do_userquota_updates(objset_t *os, dmu_tx_t *tx)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(list_head(list) == NULL || dmu_objset_userused_enabled(os));
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens avl_create(&cache.uqc_user_deltas, userquota_compare,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens sizeof (userquota_node_t), offsetof(userquota_node_t, uqn_node));
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens avl_create(&cache.uqc_group_deltas, userquota_compare,
8b70546b0a686e4eee3d28878728f3b3ce980b06Matthew Ahrens sizeof (userquota_node_t), offsetof(userquota_node_t, uqn_node));
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(!DMU_OBJECT_IS_SPECIAL(dn->dn_object));
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE ||
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /* Allocate the user/groupused objects if necessary. */
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson if (DMU_USERUSED_DNODE(os)->dn_type == DMU_OT_NONE) {
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * Returns a pointer to data to find uid/gid from
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * If a dirty record for transaction group that is syncing can't
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * be found then NULL is returned. In the NULL case it is assumed
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * the uid/gid aren't changing.
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaumdmu_objset_userquota_find_data(dmu_buf_impl_t *db, dmu_tx_t *tx)
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum return (db->db.db_data); /* Nothing is changing */
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum for (drp = &db->db_last_dirty; (dr = *drp) != NULL; drp = &dr->dr_next)
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaumdmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (!dmu_objset_userused_enabled(dn->dn_objset))
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (before && (flags & (DN_ID_CHKED_BONUS|DN_ID_OLD_EXIST|
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum else if (!before && dn->dn_bonuslen != 0) {
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum data = dmu_objset_userquota_find_data(db, tx);
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum } else if (dn->dn_bonuslen == 0 && dn->dn_bonustype == DMU_OT_SA) {
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum } else if (data) {
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * Must always call the callback in case the object
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * type has changed and that type isn't an object type to track
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum error = used_cbs[os->os_phys->os_type](dn->dn_bonustype, data,
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * Preserve existing uid/gid when the callback can't determine
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * what the new uid/gid are and the callback returned EEXIST.
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * The EEXIST error tells us to just use the existing uid/gid.
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * If we don't know what the old values are then just assign
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * them to 0, since that is a new file being created.
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum if (!before && data == NULL && error == EEXIST) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * We simply need to mark every object dirty, so that it will be
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * synced out and now accounted. If this is called
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * concurrently, or if we already did some work before crashing,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * that's fine, since we track each object's accounted state
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * independently.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE, 0)) {
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens os->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrensdmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens dsl_dataset_space(os->os_dsl_dataset, refdbytesp, availbytesp,
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens return (dsl_dataset_fsid_guid(os->os_dsl_dataset));
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrensdmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat)
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens dsl_dataset_fast_stat(os->os_dsl_dataset, stat);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERACCOUNTING,
ab04eb8ef60d9dc9614d6cccffc474f24ca1d162timhdmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0)
ab04eb8ef60d9dc9614d6cccffc474f24ca1d162timh return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_snapnames_zapobj, name, 8, 1, &ignored,
fa9e4066f08beec538e775443c5be79dd423fcabahrensdmu_snapshot_list_next(objset_t *os, int namelen, char *name,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(dsl_pool_config_held(dmu_objset_pool(os)));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_snapnames_zapobj, *offp);
87e5029a3226958edab1512d6182bc74d8d80c9aahrens return (0);
87e5029a3226958edab1512d6182bc74d8d80c9aahrensdmu_dir_list_next(objset_t *os, int namelen, char *name,
87e5029a3226958edab1512d6182bc74d8d80c9aahrens /* there is no next dir on a snapshot! */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(dd)->dd_child_dir_zapobj, *offp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens char *dc_ddname; /* last component of ddobj's name */
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen int (*dc_func)(dsl_pool_t *, dsl_dataset_t *, void *);
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansendmu_objset_find_dp_impl(dmu_objset_find_ctx_t *dcp)
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen /* don't process if there already was an error */
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * Note: passing the name (dc_ddname) here is optional, but it
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * improves performance because we don't need to call
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * zap_value_search() to determine the name.
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens err = dsl_dir_hold_obj(dp, dcp->dc_ddobj, dcp->dc_ddname, FTAG, &dd);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Don't visit hidden ($MOS & $ORIGIN) objsets. */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Iterate over all children.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (zap_cursor_init(&zc, dp->dp_meta_objset,
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens child_dcp->dc_ddname = spa_strdup(attr->za_name);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Iterate over all snapshots.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs snapobj = dsl_dataset_phys(ds)->ds_snapnames_zapobj;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Apply to self.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * Note: we hold the dir while calling dsl_dataset_hold_obj() so
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * that the dir will remain cached, and we won't have to re-instantiate
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * it (which could be expensive due to finding its name via
7588687e6ba67c47bf7c9805086dec4a97fcac7bMatthew Ahrens * zap_value_search()).
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen /* only keep first error */
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansen * We need to get a pool_config_lock here, as there are several
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansen * asssert(pool_config_held) down the stack. Getting a lock via
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansen * dsl_pool_config_enter is risky, as it might be stalled by a
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansen * pending writer. This would deadlock, as the write lock can
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansen * only be granted when our parent thread gives up the lock.
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansen * The _prio interface gives us priority over a pending writer.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * Find objsets under and including ddobj, call func(ds) on each.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * The order for the enumeration is completely undefined.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * func is called with dsl_pool_config held.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansendmu_objset_find_dp(dsl_pool_t *dp, uint64_t ddobj,
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen int func(dsl_pool_t *, dsl_dataset_t *, void *), void *arg, int flags)
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen mutex_init(&err_lock, NULL, MUTEX_DEFAULT, NULL);
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen if ((flags & DS_FIND_SERIALIZE) || dsl_pool_config_held_writer(dp)) {
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * In case a write lock is held we can't make use of
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * parallelism, as down the stack of the worker threads
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * the lock is asserted via dsl_pool_config_held.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * In case of a read lock this is solved by getting a read
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * lock in each worker thread, which isn't possible in case
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * of a writer lock. So we fall back to the synchronous path
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * In the future it might be possible to get some magic into
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * dsl_pool_config_held in a way that it returns true for
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * the worker threads so that a single lock held from this
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * thread suffices. For now, stay single threaded.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen tq = taskq_create("dmu_objset_find", ntasks, minclsyspri, ntasks,
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen /* dcp will be freed by task */
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen (void) taskq_dispatch(tq, dmu_objset_find_dp_cb, dcp, TQ_SLEEP);
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * PORTING: this code relies on the property of taskq_wait to wait
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * until no more tasks are queued and no more tasks are active. As
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * we always queue new tasks from within other tasks, task_wait
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * reliably waits for the full recursion to finish, even though we
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * enqueue new tasks after taskq_wait has been called.
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansen * On platforms other than illumos, taskq_wait may not have this
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Find all objsets under name, and for each, call 'func(child_name, arg)'.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The dp_config_rwlock must not be held when this is called, and it
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * will not be held when the callback is called.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Therefore this function should only be used when the pool is not changing
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (e.g. in syncing context), or the callback can deal with the possible races.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_find_impl(spa_t *spa, const char *name,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens int func(const char *, void *), void *arg, int flags)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dir_hold(dp, name, FTAG, &dd, NULL);
088f389458728c464569a5506b58070254fa4f7dahrens /* Don't visit hidden ($MOS & $ORIGIN) objsets. */
088f389458728c464569a5506b58070254fa4f7dahrens return (0);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj;
b7661ccca92e6bf5160f4d5d2601efaeaa1f5161mmusante attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all children.
486ae710326c477d7237ab803b67abb9119c0799Matthew Ahrens child = kmem_asprintf("%s/%s", name, attr->za_name);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all snapshots.
088f389458728c464569a5506b58070254fa4f7dahrens if (err == 0) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs snapobj = dsl_dataset_phys(ds)->ds_snapnames_zapobj;
088f389458728c464569a5506b58070254fa4f7dahrens for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Apply to self. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * See comment above dmu_objset_find_impl().
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_objset_find(char *name, int func(const char *, void *), void *arg,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_objset_find_impl(spa, name, func, arg, flags);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Determine name of filesystem, given name of snapshot.
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens * buf must be at least ZFS_MAX_DATASET_NAME_LEN bytes
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens if (atp - snapname >= ZFS_MAX_DATASET_NAME_LEN)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) strlcpy(buf, snapname, atp - snapname + 1);