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 /* 229082849eSck * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_DSL_DATASET_H 27fa9e4066Sahrens #define _SYS_DSL_DATASET_H 28fa9e4066Sahrens 29fa9e4066Sahrens #include <sys/dmu.h> 30fa9e4066Sahrens #include <sys/spa.h> 31fa9e4066Sahrens #include <sys/txg.h> 32c717a561Smaybee #include <sys/zio.h> 33fa9e4066Sahrens #include <sys/bplist.h> 341d452cf5Sahrens #include <sys/dsl_synctask.h> 35fa9e4066Sahrens #include <sys/zfs_context.h> 36fa9e4066Sahrens 37fa9e4066Sahrens #ifdef __cplusplus 38fa9e4066Sahrens extern "C" { 39fa9e4066Sahrens #endif 40fa9e4066Sahrens 41fa9e4066Sahrens struct dsl_dataset; 42fa9e4066Sahrens struct dsl_dir; 43fa9e4066Sahrens struct dsl_pool; 44fa9e4066Sahrens 45fa9e4066Sahrens typedef void dsl_dataset_evict_func_t(struct dsl_dataset *, void *); 46fa9e4066Sahrens 4799653d4eSeschrock #define DS_FLAG_INCONSISTENT (1ULL<<0) 48745cd3c5Smaybee #define DS_IS_INCONSISTENT(ds) \ 49745cd3c5Smaybee ((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT) 5099653d4eSeschrock /* 5199653d4eSeschrock * NB: nopromote can not yet be set, but we want support for it in this 5299653d4eSeschrock * on-disk version, so that we don't need to upgrade for it later. It 5399653d4eSeschrock * will be needed when we implement 'zfs split' (where the split off 5499653d4eSeschrock * clone should not be promoted). 5599653d4eSeschrock */ 5699653d4eSeschrock #define DS_FLAG_NOPROMOTE (1ULL<<1) 5799653d4eSeschrock 58a9799022Sck /* 59a9799022Sck * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly 60a9799022Sck * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE, 61a9799022Sck * refquota/refreservations). 62a9799022Sck */ 63a9799022Sck #define DS_FLAG_UNIQUE_ACCURATE (1ULL<<2) 64a9799022Sck 65ab04eb8eStimh /* 66ab04eb8eStimh * DS_FLAG_CI_DATASET is set if the dataset contains a file system whose 67ab04eb8eStimh * name lookups should be performed case-insensitively. 68ab04eb8eStimh */ 69ab04eb8eStimh #define DS_FLAG_CI_DATASET (1ULL<<16) 70ab04eb8eStimh 71fa9e4066Sahrens typedef struct dsl_dataset_phys { 72088f3894Sahrens uint64_t ds_dir_obj; /* DMU_OT_DSL_DIR */ 73088f3894Sahrens uint64_t ds_prev_snap_obj; /* DMU_OT_DSL_DATASET */ 74fa9e4066Sahrens uint64_t ds_prev_snap_txg; 75088f3894Sahrens uint64_t ds_next_snap_obj; /* DMU_OT_DSL_DATASET */ 76088f3894Sahrens uint64_t ds_snapnames_zapobj; /* DMU_OT_DSL_DS_SNAP_MAP 0 for snaps */ 77fa9e4066Sahrens uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 78fa9e4066Sahrens uint64_t ds_creation_time; /* seconds since 1970 */ 79fa9e4066Sahrens uint64_t ds_creation_txg; 80088f3894Sahrens uint64_t ds_deadlist_obj; /* DMU_OT_BPLIST */ 81fa9e4066Sahrens uint64_t ds_used_bytes; 82fa9e4066Sahrens uint64_t ds_compressed_bytes; 83fa9e4066Sahrens uint64_t ds_uncompressed_bytes; 8463360950Smp uint64_t ds_unique_bytes; /* only relevant to snapshots */ 85fa9e4066Sahrens /* 86fa9e4066Sahrens * The ds_fsid_guid is a 56-bit ID that can change to avoid 87fa9e4066Sahrens * collisions. The ds_guid is a 64-bit ID that will never 88fa9e4066Sahrens * change, so there is a small probability that it will collide. 89fa9e4066Sahrens */ 90fa9e4066Sahrens uint64_t ds_fsid_guid; 91fa9e4066Sahrens uint64_t ds_guid; 92088f3894Sahrens uint64_t ds_flags; /* DS_FLAG_* */ 93fa9e4066Sahrens blkptr_t ds_bp; 94bb0ade09Sahrens uint64_t ds_next_clones_obj; /* DMU_OT_DSL_CLONES */ 95bb0ade09Sahrens uint64_t ds_props_obj; /* DMU_OT_DSL_PROPS for snaps */ 96bb0ade09Sahrens uint64_t ds_pad[6]; /* pad out to 320 bytes for good measure */ 97fa9e4066Sahrens } dsl_dataset_phys_t; 98fa9e4066Sahrens 99fa9e4066Sahrens typedef struct dsl_dataset { 100fa9e4066Sahrens /* Immutable: */ 101fa9e4066Sahrens struct dsl_dir *ds_dir; 102fa9e4066Sahrens dsl_dataset_phys_t *ds_phys; 103fa9e4066Sahrens dmu_buf_t *ds_dbuf; 104fa9e4066Sahrens uint64_t ds_object; 10591ebeef5Sahrens uint64_t ds_fsid_guid; 106fa9e4066Sahrens 107*74e7dc98SMatthew Ahrens /* only used in syncing context, only valid for non-snapshots: */ 108*74e7dc98SMatthew Ahrens struct dsl_dataset *ds_prev; 109*74e7dc98SMatthew Ahrens uint64_t ds_origin_txg; 110fa9e4066Sahrens 111fa9e4066Sahrens /* has internal locking: */ 112fa9e4066Sahrens bplist_t ds_deadlist; 113fa9e4066Sahrens 114fa9e4066Sahrens /* protected by lock on pool's dp_dirty_datasets list */ 115fa9e4066Sahrens txg_node_t ds_dirty_link; 116fa9e4066Sahrens list_node_t ds_synced_link; 117fa9e4066Sahrens 118fa9e4066Sahrens /* 119fa9e4066Sahrens * ds_phys->ds_<accounting> is also protected by ds_lock. 120fa9e4066Sahrens * Protected by ds_lock: 121fa9e4066Sahrens */ 122fa9e4066Sahrens kmutex_t ds_lock; 123fa9e4066Sahrens void *ds_user_ptr; 124fa9e4066Sahrens dsl_dataset_evict_func_t *ds_user_evict_func; 125745cd3c5Smaybee 126745cd3c5Smaybee /* 127745cd3c5Smaybee * ds_owner is protected by the ds_rwlock and the ds_lock 128745cd3c5Smaybee */ 129745cd3c5Smaybee krwlock_t ds_rwlock; 130745cd3c5Smaybee kcondvar_t ds_exclusive_cv; 131745cd3c5Smaybee void *ds_owner; 132fa9e4066Sahrens 1331d452cf5Sahrens /* no locking; only for making guesses */ 1341d452cf5Sahrens uint64_t ds_trysnap_txg; 1351d452cf5Sahrens 13691ebeef5Sahrens /* for objset_open() */ 13791ebeef5Sahrens kmutex_t ds_opening_lock; 13891ebeef5Sahrens 139a9799022Sck uint64_t ds_reserved; /* cached refreservation */ 140a9799022Sck uint64_t ds_quota; /* cached refquota */ 141a9799022Sck 142fa9e4066Sahrens /* Protected by ds_lock; keep at end of struct for better locality */ 143fa9e4066Sahrens char ds_snapname[MAXNAMELEN]; 144fa9e4066Sahrens } dsl_dataset_t; 145fa9e4066Sahrens 146fa9e4066Sahrens #define dsl_dataset_is_snapshot(ds) \ 147fa9e4066Sahrens ((ds)->ds_phys->ds_num_children != 0) 148fa9e4066Sahrens 149a9799022Sck #define DS_UNIQUE_IS_ACCURATE(ds) \ 150a9799022Sck (((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0) 151a9799022Sck 152745cd3c5Smaybee int dsl_dataset_hold(const char *name, void *tag, dsl_dataset_t **dsp); 153745cd3c5Smaybee int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, 154745cd3c5Smaybee void *tag, dsl_dataset_t **); 155745cd3c5Smaybee int dsl_dataset_own(const char *name, int flags, void *owner, 156fa9e4066Sahrens dsl_dataset_t **dsp); 157745cd3c5Smaybee int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj, 158745cd3c5Smaybee int flags, void *owner, dsl_dataset_t **); 159fa9e4066Sahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name); 160745cd3c5Smaybee void dsl_dataset_rele(dsl_dataset_t *ds, void *tag); 161745cd3c5Smaybee void dsl_dataset_disown(dsl_dataset_t *ds, void *owner); 162088f3894Sahrens void dsl_dataset_drop_ref(dsl_dataset_t *ds, void *tag); 163745cd3c5Smaybee boolean_t dsl_dataset_tryown(dsl_dataset_t *ds, boolean_t inconsistentok, 164745cd3c5Smaybee void *owner); 165745cd3c5Smaybee void dsl_dataset_make_exclusive(dsl_dataset_t *ds, void *owner); 166745cd3c5Smaybee uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname, 167745cd3c5Smaybee dsl_dataset_t *origin, uint64_t flags, cred_t *, dmu_tx_t *); 168088f3894Sahrens uint64_t dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin, 169088f3894Sahrens uint64_t flags, dmu_tx_t *tx); 1703cb34c60Sahrens int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag); 1711d452cf5Sahrens int dsl_snapshots_destroy(char *fsname, char *snapname); 1723cb34c60Sahrens dsl_checkfunc_t dsl_dataset_destroy_check; 1733cb34c60Sahrens dsl_syncfunc_t dsl_dataset_destroy_sync; 1741d452cf5Sahrens dsl_checkfunc_t dsl_dataset_snapshot_check; 1751d452cf5Sahrens dsl_syncfunc_t dsl_dataset_snapshot_sync; 1763cb34c60Sahrens int dsl_dataset_rollback(dsl_dataset_t *ds, dmu_objset_type_t ost); 177cdf5b4caSmmusante int dsl_dataset_rename(char *name, const char *newname, boolean_t recursive); 17899653d4eSeschrock int dsl_dataset_promote(const char *name); 1793cb34c60Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head, 1803cb34c60Sahrens boolean_t force); 181fa9e4066Sahrens 182fa9e4066Sahrens void *dsl_dataset_set_user_ptr(dsl_dataset_t *ds, 183fa9e4066Sahrens void *p, dsl_dataset_evict_func_t func); 184fa9e4066Sahrens void *dsl_dataset_get_user_ptr(dsl_dataset_t *ds); 185fa9e4066Sahrens 186c717a561Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds); 187fa9e4066Sahrens void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 188fa9e4066Sahrens 189fa9e4066Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds); 190fa9e4066Sahrens 191f18faf3fSek boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds); 192f18faf3fSek 193c717a561Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx); 194fa9e4066Sahrens 195fa9e4066Sahrens void dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 196cdb0ab79Smaybee int dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, zio_t *pio, 197c717a561Smaybee dmu_tx_t *tx); 198ea8dc4b6Seschrock int dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth); 199ea8dc4b6Seschrock uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds); 200fa9e4066Sahrens 201fa9e4066Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx); 202a2eea2e1Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv); 203a2eea2e1Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat); 204a2eea2e1Sahrens void dsl_dataset_space(dsl_dataset_t *ds, 205a2eea2e1Sahrens uint64_t *refdbytesp, uint64_t *availbytesp, 206a2eea2e1Sahrens uint64_t *usedobjsp, uint64_t *availobjsp); 207a2eea2e1Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds); 208fa9e4066Sahrens 209b1b8ab34Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf); 210b1b8ab34Slling 211a9799022Sck int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota, 2129082849eSck uint64_t asize, uint64_t inflight, uint64_t *used, 2139082849eSck uint64_t *ref_rsrv); 214a9799022Sck int dsl_dataset_set_quota(const char *dsname, uint64_t quota); 215a9799022Sck void dsl_dataset_set_quota_sync(void *arg1, void *arg2, cred_t *cr, 216a9799022Sck dmu_tx_t *tx); 217a9799022Sck int dsl_dataset_set_reservation(const char *dsname, uint64_t reservation); 218ab04eb8eStimh void dsl_dataset_set_flags(dsl_dataset_t *ds, uint64_t flags); 219a9799022Sck 220fa9e4066Sahrens #ifdef ZFS_DEBUG 221fa9e4066Sahrens #define dprintf_ds(ds, fmt, ...) do { \ 222fa9e4066Sahrens if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 223fa9e4066Sahrens char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \ 224fa9e4066Sahrens dsl_dataset_name(ds, __ds_name); \ 225fa9e4066Sahrens dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \ 226fa9e4066Sahrens kmem_free(__ds_name, MAXNAMELEN); \ 227fa9e4066Sahrens } \ 228fa9e4066Sahrens _NOTE(CONSTCOND) } while (0) 229fa9e4066Sahrens #else 230fa9e4066Sahrens #define dprintf_ds(dd, fmt, ...) 231fa9e4066Sahrens #endif 232fa9e4066Sahrens 233fa9e4066Sahrens #ifdef __cplusplus 234fa9e4066Sahrens } 235fa9e4066Sahrens #endif 236fa9e4066Sahrens 237fa9e4066Sahrens #endif /* _SYS_DSL_DATASET_H */ 238