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. 2394c2d0ebSMatthew Ahrens * Copyright (c) 2013, 2017 by Delphix. All rights reserved. 24ff5177eeSAlek Pinchuk * Copyright 2016 Nexenta Systems, Inc. All rights reserved. 25fa9e4066Sahrens */ 26fa9e4066Sahrens 27fa9e4066Sahrens #ifndef _SYS_DSL_POOL_H 28fa9e4066Sahrens #define _SYS_DSL_POOL_H 29fa9e4066Sahrens 30fa9e4066Sahrens #include <sys/spa.h> 31fa9e4066Sahrens #include <sys/txg.h> 32fa9e4066Sahrens #include <sys/txg_impl.h> 33fa9e4066Sahrens #include <sys/zfs_context.h> 34088f3894Sahrens #include <sys/zio.h> 3588b7b0f2SMatthew Ahrens #include <sys/dnode.h> 36bbfd46c4SJeff Bonwick #include <sys/ddt.h> 373f9d6ad7SLin Ling #include <sys/arc.h> 38cde58dbcSMatthew Ahrens #include <sys/bpobj.h> 39ad135b5dSChristopher Siden #include <sys/bptree.h> 403b2aab18SMatthew Ahrens #include <sys/rrwlock.h> 4186714001SSerapheim Dimitropoulos #include <sys/dsl_synctask.h> 42e0f1c0afSOlaf Faaland #include <sys/mmp.h> 43fa9e4066Sahrens 44fa9e4066Sahrens #ifdef __cplusplus 45fa9e4066Sahrens extern "C" { 46fa9e4066Sahrens #endif 47fa9e4066Sahrens 48fa9e4066Sahrens struct objset; 49fa9e4066Sahrens struct dsl_dir; 50088f3894Sahrens struct dsl_dataset; 51088f3894Sahrens struct dsl_pool; 52088f3894Sahrens struct dmu_tx; 533f9d6ad7SLin Ling struct dsl_scan; 54088f3894Sahrens 5569962b56SMatthew Ahrens extern uint64_t zfs_dirty_data_max; 5669962b56SMatthew Ahrens extern uint64_t zfs_dirty_data_max_max; 577928f4baSMatthew Ahrens extern uint64_t zfs_dirty_data_sync_pct; 5869962b56SMatthew Ahrens extern int zfs_dirty_data_max_percent; 5969962b56SMatthew Ahrens extern int zfs_delay_min_dirty_percent; 6069962b56SMatthew Ahrens extern uint64_t zfs_delay_scale; 6169962b56SMatthew Ahrens 6288b7b0f2SMatthew Ahrens /* These macros are for indexing into the zfs_all_blkstats_t. */ 6388b7b0f2SMatthew Ahrens #define DMU_OT_DEFERRED DMU_OT_NONE 64ad135b5dSChristopher Siden #define DMU_OT_OTHER DMU_OT_NUMTYPES /* place holder for DMU_OT() types */ 65ad135b5dSChristopher Siden #define DMU_OT_TOTAL (DMU_OT_NUMTYPES + 1) 6688b7b0f2SMatthew Ahrens 6788b7b0f2SMatthew Ahrens typedef struct zfs_blkstat { 6888b7b0f2SMatthew Ahrens uint64_t zb_count; 6988b7b0f2SMatthew Ahrens uint64_t zb_asize; 7088b7b0f2SMatthew Ahrens uint64_t zb_lsize; 7188b7b0f2SMatthew Ahrens uint64_t zb_psize; 7288b7b0f2SMatthew Ahrens uint64_t zb_gangs; 7388b7b0f2SMatthew Ahrens uint64_t zb_ditto_2_of_2_samevdev; 7488b7b0f2SMatthew Ahrens uint64_t zb_ditto_2_of_3_samevdev; 7588b7b0f2SMatthew Ahrens uint64_t zb_ditto_3_of_3_samevdev; 7688b7b0f2SMatthew Ahrens } zfs_blkstat_t; 7788b7b0f2SMatthew Ahrens 7888b7b0f2SMatthew Ahrens typedef struct zfs_all_blkstats { 7988b7b0f2SMatthew Ahrens zfs_blkstat_t zab_type[DN_MAX_LEVELS + 1][DMU_OT_TOTAL + 1]; 80*a3874b8bSToomas Soome kmutex_t zab_lock; 8188b7b0f2SMatthew Ahrens } zfs_all_blkstats_t; 8288b7b0f2SMatthew Ahrens 83fa9e4066Sahrens 84fa9e4066Sahrens typedef struct dsl_pool { 85fa9e4066Sahrens /* Immutable */ 86fa9e4066Sahrens spa_t *dp_spa; 87fa9e4066Sahrens struct objset *dp_meta_objset; 88fa9e4066Sahrens struct dsl_dir *dp_root_dir; 89fa9e4066Sahrens struct dsl_dir *dp_mos_dir; 90cde58dbcSMatthew Ahrens struct dsl_dir *dp_free_dir; 917fd05ac4SMatthew Ahrens struct dsl_dir *dp_leak_dir; 92088f3894Sahrens struct dsl_dataset *dp_origin_snap; 93fa9e4066Sahrens uint64_t dp_root_dir_obj; 94591e0e13SSebastien Roy taskq_t *dp_vnrele_taskq; 95fa9e4066Sahrens 96fa9e4066Sahrens /* No lock needed - sync context only */ 97fa9e4066Sahrens blkptr_t dp_meta_rootbp; 98ca45db41SChris Kirby uint64_t dp_tmp_userrefs_obj; 99cde58dbcSMatthew Ahrens bpobj_t dp_free_bpobj; 100ad135b5dSChristopher Siden uint64_t dp_bptree_obj; 101f1745736SMatthew Ahrens uint64_t dp_empty_bpobj; 1025cabbc6bSPrashanth Sreenivasa bpobj_t dp_obsolete_bpobj; 1031ab7f2deSmaybee 1043f9d6ad7SLin Ling struct dsl_scan *dp_scan; 1053f9d6ad7SLin Ling 1061ab7f2deSmaybee /* Uses dp_lock */ 1071ab7f2deSmaybee kmutex_t dp_lock; 10869962b56SMatthew Ahrens kcondvar_t dp_spaceavail_cv; 10969962b56SMatthew Ahrens uint64_t dp_dirty_pertxg[TXG_SIZE]; 11069962b56SMatthew Ahrens uint64_t dp_dirty_total; 111ff5177eeSAlek Pinchuk uint64_t dp_long_free_dirty_pertxg[TXG_SIZE]; 112ce636f8bSMatthew Ahrens uint64_t dp_mos_used_delta; 113ce636f8bSMatthew Ahrens uint64_t dp_mos_compressed_delta; 114ce636f8bSMatthew Ahrens uint64_t dp_mos_uncompressed_delta; 115fa9e4066Sahrens 11669962b56SMatthew Ahrens /* 11769962b56SMatthew Ahrens * Time of most recently scheduled (furthest in the future) 11869962b56SMatthew Ahrens * wakeup for delayed transactions. 11969962b56SMatthew Ahrens */ 12069962b56SMatthew Ahrens hrtime_t dp_last_wakeup; 12169962b56SMatthew Ahrens 122fa9e4066Sahrens /* Has its own locking */ 123fa9e4066Sahrens tx_state_t dp_tx; 124fa9e4066Sahrens txg_list_t dp_dirty_datasets; 125ce636f8bSMatthew Ahrens txg_list_t dp_dirty_zilogs; 126fa9e4066Sahrens txg_list_t dp_dirty_dirs; 1271d452cf5Sahrens txg_list_t dp_sync_tasks; 12886714001SSerapheim Dimitropoulos txg_list_t dp_early_sync_tasks; 12994c2d0ebSMatthew Ahrens taskq_t *dp_sync_taskq; 130216d7723SPrakash Surya taskq_t *dp_zil_clean_taskq; 131fa9e4066Sahrens 132fa9e4066Sahrens /* 133fa9e4066Sahrens * Protects administrative changes (properties, namespace) 134f7170741SWill Andrews * 135fa9e4066Sahrens * It is only held for write in syncing context. Therefore 136fa9e4066Sahrens * syncing context does not need to ever have it for read, since 137fa9e4066Sahrens * nobody else could possibly have it for write. 138fa9e4066Sahrens */ 1393b2aab18SMatthew Ahrens rrwlock_t dp_config_rwlock; 14088b7b0f2SMatthew Ahrens 14188b7b0f2SMatthew Ahrens zfs_all_blkstats_t *dp_blkstats; 142fa9e4066Sahrens } dsl_pool_t; 143fa9e4066Sahrens 144ad135b5dSChristopher Siden int dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp); 145ad135b5dSChristopher Siden int dsl_pool_open(dsl_pool_t *dp); 146fa9e4066Sahrens void dsl_pool_close(dsl_pool_t *dp); 1470a48a24eStimh dsl_pool_t *dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg); 148fa9e4066Sahrens void dsl_pool_sync(dsl_pool_t *dp, uint64_t txg); 149b24ab676SJeff Bonwick void dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg); 150fa9e4066Sahrens int dsl_pool_sync_context(dsl_pool_t *dp); 15186714001SSerapheim Dimitropoulos uint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, zfs_space_check_t slop_policy); 15286714001SSerapheim Dimitropoulos uint64_t dsl_pool_unreserved_space(dsl_pool_t *dp, 15386714001SSerapheim Dimitropoulos zfs_space_check_t slop_policy); 15469962b56SMatthew Ahrens void dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx); 15569962b56SMatthew Ahrens void dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg); 156b24ab676SJeff Bonwick void dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp); 1573113f7ceSGeorge Wilson void dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg, 1583113f7ceSGeorge Wilson const blkptr_t *bpp); 159088f3894Sahrens void dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx); 160088f3894Sahrens void dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx); 161cde58dbcSMatthew Ahrens void dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx); 162ce636f8bSMatthew Ahrens void dsl_pool_mos_diduse_space(dsl_pool_t *dp, 163ce636f8bSMatthew Ahrens int64_t used, int64_t comp, int64_t uncomp); 16486714001SSerapheim Dimitropoulos void dsl_pool_ckpoint_diduse_space(dsl_pool_t *dp, 16586714001SSerapheim Dimitropoulos int64_t used, int64_t comp, int64_t uncomp); 1663b2aab18SMatthew Ahrens void dsl_pool_config_enter(dsl_pool_t *dp, void *tag); 1671d3f896fSArne Jansen void dsl_pool_config_enter_prio(dsl_pool_t *dp, void *tag); 1683b2aab18SMatthew Ahrens void dsl_pool_config_exit(dsl_pool_t *dp, void *tag); 1693b2aab18SMatthew Ahrens boolean_t dsl_pool_config_held(dsl_pool_t *dp); 17012380e1eSArne Jansen boolean_t dsl_pool_config_held_writer(dsl_pool_t *dp); 17169962b56SMatthew Ahrens boolean_t dsl_pool_need_dirty_delay(dsl_pool_t *dp); 172088f3894Sahrens 1739d3574bfSNeil Perrin taskq_t *dsl_pool_vnrele_taskq(dsl_pool_t *dp); 1749d3574bfSNeil Perrin 1753b2aab18SMatthew Ahrens int dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, 1763b2aab18SMatthew Ahrens const char *tag, uint64_t now, dmu_tx_t *tx); 1773b2aab18SMatthew Ahrens int dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, 178ca45db41SChris Kirby const char *tag, dmu_tx_t *tx); 1793b2aab18SMatthew Ahrens void dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp); 1803f9d6ad7SLin Ling int dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **); 1813b2aab18SMatthew Ahrens int dsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp); 1823b2aab18SMatthew Ahrens void dsl_pool_rele(dsl_pool_t *dp, void *tag); 183ca45db41SChris Kirby 1845cabbc6bSPrashanth Sreenivasa void dsl_pool_create_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx); 1855cabbc6bSPrashanth Sreenivasa void dsl_pool_destroy_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx); 1865cabbc6bSPrashanth Sreenivasa 187fa9e4066Sahrens #ifdef __cplusplus 188fa9e4066Sahrens } 189fa9e4066Sahrens #endif 190fa9e4066Sahrens 191fa9e4066Sahrens #endif /* _SYS_DSL_POOL_H */ 192