1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 21789Sahrens /* 2212296SLin.Ling@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23789Sahrens */ 24789Sahrens 25789Sahrens #ifndef _SYS_DSL_DATASET_H 26789Sahrens #define _SYS_DSL_DATASET_H 27789Sahrens 28789Sahrens #include <sys/dmu.h> 29789Sahrens #include <sys/spa.h> 30789Sahrens #include <sys/txg.h> 313547Smaybee #include <sys/zio.h> 32789Sahrens #include <sys/bplist.h> 332199Sahrens #include <sys/dsl_synctask.h> 34789Sahrens #include <sys/zfs_context.h> 3512470SMatthew.Ahrens@Sun.COM #include <sys/dsl_deadlist.h> 36789Sahrens 37789Sahrens #ifdef __cplusplus 38789Sahrens extern "C" { 39789Sahrens #endif 40789Sahrens 41789Sahrens struct dsl_dataset; 42789Sahrens struct dsl_dir; 43789Sahrens struct dsl_pool; 44789Sahrens 452082Seschrock #define DS_FLAG_INCONSISTENT (1ULL<<0) 466689Smaybee #define DS_IS_INCONSISTENT(ds) \ 476689Smaybee ((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT) 482082Seschrock /* 492082Seschrock * NB: nopromote can not yet be set, but we want support for it in this 502082Seschrock * on-disk version, so that we don't need to upgrade for it later. It 512082Seschrock * will be needed when we implement 'zfs split' (where the split off 522082Seschrock * clone should not be promoted). 532082Seschrock */ 542082Seschrock #define DS_FLAG_NOPROMOTE (1ULL<<1) 552082Seschrock 565378Sck153898 /* 575378Sck153898 * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly 585378Sck153898 * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE, 595378Sck153898 * refquota/refreservations). 605378Sck153898 */ 615378Sck153898 #define DS_FLAG_UNIQUE_ACCURATE (1ULL<<2) 625378Sck153898 636492Stimh /* 6410242Schris.kirby@sun.com * DS_FLAG_DEFER_DESTROY is set after 'zfs destroy -d' has been called 6510242Schris.kirby@sun.com * on a dataset. This allows the dataset to be destroyed using 'zfs release'. 6610242Schris.kirby@sun.com */ 6710242Schris.kirby@sun.com #define DS_FLAG_DEFER_DESTROY (1ULL<<3) 6810242Schris.kirby@sun.com #define DS_IS_DEFER_DESTROY(ds) \ 6910242Schris.kirby@sun.com ((ds)->ds_phys->ds_flags & DS_FLAG_DEFER_DESTROY) 7010242Schris.kirby@sun.com 7110242Schris.kirby@sun.com /* 726492Stimh * DS_FLAG_CI_DATASET is set if the dataset contains a file system whose 736492Stimh * name lookups should be performed case-insensitively. 746492Stimh */ 756492Stimh #define DS_FLAG_CI_DATASET (1ULL<<16) 766492Stimh 77789Sahrens typedef struct dsl_dataset_phys { 787046Sahrens uint64_t ds_dir_obj; /* DMU_OT_DSL_DIR */ 797046Sahrens uint64_t ds_prev_snap_obj; /* DMU_OT_DSL_DATASET */ 80789Sahrens uint64_t ds_prev_snap_txg; 817046Sahrens uint64_t ds_next_snap_obj; /* DMU_OT_DSL_DATASET */ 827046Sahrens uint64_t ds_snapnames_zapobj; /* DMU_OT_DSL_DS_SNAP_MAP 0 for snaps */ 83789Sahrens uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 84789Sahrens uint64_t ds_creation_time; /* seconds since 1970 */ 85789Sahrens uint64_t ds_creation_txg; 8612470SMatthew.Ahrens@Sun.COM uint64_t ds_deadlist_obj; /* DMU_OT_DEADLIST */ 87789Sahrens uint64_t ds_used_bytes; 88789Sahrens uint64_t ds_compressed_bytes; 89789Sahrens uint64_t ds_uncompressed_bytes; 903517Smp204432 uint64_t ds_unique_bytes; /* only relevant to snapshots */ 91789Sahrens /* 92789Sahrens * The ds_fsid_guid is a 56-bit ID that can change to avoid 93789Sahrens * collisions. The ds_guid is a 64-bit ID that will never 94789Sahrens * change, so there is a small probability that it will collide. 95789Sahrens */ 96789Sahrens uint64_t ds_fsid_guid; 97789Sahrens uint64_t ds_guid; 987046Sahrens uint64_t ds_flags; /* DS_FLAG_* */ 99789Sahrens blkptr_t ds_bp; 1007265Sahrens uint64_t ds_next_clones_obj; /* DMU_OT_DSL_CLONES */ 1017265Sahrens uint64_t ds_props_obj; /* DMU_OT_DSL_PROPS for snaps */ 10210242Schris.kirby@sun.com uint64_t ds_userrefs_obj; /* DMU_OT_USERREFS */ 10310242Schris.kirby@sun.com uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */ 104789Sahrens } dsl_dataset_phys_t; 105789Sahrens 106789Sahrens typedef struct dsl_dataset { 107789Sahrens /* Immutable: */ 108789Sahrens struct dsl_dir *ds_dir; 109789Sahrens dsl_dataset_phys_t *ds_phys; 110789Sahrens dmu_buf_t *ds_dbuf; 111789Sahrens uint64_t ds_object; 1124787Sahrens uint64_t ds_fsid_guid; 113789Sahrens 1147390SMatthew.Ahrens@Sun.COM /* only used in syncing context, only valid for non-snapshots: */ 1157390SMatthew.Ahrens@Sun.COM struct dsl_dataset *ds_prev; 116789Sahrens 117789Sahrens /* has internal locking: */ 11812470SMatthew.Ahrens@Sun.COM dsl_deadlist_t ds_deadlist; 11912470SMatthew.Ahrens@Sun.COM bplist_t ds_pending_deadlist; 120789Sahrens 12110204SMatthew.Ahrens@Sun.COM /* to protect against multiple concurrent incremental recv */ 12210204SMatthew.Ahrens@Sun.COM kmutex_t ds_recvlock; 12310204SMatthew.Ahrens@Sun.COM 124789Sahrens /* protected by lock on pool's dp_dirty_datasets list */ 125789Sahrens txg_node_t ds_dirty_link; 126789Sahrens list_node_t ds_synced_link; 127789Sahrens 128789Sahrens /* 129789Sahrens * ds_phys->ds_<accounting> is also protected by ds_lock. 130789Sahrens * Protected by ds_lock: 131789Sahrens */ 132789Sahrens kmutex_t ds_lock; 13310298SMatthew.Ahrens@Sun.COM objset_t *ds_objset; 13410242Schris.kirby@sun.com uint64_t ds_userrefs; 1356689Smaybee 1366689Smaybee /* 1376689Smaybee * ds_owner is protected by the ds_rwlock and the ds_lock 1386689Smaybee */ 1396689Smaybee krwlock_t ds_rwlock; 1406689Smaybee kcondvar_t ds_exclusive_cv; 1416689Smaybee void *ds_owner; 142789Sahrens 1432199Sahrens /* no locking; only for making guesses */ 1442199Sahrens uint64_t ds_trysnap_txg; 1452199Sahrens 1464787Sahrens /* for objset_open() */ 1474787Sahrens kmutex_t ds_opening_lock; 1484787Sahrens 1495378Sck153898 uint64_t ds_reserved; /* cached refreservation */ 1505378Sck153898 uint64_t ds_quota; /* cached refquota */ 1515378Sck153898 152789Sahrens /* Protected by ds_lock; keep at end of struct for better locality */ 153789Sahrens char ds_snapname[MAXNAMELEN]; 154789Sahrens } dsl_dataset_t; 155789Sahrens 15610242Schris.kirby@sun.com struct dsl_ds_destroyarg { 15710242Schris.kirby@sun.com dsl_dataset_t *ds; /* ds to destroy */ 15810242Schris.kirby@sun.com dsl_dataset_t *rm_origin; /* also remove our origin? */ 15910242Schris.kirby@sun.com boolean_t is_origin_rm; /* set if removing origin snap */ 16010242Schris.kirby@sun.com boolean_t defer; /* destroy -d requested? */ 16110242Schris.kirby@sun.com boolean_t releasing; /* destroying due to release? */ 16210242Schris.kirby@sun.com boolean_t need_prep; /* do we need to retry due to EBUSY? */ 16310242Schris.kirby@sun.com }; 16410242Schris.kirby@sun.com 165*13043STim.Haley@Sun.COM /* 166*13043STim.Haley@Sun.COM * The max length of a temporary tag prefix is the number of hex digits 167*13043STim.Haley@Sun.COM * required to express UINT64_MAX plus one for the hyphen. 168*13043STim.Haley@Sun.COM */ 169*13043STim.Haley@Sun.COM #define MAX_TAG_PREFIX_LEN 17 170*13043STim.Haley@Sun.COM 171*13043STim.Haley@Sun.COM struct dsl_ds_holdarg { 172*13043STim.Haley@Sun.COM dsl_sync_task_group_t *dstg; 173*13043STim.Haley@Sun.COM char *htag; 174*13043STim.Haley@Sun.COM char *snapname; 175*13043STim.Haley@Sun.COM boolean_t recursive; 176*13043STim.Haley@Sun.COM boolean_t gotone; 177*13043STim.Haley@Sun.COM boolean_t temphold; 178*13043STim.Haley@Sun.COM char failed[MAXPATHLEN]; 179*13043STim.Haley@Sun.COM }; 180*13043STim.Haley@Sun.COM 18112470SMatthew.Ahrens@Sun.COM #define dsl_dataset_is_snapshot(ds) \ 182789Sahrens ((ds)->ds_phys->ds_num_children != 0) 183789Sahrens 1845378Sck153898 #define DS_UNIQUE_IS_ACCURATE(ds) \ 1855378Sck153898 (((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0) 1865378Sck153898 1876689Smaybee int dsl_dataset_hold(const char *name, void *tag, dsl_dataset_t **dsp); 1886689Smaybee int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, 1896689Smaybee void *tag, dsl_dataset_t **); 19010298SMatthew.Ahrens@Sun.COM int dsl_dataset_own(const char *name, boolean_t inconsistentok, 19110298SMatthew.Ahrens@Sun.COM void *tag, dsl_dataset_t **dsp); 1926689Smaybee int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj, 19310298SMatthew.Ahrens@Sun.COM boolean_t inconsistentok, void *tag, dsl_dataset_t **dsp); 194789Sahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name); 1956689Smaybee void dsl_dataset_rele(dsl_dataset_t *ds, void *tag); 19610298SMatthew.Ahrens@Sun.COM void dsl_dataset_disown(dsl_dataset_t *ds, void *tag); 1977046Sahrens void dsl_dataset_drop_ref(dsl_dataset_t *ds, void *tag); 1986689Smaybee boolean_t dsl_dataset_tryown(dsl_dataset_t *ds, boolean_t inconsistentok, 19910298SMatthew.Ahrens@Sun.COM void *tag); 20010298SMatthew.Ahrens@Sun.COM void dsl_dataset_make_exclusive(dsl_dataset_t *ds, void *tag); 20112786SChris.Kirby@oracle.com void dsl_register_onexit_hold_cleanup(dsl_dataset_t *ds, const char *htag, 20212786SChris.Kirby@oracle.com minor_t minor); 2036689Smaybee uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname, 2046689Smaybee dsl_dataset_t *origin, uint64_t flags, cred_t *, dmu_tx_t *); 2057046Sahrens uint64_t dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin, 2067046Sahrens uint64_t flags, dmu_tx_t *tx); 20710242Schris.kirby@sun.com int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag, boolean_t defer); 20810242Schris.kirby@sun.com int dsl_snapshots_destroy(char *fsname, char *snapname, boolean_t defer); 2095367Sahrens dsl_checkfunc_t dsl_dataset_destroy_check; 2105367Sahrens dsl_syncfunc_t dsl_dataset_destroy_sync; 2112199Sahrens dsl_checkfunc_t dsl_dataset_snapshot_check; 2122199Sahrens dsl_syncfunc_t dsl_dataset_snapshot_sync; 213*13043STim.Haley@Sun.COM dsl_syncfunc_t dsl_dataset_user_hold_sync; 2144007Smmusante int dsl_dataset_rename(char *name, const char *newname, boolean_t recursive); 21510588SEric.Taylor@Sun.COM int dsl_dataset_promote(const char *name, char *conflsnap); 2165367Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head, 2175367Sahrens boolean_t force); 21810242Schris.kirby@sun.com int dsl_dataset_user_hold(char *dsname, char *snapname, char *htag, 21912527SChris.Kirby@oracle.com boolean_t recursive, boolean_t temphold, int cleanup_fd); 22012786SChris.Kirby@oracle.com int dsl_dataset_user_hold_for_send(dsl_dataset_t *ds, char *htag, 22112786SChris.Kirby@oracle.com boolean_t temphold); 22210242Schris.kirby@sun.com int dsl_dataset_user_release(char *dsname, char *snapname, char *htag, 22310242Schris.kirby@sun.com boolean_t recursive); 22410342Schris.kirby@sun.com int dsl_dataset_user_release_tmp(struct dsl_pool *dp, uint64_t dsobj, 22512786SChris.Kirby@oracle.com char *htag, boolean_t retry); 22610242Schris.kirby@sun.com int dsl_dataset_get_holds(const char *dsname, nvlist_t **nvp); 227789Sahrens 2283547Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds); 229789Sahrens void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 230789Sahrens 231789Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds); 232789Sahrens 2335326Sek110237 boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds); 2345326Sek110237 2353547Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx); 236789Sahrens 23710922SJeff.Bonwick@Sun.COM void dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp, 2383547Smaybee dmu_tx_t *tx); 23910922SJeff.Bonwick@Sun.COM int dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp, 24010922SJeff.Bonwick@Sun.COM dmu_tx_t *tx, boolean_t async); 24112450SGeorge.Wilson@Sun.COM boolean_t dsl_dataset_block_freeable(dsl_dataset_t *ds, const blkptr_t *bp, 24212450SGeorge.Wilson@Sun.COM uint64_t blk_birth); 2431544Seschrock uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds); 244789Sahrens 245789Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx); 2462885Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv); 2472885Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat); 2482885Sahrens void dsl_dataset_space(dsl_dataset_t *ds, 2492885Sahrens uint64_t *refdbytesp, uint64_t *availbytesp, 2502885Sahrens uint64_t *usedobjsp, uint64_t *availobjsp); 2512885Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds); 252789Sahrens 2533912Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf); 2543912Slling 2555378Sck153898 int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota, 2565831Sck153898 uint64_t asize, uint64_t inflight, uint64_t *used, 2575831Sck153898 uint64_t *ref_rsrv); 25811022STom.Erickson@Sun.COM int dsl_dataset_set_quota(const char *dsname, zprop_source_t source, 25911022STom.Erickson@Sun.COM uint64_t quota); 26012296SLin.Ling@Sun.COM dsl_syncfunc_t dsl_dataset_set_quota_sync; 26111022STom.Erickson@Sun.COM int dsl_dataset_set_reservation(const char *dsname, zprop_source_t source, 26211022STom.Erickson@Sun.COM uint64_t reservation); 2635378Sck153898 26411209SMatthew.Ahrens@Sun.COM int dsl_destroy_inconsistent(const char *dsname, void *arg); 26510298SMatthew.Ahrens@Sun.COM 266789Sahrens #ifdef ZFS_DEBUG 267789Sahrens #define dprintf_ds(ds, fmt, ...) do { \ 268789Sahrens if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 269789Sahrens char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \ 270789Sahrens dsl_dataset_name(ds, __ds_name); \ 271789Sahrens dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \ 272789Sahrens kmem_free(__ds_name, MAXNAMELEN); \ 273789Sahrens } \ 274789Sahrens _NOTE(CONSTCOND) } while (0) 275789Sahrens #else 276789Sahrens #define dprintf_ds(dd, fmt, ...) 277789Sahrens #endif 278789Sahrens 279789Sahrens #ifdef __cplusplus 280789Sahrens } 281789Sahrens #endif 282789Sahrens 283789Sahrens #endif /* _SYS_DSL_DATASET_H */ 284