xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dataset.h (revision 99653d4ee642c6528e88224f12409a5f23060994)
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_DATASET_H
27 #define	_SYS_DSL_DATASET_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/dmu.h>
32 #include <sys/spa.h>
33 #include <sys/txg.h>
34 #include <sys/bplist.h>
35 #include <sys/zfs_context.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 struct dsl_dataset;
42 struct dsl_dir;
43 struct dsl_pool;
44 
45 typedef void dsl_dataset_evict_func_t(struct dsl_dataset *, void *);
46 
47 #define	DS_FLAG_INCONSISTENT	(1ULL<<0)
48 /*
49  * NB: nopromote can not yet be set, but we want support for it in this
50  * on-disk version, so that we don't need to upgrade for it later.  It
51  * will be needed when we implement 'zfs split' (where the split off
52  * clone should not be promoted).
53  */
54 #define	DS_FLAG_NOPROMOTE	(1ULL<<1)
55 
56 typedef struct dsl_dataset_phys {
57 	uint64_t ds_dir_obj;
58 	uint64_t ds_prev_snap_obj;
59 	uint64_t ds_prev_snap_txg;
60 	uint64_t ds_next_snap_obj;
61 	uint64_t ds_snapnames_zapobj;	/* zap obj of snaps; ==0 for snaps */
62 	uint64_t ds_num_children;	/* clone/snap children; ==0 for head */
63 	uint64_t ds_creation_time;	/* seconds since 1970 */
64 	uint64_t ds_creation_txg;
65 	uint64_t ds_deadlist_obj;
66 	uint64_t ds_used_bytes;
67 	uint64_t ds_compressed_bytes;
68 	uint64_t ds_uncompressed_bytes;
69 	uint64_t ds_unique_bytes;	/* only relavent to snapshots */
70 	/*
71 	 * The ds_fsid_guid is a 56-bit ID that can change to avoid
72 	 * collisions.  The ds_guid is a 64-bit ID that will never
73 	 * change, so there is a small probability that it will collide.
74 	 */
75 	uint64_t ds_fsid_guid;
76 	uint64_t ds_guid;
77 	uint64_t ds_flags;
78 	blkptr_t ds_bp;
79 	uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
80 } dsl_dataset_phys_t;
81 
82 typedef struct dsl_dataset {
83 	/* Immutable: */
84 	struct dsl_dir *ds_dir;
85 	dsl_dataset_phys_t *ds_phys;
86 	dmu_buf_t *ds_dbuf;
87 	uint64_t ds_object;
88 
89 	/* only used in syncing context: */
90 	struct dsl_dataset *ds_prev; /* only valid for non-snapshots */
91 
92 	/* has internal locking: */
93 	bplist_t ds_deadlist;
94 
95 	/* protected by lock on pool's dp_dirty_datasets list */
96 	txg_node_t ds_dirty_link;
97 	list_node_t ds_synced_link;
98 
99 	/*
100 	 * ds_phys->ds_<accounting> is also protected by ds_lock.
101 	 * Protected by ds_lock:
102 	 */
103 	kmutex_t ds_lock;
104 	void *ds_user_ptr;
105 	dsl_dataset_evict_func_t *ds_user_evict_func;
106 	uint64_t ds_open_refcount;
107 
108 	/* Protected by ds_lock; keep at end of struct for better locality */
109 	char ds_snapname[MAXNAMELEN];
110 } dsl_dataset_t;
111 
112 #define	dsl_dataset_is_snapshot(ds)	\
113 	((ds)->ds_phys->ds_num_children != 0)
114 
115 int dsl_dataset_open_spa(spa_t *spa, const char *name, int mode,
116     void *tag, dsl_dataset_t **dsp);
117 int dsl_dataset_open(const char *name, int mode, void *tag,
118     dsl_dataset_t **dsp);
119 int dsl_dataset_open_obj(struct dsl_pool *dp, uint64_t dsobj,
120     const char *tail, int mode, void *tag, dsl_dataset_t **);
121 void dsl_dataset_name(dsl_dataset_t *ds, char *name);
122 void dsl_dataset_close(dsl_dataset_t *ds, int mode, void *tag);
123 int dsl_dataset_create_sync(dsl_dir_t *pds, const char *fullname,
124     const char *lastname, dsl_dataset_t *clone_parent, dmu_tx_t *tx);
125 int dsl_dataset_snapshot_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx);
126 int dsl_dataset_destroy(const char *name);
127 int dsl_dataset_destroy_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx);
128 int dsl_dataset_rollback(const char *name);
129 int dsl_dataset_rollback_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx);
130 int dsl_dataset_rename(const char *name, const char *newname);
131 int dsl_dataset_promote(const char *name);
132 
133 void *dsl_dataset_set_user_ptr(dsl_dataset_t *ds,
134     void *p, dsl_dataset_evict_func_t func);
135 void *dsl_dataset_get_user_ptr(dsl_dataset_t *ds);
136 
137 void dsl_dataset_get_blkptr(dsl_dataset_t *ds, blkptr_t *bp);
138 void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
139 
140 spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
141 
142 void dsl_dataset_sync(dsl_dataset_t *os, dmu_tx_t *tx);
143 
144 void dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
145 void dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
146 int dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth);
147 uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds);
148 
149 void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
150 void dsl_dataset_stats(dsl_dataset_t *os, dmu_objset_stats_t *dds);
151 struct dsl_pool *dsl_dataset_pool(dsl_dataset_t *ds);
152 
153 void dsl_dataset_create_root(struct dsl_pool *dp, uint64_t *ddobjp,
154     dmu_tx_t *tx);
155 
156 #ifdef ZFS_DEBUG
157 #define	dprintf_ds(ds, fmt, ...) do { \
158 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
159 	char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \
160 	dsl_dataset_name(ds, __ds_name); \
161 	dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
162 	kmem_free(__ds_name, MAXNAMELEN); \
163 	} \
164 _NOTE(CONSTCOND) } while (0)
165 #else
166 #define	dprintf_ds(dd, fmt, ...)
167 #endif
168 
169 #ifdef	__cplusplus
170 }
171 #endif
172 
173 #endif /* _SYS_DSL_DATASET_H */
174