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 /* 2214843421SMatthew Ahrens * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_DSL_DIR_H 27fa9e4066Sahrens #define _SYS_DSL_DIR_H 28fa9e4066Sahrens 29fa9e4066Sahrens #include <sys/dmu.h> 30fa9e4066Sahrens #include <sys/dsl_pool.h> 311d452cf5Sahrens #include <sys/dsl_synctask.h> 32fa9e4066Sahrens #include <sys/refcount.h> 33fa9e4066Sahrens #include <sys/zfs_context.h> 34fa9e4066Sahrens 35fa9e4066Sahrens #ifdef __cplusplus 36fa9e4066Sahrens extern "C" { 37fa9e4066Sahrens #endif 38fa9e4066Sahrens 39fa9e4066Sahrens struct dsl_dataset; 40fa9e4066Sahrens 4174e7dc98SMatthew Ahrens typedef enum dd_used { 4274e7dc98SMatthew Ahrens DD_USED_HEAD, 4374e7dc98SMatthew Ahrens DD_USED_SNAP, 4474e7dc98SMatthew Ahrens DD_USED_CHILD, 4574e7dc98SMatthew Ahrens DD_USED_CHILD_RSRV, 4674e7dc98SMatthew Ahrens DD_USED_REFRSRV, 4774e7dc98SMatthew Ahrens DD_USED_NUM 4874e7dc98SMatthew Ahrens } dd_used_t; 4974e7dc98SMatthew Ahrens 5074e7dc98SMatthew Ahrens #define DD_FLAG_USED_BREAKDOWN (1<<0) 5174e7dc98SMatthew Ahrens 52fa9e4066Sahrens typedef struct dsl_dir_phys { 53a2eea2e1Sahrens uint64_t dd_creation_time; /* not actually used */ 54fa9e4066Sahrens uint64_t dd_head_dataset_obj; 55fa9e4066Sahrens uint64_t dd_parent_obj; 563cb34c60Sahrens uint64_t dd_origin_obj; 57fa9e4066Sahrens uint64_t dd_child_dir_zapobj; 58fa9e4066Sahrens /* 59fa9e4066Sahrens * how much space our children are accounting for; for leaf 60fa9e4066Sahrens * datasets, == physical space used by fs + snaps 61fa9e4066Sahrens */ 62fa9e4066Sahrens uint64_t dd_used_bytes; 63fa9e4066Sahrens uint64_t dd_compressed_bytes; 64fa9e4066Sahrens uint64_t dd_uncompressed_bytes; 65fa9e4066Sahrens /* Administrative quota setting */ 66fa9e4066Sahrens uint64_t dd_quota; 67fa9e4066Sahrens /* Administrative reservation setting */ 68fa9e4066Sahrens uint64_t dd_reserved; 69fa9e4066Sahrens uint64_t dd_props_zapobj; 70ecd6cf80Smarks uint64_t dd_deleg_zapobj; /* dataset delegation permissions */ 7174e7dc98SMatthew Ahrens uint64_t dd_flags; 7274e7dc98SMatthew Ahrens uint64_t dd_used_breakdown[DD_USED_NUM]; 7374e7dc98SMatthew Ahrens uint64_t dd_pad[14]; /* pad out to 256 bytes for good measure */ 74fa9e4066Sahrens } dsl_dir_phys_t; 75fa9e4066Sahrens 76fa9e4066Sahrens struct dsl_dir { 77fa9e4066Sahrens /* These are immutable; no lock needed: */ 78fa9e4066Sahrens uint64_t dd_object; 79fa9e4066Sahrens dsl_dir_phys_t *dd_phys; 80fa9e4066Sahrens dmu_buf_t *dd_dbuf; 81fa9e4066Sahrens dsl_pool_t *dd_pool; 82fa9e4066Sahrens 83fa9e4066Sahrens /* protected by lock on pool's dp_dirty_dirs list */ 84fa9e4066Sahrens txg_node_t dd_dirty_link; 85fa9e4066Sahrens 86fa9e4066Sahrens /* protected by dp_config_rwlock */ 87fa9e4066Sahrens dsl_dir_t *dd_parent; 88fa9e4066Sahrens 89fa9e4066Sahrens /* Protected by dd_lock */ 90fa9e4066Sahrens kmutex_t dd_lock; 91fa9e4066Sahrens list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */ 9271eb0538SChris Kirby timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */ 93fa9e4066Sahrens 94fa9e4066Sahrens /* gross estimate of space used by in-flight tx's */ 95fa9e4066Sahrens uint64_t dd_tempreserved[TXG_SIZE]; 96fa9e4066Sahrens /* amount of space we expect to write; == amount of dirty data */ 97fa9e4066Sahrens int64_t dd_space_towrite[TXG_SIZE]; 98fa9e4066Sahrens 99fa9e4066Sahrens /* protected by dd_lock; keep at end of struct for better locality */ 100fa9e4066Sahrens char dd_myname[MAXNAMELEN]; 101fa9e4066Sahrens }; 102fa9e4066Sahrens 103fa9e4066Sahrens void dsl_dir_close(dsl_dir_t *dd, void *tag); 104ea8dc4b6Seschrock int dsl_dir_open(const char *name, void *tag, dsl_dir_t **, const char **tail); 105ea8dc4b6Seschrock int dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, dsl_dir_t **, 106fa9e4066Sahrens const char **tailp); 107ea8dc4b6Seschrock int dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj, 108ea8dc4b6Seschrock const char *tail, void *tag, dsl_dir_t **); 109fa9e4066Sahrens void dsl_dir_name(dsl_dir_t *dd, char *buf); 110b7661cccSmmusante int dsl_dir_namelen(dsl_dir_t *dd); 111088f3894Sahrens uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds, 112088f3894Sahrens const char *name, dmu_tx_t *tx); 1131d452cf5Sahrens dsl_checkfunc_t dsl_dir_destroy_check; 1141d452cf5Sahrens dsl_syncfunc_t dsl_dir_destroy_sync; 115a2eea2e1Sahrens void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv); 116a2eea2e1Sahrens uint64_t dsl_dir_space_available(dsl_dir_t *dd, 117a2eea2e1Sahrens dsl_dir_t *ancestor, int64_t delta, int ondiskonly); 118fa9e4066Sahrens void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx); 119fa9e4066Sahrens void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx); 120fa9e4066Sahrens int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem, 121a9799022Sck uint64_t asize, uint64_t fsize, uint64_t usize, void **tr_cookiep, 122a9799022Sck dmu_tx_t *tx); 123fa9e4066Sahrens void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx); 124fa9e4066Sahrens void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx); 12574e7dc98SMatthew Ahrens void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type, 126fa9e4066Sahrens int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx); 12774e7dc98SMatthew Ahrens void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta, 12874e7dc98SMatthew Ahrens dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx); 129*92241e0bSTom Erickson int dsl_dir_set_quota(const char *ddname, zprop_source_t source, 130*92241e0bSTom Erickson uint64_t quota); 131*92241e0bSTom Erickson int dsl_dir_set_reservation(const char *ddname, zprop_source_t source, 132*92241e0bSTom Erickson uint64_t reservation); 1331d452cf5Sahrens int dsl_dir_rename(dsl_dir_t *dd, const char *newname); 13499653d4eSeschrock int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space); 135a9799022Sck int dsl_dir_set_reservation_check(void *arg1, void *arg2, dmu_tx_t *tx); 136088f3894Sahrens boolean_t dsl_dir_is_clone(dsl_dir_t *dd); 1370b383af7SChris Kirby void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds, 1380b383af7SChris Kirby uint64_t reservation, cred_t *cr, dmu_tx_t *tx); 13971eb0538SChris Kirby void dsl_dir_snap_cmtime_update(dsl_dir_t *dd); 14071eb0538SChris Kirby timestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd); 141fa9e4066Sahrens 14215f66a7fSek /* internal reserved dir name */ 14315f66a7fSek #define MOS_DIR_NAME "$MOS" 144088f3894Sahrens #define ORIGIN_DIR_NAME "$ORIGIN" 14515f66a7fSek 146fa9e4066Sahrens #ifdef ZFS_DEBUG 147fa9e4066Sahrens #define dprintf_dd(dd, fmt, ...) do { \ 148fa9e4066Sahrens if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 14915f66a7fSek char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \ 15015f66a7fSek KM_SLEEP); \ 151fa9e4066Sahrens dsl_dir_name(dd, __ds_name); \ 152fa9e4066Sahrens dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \ 15315f66a7fSek kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \ 154fa9e4066Sahrens } \ 155fa9e4066Sahrens _NOTE(CONSTCOND) } while (0) 156fa9e4066Sahrens #else 157fa9e4066Sahrens #define dprintf_dd(dd, fmt, ...) 158fa9e4066Sahrens #endif 159fa9e4066Sahrens 160fa9e4066Sahrens #ifdef __cplusplus 161fa9e4066Sahrens } 162fa9e4066Sahrens #endif 163fa9e4066Sahrens 164fa9e4066Sahrens #endif /* _SYS_DSL_DIR_H */ 165