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. 23*ad135b5dSChristopher Siden * Copyright (c) 2012 by Delphix. All rights reserved. 244e3c9f44SBill Pijewski * Copyright (c) 2012, Joyent, Inc. All rights reserved. 25fa9e4066Sahrens */ 26fa9e4066Sahrens 27fa9e4066Sahrens #ifndef _SYS_DSL_DATASET_H 28fa9e4066Sahrens #define _SYS_DSL_DATASET_H 29fa9e4066Sahrens 30fa9e4066Sahrens #include <sys/dmu.h> 31fa9e4066Sahrens #include <sys/spa.h> 32fa9e4066Sahrens #include <sys/txg.h> 33c717a561Smaybee #include <sys/zio.h> 34fa9e4066Sahrens #include <sys/bplist.h> 351d452cf5Sahrens #include <sys/dsl_synctask.h> 36fa9e4066Sahrens #include <sys/zfs_context.h> 37cde58dbcSMatthew Ahrens #include <sys/dsl_deadlist.h> 38fa9e4066Sahrens 39fa9e4066Sahrens #ifdef __cplusplus 40fa9e4066Sahrens extern "C" { 41fa9e4066Sahrens #endif 42fa9e4066Sahrens 43fa9e4066Sahrens struct dsl_dataset; 44fa9e4066Sahrens struct dsl_dir; 45fa9e4066Sahrens struct dsl_pool; 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 65842727c2SChris Kirby /* 66842727c2SChris Kirby * DS_FLAG_DEFER_DESTROY is set after 'zfs destroy -d' has been called 67842727c2SChris Kirby * on a dataset. This allows the dataset to be destroyed using 'zfs release'. 68842727c2SChris Kirby */ 69842727c2SChris Kirby #define DS_FLAG_DEFER_DESTROY (1ULL<<3) 70842727c2SChris Kirby #define DS_IS_DEFER_DESTROY(ds) \ 71842727c2SChris Kirby ((ds)->ds_phys->ds_flags & DS_FLAG_DEFER_DESTROY) 72842727c2SChris Kirby 73ab04eb8eStimh /* 74ab04eb8eStimh * DS_FLAG_CI_DATASET is set if the dataset contains a file system whose 75ab04eb8eStimh * name lookups should be performed case-insensitively. 76ab04eb8eStimh */ 77ab04eb8eStimh #define DS_FLAG_CI_DATASET (1ULL<<16) 78ab04eb8eStimh 79fa9e4066Sahrens typedef struct dsl_dataset_phys { 80088f3894Sahrens uint64_t ds_dir_obj; /* DMU_OT_DSL_DIR */ 81088f3894Sahrens uint64_t ds_prev_snap_obj; /* DMU_OT_DSL_DATASET */ 82fa9e4066Sahrens uint64_t ds_prev_snap_txg; 83088f3894Sahrens uint64_t ds_next_snap_obj; /* DMU_OT_DSL_DATASET */ 84088f3894Sahrens uint64_t ds_snapnames_zapobj; /* DMU_OT_DSL_DS_SNAP_MAP 0 for snaps */ 85fa9e4066Sahrens uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 86fa9e4066Sahrens uint64_t ds_creation_time; /* seconds since 1970 */ 87fa9e4066Sahrens uint64_t ds_creation_txg; 88cde58dbcSMatthew Ahrens uint64_t ds_deadlist_obj; /* DMU_OT_DEADLIST */ 89*ad135b5dSChristopher Siden /* 90*ad135b5dSChristopher Siden * ds_referenced_bytes, ds_compressed_bytes, and ds_uncompressed_bytes 91*ad135b5dSChristopher Siden * include all blocks referenced by this dataset, including those 92*ad135b5dSChristopher Siden * shared with any other datasets. 93*ad135b5dSChristopher Siden */ 94*ad135b5dSChristopher Siden uint64_t ds_referenced_bytes; 95fa9e4066Sahrens uint64_t ds_compressed_bytes; 96fa9e4066Sahrens uint64_t ds_uncompressed_bytes; 9763360950Smp uint64_t ds_unique_bytes; /* only relevant to snapshots */ 98fa9e4066Sahrens /* 99fa9e4066Sahrens * The ds_fsid_guid is a 56-bit ID that can change to avoid 100fa9e4066Sahrens * collisions. The ds_guid is a 64-bit ID that will never 101fa9e4066Sahrens * change, so there is a small probability that it will collide. 102fa9e4066Sahrens */ 103fa9e4066Sahrens uint64_t ds_fsid_guid; 104fa9e4066Sahrens uint64_t ds_guid; 105088f3894Sahrens uint64_t ds_flags; /* DS_FLAG_* */ 106fa9e4066Sahrens blkptr_t ds_bp; 107bb0ade09Sahrens uint64_t ds_next_clones_obj; /* DMU_OT_DSL_CLONES */ 108bb0ade09Sahrens uint64_t ds_props_obj; /* DMU_OT_DSL_PROPS for snaps */ 109842727c2SChris Kirby uint64_t ds_userrefs_obj; /* DMU_OT_USERREFS */ 110842727c2SChris Kirby uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */ 111fa9e4066Sahrens } dsl_dataset_phys_t; 112fa9e4066Sahrens 113fa9e4066Sahrens typedef struct dsl_dataset { 114fa9e4066Sahrens /* Immutable: */ 115fa9e4066Sahrens struct dsl_dir *ds_dir; 116fa9e4066Sahrens dsl_dataset_phys_t *ds_phys; 117fa9e4066Sahrens dmu_buf_t *ds_dbuf; 118fa9e4066Sahrens uint64_t ds_object; 11991ebeef5Sahrens uint64_t ds_fsid_guid; 120fa9e4066Sahrens 12174e7dc98SMatthew Ahrens /* only used in syncing context, only valid for non-snapshots: */ 12274e7dc98SMatthew Ahrens struct dsl_dataset *ds_prev; 123fa9e4066Sahrens 124fa9e4066Sahrens /* has internal locking: */ 125cde58dbcSMatthew Ahrens dsl_deadlist_t ds_deadlist; 126cde58dbcSMatthew Ahrens bplist_t ds_pending_deadlist; 127fa9e4066Sahrens 128f4b94bdeSMatthew Ahrens /* to protect against multiple concurrent incremental recv */ 129f4b94bdeSMatthew Ahrens kmutex_t ds_recvlock; 130f4b94bdeSMatthew Ahrens 131fa9e4066Sahrens /* protected by lock on pool's dp_dirty_datasets list */ 132fa9e4066Sahrens txg_node_t ds_dirty_link; 133fa9e4066Sahrens list_node_t ds_synced_link; 134fa9e4066Sahrens 135fa9e4066Sahrens /* 136fa9e4066Sahrens * ds_phys->ds_<accounting> is also protected by ds_lock. 137fa9e4066Sahrens * Protected by ds_lock: 138fa9e4066Sahrens */ 139fa9e4066Sahrens kmutex_t ds_lock; 140503ad85cSMatthew Ahrens objset_t *ds_objset; 141842727c2SChris Kirby uint64_t ds_userrefs; 142745cd3c5Smaybee 143745cd3c5Smaybee /* 144745cd3c5Smaybee * ds_owner is protected by the ds_rwlock and the ds_lock 145745cd3c5Smaybee */ 146745cd3c5Smaybee krwlock_t ds_rwlock; 147745cd3c5Smaybee kcondvar_t ds_exclusive_cv; 148745cd3c5Smaybee void *ds_owner; 149fa9e4066Sahrens 1501d452cf5Sahrens /* no locking; only for making guesses */ 1511d452cf5Sahrens uint64_t ds_trysnap_txg; 1521d452cf5Sahrens 15391ebeef5Sahrens /* for objset_open() */ 15491ebeef5Sahrens kmutex_t ds_opening_lock; 15591ebeef5Sahrens 156a9799022Sck uint64_t ds_reserved; /* cached refreservation */ 157a9799022Sck uint64_t ds_quota; /* cached refquota */ 158a9799022Sck 1594e3c9f44SBill Pijewski kmutex_t ds_sendstream_lock; 1604e3c9f44SBill Pijewski list_t ds_sendstreams; 1614e3c9f44SBill Pijewski 162fa9e4066Sahrens /* Protected by ds_lock; keep at end of struct for better locality */ 163fa9e4066Sahrens char ds_snapname[MAXNAMELEN]; 164fa9e4066Sahrens } dsl_dataset_t; 165fa9e4066Sahrens 166842727c2SChris Kirby struct dsl_ds_destroyarg { 167842727c2SChris Kirby dsl_dataset_t *ds; /* ds to destroy */ 168842727c2SChris Kirby dsl_dataset_t *rm_origin; /* also remove our origin? */ 169842727c2SChris Kirby boolean_t is_origin_rm; /* set if removing origin snap */ 170842727c2SChris Kirby boolean_t defer; /* destroy -d requested? */ 171842727c2SChris Kirby boolean_t releasing; /* destroying due to release? */ 172842727c2SChris Kirby boolean_t need_prep; /* do we need to retry due to EBUSY? */ 173842727c2SChris Kirby }; 174842727c2SChris Kirby 17599d5e173STim Haley /* 17699d5e173STim Haley * The max length of a temporary tag prefix is the number of hex digits 17799d5e173STim Haley * required to express UINT64_MAX plus one for the hyphen. 17899d5e173STim Haley */ 17999d5e173STim Haley #define MAX_TAG_PREFIX_LEN 17 18099d5e173STim Haley 18199d5e173STim Haley struct dsl_ds_holdarg { 18299d5e173STim Haley dsl_sync_task_group_t *dstg; 18399d5e173STim Haley char *htag; 18499d5e173STim Haley char *snapname; 18599d5e173STim Haley boolean_t recursive; 18699d5e173STim Haley boolean_t gotone; 18799d5e173STim Haley boolean_t temphold; 18899d5e173STim Haley char failed[MAXPATHLEN]; 18999d5e173STim Haley }; 19099d5e173STim Haley 191cde58dbcSMatthew Ahrens #define dsl_dataset_is_snapshot(ds) \ 192fa9e4066Sahrens ((ds)->ds_phys->ds_num_children != 0) 193fa9e4066Sahrens 194a9799022Sck #define DS_UNIQUE_IS_ACCURATE(ds) \ 195a9799022Sck (((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0) 196a9799022Sck 197745cd3c5Smaybee int dsl_dataset_hold(const char *name, void *tag, dsl_dataset_t **dsp); 198745cd3c5Smaybee int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, 199745cd3c5Smaybee void *tag, dsl_dataset_t **); 200503ad85cSMatthew Ahrens int dsl_dataset_own(const char *name, boolean_t inconsistentok, 201503ad85cSMatthew Ahrens void *tag, dsl_dataset_t **dsp); 202745cd3c5Smaybee int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj, 203503ad85cSMatthew Ahrens boolean_t inconsistentok, void *tag, dsl_dataset_t **dsp); 204fa9e4066Sahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name); 205745cd3c5Smaybee void dsl_dataset_rele(dsl_dataset_t *ds, void *tag); 206503ad85cSMatthew Ahrens void dsl_dataset_disown(dsl_dataset_t *ds, void *tag); 207088f3894Sahrens void dsl_dataset_drop_ref(dsl_dataset_t *ds, void *tag); 208745cd3c5Smaybee boolean_t dsl_dataset_tryown(dsl_dataset_t *ds, boolean_t inconsistentok, 209503ad85cSMatthew Ahrens void *tag); 210503ad85cSMatthew Ahrens void dsl_dataset_make_exclusive(dsl_dataset_t *ds, void *tag); 211a7f53a56SChris Kirby void dsl_register_onexit_hold_cleanup(dsl_dataset_t *ds, const char *htag, 212a7f53a56SChris Kirby minor_t minor); 213745cd3c5Smaybee uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname, 214745cd3c5Smaybee dsl_dataset_t *origin, uint64_t flags, cred_t *, dmu_tx_t *); 215088f3894Sahrens uint64_t dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin, 216088f3894Sahrens uint64_t flags, dmu_tx_t *tx); 217842727c2SChris Kirby int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag, boolean_t defer); 218842727c2SChris Kirby int dsl_snapshots_destroy(char *fsname, char *snapname, boolean_t defer); 2193cb34c60Sahrens dsl_checkfunc_t dsl_dataset_destroy_check; 2203cb34c60Sahrens dsl_syncfunc_t dsl_dataset_destroy_sync; 2211d452cf5Sahrens dsl_checkfunc_t dsl_dataset_snapshot_check; 2221d452cf5Sahrens dsl_syncfunc_t dsl_dataset_snapshot_sync; 22399d5e173STim Haley dsl_syncfunc_t dsl_dataset_user_hold_sync; 224cdf5b4caSmmusante int dsl_dataset_rename(char *name, const char *newname, boolean_t recursive); 225681d9761SEric Taylor int dsl_dataset_promote(const char *name, char *conflsnap); 2263cb34c60Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head, 2273cb34c60Sahrens boolean_t force); 228842727c2SChris Kirby int dsl_dataset_user_hold(char *dsname, char *snapname, char *htag, 229c99e4bdcSChris Kirby boolean_t recursive, boolean_t temphold, int cleanup_fd); 230a7f53a56SChris Kirby int dsl_dataset_user_hold_for_send(dsl_dataset_t *ds, char *htag, 231a7f53a56SChris Kirby boolean_t temphold); 232842727c2SChris Kirby int dsl_dataset_user_release(char *dsname, char *snapname, char *htag, 233842727c2SChris Kirby boolean_t recursive); 234ca45db41SChris Kirby int dsl_dataset_user_release_tmp(struct dsl_pool *dp, uint64_t dsobj, 235a7f53a56SChris Kirby char *htag, boolean_t retry); 236842727c2SChris Kirby int dsl_dataset_get_holds(const char *dsname, nvlist_t **nvp); 237fa9e4066Sahrens 238c717a561Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds); 239fa9e4066Sahrens void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 240fa9e4066Sahrens 241fa9e4066Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds); 242fa9e4066Sahrens 243f18faf3fSek boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds); 244f18faf3fSek 245c717a561Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx); 246fa9e4066Sahrens 247b24ab676SJeff Bonwick void dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp, 248c717a561Smaybee dmu_tx_t *tx); 249b24ab676SJeff Bonwick int dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp, 250b24ab676SJeff Bonwick dmu_tx_t *tx, boolean_t async); 251c7cd2421SGeorge Wilson boolean_t dsl_dataset_block_freeable(dsl_dataset_t *ds, const blkptr_t *bp, 252c7cd2421SGeorge Wilson uint64_t blk_birth); 253ea8dc4b6Seschrock uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds); 254fa9e4066Sahrens 255fa9e4066Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx); 256a2eea2e1Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv); 257a2eea2e1Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat); 258a2eea2e1Sahrens void dsl_dataset_space(dsl_dataset_t *ds, 259a2eea2e1Sahrens uint64_t *refdbytesp, uint64_t *availbytesp, 260a2eea2e1Sahrens uint64_t *usedobjsp, uint64_t *availobjsp); 261a2eea2e1Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds); 26219b94df9SMatthew Ahrens int dsl_dataset_space_written(dsl_dataset_t *oldsnap, dsl_dataset_t *new, 26319b94df9SMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp); 26419b94df9SMatthew Ahrens int dsl_dataset_space_wouldfree(dsl_dataset_t *firstsnap, dsl_dataset_t *last, 26519b94df9SMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp); 266fa9e4066Sahrens 267b1b8ab34Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf); 268b1b8ab34Slling 269a9799022Sck int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota, 2709082849eSck uint64_t asize, uint64_t inflight, uint64_t *used, 2719082849eSck uint64_t *ref_rsrv); 27292241e0bSTom Erickson int dsl_dataset_set_quota(const char *dsname, zprop_source_t source, 27392241e0bSTom Erickson uint64_t quota); 2743f9d6ad7SLin Ling dsl_syncfunc_t dsl_dataset_set_quota_sync; 27592241e0bSTom Erickson int dsl_dataset_set_reservation(const char *dsname, zprop_source_t source, 27692241e0bSTom Erickson uint64_t reservation); 277a9799022Sck 278fd136879SMatthew Ahrens int dsl_destroy_inconsistent(const char *dsname, void *arg); 279503ad85cSMatthew Ahrens 280fa9e4066Sahrens #ifdef ZFS_DEBUG 281fa9e4066Sahrens #define dprintf_ds(ds, fmt, ...) do { \ 282fa9e4066Sahrens if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 283fa9e4066Sahrens char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \ 284fa9e4066Sahrens dsl_dataset_name(ds, __ds_name); \ 285fa9e4066Sahrens dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \ 286fa9e4066Sahrens kmem_free(__ds_name, MAXNAMELEN); \ 287fa9e4066Sahrens } \ 288fa9e4066Sahrens _NOTE(CONSTCOND) } while (0) 289fa9e4066Sahrens #else 290fa9e4066Sahrens #define dprintf_ds(dd, fmt, ...) 291fa9e4066Sahrens #endif 292fa9e4066Sahrens 293fa9e4066Sahrens #ifdef __cplusplus 294fa9e4066Sahrens } 295fa9e4066Sahrens #endif 296fa9e4066Sahrens 297fa9e4066Sahrens #endif /* _SYS_DSL_DATASET_H */ 298