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 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_DSL_DIR_H 27 #define _SYS_DSL_DIR_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/dmu.h> 32 #include <sys/dsl_pool.h> 33 #include <sys/refcount.h> 34 #include <sys/zfs_context.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 struct dsl_dataset; 41 42 typedef struct dsl_dir_phys { 43 uint64_t dd_creation_time; 44 uint64_t dd_head_dataset_obj; 45 uint64_t dd_parent_obj; 46 uint64_t dd_clone_parent_obj; 47 uint64_t dd_child_dir_zapobj; 48 /* 49 * how much space our children are accounting for; for leaf 50 * datasets, == physical space used by fs + snaps 51 */ 52 uint64_t dd_used_bytes; 53 uint64_t dd_compressed_bytes; 54 uint64_t dd_uncompressed_bytes; 55 /* Administrative quota setting */ 56 uint64_t dd_quota; 57 /* Administrative reservation setting */ 58 uint64_t dd_reserved; 59 uint64_t dd_props_zapobj; 60 uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */ 61 } dsl_dir_phys_t; 62 63 struct dsl_dir { 64 /* These are immutable; no lock needed: */ 65 uint64_t dd_object; 66 dsl_dir_phys_t *dd_phys; 67 dmu_buf_t *dd_dbuf; 68 dsl_pool_t *dd_pool; 69 70 /* protected by lock on pool's dp_dirty_dirs list */ 71 txg_node_t dd_dirty_link; 72 73 /* protected by dp_config_rwlock */ 74 dsl_dir_t *dd_parent; 75 76 /* Protected by dd_lock */ 77 kmutex_t dd_lock; 78 list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */ 79 /* Thing to do when we sync */ 80 uint64_t dd_sync_txg; 81 int (*dd_sync_func)(dsl_dir_t *dd, void *arg, dmu_tx_t *tx); 82 void *dd_sync_arg; 83 int dd_sync_err; 84 85 /* Accounting */ 86 /* reflects any changes to dd_phys->dd_used_bytes made this syncing */ 87 int64_t dd_used_bytes; 88 /* int64_t dd_compressed_bytes; */ 89 /* int64_t dd_uncompressed_bytes; */ 90 /* gross estimate of space used by in-flight tx's */ 91 uint64_t dd_tempreserved[TXG_SIZE]; 92 /* amount of space we expect to write; == amount of dirty data */ 93 int64_t dd_space_towrite[TXG_SIZE]; 94 95 /* protected by dd_lock; keep at end of struct for better locality */ 96 char dd_myname[MAXNAMELEN]; 97 }; 98 99 void dsl_dir_close(dsl_dir_t *dd, void *tag); 100 int dsl_dir_open(const char *name, void *tag, dsl_dir_t **, const char **tail); 101 int dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, dsl_dir_t **, 102 const char **tailp); 103 int dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj, 104 const char *tail, void *tag, dsl_dir_t **); 105 void dsl_dir_name(dsl_dir_t *dd, char *buf); 106 int dsl_dir_is_private(dsl_dir_t *dd); 107 int dsl_dir_create_sync(dsl_dir_t *pds, const char *name, dmu_tx_t *tx); 108 void dsl_dir_create_root(objset_t *mos, uint64_t *ddobjp, dmu_tx_t *tx); 109 int dsl_dir_destroy_sync(dsl_dir_t *pds, void *arg, dmu_tx_t *tx); 110 void dsl_dir_stats(dsl_dir_t *dd, dmu_objset_stats_t *dds); 111 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx); 112 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx); 113 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem, 114 uint64_t asize, uint64_t fsize, void **tr_cookiep, dmu_tx_t *tx); 115 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx); 116 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx); 117 void dsl_dir_diduse_space(dsl_dir_t *dd, 118 int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx); 119 int dsl_dir_sync_task(dsl_dir_t *dd, 120 int (*func)(dsl_dir_t *, void*, dmu_tx_t *), void *arg, uint64_t space); 121 int dsl_dir_set_quota(const char *ddname, uint64_t quota); 122 int dsl_dir_set_reservation(const char *ddname, uint64_t reservation); 123 int dsl_dir_rename_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx); 124 125 #ifdef ZFS_DEBUG 126 #define dprintf_dd(dd, fmt, ...) do { \ 127 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 128 char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \ 129 dsl_dir_name(dd, __ds_name); \ 130 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \ 131 kmem_free(__ds_name, MAXNAMELEN); \ 132 } \ 133 _NOTE(CONSTCOND) } while (0) 134 #else 135 #define dprintf_dd(dd, fmt, ...) 136 #endif 137 138 #ifdef __cplusplus 139 } 140 #endif 141 142 #endif /* _SYS_DSL_DIR_H */ 143