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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_DSL_DIR_H
27 #define _SYS_DSL_DIR_H
30 #include <sys/dsl_pool.h>
31 #include <sys/dsl_synctask.h>
32 #include <sys/refcount.h>
33 #include <sys/zfs_context.h>
41 typedef enum dd_used
{
50 #define DD_FLAG_USED_BREAKDOWN (1<<0)
52 typedef struct dsl_dir_phys
{
53 uint64_t dd_creation_time
; /* not actually used */
54 uint64_t dd_head_dataset_obj
;
55 uint64_t dd_parent_obj
;
56 uint64_t dd_origin_obj
;
57 uint64_t dd_child_dir_zapobj
;
59 * how much space our children are accounting for; for leaf
60 * datasets, == physical space used by fs + snaps
62 uint64_t dd_used_bytes
;
63 uint64_t dd_compressed_bytes
;
64 uint64_t dd_uncompressed_bytes
;
65 /* Administrative quota setting */
67 /* Administrative reservation setting */
69 uint64_t dd_props_zapobj
;
70 uint64_t dd_deleg_zapobj
; /* dataset delegation permissions */
72 uint64_t dd_used_breakdown
[DD_USED_NUM
];
73 uint64_t dd_pad
[14]; /* pad out to 256 bytes for good measure */
77 /* These are immutable; no lock needed: */
79 dsl_dir_phys_t
*dd_phys
;
83 /* protected by lock on pool's dp_dirty_dirs list */
84 txg_node_t dd_dirty_link
;
86 /* protected by dp_config_rwlock */
89 /* Protected by dd_lock */
91 list_t dd_prop_cbs
; /* list of dsl_prop_cb_record_t's */
93 /* gross estimate of space used by in-flight tx's */
94 uint64_t dd_tempreserved
[TXG_SIZE
];
95 /* amount of space we expect to write; == amount of dirty data */
96 int64_t dd_space_towrite
[TXG_SIZE
];
98 /* protected by dd_lock; keep at end of struct for better locality */
99 char dd_myname
[MAXNAMELEN
];
102 void dsl_dir_close(dsl_dir_t
*dd
, void *tag
);
103 int dsl_dir_open(const char *name
, void *tag
, dsl_dir_t
**, const char **tail
);
104 int dsl_dir_open_spa(spa_t
*spa
, const char *name
, void *tag
, dsl_dir_t
**,
106 int dsl_dir_open_obj(dsl_pool_t
*dp
, uint64_t ddobj
,
107 const char *tail
, void *tag
, dsl_dir_t
**);
108 void dsl_dir_name(dsl_dir_t
*dd
, char *buf
);
109 int dsl_dir_namelen(dsl_dir_t
*dd
);
110 int dsl_dir_is_private(dsl_dir_t
*dd
);
111 uint64_t dsl_dir_create_sync(dsl_pool_t
*dp
, dsl_dir_t
*pds
,
112 const char *name
, dmu_tx_t
*tx
);
113 dsl_checkfunc_t dsl_dir_destroy_check
;
114 dsl_syncfunc_t dsl_dir_destroy_sync
;
115 void dsl_dir_stats(dsl_dir_t
*dd
, nvlist_t
*nv
);
116 uint64_t dsl_dir_space_available(dsl_dir_t
*dd
,
117 dsl_dir_t
*ancestor
, int64_t delta
, int ondiskonly
);
118 void dsl_dir_dirty(dsl_dir_t
*dd
, dmu_tx_t
*tx
);
119 void dsl_dir_sync(dsl_dir_t
*dd
, dmu_tx_t
*tx
);
120 int dsl_dir_tempreserve_space(dsl_dir_t
*dd
, uint64_t mem
,
121 uint64_t asize
, uint64_t fsize
, uint64_t usize
, void **tr_cookiep
,
123 void dsl_dir_tempreserve_clear(void *tr_cookie
, dmu_tx_t
*tx
);
124 void dsl_dir_willuse_space(dsl_dir_t
*dd
, int64_t space
, dmu_tx_t
*tx
);
125 void dsl_dir_diduse_space(dsl_dir_t
*dd
, dd_used_t type
,
126 int64_t used
, int64_t compressed
, int64_t uncompressed
, dmu_tx_t
*tx
);
127 void dsl_dir_transfer_space(dsl_dir_t
*dd
, int64_t delta
,
128 dd_used_t oldtype
, dd_used_t newtype
, dmu_tx_t
*tx
);
129 int dsl_dir_set_quota(const char *ddname
, uint64_t quota
);
130 int dsl_dir_set_reservation(const char *ddname
, uint64_t reservation
);
131 int dsl_dir_rename(dsl_dir_t
*dd
, const char *newname
);
132 int dsl_dir_transfer_possible(dsl_dir_t
*sdd
, dsl_dir_t
*tdd
, uint64_t space
);
133 int dsl_dir_set_reservation_check(void *arg1
, void *arg2
, dmu_tx_t
*tx
);
134 boolean_t
dsl_dir_is_clone(dsl_dir_t
*dd
);
135 void dsl_dir_new_refreservation(dsl_dir_t
*dd
, struct dsl_dataset
*ds
,
136 uint64_t reservation
, cred_t
*cr
, dmu_tx_t
*tx
);
138 /* internal reserved dir name */
139 #define MOS_DIR_NAME "$MOS"
140 #define ORIGIN_DIR_NAME "$ORIGIN"
143 #define dprintf_dd(dd, fmt, ...) do { \
144 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
145 char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
147 dsl_dir_name(dd, __ds_name); \
148 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
149 kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
151 _NOTE(CONSTCOND) } while (0)
153 #define dprintf_dd(dd, fmt, ...)
160 #endif /* _SYS_DSL_DIR_H */