1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 223f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23be6fd75aSMatthew Ahrens * Copyright (c) 2013 by Delphix. All rights reserved. 24a7a845e4SSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved. 25fa9e4066Sahrens */ 26fa9e4066Sahrens 27fa9e4066Sahrens #include <sys/dsl_pool.h> 28fa9e4066Sahrens #include <sys/dsl_dataset.h> 293f9d6ad7SLin Ling #include <sys/dsl_prop.h> 30fa9e4066Sahrens #include <sys/dsl_dir.h> 311d452cf5Sahrens #include <sys/dsl_synctask.h> 323f9d6ad7SLin Ling #include <sys/dsl_scan.h> 333f9d6ad7SLin Ling #include <sys/dnode.h> 34fa9e4066Sahrens #include <sys/dmu_tx.h> 35fa9e4066Sahrens #include <sys/dmu_objset.h> 36fa9e4066Sahrens #include <sys/arc.h> 37fa9e4066Sahrens #include <sys/zap.h> 38c717a561Smaybee #include <sys/zio.h> 39fa9e4066Sahrens #include <sys/zfs_context.h> 40fa9e4066Sahrens #include <sys/fs/zfs.h> 41088f3894Sahrens #include <sys/zfs_znode.h> 42088f3894Sahrens #include <sys/spa_impl.h> 43cde58dbcSMatthew Ahrens #include <sys/dsl_deadlist.h> 44ad135b5dSChristopher Siden #include <sys/bptree.h> 45ad135b5dSChristopher Siden #include <sys/zfeature.h> 46ce636f8bSMatthew Ahrens #include <sys/zil_impl.h> 473b2aab18SMatthew Ahrens #include <sys/dsl_userhold.h> 48fa9e4066Sahrens 49*69962b56SMatthew Ahrens /* 50*69962b56SMatthew Ahrens * ZFS Write Throttle 51*69962b56SMatthew Ahrens * ------------------ 52*69962b56SMatthew Ahrens * 53*69962b56SMatthew Ahrens * ZFS must limit the rate of incoming writes to the rate at which it is able 54*69962b56SMatthew Ahrens * to sync data modifications to the backend storage. Throttling by too much 55*69962b56SMatthew Ahrens * creates an artificial limit; throttling by too little can only be sustained 56*69962b56SMatthew Ahrens * for short periods and would lead to highly lumpy performance. On a per-pool 57*69962b56SMatthew Ahrens * basis, ZFS tracks the amount of modified (dirty) data. As operations change 58*69962b56SMatthew Ahrens * data, the amount of dirty data increases; as ZFS syncs out data, the amount 59*69962b56SMatthew Ahrens * of dirty data decreases. When the amount of dirty data exceeds a 60*69962b56SMatthew Ahrens * predetermined threshold further modifications are blocked until the amount 61*69962b56SMatthew Ahrens * of dirty data decreases (as data is synced out). 62*69962b56SMatthew Ahrens * 63*69962b56SMatthew Ahrens * The limit on dirty data is tunable, and should be adjusted according to 64*69962b56SMatthew Ahrens * both the IO capacity and available memory of the system. The larger the 65*69962b56SMatthew Ahrens * window, the more ZFS is able to aggregate and amortize metadata (and data) 66*69962b56SMatthew Ahrens * changes. However, memory is a limited resource, and allowing for more dirty 67*69962b56SMatthew Ahrens * data comes at the cost of keeping other useful data in memory (for example 68*69962b56SMatthew Ahrens * ZFS data cached by the ARC). 69*69962b56SMatthew Ahrens * 70*69962b56SMatthew Ahrens * Implementation 71*69962b56SMatthew Ahrens * 72*69962b56SMatthew Ahrens * As buffers are modified dsl_pool_willuse_space() increments both the per- 73*69962b56SMatthew Ahrens * txg (dp_dirty_pertxg[]) and poolwide (dp_dirty_total) accounting of 74*69962b56SMatthew Ahrens * dirty space used; dsl_pool_dirty_space() decrements those values as data 75*69962b56SMatthew Ahrens * is synced out from dsl_pool_sync(). While only the poolwide value is 76*69962b56SMatthew Ahrens * relevant, the per-txg value is useful for debugging. The tunable 77*69962b56SMatthew Ahrens * zfs_dirty_data_max determines the dirty space limit. Once that value is 78*69962b56SMatthew Ahrens * exceeded, new writes are halted until space frees up. 79*69962b56SMatthew Ahrens * 80*69962b56SMatthew Ahrens * The zfs_dirty_data_sync tunable dictates the threshold at which we 81*69962b56SMatthew Ahrens * ensure that there is a txg syncing (see the comment in txg.c for a full 82*69962b56SMatthew Ahrens * description of transaction group stages). 83*69962b56SMatthew Ahrens * 84*69962b56SMatthew Ahrens * The IO scheduler uses both the dirty space limit and current amount of 85*69962b56SMatthew Ahrens * dirty data as inputs. Those values affect the number of concurrent IOs ZFS 86*69962b56SMatthew Ahrens * issues. See the comment in vdev_queue.c for details of the IO scheduler. 87*69962b56SMatthew Ahrens * 88*69962b56SMatthew Ahrens * The delay is also calculated based on the amount of dirty data. See the 89*69962b56SMatthew Ahrens * comment above dmu_tx_delay() for details. 90*69962b56SMatthew Ahrens */ 91*69962b56SMatthew Ahrens 92*69962b56SMatthew Ahrens /* 93*69962b56SMatthew Ahrens * zfs_dirty_data_max will be set to zfs_dirty_data_max_percent% of all memory, 94*69962b56SMatthew Ahrens * capped at zfs_dirty_data_max_max. It can also be overridden in /etc/system. 95*69962b56SMatthew Ahrens */ 96*69962b56SMatthew Ahrens uint64_t zfs_dirty_data_max; 97*69962b56SMatthew Ahrens uint64_t zfs_dirty_data_max_max = 4ULL * 1024 * 1024 * 1024; 98*69962b56SMatthew Ahrens int zfs_dirty_data_max_percent = 10; 99*69962b56SMatthew Ahrens 100*69962b56SMatthew Ahrens /* 101*69962b56SMatthew Ahrens * If there is at least this much dirty data, push out a txg. 102*69962b56SMatthew Ahrens */ 103*69962b56SMatthew Ahrens uint64_t zfs_dirty_data_sync = 64 * 1024 * 1024; 104*69962b56SMatthew Ahrens 105*69962b56SMatthew Ahrens /* 106*69962b56SMatthew Ahrens * Once there is this amount of dirty data, the dmu_tx_delay() will kick in 107*69962b56SMatthew Ahrens * and delay each transaction. 108*69962b56SMatthew Ahrens * This value should be >= zfs_vdev_async_write_active_max_dirty_percent. 109*69962b56SMatthew Ahrens */ 110*69962b56SMatthew Ahrens int zfs_delay_min_dirty_percent = 60; 111*69962b56SMatthew Ahrens 112*69962b56SMatthew Ahrens /* 113*69962b56SMatthew Ahrens * This controls how quickly the delay approaches infinity. 114*69962b56SMatthew Ahrens * Larger values cause it to delay less for a given amount of dirty data. 115*69962b56SMatthew Ahrens * Therefore larger values will cause there to be more dirty data for a 116*69962b56SMatthew Ahrens * given throughput. 117*69962b56SMatthew Ahrens * 118*69962b56SMatthew Ahrens * For the smoothest delay, this value should be about 1 billion divided 119*69962b56SMatthew Ahrens * by the maximum number of operations per second. This will smoothly 120*69962b56SMatthew Ahrens * handle between 10x and 1/10th this number. 121*69962b56SMatthew Ahrens * 122*69962b56SMatthew Ahrens * Note: zfs_delay_scale * zfs_dirty_data_max must be < 2^64, due to the 123*69962b56SMatthew Ahrens * multiply in dmu_tx_delay(). 124*69962b56SMatthew Ahrens */ 125*69962b56SMatthew Ahrens uint64_t zfs_delay_scale = 1000 * 1000 * 1000 / 2000; 12605715f94SMark Maybee 1271ab7f2deSmaybee 128*69962b56SMatthew Ahrens /* 129*69962b56SMatthew Ahrens * XXX someday maybe turn these into #defines, and you have to tune it on a 130*69962b56SMatthew Ahrens * per-pool basis using zfs.conf. 131*69962b56SMatthew Ahrens */ 13205715f94SMark Maybee 133088f3894Sahrens 1340689f76cSAdam Leventhal hrtime_t zfs_throttle_delay = MSEC2NSEC(10); 1350689f76cSAdam Leventhal hrtime_t zfs_throttle_resolution = MSEC2NSEC(10); 1360689f76cSAdam Leventhal 1373f9d6ad7SLin Ling int 138088f3894Sahrens dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp) 139fa9e4066Sahrens { 140fa9e4066Sahrens uint64_t obj; 141fa9e4066Sahrens int err; 142fa9e4066Sahrens 143fa9e4066Sahrens err = zap_lookup(dp->dp_meta_objset, 144fa9e4066Sahrens dp->dp_root_dir->dd_phys->dd_child_dir_zapobj, 145088f3894Sahrens name, sizeof (obj), 1, &obj); 146ea8dc4b6Seschrock if (err) 147ea8dc4b6Seschrock return (err); 148fa9e4066Sahrens 1493b2aab18SMatthew Ahrens return (dsl_dir_hold_obj(dp, obj, name, dp, ddp)); 150fa9e4066Sahrens } 151fa9e4066Sahrens 152fa9e4066Sahrens static dsl_pool_t * 153fa9e4066Sahrens dsl_pool_open_impl(spa_t *spa, uint64_t txg) 154fa9e4066Sahrens { 155fa9e4066Sahrens dsl_pool_t *dp; 156fa9e4066Sahrens blkptr_t *bp = spa_get_rootblkptr(spa); 157fa9e4066Sahrens 158fa9e4066Sahrens dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP); 159fa9e4066Sahrens dp->dp_spa = spa; 160fa9e4066Sahrens dp->dp_meta_rootbp = *bp; 1613b2aab18SMatthew Ahrens rrw_init(&dp->dp_config_rwlock, B_TRUE); 162fa9e4066Sahrens txg_init(dp, txg); 163fa9e4066Sahrens 164fa9e4066Sahrens txg_list_create(&dp->dp_dirty_datasets, 165fa9e4066Sahrens offsetof(dsl_dataset_t, ds_dirty_link)); 166ce636f8bSMatthew Ahrens txg_list_create(&dp->dp_dirty_zilogs, 167ce636f8bSMatthew Ahrens offsetof(zilog_t, zl_dirty_link)); 168fa9e4066Sahrens txg_list_create(&dp->dp_dirty_dirs, 169fa9e4066Sahrens offsetof(dsl_dir_t, dd_dirty_link)); 1701d452cf5Sahrens txg_list_create(&dp->dp_sync_tasks, 1713b2aab18SMatthew Ahrens offsetof(dsl_sync_task_t, dst_node)); 172fa9e4066Sahrens 1731ab7f2deSmaybee mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL); 174*69962b56SMatthew Ahrens cv_init(&dp->dp_spaceavail_cv, NULL, CV_DEFAULT, NULL); 1751ab7f2deSmaybee 1769d3574bfSNeil Perrin dp->dp_vnrele_taskq = taskq_create("zfs_vn_rele_taskq", 1, minclsyspri, 1779d3574bfSNeil Perrin 1, 4, 0); 1789d3574bfSNeil Perrin 179fa9e4066Sahrens return (dp); 180fa9e4066Sahrens } 181fa9e4066Sahrens 182ea8dc4b6Seschrock int 183ad135b5dSChristopher Siden dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp) 184fa9e4066Sahrens { 185fa9e4066Sahrens int err; 186fa9e4066Sahrens dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); 187ad135b5dSChristopher Siden 188ad135b5dSChristopher Siden err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp, 189ad135b5dSChristopher Siden &dp->dp_meta_objset); 190ad135b5dSChristopher Siden if (err != 0) 191ad135b5dSChristopher Siden dsl_pool_close(dp); 192ad135b5dSChristopher Siden else 193ad135b5dSChristopher Siden *dpp = dp; 194ad135b5dSChristopher Siden 195ad135b5dSChristopher Siden return (err); 196ad135b5dSChristopher Siden } 197ad135b5dSChristopher Siden 198ad135b5dSChristopher Siden int 199ad135b5dSChristopher Siden dsl_pool_open(dsl_pool_t *dp) 200ad135b5dSChristopher Siden { 201ad135b5dSChristopher Siden int err; 202088f3894Sahrens dsl_dir_t *dd; 203088f3894Sahrens dsl_dataset_t *ds; 204cde58dbcSMatthew Ahrens uint64_t obj; 205fa9e4066Sahrens 2063b2aab18SMatthew Ahrens rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG); 207fa9e4066Sahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 208fa9e4066Sahrens DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1, 209fa9e4066Sahrens &dp->dp_root_dir_obj); 210ea8dc4b6Seschrock if (err) 211ea8dc4b6Seschrock goto out; 212ea8dc4b6Seschrock 2133b2aab18SMatthew Ahrens err = dsl_dir_hold_obj(dp, dp->dp_root_dir_obj, 214ea8dc4b6Seschrock NULL, dp, &dp->dp_root_dir); 215ea8dc4b6Seschrock if (err) 216ea8dc4b6Seschrock goto out; 217fa9e4066Sahrens 218088f3894Sahrens err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir); 219ea8dc4b6Seschrock if (err) 220ea8dc4b6Seschrock goto out; 221ea8dc4b6Seschrock 222ad135b5dSChristopher Siden if (spa_version(dp->dp_spa) >= SPA_VERSION_ORIGIN) { 223088f3894Sahrens err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd); 224088f3894Sahrens if (err) 225088f3894Sahrens goto out; 226088f3894Sahrens err = dsl_dataset_hold_obj(dp, dd->dd_phys->dd_head_dataset_obj, 227088f3894Sahrens FTAG, &ds); 2288f63aa46SLin Ling if (err == 0) { 2298f63aa46SLin Ling err = dsl_dataset_hold_obj(dp, 2308f63aa46SLin Ling ds->ds_phys->ds_prev_snap_obj, dp, 2318f63aa46SLin Ling &dp->dp_origin_snap); 2328f63aa46SLin Ling dsl_dataset_rele(ds, FTAG); 2338f63aa46SLin Ling } 2343b2aab18SMatthew Ahrens dsl_dir_rele(dd, dp); 235088f3894Sahrens if (err) 236088f3894Sahrens goto out; 237088f3894Sahrens } 238088f3894Sahrens 239ad135b5dSChristopher Siden if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) { 240cde58dbcSMatthew Ahrens err = dsl_pool_open_special_dir(dp, FREE_DIR_NAME, 241cde58dbcSMatthew Ahrens &dp->dp_free_dir); 242cde58dbcSMatthew Ahrens if (err) 243cde58dbcSMatthew Ahrens goto out; 244cde58dbcSMatthew Ahrens 245cde58dbcSMatthew Ahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 246cde58dbcSMatthew Ahrens DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj); 247cde58dbcSMatthew Ahrens if (err) 248cde58dbcSMatthew Ahrens goto out; 2493b2aab18SMatthew Ahrens VERIFY0(bpobj_open(&dp->dp_free_bpobj, 250cde58dbcSMatthew Ahrens dp->dp_meta_objset, obj)); 251cde58dbcSMatthew Ahrens } 252cde58dbcSMatthew Ahrens 253ad135b5dSChristopher Siden if (spa_feature_is_active(dp->dp_spa, 254ad135b5dSChristopher Siden &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) { 255ad135b5dSChristopher Siden err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 256ad135b5dSChristopher Siden DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1, 257ad135b5dSChristopher Siden &dp->dp_bptree_obj); 258ad135b5dSChristopher Siden if (err != 0) 259ad135b5dSChristopher Siden goto out; 260ad135b5dSChristopher Siden } 261ad135b5dSChristopher Siden 262f1745736SMatthew Ahrens if (spa_feature_is_active(dp->dp_spa, 263f1745736SMatthew Ahrens &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ])) { 264f1745736SMatthew Ahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 265f1745736SMatthew Ahrens DMU_POOL_EMPTY_BPOBJ, sizeof (uint64_t), 1, 266f1745736SMatthew Ahrens &dp->dp_empty_bpobj); 267f1745736SMatthew Ahrens if (err != 0) 268f1745736SMatthew Ahrens goto out; 269f1745736SMatthew Ahrens } 270f1745736SMatthew Ahrens 271ca45db41SChris Kirby err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 272ca45db41SChris Kirby DMU_POOL_TMP_USERREFS, sizeof (uint64_t), 1, 273ca45db41SChris Kirby &dp->dp_tmp_userrefs_obj); 274ca45db41SChris Kirby if (err == ENOENT) 275ca45db41SChris Kirby err = 0; 276ca45db41SChris Kirby if (err) 277ca45db41SChris Kirby goto out; 278ca45db41SChris Kirby 279ad135b5dSChristopher Siden err = dsl_scan_init(dp, dp->dp_tx.tx_open_txg); 280088f3894Sahrens 281ea8dc4b6Seschrock out: 2823b2aab18SMatthew Ahrens rrw_exit(&dp->dp_config_rwlock, FTAG); 283ea8dc4b6Seschrock return (err); 284fa9e4066Sahrens } 285fa9e4066Sahrens 286fa9e4066Sahrens void 287fa9e4066Sahrens dsl_pool_close(dsl_pool_t *dp) 288fa9e4066Sahrens { 289088f3894Sahrens /* 290*69962b56SMatthew Ahrens * Drop our references from dsl_pool_open(). 291*69962b56SMatthew Ahrens * 292088f3894Sahrens * Since we held the origin_snap from "syncing" context (which 293088f3894Sahrens * includes pool-opening context), it actually only got a "ref" 294088f3894Sahrens * and not a hold, so just drop that here. 295088f3894Sahrens */ 296088f3894Sahrens if (dp->dp_origin_snap) 2973b2aab18SMatthew Ahrens dsl_dataset_rele(dp->dp_origin_snap, dp); 298ea8dc4b6Seschrock if (dp->dp_mos_dir) 2993b2aab18SMatthew Ahrens dsl_dir_rele(dp->dp_mos_dir, dp); 300cde58dbcSMatthew Ahrens if (dp->dp_free_dir) 3013b2aab18SMatthew Ahrens dsl_dir_rele(dp->dp_free_dir, dp); 302ea8dc4b6Seschrock if (dp->dp_root_dir) 3033b2aab18SMatthew Ahrens dsl_dir_rele(dp->dp_root_dir, dp); 304fa9e4066Sahrens 305cde58dbcSMatthew Ahrens bpobj_close(&dp->dp_free_bpobj); 306cde58dbcSMatthew Ahrens 307fa9e4066Sahrens /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */ 308ea8dc4b6Seschrock if (dp->dp_meta_objset) 309503ad85cSMatthew Ahrens dmu_objset_evict(dp->dp_meta_objset); 310fa9e4066Sahrens 311fa9e4066Sahrens txg_list_destroy(&dp->dp_dirty_datasets); 312ce636f8bSMatthew Ahrens txg_list_destroy(&dp->dp_dirty_zilogs); 31354a91118SChris Kirby txg_list_destroy(&dp->dp_sync_tasks); 314fa9e4066Sahrens txg_list_destroy(&dp->dp_dirty_dirs); 315fa9e4066Sahrens 316874395d5Smaybee arc_flush(dp->dp_spa); 317fa9e4066Sahrens txg_fini(dp); 3183f9d6ad7SLin Ling dsl_scan_fini(dp); 3193b2aab18SMatthew Ahrens rrw_destroy(&dp->dp_config_rwlock); 3201ab7f2deSmaybee mutex_destroy(&dp->dp_lock); 3219d3574bfSNeil Perrin taskq_destroy(dp->dp_vnrele_taskq); 32288b7b0f2SMatthew Ahrens if (dp->dp_blkstats) 32388b7b0f2SMatthew Ahrens kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t)); 324fa9e4066Sahrens kmem_free(dp, sizeof (dsl_pool_t)); 325fa9e4066Sahrens } 326fa9e4066Sahrens 327fa9e4066Sahrens dsl_pool_t * 3280a48a24eStimh dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg) 329fa9e4066Sahrens { 330fa9e4066Sahrens int err; 331fa9e4066Sahrens dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); 332fa9e4066Sahrens dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg); 333503ad85cSMatthew Ahrens objset_t *os; 334088f3894Sahrens dsl_dataset_t *ds; 335cde58dbcSMatthew Ahrens uint64_t obj; 336088f3894Sahrens 3373b2aab18SMatthew Ahrens rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG); 3383b2aab18SMatthew Ahrens 339088f3894Sahrens /* create and open the MOS (meta-objset) */ 340503ad85cSMatthew Ahrens dp->dp_meta_objset = dmu_objset_create_impl(spa, 341503ad85cSMatthew Ahrens NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx); 342fa9e4066Sahrens 343fa9e4066Sahrens /* create the pool directory */ 344fa9e4066Sahrens err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 345fa9e4066Sahrens DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx); 346fb09f5aaSMadhav Suresh ASSERT0(err); 347fa9e4066Sahrens 3483f9d6ad7SLin Ling /* Initialize scan structures */ 3493b2aab18SMatthew Ahrens VERIFY0(dsl_scan_init(dp, txg)); 3503f9d6ad7SLin Ling 351fa9e4066Sahrens /* create and open the root dir */ 352088f3894Sahrens dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx); 3533b2aab18SMatthew Ahrens VERIFY0(dsl_dir_hold_obj(dp, dp->dp_root_dir_obj, 354ea8dc4b6Seschrock NULL, dp, &dp->dp_root_dir)); 355fa9e4066Sahrens 356fa9e4066Sahrens /* create and open the meta-objset dir */ 357088f3894Sahrens (void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx); 3583b2aab18SMatthew Ahrens VERIFY0(dsl_pool_open_special_dir(dp, 359088f3894Sahrens MOS_DIR_NAME, &dp->dp_mos_dir)); 360088f3894Sahrens 361cde58dbcSMatthew Ahrens if (spa_version(spa) >= SPA_VERSION_DEADLISTS) { 362cde58dbcSMatthew Ahrens /* create and open the free dir */ 363cde58dbcSMatthew Ahrens (void) dsl_dir_create_sync(dp, dp->dp_root_dir, 364cde58dbcSMatthew Ahrens FREE_DIR_NAME, tx); 3653b2aab18SMatthew Ahrens VERIFY0(dsl_pool_open_special_dir(dp, 366cde58dbcSMatthew Ahrens FREE_DIR_NAME, &dp->dp_free_dir)); 367cde58dbcSMatthew Ahrens 368cde58dbcSMatthew Ahrens /* create and open the free_bplist */ 369cde58dbcSMatthew Ahrens obj = bpobj_alloc(dp->dp_meta_objset, SPA_MAXBLOCKSIZE, tx); 370cde58dbcSMatthew Ahrens VERIFY(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 371cde58dbcSMatthew Ahrens DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx) == 0); 3723b2aab18SMatthew Ahrens VERIFY0(bpobj_open(&dp->dp_free_bpobj, 373cde58dbcSMatthew Ahrens dp->dp_meta_objset, obj)); 374cde58dbcSMatthew Ahrens } 375cde58dbcSMatthew Ahrens 376088f3894Sahrens if (spa_version(spa) >= SPA_VERSION_DSL_SCRUB) 377088f3894Sahrens dsl_pool_create_origin(dp, tx); 378088f3894Sahrens 379088f3894Sahrens /* create the root dataset */ 380cde58dbcSMatthew Ahrens obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx); 381088f3894Sahrens 382088f3894Sahrens /* create the root objset */ 3833b2aab18SMatthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, obj, FTAG, &ds)); 384503ad85cSMatthew Ahrens os = dmu_objset_create_impl(dp->dp_spa, ds, 385088f3894Sahrens dsl_dataset_get_blkptr(ds), DMU_OST_ZFS, tx); 386088f3894Sahrens #ifdef _KERNEL 387503ad85cSMatthew Ahrens zfs_create_fs(os, kcred, zplprops, tx); 388088f3894Sahrens #endif 389088f3894Sahrens dsl_dataset_rele(ds, FTAG); 390fa9e4066Sahrens 391fa9e4066Sahrens dmu_tx_commit(tx); 392fa9e4066Sahrens 3933b2aab18SMatthew Ahrens rrw_exit(&dp->dp_config_rwlock, FTAG); 3943b2aab18SMatthew Ahrens 395fa9e4066Sahrens return (dp); 396fa9e4066Sahrens } 397fa9e4066Sahrens 398ce636f8bSMatthew Ahrens /* 399ce636f8bSMatthew Ahrens * Account for the meta-objset space in its placeholder dsl_dir. 400ce636f8bSMatthew Ahrens */ 401ce636f8bSMatthew Ahrens void 402ce636f8bSMatthew Ahrens dsl_pool_mos_diduse_space(dsl_pool_t *dp, 403ce636f8bSMatthew Ahrens int64_t used, int64_t comp, int64_t uncomp) 404ce636f8bSMatthew Ahrens { 405ce636f8bSMatthew Ahrens ASSERT3U(comp, ==, uncomp); /* it's all metadata */ 406ce636f8bSMatthew Ahrens mutex_enter(&dp->dp_lock); 407ce636f8bSMatthew Ahrens dp->dp_mos_used_delta += used; 408ce636f8bSMatthew Ahrens dp->dp_mos_compressed_delta += comp; 409ce636f8bSMatthew Ahrens dp->dp_mos_uncompressed_delta += uncomp; 410ce636f8bSMatthew Ahrens mutex_exit(&dp->dp_lock); 411ce636f8bSMatthew Ahrens } 412ce636f8bSMatthew Ahrens 413cde58dbcSMatthew Ahrens static int 414cde58dbcSMatthew Ahrens deadlist_enqueue_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) 415cde58dbcSMatthew Ahrens { 416cde58dbcSMatthew Ahrens dsl_deadlist_t *dl = arg; 417cde58dbcSMatthew Ahrens dsl_deadlist_insert(dl, bp, tx); 418cde58dbcSMatthew Ahrens return (0); 419cde58dbcSMatthew Ahrens } 420cde58dbcSMatthew Ahrens 421*69962b56SMatthew Ahrens static void 422*69962b56SMatthew Ahrens dsl_pool_sync_mos(dsl_pool_t *dp, dmu_tx_t *tx) 423*69962b56SMatthew Ahrens { 424*69962b56SMatthew Ahrens zio_t *zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 425*69962b56SMatthew Ahrens dmu_objset_sync(dp->dp_meta_objset, zio, tx); 426*69962b56SMatthew Ahrens VERIFY0(zio_wait(zio)); 427*69962b56SMatthew Ahrens dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", ""); 428*69962b56SMatthew Ahrens spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp); 429*69962b56SMatthew Ahrens } 430*69962b56SMatthew Ahrens 431*69962b56SMatthew Ahrens static void 432*69962b56SMatthew Ahrens dsl_pool_dirty_delta(dsl_pool_t *dp, int64_t delta) 433*69962b56SMatthew Ahrens { 434*69962b56SMatthew Ahrens ASSERT(MUTEX_HELD(&dp->dp_lock)); 435*69962b56SMatthew Ahrens 436*69962b56SMatthew Ahrens if (delta < 0) 437*69962b56SMatthew Ahrens ASSERT3U(-delta, <=, dp->dp_dirty_total); 438*69962b56SMatthew Ahrens 439*69962b56SMatthew Ahrens dp->dp_dirty_total += delta; 440*69962b56SMatthew Ahrens 441*69962b56SMatthew Ahrens /* 442*69962b56SMatthew Ahrens * Note: we signal even when increasing dp_dirty_total. 443*69962b56SMatthew Ahrens * This ensures forward progress -- each thread wakes the next waiter. 444*69962b56SMatthew Ahrens */ 445*69962b56SMatthew Ahrens if (dp->dp_dirty_total <= zfs_dirty_data_max) 446*69962b56SMatthew Ahrens cv_signal(&dp->dp_spaceavail_cv); 447*69962b56SMatthew Ahrens } 448*69962b56SMatthew Ahrens 449fa9e4066Sahrens void 450fa9e4066Sahrens dsl_pool_sync(dsl_pool_t *dp, uint64_t txg) 451fa9e4066Sahrens { 452c717a561Smaybee zio_t *zio; 453fa9e4066Sahrens dmu_tx_t *tx; 454c717a561Smaybee dsl_dir_t *dd; 455c717a561Smaybee dsl_dataset_t *ds; 456503ad85cSMatthew Ahrens objset_t *mos = dp->dp_meta_objset; 457ce636f8bSMatthew Ahrens list_t synced_datasets; 458ce636f8bSMatthew Ahrens 459ce636f8bSMatthew Ahrens list_create(&synced_datasets, sizeof (dsl_dataset_t), 460ce636f8bSMatthew Ahrens offsetof(dsl_dataset_t, ds_synced_link)); 461fa9e4066Sahrens 462fa9e4066Sahrens tx = dmu_tx_create_assigned(dp, txg); 463fa9e4066Sahrens 464*69962b56SMatthew Ahrens /* 465*69962b56SMatthew Ahrens * Write out all dirty blocks of dirty datasets. 466*69962b56SMatthew Ahrens */ 467c717a561Smaybee zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 468*69962b56SMatthew Ahrens while ((ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) != NULL) { 46914843421SMatthew Ahrens /* 47014843421SMatthew Ahrens * We must not sync any non-MOS datasets twice, because 47114843421SMatthew Ahrens * we may have taken a snapshot of them. However, we 47214843421SMatthew Ahrens * may sync newly-created datasets on pass 2. 47314843421SMatthew Ahrens */ 47414843421SMatthew Ahrens ASSERT(!list_link_active(&ds->ds_synced_link)); 475ce636f8bSMatthew Ahrens list_insert_tail(&synced_datasets, ds); 476c717a561Smaybee dsl_dataset_sync(ds, zio, tx); 477c717a561Smaybee } 478*69962b56SMatthew Ahrens VERIFY0(zio_wait(zio)); 47914843421SMatthew Ahrens 480*69962b56SMatthew Ahrens /* 481*69962b56SMatthew Ahrens * We have written all of the accounted dirty data, so our 482*69962b56SMatthew Ahrens * dp_space_towrite should now be zero. However, some seldom-used 483*69962b56SMatthew Ahrens * code paths do not adhere to this (e.g. dbuf_undirty(), also 484*69962b56SMatthew Ahrens * rounding error in dbuf_write_physdone). 485*69962b56SMatthew Ahrens * Shore up the accounting of any dirtied space now. 486*69962b56SMatthew Ahrens */ 487*69962b56SMatthew Ahrens dsl_pool_undirty_space(dp, dp->dp_dirty_pertxg[txg & TXG_MASK], txg); 488c717a561Smaybee 489ce636f8bSMatthew Ahrens /* 490ce636f8bSMatthew Ahrens * After the data blocks have been written (ensured by the zio_wait() 491ce636f8bSMatthew Ahrens * above), update the user/group space accounting. 492ce636f8bSMatthew Ahrens */ 493*69962b56SMatthew Ahrens for (ds = list_head(&synced_datasets); ds != NULL; 494*69962b56SMatthew Ahrens ds = list_next(&synced_datasets, ds)) { 4950a586ceaSMark Shellenbaum dmu_objset_do_userquota_updates(ds->ds_objset, tx); 496*69962b56SMatthew Ahrens } 49714843421SMatthew Ahrens 49814843421SMatthew Ahrens /* 49914843421SMatthew Ahrens * Sync the datasets again to push out the changes due to 5003f9d6ad7SLin Ling * userspace updates. This must be done before we process the 501ce636f8bSMatthew Ahrens * sync tasks, so that any snapshots will have the correct 502ce636f8bSMatthew Ahrens * user accounting information (and we won't get confused 503ce636f8bSMatthew Ahrens * about which blocks are part of the snapshot). 50414843421SMatthew Ahrens */ 50514843421SMatthew Ahrens zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 506*69962b56SMatthew Ahrens while ((ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) != NULL) { 50714843421SMatthew Ahrens ASSERT(list_link_active(&ds->ds_synced_link)); 50814843421SMatthew Ahrens dmu_buf_rele(ds->ds_dbuf, ds); 50914843421SMatthew Ahrens dsl_dataset_sync(ds, zio, tx); 51014843421SMatthew Ahrens } 511*69962b56SMatthew Ahrens VERIFY0(zio_wait(zio)); 51214843421SMatthew Ahrens 513b24ab676SJeff Bonwick /* 514ce636f8bSMatthew Ahrens * Now that the datasets have been completely synced, we can 515ce636f8bSMatthew Ahrens * clean up our in-memory structures accumulated while syncing: 516ce636f8bSMatthew Ahrens * 517ce636f8bSMatthew Ahrens * - move dead blocks from the pending deadlist to the on-disk deadlist 518ce636f8bSMatthew Ahrens * - release hold from dsl_dataset_dirty() 519b24ab676SJeff Bonwick */ 520*69962b56SMatthew Ahrens while ((ds = list_remove_head(&synced_datasets)) != NULL) { 521ce636f8bSMatthew Ahrens objset_t *os = ds->ds_objset; 522cde58dbcSMatthew Ahrens bplist_iterate(&ds->ds_pending_deadlist, 523cde58dbcSMatthew Ahrens deadlist_enqueue_cb, &ds->ds_deadlist, tx); 524ce636f8bSMatthew Ahrens ASSERT(!dmu_objset_is_dirty(os, txg)); 525ce636f8bSMatthew Ahrens dmu_buf_rele(ds->ds_dbuf, ds); 526cde58dbcSMatthew Ahrens } 527*69962b56SMatthew Ahrens while ((dd = txg_list_remove(&dp->dp_dirty_dirs, txg)) != NULL) { 528c717a561Smaybee dsl_dir_sync(dd, tx); 529*69962b56SMatthew Ahrens } 530fa9e4066Sahrens 531ce636f8bSMatthew Ahrens /* 532ce636f8bSMatthew Ahrens * The MOS's space is accounted for in the pool/$MOS 533ce636f8bSMatthew Ahrens * (dp_mos_dir). We can't modify the mos while we're syncing 534ce636f8bSMatthew Ahrens * it, so we remember the deltas and apply them here. 535ce636f8bSMatthew Ahrens */ 536ce636f8bSMatthew Ahrens if (dp->dp_mos_used_delta != 0 || dp->dp_mos_compressed_delta != 0 || 537ce636f8bSMatthew Ahrens dp->dp_mos_uncompressed_delta != 0) { 538ce636f8bSMatthew Ahrens dsl_dir_diduse_space(dp->dp_mos_dir, DD_USED_HEAD, 539ce636f8bSMatthew Ahrens dp->dp_mos_used_delta, 540ce636f8bSMatthew Ahrens dp->dp_mos_compressed_delta, 541ce636f8bSMatthew Ahrens dp->dp_mos_uncompressed_delta, tx); 542ce636f8bSMatthew Ahrens dp->dp_mos_used_delta = 0; 543ce636f8bSMatthew Ahrens dp->dp_mos_compressed_delta = 0; 544ce636f8bSMatthew Ahrens dp->dp_mos_uncompressed_delta = 0; 545ce636f8bSMatthew Ahrens } 546ce636f8bSMatthew Ahrens 547503ad85cSMatthew Ahrens if (list_head(&mos->os_dirty_dnodes[txg & TXG_MASK]) != NULL || 548503ad85cSMatthew Ahrens list_head(&mos->os_free_dnodes[txg & TXG_MASK]) != NULL) { 549*69962b56SMatthew Ahrens dsl_pool_sync_mos(dp, tx); 550fa9e4066Sahrens } 551fa9e4066Sahrens 552ce636f8bSMatthew Ahrens /* 553ce636f8bSMatthew Ahrens * If we modify a dataset in the same txg that we want to destroy it, 554ce636f8bSMatthew Ahrens * its dsl_dir's dd_dbuf will be dirty, and thus have a hold on it. 555ce636f8bSMatthew Ahrens * dsl_dir_destroy_check() will fail if there are unexpected holds. 556ce636f8bSMatthew Ahrens * Therefore, we want to sync the MOS (thus syncing the dd_dbuf 557ce636f8bSMatthew Ahrens * and clearing the hold on it) before we process the sync_tasks. 558ce636f8bSMatthew Ahrens * The MOS data dirtied by the sync_tasks will be synced on the next 559ce636f8bSMatthew Ahrens * pass. 560ce636f8bSMatthew Ahrens */ 561ce636f8bSMatthew Ahrens if (!txg_list_empty(&dp->dp_sync_tasks, txg)) { 5623b2aab18SMatthew Ahrens dsl_sync_task_t *dst; 563ce636f8bSMatthew Ahrens /* 564ce636f8bSMatthew Ahrens * No more sync tasks should have been added while we 565ce636f8bSMatthew Ahrens * were syncing. 566ce636f8bSMatthew Ahrens */ 567*69962b56SMatthew Ahrens ASSERT3U(spa_sync_pass(dp->dp_spa), ==, 1); 568*69962b56SMatthew Ahrens while ((dst = txg_list_remove(&dp->dp_sync_tasks, txg)) != NULL) 5693b2aab18SMatthew Ahrens dsl_sync_task_sync(dst, tx); 570ce636f8bSMatthew Ahrens } 571ce636f8bSMatthew Ahrens 572fa9e4066Sahrens dmu_tx_commit(tx); 57305715f94SMark Maybee 574*69962b56SMatthew Ahrens DTRACE_PROBE2(dsl_pool_sync__done, dsl_pool_t *dp, dp, uint64_t, txg); 575fa9e4066Sahrens } 576fa9e4066Sahrens 577fa9e4066Sahrens void 578b24ab676SJeff Bonwick dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg) 579fa9e4066Sahrens { 580ce636f8bSMatthew Ahrens zilog_t *zilog; 581fa9e4066Sahrens 582ce636f8bSMatthew Ahrens while (zilog = txg_list_remove(&dp->dp_dirty_zilogs, txg)) { 583*69962b56SMatthew Ahrens dsl_dataset_t *ds = dmu_objset_ds(zilog->zl_os); 584ce636f8bSMatthew Ahrens zil_clean(zilog, txg); 585ce636f8bSMatthew Ahrens ASSERT(!dmu_objset_is_dirty(zilog->zl_os, txg)); 586ce636f8bSMatthew Ahrens dmu_buf_rele(ds->ds_dbuf, zilog); 587fa9e4066Sahrens } 588b24ab676SJeff Bonwick ASSERT(!dmu_objset_is_dirty(dp->dp_meta_objset, txg)); 589fa9e4066Sahrens } 590fa9e4066Sahrens 591c717a561Smaybee /* 592c717a561Smaybee * TRUE if the current thread is the tx_sync_thread or if we 593c717a561Smaybee * are being called from SPA context during pool initialization. 594c717a561Smaybee */ 595fa9e4066Sahrens int 596fa9e4066Sahrens dsl_pool_sync_context(dsl_pool_t *dp) 597fa9e4066Sahrens { 598fa9e4066Sahrens return (curthread == dp->dp_tx.tx_sync_thread || 599ad135b5dSChristopher Siden spa_is_initializing(dp->dp_spa)); 600fa9e4066Sahrens } 601fa9e4066Sahrens 602fa9e4066Sahrens uint64_t 603fa9e4066Sahrens dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree) 604fa9e4066Sahrens { 605fa9e4066Sahrens uint64_t space, resv; 606fa9e4066Sahrens 607fa9e4066Sahrens /* 60844cd46caSbillm * Reserve about 1.6% (1/64), or at least 32MB, for allocation 609fa9e4066Sahrens * efficiency. 610fa9e4066Sahrens * XXX The intent log is not accounted for, so it must fit 611fa9e4066Sahrens * within this slop. 612fa9e4066Sahrens * 613fa9e4066Sahrens * If we're trying to assess whether it's OK to do a free, 614fa9e4066Sahrens * cut the reservation in half to allow forward progress 615fa9e4066Sahrens * (e.g. make it possible to rm(1) files from a full pool). 616fa9e4066Sahrens */ 617485bbbf5SGeorge Wilson space = spa_get_dspace(dp->dp_spa); 61844cd46caSbillm resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1); 619fa9e4066Sahrens if (netfree) 620fa9e4066Sahrens resv >>= 1; 621fa9e4066Sahrens 622fa9e4066Sahrens return (space - resv); 623fa9e4066Sahrens } 6241ab7f2deSmaybee 625*69962b56SMatthew Ahrens boolean_t 626*69962b56SMatthew Ahrens dsl_pool_need_dirty_delay(dsl_pool_t *dp) 6271ab7f2deSmaybee { 628*69962b56SMatthew Ahrens uint64_t delay_min_bytes = 629*69962b56SMatthew Ahrens zfs_dirty_data_max * zfs_delay_min_dirty_percent / 100; 630*69962b56SMatthew Ahrens boolean_t rv; 6311ab7f2deSmaybee 632*69962b56SMatthew Ahrens mutex_enter(&dp->dp_lock); 633*69962b56SMatthew Ahrens if (dp->dp_dirty_total > zfs_dirty_data_sync) 634*69962b56SMatthew Ahrens txg_kick(dp); 635*69962b56SMatthew Ahrens rv = (dp->dp_dirty_total > delay_min_bytes); 636*69962b56SMatthew Ahrens mutex_exit(&dp->dp_lock); 637*69962b56SMatthew Ahrens return (rv); 6381ab7f2deSmaybee } 6391ab7f2deSmaybee 6401ab7f2deSmaybee void 641*69962b56SMatthew Ahrens dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx) 6421ab7f2deSmaybee { 643*69962b56SMatthew Ahrens if (space > 0) { 644*69962b56SMatthew Ahrens mutex_enter(&dp->dp_lock); 645*69962b56SMatthew Ahrens dp->dp_dirty_pertxg[tx->tx_txg & TXG_MASK] += space; 646*69962b56SMatthew Ahrens dsl_pool_dirty_delta(dp, space); 647*69962b56SMatthew Ahrens mutex_exit(&dp->dp_lock); 6481ab7f2deSmaybee } 6491ab7f2deSmaybee } 6501ab7f2deSmaybee 6511ab7f2deSmaybee void 652*69962b56SMatthew Ahrens dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg) 6531ab7f2deSmaybee { 654*69962b56SMatthew Ahrens ASSERT3S(space, >=, 0); 655*69962b56SMatthew Ahrens if (space == 0) 656*69962b56SMatthew Ahrens return; 657*69962b56SMatthew Ahrens mutex_enter(&dp->dp_lock); 658*69962b56SMatthew Ahrens if (dp->dp_dirty_pertxg[txg & TXG_MASK] < space) { 659*69962b56SMatthew Ahrens /* XXX writing something we didn't dirty? */ 660*69962b56SMatthew Ahrens space = dp->dp_dirty_pertxg[txg & TXG_MASK]; 6611ab7f2deSmaybee } 662*69962b56SMatthew Ahrens ASSERT3U(dp->dp_dirty_pertxg[txg & TXG_MASK], >=, space); 663*69962b56SMatthew Ahrens dp->dp_dirty_pertxg[txg & TXG_MASK] -= space; 664*69962b56SMatthew Ahrens ASSERT3U(dp->dp_dirty_total, >=, space); 665*69962b56SMatthew Ahrens dsl_pool_dirty_delta(dp, -space); 666*69962b56SMatthew Ahrens mutex_exit(&dp->dp_lock); 6671ab7f2deSmaybee } 668088f3894Sahrens 669088f3894Sahrens /* ARGSUSED */ 670088f3894Sahrens static int 6713b2aab18SMatthew Ahrens upgrade_clones_cb(dsl_pool_t *dp, dsl_dataset_t *hds, void *arg) 672088f3894Sahrens { 673088f3894Sahrens dmu_tx_t *tx = arg; 674088f3894Sahrens dsl_dataset_t *ds, *prev = NULL; 675088f3894Sahrens int err; 676088f3894Sahrens 6773b2aab18SMatthew Ahrens err = dsl_dataset_hold_obj(dp, hds->ds_object, FTAG, &ds); 678088f3894Sahrens if (err) 679088f3894Sahrens return (err); 680088f3894Sahrens 681088f3894Sahrens while (ds->ds_phys->ds_prev_snap_obj != 0) { 682088f3894Sahrens err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj, 683088f3894Sahrens FTAG, &prev); 684088f3894Sahrens if (err) { 685088f3894Sahrens dsl_dataset_rele(ds, FTAG); 686088f3894Sahrens return (err); 687088f3894Sahrens } 688088f3894Sahrens 689088f3894Sahrens if (prev->ds_phys->ds_next_snap_obj != ds->ds_object) 690088f3894Sahrens break; 691088f3894Sahrens dsl_dataset_rele(ds, FTAG); 692088f3894Sahrens ds = prev; 693088f3894Sahrens prev = NULL; 694088f3894Sahrens } 695088f3894Sahrens 696088f3894Sahrens if (prev == NULL) { 697088f3894Sahrens prev = dp->dp_origin_snap; 698088f3894Sahrens 699088f3894Sahrens /* 700088f3894Sahrens * The $ORIGIN can't have any data, or the accounting 701088f3894Sahrens * will be wrong. 702088f3894Sahrens */ 7033b2aab18SMatthew Ahrens ASSERT0(prev->ds_phys->ds_bp.blk_birth); 704088f3894Sahrens 705088f3894Sahrens /* The origin doesn't get attached to itself */ 706088f3894Sahrens if (ds->ds_object == prev->ds_object) { 707088f3894Sahrens dsl_dataset_rele(ds, FTAG); 708088f3894Sahrens return (0); 709088f3894Sahrens } 710088f3894Sahrens 711088f3894Sahrens dmu_buf_will_dirty(ds->ds_dbuf, tx); 712088f3894Sahrens ds->ds_phys->ds_prev_snap_obj = prev->ds_object; 713088f3894Sahrens ds->ds_phys->ds_prev_snap_txg = prev->ds_phys->ds_creation_txg; 714088f3894Sahrens 715088f3894Sahrens dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx); 716088f3894Sahrens ds->ds_dir->dd_phys->dd_origin_obj = prev->ds_object; 717088f3894Sahrens 718088f3894Sahrens dmu_buf_will_dirty(prev->ds_dbuf, tx); 719088f3894Sahrens prev->ds_phys->ds_num_children++; 720088f3894Sahrens 721088f3894Sahrens if (ds->ds_phys->ds_next_snap_obj == 0) { 722088f3894Sahrens ASSERT(ds->ds_prev == NULL); 7233b2aab18SMatthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, 724088f3894Sahrens ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev)); 725088f3894Sahrens } 726088f3894Sahrens } 727088f3894Sahrens 7283b2aab18SMatthew Ahrens ASSERT3U(ds->ds_dir->dd_phys->dd_origin_obj, ==, prev->ds_object); 7293b2aab18SMatthew Ahrens ASSERT3U(ds->ds_phys->ds_prev_snap_obj, ==, prev->ds_object); 730088f3894Sahrens 731088f3894Sahrens if (prev->ds_phys->ds_next_clones_obj == 0) { 732c33e334fSMatthew Ahrens dmu_buf_will_dirty(prev->ds_dbuf, tx); 733088f3894Sahrens prev->ds_phys->ds_next_clones_obj = 734088f3894Sahrens zap_create(dp->dp_meta_objset, 735088f3894Sahrens DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx); 736088f3894Sahrens } 7373b2aab18SMatthew Ahrens VERIFY0(zap_add_int(dp->dp_meta_objset, 738088f3894Sahrens prev->ds_phys->ds_next_clones_obj, ds->ds_object, tx)); 739088f3894Sahrens 740088f3894Sahrens dsl_dataset_rele(ds, FTAG); 741088f3894Sahrens if (prev != dp->dp_origin_snap) 742088f3894Sahrens dsl_dataset_rele(prev, FTAG); 743088f3894Sahrens return (0); 744088f3894Sahrens } 745088f3894Sahrens 746088f3894Sahrens void 747088f3894Sahrens dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx) 748088f3894Sahrens { 749088f3894Sahrens ASSERT(dmu_tx_is_syncing(tx)); 750088f3894Sahrens ASSERT(dp->dp_origin_snap != NULL); 751088f3894Sahrens 7523b2aab18SMatthew Ahrens VERIFY0(dmu_objset_find_dp(dp, dp->dp_root_dir_obj, upgrade_clones_cb, 753c33e334fSMatthew Ahrens tx, DS_FIND_CHILDREN)); 754088f3894Sahrens } 755088f3894Sahrens 756cde58dbcSMatthew Ahrens /* ARGSUSED */ 757cde58dbcSMatthew Ahrens static int 7583b2aab18SMatthew Ahrens upgrade_dir_clones_cb(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg) 759cde58dbcSMatthew Ahrens { 760cde58dbcSMatthew Ahrens dmu_tx_t *tx = arg; 761cde58dbcSMatthew Ahrens objset_t *mos = dp->dp_meta_objset; 762cde58dbcSMatthew Ahrens 7633b2aab18SMatthew Ahrens if (ds->ds_dir->dd_phys->dd_origin_obj != 0) { 764cde58dbcSMatthew Ahrens dsl_dataset_t *origin; 765cde58dbcSMatthew Ahrens 7663b2aab18SMatthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, 767cde58dbcSMatthew Ahrens ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &origin)); 768cde58dbcSMatthew Ahrens 769cde58dbcSMatthew Ahrens if (origin->ds_dir->dd_phys->dd_clones == 0) { 770cde58dbcSMatthew Ahrens dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx); 771cde58dbcSMatthew Ahrens origin->ds_dir->dd_phys->dd_clones = zap_create(mos, 772cde58dbcSMatthew Ahrens DMU_OT_DSL_CLONES, DMU_OT_NONE, 0, tx); 773cde58dbcSMatthew Ahrens } 774cde58dbcSMatthew Ahrens 7753b2aab18SMatthew Ahrens VERIFY0(zap_add_int(dp->dp_meta_objset, 7763b2aab18SMatthew Ahrens origin->ds_dir->dd_phys->dd_clones, ds->ds_object, tx)); 777cde58dbcSMatthew Ahrens 778cde58dbcSMatthew Ahrens dsl_dataset_rele(origin, FTAG); 779cde58dbcSMatthew Ahrens } 780cde58dbcSMatthew Ahrens return (0); 781cde58dbcSMatthew Ahrens } 782cde58dbcSMatthew Ahrens 783cde58dbcSMatthew Ahrens void 784cde58dbcSMatthew Ahrens dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx) 785cde58dbcSMatthew Ahrens { 786cde58dbcSMatthew Ahrens ASSERT(dmu_tx_is_syncing(tx)); 787cde58dbcSMatthew Ahrens uint64_t obj; 788cde58dbcSMatthew Ahrens 789cde58dbcSMatthew Ahrens (void) dsl_dir_create_sync(dp, dp->dp_root_dir, FREE_DIR_NAME, tx); 7903b2aab18SMatthew Ahrens VERIFY0(dsl_pool_open_special_dir(dp, 791cde58dbcSMatthew Ahrens FREE_DIR_NAME, &dp->dp_free_dir)); 792cde58dbcSMatthew Ahrens 793cde58dbcSMatthew Ahrens /* 794cde58dbcSMatthew Ahrens * We can't use bpobj_alloc(), because spa_version() still 795cde58dbcSMatthew Ahrens * returns the old version, and we need a new-version bpobj with 796cde58dbcSMatthew Ahrens * subobj support. So call dmu_object_alloc() directly. 797cde58dbcSMatthew Ahrens */ 798cde58dbcSMatthew Ahrens obj = dmu_object_alloc(dp->dp_meta_objset, DMU_OT_BPOBJ, 799cde58dbcSMatthew Ahrens SPA_MAXBLOCKSIZE, DMU_OT_BPOBJ_HDR, sizeof (bpobj_phys_t), tx); 8003b2aab18SMatthew Ahrens VERIFY0(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 801cde58dbcSMatthew Ahrens DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx)); 8023b2aab18SMatthew Ahrens VERIFY0(bpobj_open(&dp->dp_free_bpobj, dp->dp_meta_objset, obj)); 803cde58dbcSMatthew Ahrens 8043b2aab18SMatthew Ahrens VERIFY0(dmu_objset_find_dp(dp, dp->dp_root_dir_obj, 805cde58dbcSMatthew Ahrens upgrade_dir_clones_cb, tx, DS_FIND_CHILDREN)); 806cde58dbcSMatthew Ahrens } 807cde58dbcSMatthew Ahrens 808088f3894Sahrens void 809088f3894Sahrens dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx) 810088f3894Sahrens { 811088f3894Sahrens uint64_t dsobj; 812088f3894Sahrens dsl_dataset_t *ds; 813088f3894Sahrens 814088f3894Sahrens ASSERT(dmu_tx_is_syncing(tx)); 815088f3894Sahrens ASSERT(dp->dp_origin_snap == NULL); 8163b2aab18SMatthew Ahrens ASSERT(rrw_held(&dp->dp_config_rwlock, RW_WRITER)); 817088f3894Sahrens 818088f3894Sahrens /* create the origin dir, ds, & snap-ds */ 819088f3894Sahrens dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME, 820088f3894Sahrens NULL, 0, kcred, tx); 8213b2aab18SMatthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds)); 8223b2aab18SMatthew Ahrens dsl_dataset_snapshot_sync_impl(ds, ORIGIN_DIR_NAME, tx); 8233b2aab18SMatthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj, 824088f3894Sahrens dp, &dp->dp_origin_snap)); 825088f3894Sahrens dsl_dataset_rele(ds, FTAG); 826088f3894Sahrens } 8279d3574bfSNeil Perrin 8289d3574bfSNeil Perrin taskq_t * 8299d3574bfSNeil Perrin dsl_pool_vnrele_taskq(dsl_pool_t *dp) 8309d3574bfSNeil Perrin { 8319d3574bfSNeil Perrin return (dp->dp_vnrele_taskq); 8329d3574bfSNeil Perrin } 833ca45db41SChris Kirby 834ca45db41SChris Kirby /* 835ca45db41SChris Kirby * Walk through the pool-wide zap object of temporary snapshot user holds 836ca45db41SChris Kirby * and release them. 837ca45db41SChris Kirby */ 838ca45db41SChris Kirby void 839ca45db41SChris Kirby dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp) 840ca45db41SChris Kirby { 841ca45db41SChris Kirby zap_attribute_t za; 842ca45db41SChris Kirby zap_cursor_t zc; 843ca45db41SChris Kirby objset_t *mos = dp->dp_meta_objset; 844ca45db41SChris Kirby uint64_t zapobj = dp->dp_tmp_userrefs_obj; 845a7a845e4SSteven Hartland nvlist_t *holds; 846ca45db41SChris Kirby 847ca45db41SChris Kirby if (zapobj == 0) 848ca45db41SChris Kirby return; 849ca45db41SChris Kirby ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS); 850ca45db41SChris Kirby 851a7a845e4SSteven Hartland holds = fnvlist_alloc(); 852a7a845e4SSteven Hartland 853ca45db41SChris Kirby for (zap_cursor_init(&zc, mos, zapobj); 854ca45db41SChris Kirby zap_cursor_retrieve(&zc, &za) == 0; 855ca45db41SChris Kirby zap_cursor_advance(&zc)) { 856ca45db41SChris Kirby char *htag; 857a7a845e4SSteven Hartland nvlist_t *tags; 858ca45db41SChris Kirby 859ca45db41SChris Kirby htag = strchr(za.za_name, '-'); 860ca45db41SChris Kirby *htag = '\0'; 861ca45db41SChris Kirby ++htag; 862a7a845e4SSteven Hartland if (nvlist_lookup_nvlist(holds, za.za_name, &tags) != 0) { 863a7a845e4SSteven Hartland tags = fnvlist_alloc(); 864a7a845e4SSteven Hartland fnvlist_add_boolean(tags, htag); 865a7a845e4SSteven Hartland fnvlist_add_nvlist(holds, za.za_name, tags); 866a7a845e4SSteven Hartland fnvlist_free(tags); 867a7a845e4SSteven Hartland } else { 868a7a845e4SSteven Hartland fnvlist_add_boolean(tags, htag); 869a7a845e4SSteven Hartland } 870ca45db41SChris Kirby } 871a7a845e4SSteven Hartland dsl_dataset_user_release_tmp(dp, holds); 872a7a845e4SSteven Hartland fnvlist_free(holds); 873ca45db41SChris Kirby zap_cursor_fini(&zc); 874ca45db41SChris Kirby } 875ca45db41SChris Kirby 876ca45db41SChris Kirby /* 877ca45db41SChris Kirby * Create the pool-wide zap object for storing temporary snapshot holds. 878ca45db41SChris Kirby */ 879ca45db41SChris Kirby void 880ca45db41SChris Kirby dsl_pool_user_hold_create_obj(dsl_pool_t *dp, dmu_tx_t *tx) 881ca45db41SChris Kirby { 882ca45db41SChris Kirby objset_t *mos = dp->dp_meta_objset; 883ca45db41SChris Kirby 884ca45db41SChris Kirby ASSERT(dp->dp_tmp_userrefs_obj == 0); 885ca45db41SChris Kirby ASSERT(dmu_tx_is_syncing(tx)); 886ca45db41SChris Kirby 887ad135b5dSChristopher Siden dp->dp_tmp_userrefs_obj = zap_create_link(mos, DMU_OT_USERREFS, 888ad135b5dSChristopher Siden DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS, tx); 889ca45db41SChris Kirby } 890ca45db41SChris Kirby 891ca45db41SChris Kirby static int 892ca45db41SChris Kirby dsl_pool_user_hold_rele_impl(dsl_pool_t *dp, uint64_t dsobj, 8933b2aab18SMatthew Ahrens const char *tag, uint64_t now, dmu_tx_t *tx, boolean_t holding) 894ca45db41SChris Kirby { 895ca45db41SChris Kirby objset_t *mos = dp->dp_meta_objset; 896ca45db41SChris Kirby uint64_t zapobj = dp->dp_tmp_userrefs_obj; 897ca45db41SChris Kirby char *name; 898ca45db41SChris Kirby int error; 899ca45db41SChris Kirby 900ca45db41SChris Kirby ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS); 901ca45db41SChris Kirby ASSERT(dmu_tx_is_syncing(tx)); 902ca45db41SChris Kirby 903ca45db41SChris Kirby /* 904ca45db41SChris Kirby * If the pool was created prior to SPA_VERSION_USERREFS, the 905ca45db41SChris Kirby * zap object for temporary holds might not exist yet. 906ca45db41SChris Kirby */ 907ca45db41SChris Kirby if (zapobj == 0) { 908ca45db41SChris Kirby if (holding) { 909ca45db41SChris Kirby dsl_pool_user_hold_create_obj(dp, tx); 910ca45db41SChris Kirby zapobj = dp->dp_tmp_userrefs_obj; 911ca45db41SChris Kirby } else { 912be6fd75aSMatthew Ahrens return (SET_ERROR(ENOENT)); 913ca45db41SChris Kirby } 914ca45db41SChris Kirby } 915ca45db41SChris Kirby 916ca45db41SChris Kirby name = kmem_asprintf("%llx-%s", (u_longlong_t)dsobj, tag); 917ca45db41SChris Kirby if (holding) 9183b2aab18SMatthew Ahrens error = zap_add(mos, zapobj, name, 8, 1, &now, tx); 919ca45db41SChris Kirby else 920ca45db41SChris Kirby error = zap_remove(mos, zapobj, name, tx); 921ca45db41SChris Kirby strfree(name); 922ca45db41SChris Kirby 923ca45db41SChris Kirby return (error); 924ca45db41SChris Kirby } 925ca45db41SChris Kirby 926ca45db41SChris Kirby /* 927ca45db41SChris Kirby * Add a temporary hold for the given dataset object and tag. 928ca45db41SChris Kirby */ 929ca45db41SChris Kirby int 930ca45db41SChris Kirby dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, const char *tag, 9313b2aab18SMatthew Ahrens uint64_t now, dmu_tx_t *tx) 932ca45db41SChris Kirby { 93315508ac0SChris Kirby return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, now, tx, B_TRUE)); 934ca45db41SChris Kirby } 935ca45db41SChris Kirby 936ca45db41SChris Kirby /* 937ca45db41SChris Kirby * Release a temporary hold for the given dataset object and tag. 938ca45db41SChris Kirby */ 939ca45db41SChris Kirby int 940ca45db41SChris Kirby dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, const char *tag, 941ca45db41SChris Kirby dmu_tx_t *tx) 942ca45db41SChris Kirby { 943ca45db41SChris Kirby return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, NULL, 944ca45db41SChris Kirby tx, B_FALSE)); 945ca45db41SChris Kirby } 9463b2aab18SMatthew Ahrens 9473b2aab18SMatthew Ahrens /* 9483b2aab18SMatthew Ahrens * DSL Pool Configuration Lock 9493b2aab18SMatthew Ahrens * 9503b2aab18SMatthew Ahrens * The dp_config_rwlock protects against changes to DSL state (e.g. dataset 9513b2aab18SMatthew Ahrens * creation / destruction / rename / property setting). It must be held for 9523b2aab18SMatthew Ahrens * read to hold a dataset or dsl_dir. I.e. you must call 9533b2aab18SMatthew Ahrens * dsl_pool_config_enter() or dsl_pool_hold() before calling 9543b2aab18SMatthew Ahrens * dsl_{dataset,dir}_hold{_obj}. In most circumstances, the dp_config_rwlock 9553b2aab18SMatthew Ahrens * must be held continuously until all datasets and dsl_dirs are released. 9563b2aab18SMatthew Ahrens * 9573b2aab18SMatthew Ahrens * The only exception to this rule is that if a "long hold" is placed on 9583b2aab18SMatthew Ahrens * a dataset, then the dp_config_rwlock may be dropped while the dataset 9593b2aab18SMatthew Ahrens * is still held. The long hold will prevent the dataset from being 9603b2aab18SMatthew Ahrens * destroyed -- the destroy will fail with EBUSY. A long hold can be 9613b2aab18SMatthew Ahrens * obtained by calling dsl_dataset_long_hold(), or by "owning" a dataset 9623b2aab18SMatthew Ahrens * (by calling dsl_{dataset,objset}_{try}own{_obj}). 9633b2aab18SMatthew Ahrens * 9643b2aab18SMatthew Ahrens * Legitimate long-holders (including owners) should be long-running, cancelable 9653b2aab18SMatthew Ahrens * tasks that should cause "zfs destroy" to fail. This includes DMU 9663b2aab18SMatthew Ahrens * consumers (i.e. a ZPL filesystem being mounted or ZVOL being open), 9673b2aab18SMatthew Ahrens * "zfs send", and "zfs diff". There are several other long-holders whose 9683b2aab18SMatthew Ahrens * uses are suboptimal (e.g. "zfs promote", and zil_suspend()). 9693b2aab18SMatthew Ahrens * 9703b2aab18SMatthew Ahrens * The usual formula for long-holding would be: 9713b2aab18SMatthew Ahrens * dsl_pool_hold() 9723b2aab18SMatthew Ahrens * dsl_dataset_hold() 9733b2aab18SMatthew Ahrens * ... perform checks ... 9743b2aab18SMatthew Ahrens * dsl_dataset_long_hold() 9753b2aab18SMatthew Ahrens * dsl_pool_rele() 9763b2aab18SMatthew Ahrens * ... perform long-running task ... 9773b2aab18SMatthew Ahrens * dsl_dataset_long_rele() 9783b2aab18SMatthew Ahrens * dsl_dataset_rele() 9793b2aab18SMatthew Ahrens * 9803b2aab18SMatthew Ahrens * Note that when the long hold is released, the dataset is still held but 9813b2aab18SMatthew Ahrens * the pool is not held. The dataset may change arbitrarily during this time 9823b2aab18SMatthew Ahrens * (e.g. it could be destroyed). Therefore you shouldn't do anything to the 9833b2aab18SMatthew Ahrens * dataset except release it. 9843b2aab18SMatthew Ahrens * 9853b2aab18SMatthew Ahrens * User-initiated operations (e.g. ioctls, zfs_ioc_*()) are either read-only 9863b2aab18SMatthew Ahrens * or modifying operations. 9873b2aab18SMatthew Ahrens * 9883b2aab18SMatthew Ahrens * Modifying operations should generally use dsl_sync_task(). The synctask 9893b2aab18SMatthew Ahrens * infrastructure enforces proper locking strategy with respect to the 9903b2aab18SMatthew Ahrens * dp_config_rwlock. See the comment above dsl_sync_task() for details. 9913b2aab18SMatthew Ahrens * 9923b2aab18SMatthew Ahrens * Read-only operations will manually hold the pool, then the dataset, obtain 9933b2aab18SMatthew Ahrens * information from the dataset, then release the pool and dataset. 9943b2aab18SMatthew Ahrens * dmu_objset_{hold,rele}() are convenience routines that also do the pool 9953b2aab18SMatthew Ahrens * hold/rele. 9963b2aab18SMatthew Ahrens */ 9973b2aab18SMatthew Ahrens 9983b2aab18SMatthew Ahrens int 9993b2aab18SMatthew Ahrens dsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp) 10003b2aab18SMatthew Ahrens { 10013b2aab18SMatthew Ahrens spa_t *spa; 10023b2aab18SMatthew Ahrens int error; 10033b2aab18SMatthew Ahrens 10043b2aab18SMatthew Ahrens error = spa_open(name, &spa, tag); 10053b2aab18SMatthew Ahrens if (error == 0) { 10063b2aab18SMatthew Ahrens *dp = spa_get_dsl(spa); 10073b2aab18SMatthew Ahrens dsl_pool_config_enter(*dp, tag); 10083b2aab18SMatthew Ahrens } 10093b2aab18SMatthew Ahrens return (error); 10103b2aab18SMatthew Ahrens } 10113b2aab18SMatthew Ahrens 10123b2aab18SMatthew Ahrens void 10133b2aab18SMatthew Ahrens dsl_pool_rele(dsl_pool_t *dp, void *tag) 10143b2aab18SMatthew Ahrens { 10153b2aab18SMatthew Ahrens dsl_pool_config_exit(dp, tag); 10163b2aab18SMatthew Ahrens spa_close(dp->dp_spa, tag); 10173b2aab18SMatthew Ahrens } 10183b2aab18SMatthew Ahrens 10193b2aab18SMatthew Ahrens void 10203b2aab18SMatthew Ahrens dsl_pool_config_enter(dsl_pool_t *dp, void *tag) 10213b2aab18SMatthew Ahrens { 10223b2aab18SMatthew Ahrens /* 10233b2aab18SMatthew Ahrens * We use a "reentrant" reader-writer lock, but not reentrantly. 10243b2aab18SMatthew Ahrens * 10253b2aab18SMatthew Ahrens * The rrwlock can (with the track_all flag) track all reading threads, 10263b2aab18SMatthew Ahrens * which is very useful for debugging which code path failed to release 10273b2aab18SMatthew Ahrens * the lock, and for verifying that the *current* thread does hold 10283b2aab18SMatthew Ahrens * the lock. 10293b2aab18SMatthew Ahrens * 10303b2aab18SMatthew Ahrens * (Unlike a rwlock, which knows that N threads hold it for 10313b2aab18SMatthew Ahrens * read, but not *which* threads, so rw_held(RW_READER) returns TRUE 10323b2aab18SMatthew Ahrens * if any thread holds it for read, even if this thread doesn't). 10333b2aab18SMatthew Ahrens */ 10343b2aab18SMatthew Ahrens ASSERT(!rrw_held(&dp->dp_config_rwlock, RW_READER)); 10353b2aab18SMatthew Ahrens rrw_enter(&dp->dp_config_rwlock, RW_READER, tag); 10363b2aab18SMatthew Ahrens } 10373b2aab18SMatthew Ahrens 10383b2aab18SMatthew Ahrens void 10393b2aab18SMatthew Ahrens dsl_pool_config_exit(dsl_pool_t *dp, void *tag) 10403b2aab18SMatthew Ahrens { 10413b2aab18SMatthew Ahrens rrw_exit(&dp->dp_config_rwlock, tag); 10423b2aab18SMatthew Ahrens } 10433b2aab18SMatthew Ahrens 10443b2aab18SMatthew Ahrens boolean_t 10453b2aab18SMatthew Ahrens dsl_pool_config_held(dsl_pool_t *dp) 10463b2aab18SMatthew Ahrens { 10473b2aab18SMatthew Ahrens return (RRW_LOCK_HELD(&dp->dp_config_rwlock)); 10483b2aab18SMatthew Ahrens } 1049