1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright (c) 2012, 2018 by Delphix. All rights reserved. 24 * Copyright (c) 2014, Joyent, Inc. All rights reserved. 25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved. 26 */ 27 28 #ifndef _SYS_DSL_DIR_H 29 #define _SYS_DSL_DIR_H 30 31 #include <sys/dmu.h> 32 #include <sys/dsl_deadlist.h> 33 #include <sys/dsl_pool.h> 34 #include <sys/dsl_synctask.h> 35 #include <sys/zfs_refcount.h> 36 #include <sys/zfs_context.h> 37 #include <sys/dsl_crypt.h> 38 #include <sys/bplist.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 struct dsl_dataset; 45 struct zthr; 46 /* 47 * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object. 48 * They should be of the format <reverse-dns>:<field>. 49 */ 50 51 #define DD_FIELD_FILESYSTEM_COUNT "com.joyent:filesystem_count" 52 #define DD_FIELD_SNAPSHOT_COUNT "com.joyent:snapshot_count" 53 #define DD_FIELD_CRYPTO_KEY_OBJ "com.datto:crypto_key_obj" 54 #define DD_FIELD_LIVELIST "com.delphix:livelist" 55 56 typedef enum dd_used { 57 DD_USED_HEAD, 58 DD_USED_SNAP, 59 DD_USED_CHILD, 60 DD_USED_CHILD_RSRV, 61 DD_USED_REFRSRV, 62 DD_USED_NUM 63 } dd_used_t; 64 65 #define DD_FLAG_USED_BREAKDOWN (1<<0) 66 67 typedef struct dsl_dir_phys { 68 uint64_t dd_creation_time; /* not actually used */ 69 uint64_t dd_head_dataset_obj; 70 uint64_t dd_parent_obj; 71 uint64_t dd_origin_obj; 72 uint64_t dd_child_dir_zapobj; 73 /* 74 * how much space our children are accounting for; for leaf 75 * datasets, == physical space used by fs + snaps 76 */ 77 uint64_t dd_used_bytes; 78 uint64_t dd_compressed_bytes; 79 uint64_t dd_uncompressed_bytes; 80 /* Administrative quota setting */ 81 uint64_t dd_quota; 82 /* Administrative reservation setting */ 83 uint64_t dd_reserved; 84 uint64_t dd_props_zapobj; 85 uint64_t dd_deleg_zapobj; /* dataset delegation permissions */ 86 uint64_t dd_flags; 87 uint64_t dd_used_breakdown[DD_USED_NUM]; 88 uint64_t dd_clones; /* dsl_dir objects */ 89 uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */ 90 } dsl_dir_phys_t; 91 92 struct dsl_dir { 93 dmu_buf_user_t dd_dbu; 94 95 /* These are immutable; no lock needed: */ 96 uint64_t dd_object; 97 uint64_t dd_crypto_obj; 98 dsl_pool_t *dd_pool; 99 100 /* Stable until user eviction; no lock needed: */ 101 dmu_buf_t *dd_dbuf; 102 103 /* protected by lock on pool's dp_dirty_dirs list */ 104 txg_node_t dd_dirty_link; 105 106 /* protected by dp_config_rwlock */ 107 dsl_dir_t *dd_parent; 108 109 /* Protected by dd_lock */ 110 kmutex_t dd_lock; 111 list_t dd_props; /* list of dsl_prop_record_t's */ 112 inode_timespec_t dd_snap_cmtime; /* last snapshot namespace change */ 113 uint64_t dd_origin_txg; 114 115 /* gross estimate of space used by in-flight tx's */ 116 uint64_t dd_tempreserved[TXG_SIZE]; 117 /* amount of space we expect to write; == amount of dirty data */ 118 int64_t dd_space_towrite[TXG_SIZE]; 119 120 dsl_deadlist_t dd_livelist; 121 bplist_t dd_pending_frees; 122 bplist_t dd_pending_allocs; 123 124 kmutex_t dd_activity_lock; 125 kcondvar_t dd_activity_cv; 126 boolean_t dd_activity_cancelled; 127 uint64_t dd_activity_waiters; 128 129 /* protected by dd_lock; keep at end of struct for better locality */ 130 char dd_myname[ZFS_MAX_DATASET_NAME_LEN]; 131 }; 132 133 static inline dsl_dir_phys_t * 134 dsl_dir_phys(dsl_dir_t *dd) 135 { 136 return (dd->dd_dbuf->db_data); 137 } 138 139 void dsl_dir_rele(dsl_dir_t *dd, void *tag); 140 void dsl_dir_async_rele(dsl_dir_t *dd, void *tag); 141 int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag, 142 dsl_dir_t **, const char **tail); 143 int dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj, 144 const char *tail, void *tag, dsl_dir_t **); 145 void dsl_dir_name(dsl_dir_t *dd, char *buf); 146 int dsl_dir_namelen(dsl_dir_t *dd); 147 uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds, 148 const char *name, dmu_tx_t *tx); 149 150 uint64_t dsl_dir_get_used(dsl_dir_t *dd); 151 uint64_t dsl_dir_get_compressed(dsl_dir_t *dd); 152 uint64_t dsl_dir_get_quota(dsl_dir_t *dd); 153 uint64_t dsl_dir_get_reservation(dsl_dir_t *dd); 154 uint64_t dsl_dir_get_compressratio(dsl_dir_t *dd); 155 uint64_t dsl_dir_get_logicalused(dsl_dir_t *dd); 156 uint64_t dsl_dir_get_usedsnap(dsl_dir_t *dd); 157 uint64_t dsl_dir_get_usedds(dsl_dir_t *dd); 158 uint64_t dsl_dir_get_usedrefreserv(dsl_dir_t *dd); 159 uint64_t dsl_dir_get_usedchild(dsl_dir_t *dd); 160 void dsl_dir_get_origin(dsl_dir_t *dd, char *buf); 161 int dsl_dir_get_filesystem_count(dsl_dir_t *dd, uint64_t *count); 162 int dsl_dir_get_snapshot_count(dsl_dir_t *dd, uint64_t *count); 163 164 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv); 165 uint64_t dsl_dir_space_available(dsl_dir_t *dd, 166 dsl_dir_t *ancestor, int64_t delta, int ondiskonly); 167 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx); 168 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx); 169 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem, 170 uint64_t asize, boolean_t netfree, void **tr_cookiep, dmu_tx_t *tx); 171 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx); 172 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx); 173 void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type, 174 int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx); 175 void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta, 176 dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx); 177 void dsl_dir_diduse_transfer_space(dsl_dir_t *dd, int64_t used, 178 int64_t compressed, int64_t uncompressed, int64_t tonew, 179 dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx); 180 int dsl_dir_set_quota(const char *ddname, zprop_source_t source, 181 uint64_t quota); 182 int dsl_dir_set_reservation(const char *ddname, zprop_source_t source, 183 uint64_t reservation); 184 int dsl_dir_activate_fs_ss_limit(const char *); 185 int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *, 186 cred_t *, proc_t *); 187 void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *); 188 int dsl_dir_rename(const char *oldname, const char *newname); 189 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, 190 uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *, proc_t *); 191 boolean_t dsl_dir_is_clone(dsl_dir_t *dd); 192 void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds, 193 uint64_t reservation, cred_t *cr, dmu_tx_t *tx); 194 void dsl_dir_snap_cmtime_update(dsl_dir_t *dd); 195 inode_timespec_t dsl_dir_snap_cmtime(dsl_dir_t *dd); 196 void dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value, 197 dmu_tx_t *tx); 198 void dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx); 199 boolean_t dsl_dir_is_zapified(dsl_dir_t *dd); 200 void dsl_dir_livelist_open(dsl_dir_t *dd, uint64_t obj); 201 void dsl_dir_livelist_close(dsl_dir_t *dd); 202 void dsl_dir_remove_livelist(dsl_dir_t *dd, dmu_tx_t *tx, boolean_t total); 203 int dsl_dir_wait(dsl_dir_t *dd, dsl_dataset_t *ds, zfs_wait_activity_t activity, 204 boolean_t *waited); 205 void dsl_dir_cancel_waiters(dsl_dir_t *dd); 206 207 /* internal reserved dir name */ 208 #define MOS_DIR_NAME "$MOS" 209 #define ORIGIN_DIR_NAME "$ORIGIN" 210 #define FREE_DIR_NAME "$FREE" 211 #define LEAK_DIR_NAME "$LEAK" 212 213 #ifdef ZFS_DEBUG 214 #define dprintf_dd(dd, fmt, ...) do { \ 215 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 216 char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \ 217 dsl_dir_name(dd, __ds_name); \ 218 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \ 219 kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \ 220 } \ 221 } while (0) 222 #else 223 #define dprintf_dd(dd, fmt, ...) 224 #endif 225 226 #ifdef __cplusplus 227 } 228 #endif 229 230 #endif /* _SYS_DSL_DIR_H */ 231