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