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 /* 223113f7ceSGeorge Wilson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23*69962b56SMatthew Ahrens * Copyright (c) 2013 by Delphix. All rights reserved. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_DSL_POOL_H 27fa9e4066Sahrens #define _SYS_DSL_POOL_H 28fa9e4066Sahrens 29fa9e4066Sahrens #include <sys/spa.h> 30fa9e4066Sahrens #include <sys/txg.h> 31fa9e4066Sahrens #include <sys/txg_impl.h> 32fa9e4066Sahrens #include <sys/zfs_context.h> 33088f3894Sahrens #include <sys/zio.h> 3488b7b0f2SMatthew Ahrens #include <sys/dnode.h> 35bbfd46c4SJeff Bonwick #include <sys/ddt.h> 363f9d6ad7SLin Ling #include <sys/arc.h> 37cde58dbcSMatthew Ahrens #include <sys/bpobj.h> 38ad135b5dSChristopher Siden #include <sys/bptree.h> 393b2aab18SMatthew Ahrens #include <sys/rrwlock.h> 40fa9e4066Sahrens 41fa9e4066Sahrens #ifdef __cplusplus 42fa9e4066Sahrens extern "C" { 43fa9e4066Sahrens #endif 44fa9e4066Sahrens 45fa9e4066Sahrens struct objset; 46fa9e4066Sahrens struct dsl_dir; 47088f3894Sahrens struct dsl_dataset; 48088f3894Sahrens struct dsl_pool; 49088f3894Sahrens struct dmu_tx; 503f9d6ad7SLin Ling struct dsl_scan; 51088f3894Sahrens 52*69962b56SMatthew Ahrens extern uint64_t zfs_dirty_data_max; 53*69962b56SMatthew Ahrens extern uint64_t zfs_dirty_data_max_max; 54*69962b56SMatthew Ahrens extern uint64_t zfs_dirty_data_sync; 55*69962b56SMatthew Ahrens extern int zfs_dirty_data_max_percent; 56*69962b56SMatthew Ahrens extern int zfs_delay_min_dirty_percent; 57*69962b56SMatthew Ahrens extern uint64_t zfs_delay_scale; 58*69962b56SMatthew Ahrens 5988b7b0f2SMatthew Ahrens /* These macros are for indexing into the zfs_all_blkstats_t. */ 6088b7b0f2SMatthew Ahrens #define DMU_OT_DEFERRED DMU_OT_NONE 61ad135b5dSChristopher Siden #define DMU_OT_OTHER DMU_OT_NUMTYPES /* place holder for DMU_OT() types */ 62ad135b5dSChristopher Siden #define DMU_OT_TOTAL (DMU_OT_NUMTYPES + 1) 6388b7b0f2SMatthew Ahrens 6488b7b0f2SMatthew Ahrens typedef struct zfs_blkstat { 6588b7b0f2SMatthew Ahrens uint64_t zb_count; 6688b7b0f2SMatthew Ahrens uint64_t zb_asize; 6788b7b0f2SMatthew Ahrens uint64_t zb_lsize; 6888b7b0f2SMatthew Ahrens uint64_t zb_psize; 6988b7b0f2SMatthew Ahrens uint64_t zb_gangs; 7088b7b0f2SMatthew Ahrens uint64_t zb_ditto_2_of_2_samevdev; 7188b7b0f2SMatthew Ahrens uint64_t zb_ditto_2_of_3_samevdev; 7288b7b0f2SMatthew Ahrens uint64_t zb_ditto_3_of_3_samevdev; 7388b7b0f2SMatthew Ahrens } zfs_blkstat_t; 7488b7b0f2SMatthew Ahrens 7588b7b0f2SMatthew Ahrens typedef struct zfs_all_blkstats { 7688b7b0f2SMatthew Ahrens zfs_blkstat_t zab_type[DN_MAX_LEVELS + 1][DMU_OT_TOTAL + 1]; 7788b7b0f2SMatthew Ahrens } zfs_all_blkstats_t; 7888b7b0f2SMatthew Ahrens 79fa9e4066Sahrens 80fa9e4066Sahrens typedef struct dsl_pool { 81fa9e4066Sahrens /* Immutable */ 82fa9e4066Sahrens spa_t *dp_spa; 83fa9e4066Sahrens struct objset *dp_meta_objset; 84fa9e4066Sahrens struct dsl_dir *dp_root_dir; 85fa9e4066Sahrens struct dsl_dir *dp_mos_dir; 86cde58dbcSMatthew Ahrens struct dsl_dir *dp_free_dir; 87088f3894Sahrens struct dsl_dataset *dp_origin_snap; 88fa9e4066Sahrens uint64_t dp_root_dir_obj; 899d3574bfSNeil Perrin struct taskq *dp_vnrele_taskq; 90fa9e4066Sahrens 91fa9e4066Sahrens /* No lock needed - sync context only */ 92fa9e4066Sahrens blkptr_t dp_meta_rootbp; 93ca45db41SChris Kirby uint64_t dp_tmp_userrefs_obj; 94cde58dbcSMatthew Ahrens bpobj_t dp_free_bpobj; 95ad135b5dSChristopher Siden uint64_t dp_bptree_obj; 96f1745736SMatthew Ahrens uint64_t dp_empty_bpobj; 971ab7f2deSmaybee 983f9d6ad7SLin Ling struct dsl_scan *dp_scan; 993f9d6ad7SLin Ling 1001ab7f2deSmaybee /* Uses dp_lock */ 1011ab7f2deSmaybee kmutex_t dp_lock; 102*69962b56SMatthew Ahrens kcondvar_t dp_spaceavail_cv; 103*69962b56SMatthew Ahrens uint64_t dp_dirty_pertxg[TXG_SIZE]; 104*69962b56SMatthew Ahrens uint64_t dp_dirty_total; 105ce636f8bSMatthew Ahrens uint64_t dp_mos_used_delta; 106ce636f8bSMatthew Ahrens uint64_t dp_mos_compressed_delta; 107ce636f8bSMatthew Ahrens uint64_t dp_mos_uncompressed_delta; 108fa9e4066Sahrens 109*69962b56SMatthew Ahrens /* 110*69962b56SMatthew Ahrens * Time of most recently scheduled (furthest in the future) 111*69962b56SMatthew Ahrens * wakeup for delayed transactions. 112*69962b56SMatthew Ahrens */ 113*69962b56SMatthew Ahrens hrtime_t dp_last_wakeup; 114*69962b56SMatthew Ahrens 115fa9e4066Sahrens /* Has its own locking */ 116fa9e4066Sahrens tx_state_t dp_tx; 117fa9e4066Sahrens txg_list_t dp_dirty_datasets; 118ce636f8bSMatthew Ahrens txg_list_t dp_dirty_zilogs; 119fa9e4066Sahrens txg_list_t dp_dirty_dirs; 1201d452cf5Sahrens txg_list_t dp_sync_tasks; 121fa9e4066Sahrens 122fa9e4066Sahrens /* 123fa9e4066Sahrens * Protects administrative changes (properties, namespace) 124f7170741SWill Andrews * 125fa9e4066Sahrens * It is only held for write in syncing context. Therefore 126fa9e4066Sahrens * syncing context does not need to ever have it for read, since 127fa9e4066Sahrens * nobody else could possibly have it for write. 128fa9e4066Sahrens */ 1293b2aab18SMatthew Ahrens rrwlock_t dp_config_rwlock; 13088b7b0f2SMatthew Ahrens 13188b7b0f2SMatthew Ahrens zfs_all_blkstats_t *dp_blkstats; 132fa9e4066Sahrens } dsl_pool_t; 133fa9e4066Sahrens 134ad135b5dSChristopher Siden int dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp); 135ad135b5dSChristopher Siden int dsl_pool_open(dsl_pool_t *dp); 136fa9e4066Sahrens void dsl_pool_close(dsl_pool_t *dp); 1370a48a24eStimh dsl_pool_t *dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg); 138fa9e4066Sahrens void dsl_pool_sync(dsl_pool_t *dp, uint64_t txg); 139b24ab676SJeff Bonwick void dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg); 140fa9e4066Sahrens int dsl_pool_sync_context(dsl_pool_t *dp); 141fa9e4066Sahrens uint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree); 142468c413aSTim Haley uint64_t dsl_pool_adjustedfree(dsl_pool_t *dp, boolean_t netfree); 143*69962b56SMatthew Ahrens void dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx); 144*69962b56SMatthew Ahrens void dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg); 145b24ab676SJeff Bonwick void dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp); 1463113f7ceSGeorge Wilson void dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg, 1473113f7ceSGeorge Wilson const blkptr_t *bpp); 148088f3894Sahrens void dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx); 149088f3894Sahrens void dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx); 150cde58dbcSMatthew Ahrens void dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx); 151ce636f8bSMatthew Ahrens void dsl_pool_mos_diduse_space(dsl_pool_t *dp, 152ce636f8bSMatthew Ahrens int64_t used, int64_t comp, int64_t uncomp); 1533b2aab18SMatthew Ahrens void dsl_pool_config_enter(dsl_pool_t *dp, void *tag); 1543b2aab18SMatthew Ahrens void dsl_pool_config_exit(dsl_pool_t *dp, void *tag); 1553b2aab18SMatthew Ahrens boolean_t dsl_pool_config_held(dsl_pool_t *dp); 156*69962b56SMatthew Ahrens boolean_t dsl_pool_need_dirty_delay(dsl_pool_t *dp); 157088f3894Sahrens 1589d3574bfSNeil Perrin taskq_t *dsl_pool_vnrele_taskq(dsl_pool_t *dp); 1599d3574bfSNeil Perrin 1603b2aab18SMatthew Ahrens int dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, 1613b2aab18SMatthew Ahrens const char *tag, uint64_t now, dmu_tx_t *tx); 1623b2aab18SMatthew Ahrens int dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, 163ca45db41SChris Kirby const char *tag, dmu_tx_t *tx); 1643b2aab18SMatthew Ahrens void dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp); 1653f9d6ad7SLin Ling int dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **); 1663b2aab18SMatthew Ahrens int dsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp); 1673b2aab18SMatthew Ahrens void dsl_pool_rele(dsl_pool_t *dp, void *tag); 168ca45db41SChris Kirby 169fa9e4066Sahrens #ifdef __cplusplus 170fa9e4066Sahrens } 171fa9e4066Sahrens #endif 172fa9e4066Sahrens 173fa9e4066Sahrens #endif /* _SYS_DSL_POOL_H */ 174