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 /* 22c717a561Smaybee * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 30fa9e4066Sahrens 31fa9e4066Sahrens #include <sys/dmu.h> 32fa9e4066Sahrens #include <sys/spa.h> 33fa9e4066Sahrens #include <sys/txg.h> 34c717a561Smaybee #include <sys/zio.h> 35fa9e4066Sahrens #include <sys/bplist.h> 361d452cf5Sahrens #include <sys/dsl_synctask.h> 37fa9e4066Sahrens #include <sys/zfs_context.h> 38fa9e4066Sahrens 39fa9e4066Sahrens #ifdef __cplusplus 40fa9e4066Sahrens extern "C" { 41fa9e4066Sahrens #endif 42fa9e4066Sahrens 43fa9e4066Sahrens struct dsl_dataset; 44fa9e4066Sahrens struct dsl_dir; 45fa9e4066Sahrens struct dsl_pool; 46fa9e4066Sahrens 47fa9e4066Sahrens typedef void dsl_dataset_evict_func_t(struct dsl_dataset *, void *); 48fa9e4066Sahrens 4999653d4eSeschrock #define DS_FLAG_INCONSISTENT (1ULL<<0) 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 58fa9e4066Sahrens typedef struct dsl_dataset_phys { 59fa9e4066Sahrens uint64_t ds_dir_obj; 60fa9e4066Sahrens uint64_t ds_prev_snap_obj; 61fa9e4066Sahrens uint64_t ds_prev_snap_txg; 62fa9e4066Sahrens uint64_t ds_next_snap_obj; 63fa9e4066Sahrens uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */ 64fa9e4066Sahrens uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 65fa9e4066Sahrens uint64_t ds_creation_time; /* seconds since 1970 */ 66fa9e4066Sahrens uint64_t ds_creation_txg; 67fa9e4066Sahrens uint64_t ds_deadlist_obj; 68fa9e4066Sahrens uint64_t ds_used_bytes; 69fa9e4066Sahrens uint64_t ds_compressed_bytes; 70fa9e4066Sahrens uint64_t ds_uncompressed_bytes; 7163360950Smp uint64_t ds_unique_bytes; /* only relevant to snapshots */ 72fa9e4066Sahrens /* 73fa9e4066Sahrens * The ds_fsid_guid is a 56-bit ID that can change to avoid 74fa9e4066Sahrens * collisions. The ds_guid is a 64-bit ID that will never 75fa9e4066Sahrens * change, so there is a small probability that it will collide. 76fa9e4066Sahrens */ 77fa9e4066Sahrens uint64_t ds_fsid_guid; 78fa9e4066Sahrens uint64_t ds_guid; 7999653d4eSeschrock uint64_t ds_flags; 80fa9e4066Sahrens blkptr_t ds_bp; 8199653d4eSeschrock uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */ 82fa9e4066Sahrens } dsl_dataset_phys_t; 83fa9e4066Sahrens 84fa9e4066Sahrens typedef struct dsl_dataset { 85fa9e4066Sahrens /* Immutable: */ 86fa9e4066Sahrens struct dsl_dir *ds_dir; 87fa9e4066Sahrens dsl_dataset_phys_t *ds_phys; 88fa9e4066Sahrens dmu_buf_t *ds_dbuf; 89fa9e4066Sahrens uint64_t ds_object; 9091ebeef5Sahrens uint64_t ds_fsid_guid; 91fa9e4066Sahrens 92fa9e4066Sahrens /* only used in syncing context: */ 93fa9e4066Sahrens struct dsl_dataset *ds_prev; /* only valid for non-snapshots */ 94fa9e4066Sahrens 95fa9e4066Sahrens /* has internal locking: */ 96fa9e4066Sahrens bplist_t ds_deadlist; 97fa9e4066Sahrens 98fa9e4066Sahrens /* protected by lock on pool's dp_dirty_datasets list */ 99fa9e4066Sahrens txg_node_t ds_dirty_link; 100fa9e4066Sahrens list_node_t ds_synced_link; 101fa9e4066Sahrens 102fa9e4066Sahrens /* 103fa9e4066Sahrens * ds_phys->ds_<accounting> is also protected by ds_lock. 104fa9e4066Sahrens * Protected by ds_lock: 105fa9e4066Sahrens */ 106fa9e4066Sahrens kmutex_t ds_lock; 107fa9e4066Sahrens void *ds_user_ptr; 108fa9e4066Sahrens dsl_dataset_evict_func_t *ds_user_evict_func; 109fa9e4066Sahrens uint64_t ds_open_refcount; 110fa9e4066Sahrens 1111d452cf5Sahrens /* no locking; only for making guesses */ 1121d452cf5Sahrens uint64_t ds_trysnap_txg; 1131d452cf5Sahrens 11491ebeef5Sahrens /* for objset_open() */ 11591ebeef5Sahrens kmutex_t ds_opening_lock; 11691ebeef5Sahrens 117fa9e4066Sahrens /* Protected by ds_lock; keep at end of struct for better locality */ 118fa9e4066Sahrens char ds_snapname[MAXNAMELEN]; 119fa9e4066Sahrens } dsl_dataset_t; 120fa9e4066Sahrens 121fa9e4066Sahrens #define dsl_dataset_is_snapshot(ds) \ 122fa9e4066Sahrens ((ds)->ds_phys->ds_num_children != 0) 123fa9e4066Sahrens 124fa9e4066Sahrens int dsl_dataset_open_spa(spa_t *spa, const char *name, int mode, 125fa9e4066Sahrens void *tag, dsl_dataset_t **dsp); 126fa9e4066Sahrens int dsl_dataset_open(const char *name, int mode, void *tag, 127fa9e4066Sahrens dsl_dataset_t **dsp); 128ea8dc4b6Seschrock int dsl_dataset_open_obj(struct dsl_pool *dp, uint64_t dsobj, 129ea8dc4b6Seschrock const char *tail, int mode, void *tag, dsl_dataset_t **); 130fa9e4066Sahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name); 131fa9e4066Sahrens void dsl_dataset_close(dsl_dataset_t *ds, int mode, void *tag); 132*3cb34c60Sahrens void dsl_dataset_downgrade(dsl_dataset_t *ds, int oldmode, int newmode); 133*3cb34c60Sahrens boolean_t dsl_dataset_tryupgrade(dsl_dataset_t *ds, int oldmode, int newmode); 134*3cb34c60Sahrens uint64_t dsl_dataset_create_sync_impl(dsl_dir_t *dd, dsl_dataset_t *origin, 135*3cb34c60Sahrens dmu_tx_t *tx); 1361d452cf5Sahrens uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, 137*3cb34c60Sahrens const char *lastname, dsl_dataset_t *origin, cred_t *, dmu_tx_t *); 138*3cb34c60Sahrens int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag); 1391d452cf5Sahrens int dsl_snapshots_destroy(char *fsname, char *snapname); 140*3cb34c60Sahrens dsl_checkfunc_t dsl_dataset_destroy_check; 141*3cb34c60Sahrens dsl_syncfunc_t dsl_dataset_destroy_sync; 1421d452cf5Sahrens dsl_checkfunc_t dsl_dataset_snapshot_check; 1431d452cf5Sahrens dsl_syncfunc_t dsl_dataset_snapshot_sync; 144*3cb34c60Sahrens int dsl_dataset_rollback(dsl_dataset_t *ds, dmu_objset_type_t ost); 145cdf5b4caSmmusante int dsl_dataset_rename(char *name, const char *newname, boolean_t recursive); 14699653d4eSeschrock int dsl_dataset_promote(const char *name); 147*3cb34c60Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head, 148*3cb34c60Sahrens boolean_t force); 149fa9e4066Sahrens 150fa9e4066Sahrens void *dsl_dataset_set_user_ptr(dsl_dataset_t *ds, 151fa9e4066Sahrens void *p, dsl_dataset_evict_func_t func); 152fa9e4066Sahrens void *dsl_dataset_get_user_ptr(dsl_dataset_t *ds); 153fa9e4066Sahrens 154c717a561Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds); 155fa9e4066Sahrens void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 156fa9e4066Sahrens 157fa9e4066Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds); 158fa9e4066Sahrens 159f18faf3fSek boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds); 160f18faf3fSek 161c717a561Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx); 162fa9e4066Sahrens 163fa9e4066Sahrens void dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 164c717a561Smaybee void dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, zio_t *pio, 165c717a561Smaybee dmu_tx_t *tx); 166ea8dc4b6Seschrock int dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth); 167ea8dc4b6Seschrock uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds); 168fa9e4066Sahrens 169fa9e4066Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx); 170a2eea2e1Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv); 171a2eea2e1Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat); 172a2eea2e1Sahrens void dsl_dataset_space(dsl_dataset_t *ds, 173a2eea2e1Sahrens uint64_t *refdbytesp, uint64_t *availbytesp, 174a2eea2e1Sahrens uint64_t *usedobjsp, uint64_t *availobjsp); 175a2eea2e1Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds); 176fa9e4066Sahrens 177fa9e4066Sahrens void dsl_dataset_create_root(struct dsl_pool *dp, uint64_t *ddobjp, 178fa9e4066Sahrens dmu_tx_t *tx); 179fa9e4066Sahrens 180b1b8ab34Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf); 181b1b8ab34Slling 182fa9e4066Sahrens #ifdef ZFS_DEBUG 183fa9e4066Sahrens #define dprintf_ds(ds, fmt, ...) do { \ 184fa9e4066Sahrens if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 185fa9e4066Sahrens char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \ 186fa9e4066Sahrens dsl_dataset_name(ds, __ds_name); \ 187fa9e4066Sahrens dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \ 188fa9e4066Sahrens kmem_free(__ds_name, MAXNAMELEN); \ 189fa9e4066Sahrens } \ 190fa9e4066Sahrens _NOTE(CONSTCOND) } while (0) 191fa9e4066Sahrens #else 192fa9e4066Sahrens #define dprintf_ds(dd, fmt, ...) 193fa9e4066Sahrens #endif 194fa9e4066Sahrens 195fa9e4066Sahrens #ifdef __cplusplus 196fa9e4066Sahrens } 197fa9e4066Sahrens #endif 198fa9e4066Sahrens 199fa9e4066Sahrens #endif /* _SYS_DSL_DATASET_H */ 200