]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_dir.h
MFC r226676, r226678, r226700, r226705, r226706, r226707:
[FreeBSD/stable/8.git] / sys / cddl / contrib / opensolaris / uts / common / fs / zfs / sys / dsl_dir.h
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) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>.
24  * All rights reserved.
25  */
26
27 #ifndef _SYS_DSL_DIR_H
28 #define _SYS_DSL_DIR_H
29
30 #include <sys/dmu.h>
31 #include <sys/dsl_pool.h>
32 #include <sys/dsl_synctask.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 enum dd_used {
43         DD_USED_HEAD,
44         DD_USED_SNAP,
45         DD_USED_CHILD,
46         DD_USED_CHILD_RSRV,
47         DD_USED_REFRSRV,
48         DD_USED_NUM
49 } dd_used_t;
50
51 #define DD_FLAG_USED_BREAKDOWN (1<<0)
52
53 typedef struct dsl_dir_phys {
54         uint64_t dd_creation_time; /* not actually used */
55         uint64_t dd_head_dataset_obj;
56         uint64_t dd_parent_obj;
57         uint64_t dd_origin_obj;
58         uint64_t dd_child_dir_zapobj;
59         /*
60          * how much space our children are accounting for; for leaf
61          * datasets, == physical space used by fs + snaps
62          */
63         uint64_t dd_used_bytes;
64         uint64_t dd_compressed_bytes;
65         uint64_t dd_uncompressed_bytes;
66         /* Administrative quota setting */
67         uint64_t dd_quota;
68         /* Administrative reservation setting */
69         uint64_t dd_reserved;
70         uint64_t dd_props_zapobj;
71         uint64_t dd_deleg_zapobj; /* dataset delegation permissions */
72         uint64_t dd_flags;
73         uint64_t dd_used_breakdown[DD_USED_NUM];
74         uint64_t dd_clones; /* dsl_dir objects */
75         uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */
76 } dsl_dir_phys_t;
77
78 struct dsl_dir {
79         /* These are immutable; no lock needed: */
80         uint64_t dd_object;
81         dsl_dir_phys_t *dd_phys;
82         dmu_buf_t *dd_dbuf;
83         dsl_pool_t *dd_pool;
84
85         /* protected by lock on pool's dp_dirty_dirs list */
86         txg_node_t dd_dirty_link;
87
88         /* protected by dp_config_rwlock */
89         dsl_dir_t *dd_parent;
90
91         /* Protected by dd_lock */
92         kmutex_t dd_lock;
93         list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */
94         timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */
95         uint64_t dd_origin_txg;
96
97         /* gross estimate of space used by in-flight tx's */
98         uint64_t dd_tempreserved[TXG_SIZE];
99         /* amount of space we expect to write; == amount of dirty data */
100         int64_t dd_space_towrite[TXG_SIZE];
101
102         /* protected by dd_lock; keep at end of struct for better locality */
103         char dd_myname[MAXNAMELEN];
104 };
105
106 void dsl_dir_close(dsl_dir_t *dd, void *tag);
107 int dsl_dir_open(const char *name, void *tag, dsl_dir_t **, const char **tail);
108 int dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, dsl_dir_t **,
109     const char **tailp);
110 int dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj,
111     const char *tail, void *tag, dsl_dir_t **);
112 void dsl_dir_name(dsl_dir_t *dd, char *buf);
113 int dsl_dir_namelen(dsl_dir_t *dd);
114 uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds,
115     const char *name, dmu_tx_t *tx);
116 dsl_checkfunc_t dsl_dir_destroy_check;
117 dsl_syncfunc_t dsl_dir_destroy_sync;
118 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
119 uint64_t dsl_dir_space_available(dsl_dir_t *dd,
120     dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
121 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
122 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
123 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
124     uint64_t asize, uint64_t fsize, uint64_t usize, void **tr_cookiep,
125     dmu_tx_t *tx);
126 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
127 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
128 void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
129     int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
130 void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta,
131     dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx);
132 int dsl_dir_set_quota(const char *ddname, zprop_source_t source,
133     uint64_t quota);
134 int dsl_dir_set_reservation(const char *ddname, zprop_source_t source,
135     uint64_t reservation);
136 int dsl_dir_rename(dsl_dir_t *dd, const char *newname, int flags);
137 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space);
138 int dsl_dir_set_reservation_check(void *arg1, void *arg2, dmu_tx_t *tx);
139 boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
140 void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
141     uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
142 void dsl_dir_snap_cmtime_update(dsl_dir_t *dd);
143 timestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd);
144
145 /* internal reserved dir name */
146 #define MOS_DIR_NAME "$MOS"
147 #define ORIGIN_DIR_NAME "$ORIGIN"
148 #define XLATION_DIR_NAME "$XLATION"
149 #define FREE_DIR_NAME "$FREE"
150
151 #ifdef ZFS_DEBUG
152 #define dprintf_dd(dd, fmt, ...) do { \
153         if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
154         char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
155             KM_SLEEP); \
156         dsl_dir_name(dd, __ds_name); \
157         dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
158         kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
159         } \
160 _NOTE(CONSTCOND) } while (0)
161 #else
162 #define dprintf_dd(dd, fmt, ...)
163 #endif
164
165 #ifdef  __cplusplus
166 }
167 #endif
168
169 #endif /* _SYS_DSL_DIR_H */