dsl_pool.c revision 3b2aab18808792cbd248a12f1edf139b89833c13
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
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden * Copyright (c) 2012 by Delphix. All rights reserved.
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybeeint zfs_write_limit_shift = 3; /* 1/8th of physical memory */
44ecc5327ab4ce0750dcca2a17e05566bf2812e2George Wilsonint zfs_txg_synctime_ms = 1000; /* target millisecs to sync a txg */
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybeeuint64_t zfs_write_limit_min = 32 << 20; /* min write limit is 32MB */
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybeeuint64_t zfs_write_limit_max = 0; /* max data payload per txg */
088f389458728c464569a5506b58070254fa4f7dahrensdsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_dir_hold_obj(dp, obj, name, dp, ddp));
9d3574bff0b382b89dd380c1e23d742ebc156772Neil Perrin dp->dp_vnrele_taskq = taskq_create("zfs_vn_rele_taskq", 1, minclsyspri,
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Sidendsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG);
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dir_hold_obj(dp, dp->dp_root_dir_obj,
088f389458728c464569a5506b58070254fa4f7dahrens err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir);
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden if (spa_version(dp->dp_spa) >= SPA_VERSION_ORIGIN) {
088f389458728c464569a5506b58070254fa4f7dahrens err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd);
088f389458728c464569a5506b58070254fa4f7dahrens err = dsl_dataset_hold_obj(dp, dd->dd_phys->dd_head_dataset_obj,
8f63aa464994c24e12bd657bac93d1b2e2df2d1cLin Ling if (err == 0) {
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens err = dsl_pool_open_special_dir(dp, FREE_DIR_NAME,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj);
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1,
f17457368189aa911f774c38c1f21875a568bdcaMatthew Ahrens &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ])) {
f17457368189aa911f774c38c1f21875a568bdcaMatthew Ahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
ca45db4129beff691dc46576c328149443788af2Chris Kirby err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden err = dsl_scan_init(dp, dp->dp_tx.tx_open_txg);
088f389458728c464569a5506b58070254fa4f7dahrens /* drop our references from dsl_pool_open() */
088f389458728c464569a5506b58070254fa4f7dahrens * Since we held the origin_snap from "syncing" context (which
088f389458728c464569a5506b58070254fa4f7dahrens * includes pool-opening context), it actually only got a "ref"
088f389458728c464569a5506b58070254fa4f7dahrens * and not a hold, so just drop that here.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhdsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG);
088f389458728c464569a5506b58070254fa4f7dahrens /* create and open the MOS (meta-objset) */
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens dp->dp_meta_objset = dmu_objset_create_impl(spa,
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the pool directory */
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling /* Initialize scan structures */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create and open the root dir */
088f389458728c464569a5506b58070254fa4f7dahrens dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dir_hold_obj(dp, dp->dp_root_dir_obj,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create and open the meta-objset dir */
088f389458728c464569a5506b58070254fa4f7dahrens (void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens /* create and open the free dir */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens (void) dsl_dir_create_sync(dp, dp->dp_root_dir,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens /* create and open the free_bplist */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens obj = bpobj_alloc(dp->dp_meta_objset, SPA_MAXBLOCKSIZE, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx) == 0);
088f389458728c464569a5506b58070254fa4f7dahrens /* create the root dataset */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx);
088f389458728c464569a5506b58070254fa4f7dahrens /* create the root objset */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, obj, FTAG, &ds));
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * Account for the meta-objset space in its placeholder dsl_dir.
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens ASSERT3U(comp, ==, uncomp); /* it's all metadata */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdeadlist_enqueue_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens list_create(&synced_datasets, sizeof (dsl_dataset_t),
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * We need to copy dp_space_towrite() before doing
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_sync_task_sync(), because
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * dsl_dataset_snapshot_reserve_space() will increase
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * dp_space_towrite but not actually write anything.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling data_written = dp->dp_space_towrite[txg & TXG_MASK];
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * We must not sync any non-MOS datasets twice, because
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * we may have taken a snapshot of them. However, we
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * may sync newly-created datasets on pass 2.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(!list_link_active(&ds->ds_synced_link));
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * After the data blocks have been written (ensured by the zio_wait()
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * above), update the user/group space accounting.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum dmu_objset_do_userquota_updates(ds->ds_objset, tx);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Sync the datasets again to push out the changes due to
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * userspace updates. This must be done before we process the
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * sync tasks, so that any snapshots will have the correct
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * user accounting information (and we won't get confused
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * about which blocks are part of the snapshot).
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(list_link_active(&ds->ds_synced_link));
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * Now that the datasets have been completely synced, we can
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * clean up our in-memory structures accumulated while syncing:
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * - move dead blocks from the pending deadlist to the on-disk deadlist
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * - release hold from dsl_dataset_dirty()
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens while (ds = list_remove_head(&synced_datasets)) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg))
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * The MOS's space is accounted for in the pool/$MOS
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * (dp_mos_dir). We can't modify the mos while we're syncing
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * it, so we remember the deltas and apply them here.
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens if (dp->dp_mos_used_delta != 0 || dp->dp_mos_compressed_delta != 0 ||
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens dsl_dir_diduse_space(dp->dp_mos_dir, DD_USED_HEAD,
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if (list_head(&mos->os_dirty_dnodes[txg & TXG_MASK]) != NULL ||
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens list_head(&mos->os_free_dnodes[txg & TXG_MASK]) != NULL) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee DTRACE_PROBE2(pool_sync__4io, hrtime_t, write_time,
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * If we modify a dataset in the same txg that we want to destroy it,
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * its dsl_dir's dd_dbuf will be dirty, and thus have a hold on it.
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * dsl_dir_destroy_check() will fail if there are unexpected holds.
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * Therefore, we want to sync the MOS (thus syncing the dd_dbuf
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * and clearing the hold on it) before we process the sync_tasks.
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * The MOS data dirtied by the sync_tasks will be synced on the next
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens if (!txg_list_empty(&dp->dp_sync_tasks, txg)) {
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * No more sync tasks should have been added while we
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens * were syncing.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens while (dst = txg_list_remove(&dp->dp_sync_tasks, txg))
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee ASSERT(dp->dp_tempreserved[txg & TXG_MASK] == 0);
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * If the write limit max has not been explicitly set, set it
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * to a fraction of available physical memory (default 1/8th).
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * Note that we must inflate the limit because the spa
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * inflates write sizes to account for data replication.
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * Check this each sync phase to catch changing memory size.
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee if (physmem != old_physmem && zfs_write_limit_shift) {
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee zfs_write_limit_max = ptob(physmem) >> zfs_write_limit_shift;
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee zfs_write_limit_inflated = MAX(zfs_write_limit_min,
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee spa_get_asize(dp->dp_spa, zfs_write_limit_max));
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * Attempt to keep the sync time consistent by adjusting the
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * amount of write traffic allowed into each transaction group.
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * Weight the throughput calculation towards the current value:
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee * thru = 3/4 old_thru + 1/4 new_thru
fb5dd802b9c6917629172c7c7fade7ee9d39cd71Lin Ling * Note: write_time is in nanosecs, so write_time/MICROSEC
fb5dd802b9c6917629172c7c7fade7ee9d39cd71Lin Ling * yields millisecs
fb5dd802b9c6917629172c7c7fade7ee9d39cd71Lin Ling if (data_written > zfs_write_limit_min / 8 && write_time > MICROSEC) {
fb5dd802b9c6917629172c7c7fade7ee9d39cd71Lin Ling uint64_t throughput = data_written / (write_time / MICROSEC);
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee dp->dp_write_limit = MIN(zfs_write_limit_inflated,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickdsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg)
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens while (zilog = txg_list_remove(&dp->dp_dirty_zilogs, txg)) {
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens ASSERT(!dmu_objset_is_dirty(zilog->zl_os, txg));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick ASSERT(!dmu_objset_is_dirty(dp->dp_meta_objset, txg));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * TRUE if the current thread is the tx_sync_thread or if we
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * are being called from SPA context during pool initialization.
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * Reserve about 1.6% (1/64), or at least 32MB, for allocation
fa9e4066f08beec538e775443c5be79dd423fcabahrens * efficiency.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * XXX The intent log is not accounted for, so it must fit
fa9e4066f08beec538e775443c5be79dd423fcabahrens * within this slop.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're trying to assess whether it's OK to do a free,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * cut the reservation in half to allow forward progress
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (e.g. make it possible to rm(1) files from a full pool).
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx)
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK],
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee return (0);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * Check to see if we have exceeded the maximum allowed IO for
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * this transaction group. We can do this without locks since
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * a little slop here is ok. Note that we do the reserved check
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * with only half the requested reserve: this is because the
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * reserve requests are worst-case, and we really don't want to
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * throttle based off of worst-case estimates.
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee reserved = dp->dp_space_towrite[tx->tx_txg & TXG_MASK]
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * If this transaction group is over 7/8ths capacity, delay
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * the caller 1 clock tick. This will slow down the "fill"
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * rate until the sync process can catch up with us.
e8397a2be4690aefe43370aae2d4214c6778327egw if (reserved && reserved > (write_limit - (write_limit >> 3)))
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee return (0);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee ASSERT(dp->dp_tempreserved[tx->tx_txg & TXG_MASK] >= space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], -space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee for (i = 0; i < TXG_SIZE; i++) {
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee dp->dp_space_towrite[tx->tx_txg & TXG_MASK] += space;
088f389458728c464569a5506b58070254fa4f7dahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensupgrade_clones_cb(dsl_pool_t *dp, dsl_dataset_t *hds, void *arg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, hds->ds_object, FTAG, &ds);
088f389458728c464569a5506b58070254fa4f7dahrens err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
088f389458728c464569a5506b58070254fa4f7dahrens if (prev->ds_phys->ds_next_snap_obj != ds->ds_object)
088f389458728c464569a5506b58070254fa4f7dahrens * The $ORIGIN can't have any data, or the accounting
088f389458728c464569a5506b58070254fa4f7dahrens * will be wrong.
088f389458728c464569a5506b58070254fa4f7dahrens /* The origin doesn't get attached to itself */
088f389458728c464569a5506b58070254fa4f7dahrens return (0);
088f389458728c464569a5506b58070254fa4f7dahrens ds->ds_phys->ds_prev_snap_txg = prev->ds_phys->ds_creation_txg;
088f389458728c464569a5506b58070254fa4f7dahrens ds->ds_dir->dd_phys->dd_origin_obj = prev->ds_object;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3U(ds->ds_dir->dd_phys->dd_origin_obj, ==, prev->ds_object);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3U(ds->ds_phys->ds_prev_snap_obj, ==, prev->ds_object);
088f389458728c464569a5506b58070254fa4f7dahrens prev->ds_phys->ds_next_clones_obj, ds->ds_object, tx));
088f389458728c464569a5506b58070254fa4f7dahrens return (0);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dmu_objset_find_dp(dp, dp->dp_root_dir_obj, upgrade_clones_cb,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensupgrade_dir_clones_cb(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (ds->ds_dir->dd_phys->dd_origin_obj != 0) {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &origin));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens if (origin->ds_dir->dd_phys->dd_clones == 0) {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens origin->ds_dir->dd_phys->dd_clones = zap_create(mos,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens origin->ds_dir->dd_phys->dd_clones, ds->ds_object, tx));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens (void) dsl_dir_create_sync(dp, dp->dp_root_dir, FREE_DIR_NAME, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * We can't use bpobj_alloc(), because spa_version() still
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * returns the old version, and we need a new-version bpobj with
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * subobj support. So call dmu_object_alloc() directly.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens obj = dmu_object_alloc(dp->dp_meta_objset, DMU_OT_BPOBJ,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens SPA_MAXBLOCKSIZE, DMU_OT_BPOBJ_HDR, sizeof (bpobj_phys_t), tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(bpobj_open(&dp->dp_free_bpobj, dp->dp_meta_objset, obj));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dmu_objset_find_dp(dp, dp->dp_root_dir_obj,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens upgrade_dir_clones_cb, tx, DS_FIND_CHILDREN));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(rrw_held(&dp->dp_config_rwlock, RW_WRITER));
088f389458728c464569a5506b58070254fa4f7dahrens /* create the origin dir, ds, & snap-ds */
088f389458728c464569a5506b58070254fa4f7dahrens dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_snapshot_sync_impl(ds, ORIGIN_DIR_NAME, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
ca45db4129beff691dc46576c328149443788af2Chris Kirby * Walk through the pool-wide zap object of temporary snapshot user holds
ca45db4129beff691dc46576c328149443788af2Chris Kirby * and release them.
ca45db4129beff691dc46576c328149443788af2Chris Kirby ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_user_release_tmp(dp, dsobj, htag);
ca45db4129beff691dc46576c328149443788af2Chris Kirby * Create the pool-wide zap object for storing temporary snapshot holds.
ca45db4129beff691dc46576c328149443788af2Chris Kirbydsl_pool_user_hold_create_obj(dsl_pool_t *dp, dmu_tx_t *tx)
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden dp->dp_tmp_userrefs_obj = zap_create_link(mos, DMU_OT_USERREFS,
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS, tx);
ca45db4129beff691dc46576c328149443788af2Chris Kirbydsl_pool_user_hold_rele_impl(dsl_pool_t *dp, uint64_t dsobj,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens const char *tag, uint64_t now, dmu_tx_t *tx, boolean_t holding)
ca45db4129beff691dc46576c328149443788af2Chris Kirby ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
ca45db4129beff691dc46576c328149443788af2Chris Kirby * If the pool was created prior to SPA_VERSION_USERREFS, the
ca45db4129beff691dc46576c328149443788af2Chris Kirby * zap object for temporary holds might not exist yet.
ca45db4129beff691dc46576c328149443788af2Chris Kirby name = kmem_asprintf("%llx-%s", (u_longlong_t)dsobj, tag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = zap_add(mos, zapobj, name, 8, 1, &now, tx);
ca45db4129beff691dc46576c328149443788af2Chris Kirby * Add a temporary hold for the given dataset object and tag.
ca45db4129beff691dc46576c328149443788af2Chris Kirbydsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
15508ac067f2fb55a439711838b971c02d42316fChris Kirby return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, now, tx, B_TRUE));
ca45db4129beff691dc46576c328149443788af2Chris Kirby * Release a temporary hold for the given dataset object and tag.
ca45db4129beff691dc46576c328149443788af2Chris Kirbydsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
ca45db4129beff691dc46576c328149443788af2Chris Kirby return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, NULL,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * DSL Pool Configuration Lock
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The dp_config_rwlock protects against changes to DSL state (e.g. dataset
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * creation / destruction / rename / property setting). It must be held for
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * read to hold a dataset or dsl_dir. I.e. you must call
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_pool_config_enter() or dsl_pool_hold() before calling
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_{dataset,dir}_hold{_obj}. In most circumstances, the dp_config_rwlock
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * must be held continuously until all datasets and dsl_dirs are released.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The only exception to this rule is that if a "long hold" is placed on
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * a dataset, then the dp_config_rwlock may be dropped while the dataset
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * is still held. The long hold will prevent the dataset from being
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * destroyed -- the destroy will fail with EBUSY. A long hold can be
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * obtained by calling dsl_dataset_long_hold(), or by "owning" a dataset
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (by calling dsl_{dataset,objset}_{try}own{_obj}).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Legitimate long-holders (including owners) should be long-running, cancelable
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * tasks that should cause "zfs destroy" to fail. This includes DMU
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * consumers (i.e. a ZPL filesystem being mounted or ZVOL being open),
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * "zfs send", and "zfs diff". There are several other long-holders whose
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * uses are suboptimal (e.g. "zfs promote", and zil_suspend()).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The usual formula for long-holding would be:
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_pool_hold()
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_dataset_hold()
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * ... perform checks ...
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_dataset_long_hold()
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_pool_rele()
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * ... perform long-running task ...
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_dataset_long_rele()
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dsl_dataset_rele()
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Note that when the long hold is released, the dataset is still held but
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * the pool is not held. The dataset may change arbitrarily during this time
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (e.g. it could be destroyed). Therefore you shouldn't do anything to the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dataset except release it.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * User-initiated operations (e.g. ioctls, zfs_ioc_*()) are either read-only
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * or modifying operations.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Modifying operations should generally use dsl_sync_task(). The synctask
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * infrastructure enforces proper locking strategy with respect to the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dp_config_rwlock. See the comment above dsl_sync_task() for details.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Read-only operations will manually hold the pool, then the dataset, obtain
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * information from the dataset, then release the pool and dataset.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * dmu_objset_{hold,rele}() are convenience routines that also do the pool
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_pool_config_enter(dsl_pool_t *dp, void *tag)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * We use a "reentrant" reader-writer lock, but not reentrantly.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The rrwlock can (with the track_all flag) track all reading threads,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * which is very useful for debugging which code path failed to release
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * the lock, and for verifying that the *current* thread does hold
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (Unlike a rwlock, which knows that N threads hold it for
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * read, but not *which* threads, so rw_held(RW_READER) returns TRUE
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * if any thread holds it for read, even if this thread doesn't).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(!rrw_held(&dp->dp_config_rwlock, RW_READER));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens rrw_enter(&dp->dp_config_rwlock, RW_READER, tag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_pool_config_exit(dsl_pool_t *dp, void *tag)