xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dataset.h (revision 745cd3c5371d020efae7a911c58c526aa1fd0dba)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
229082849eSck  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef	_SYS_DSL_DATASET_H
27fa9e4066Sahrens #define	_SYS_DSL_DATASET_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
30fa9e4066Sahrens 
31fa9e4066Sahrens #include <sys/dmu.h>
32fa9e4066Sahrens #include <sys/spa.h>
33fa9e4066Sahrens #include <sys/txg.h>
34c717a561Smaybee #include <sys/zio.h>
35fa9e4066Sahrens #include <sys/bplist.h>
361d452cf5Sahrens #include <sys/dsl_synctask.h>
37fa9e4066Sahrens #include <sys/zfs_context.h>
38fa9e4066Sahrens 
39fa9e4066Sahrens #ifdef	__cplusplus
40fa9e4066Sahrens extern "C" {
41fa9e4066Sahrens #endif
42fa9e4066Sahrens 
43fa9e4066Sahrens struct dsl_dataset;
44fa9e4066Sahrens struct dsl_dir;
45fa9e4066Sahrens struct dsl_pool;
46fa9e4066Sahrens 
47fa9e4066Sahrens typedef void dsl_dataset_evict_func_t(struct dsl_dataset *, void *);
48fa9e4066Sahrens 
4999653d4eSeschrock #define	DS_FLAG_INCONSISTENT	(1ULL<<0)
50*745cd3c5Smaybee #define	DS_IS_INCONSISTENT(ds)	\
51*745cd3c5Smaybee 	((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT)
5299653d4eSeschrock /*
5399653d4eSeschrock  * NB: nopromote can not yet be set, but we want support for it in this
5499653d4eSeschrock  * on-disk version, so that we don't need to upgrade for it later.  It
5599653d4eSeschrock  * will be needed when we implement 'zfs split' (where the split off
5699653d4eSeschrock  * clone should not be promoted).
5799653d4eSeschrock  */
5899653d4eSeschrock #define	DS_FLAG_NOPROMOTE	(1ULL<<1)
5999653d4eSeschrock 
60a9799022Sck /*
61a9799022Sck  * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly
62a9799022Sck  * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE,
63a9799022Sck  * refquota/refreservations).
64a9799022Sck  */
65a9799022Sck #define	DS_FLAG_UNIQUE_ACCURATE	(1ULL<<2)
66a9799022Sck 
67ab04eb8eStimh /*
68ab04eb8eStimh  * DS_FLAG_CI_DATASET is set if the dataset contains a file system whose
69ab04eb8eStimh  * name lookups should be performed case-insensitively.
70ab04eb8eStimh  */
71ab04eb8eStimh #define	DS_FLAG_CI_DATASET	(1ULL<<16)
72ab04eb8eStimh 
73fa9e4066Sahrens typedef struct dsl_dataset_phys {
74fa9e4066Sahrens 	uint64_t ds_dir_obj;
75fa9e4066Sahrens 	uint64_t ds_prev_snap_obj;
76fa9e4066Sahrens 	uint64_t ds_prev_snap_txg;
77fa9e4066Sahrens 	uint64_t ds_next_snap_obj;
78fa9e4066Sahrens 	uint64_t ds_snapnames_zapobj;	/* zap obj of snaps; ==0 for snaps */
79fa9e4066Sahrens 	uint64_t ds_num_children;	/* clone/snap children; ==0 for head */
80fa9e4066Sahrens 	uint64_t ds_creation_time;	/* seconds since 1970 */
81fa9e4066Sahrens 	uint64_t ds_creation_txg;
82fa9e4066Sahrens 	uint64_t ds_deadlist_obj;
83fa9e4066Sahrens 	uint64_t ds_used_bytes;
84fa9e4066Sahrens 	uint64_t ds_compressed_bytes;
85fa9e4066Sahrens 	uint64_t ds_uncompressed_bytes;
8663360950Smp 	uint64_t ds_unique_bytes;	/* only relevant to snapshots */
87fa9e4066Sahrens 	/*
88fa9e4066Sahrens 	 * The ds_fsid_guid is a 56-bit ID that can change to avoid
89fa9e4066Sahrens 	 * collisions.  The ds_guid is a 64-bit ID that will never
90fa9e4066Sahrens 	 * change, so there is a small probability that it will collide.
91fa9e4066Sahrens 	 */
92fa9e4066Sahrens 	uint64_t ds_fsid_guid;
93fa9e4066Sahrens 	uint64_t ds_guid;
9499653d4eSeschrock 	uint64_t ds_flags;
95fa9e4066Sahrens 	blkptr_t ds_bp;
9699653d4eSeschrock 	uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
97fa9e4066Sahrens } dsl_dataset_phys_t;
98fa9e4066Sahrens 
99fa9e4066Sahrens typedef struct dsl_dataset {
100fa9e4066Sahrens 	/* Immutable: */
101fa9e4066Sahrens 	struct dsl_dir *ds_dir;
102fa9e4066Sahrens 	dsl_dataset_phys_t *ds_phys;
103fa9e4066Sahrens 	dmu_buf_t *ds_dbuf;
104fa9e4066Sahrens 	uint64_t ds_object;
10591ebeef5Sahrens 	uint64_t ds_fsid_guid;
106fa9e4066Sahrens 
107fa9e4066Sahrens 	/* only used in syncing context: */
108fa9e4066Sahrens 	struct dsl_dataset *ds_prev; /* only valid for non-snapshots */
109fa9e4066Sahrens 
110fa9e4066Sahrens 	/* has internal locking: */
111fa9e4066Sahrens 	bplist_t ds_deadlist;
112fa9e4066Sahrens 
113fa9e4066Sahrens 	/* protected by lock on pool's dp_dirty_datasets list */
114fa9e4066Sahrens 	txg_node_t ds_dirty_link;
115fa9e4066Sahrens 	list_node_t ds_synced_link;
116fa9e4066Sahrens 
117fa9e4066Sahrens 	/*
118fa9e4066Sahrens 	 * ds_phys->ds_<accounting> is also protected by ds_lock.
119fa9e4066Sahrens 	 * Protected by ds_lock:
120fa9e4066Sahrens 	 */
121fa9e4066Sahrens 	kmutex_t ds_lock;
122fa9e4066Sahrens 	void *ds_user_ptr;
123fa9e4066Sahrens 	dsl_dataset_evict_func_t *ds_user_evict_func;
124*745cd3c5Smaybee 
125*745cd3c5Smaybee 	/*
126*745cd3c5Smaybee 	 * ds_owner is protected by the ds_rwlock and the ds_lock
127*745cd3c5Smaybee 	 */
128*745cd3c5Smaybee 	krwlock_t ds_rwlock;
129*745cd3c5Smaybee 	kcondvar_t ds_exclusive_cv;
130*745cd3c5Smaybee 	void *ds_owner;
131fa9e4066Sahrens 
1321d452cf5Sahrens 	/* no locking; only for making guesses */
1331d452cf5Sahrens 	uint64_t ds_trysnap_txg;
1341d452cf5Sahrens 
13591ebeef5Sahrens 	/* for objset_open() */
13691ebeef5Sahrens 	kmutex_t ds_opening_lock;
13791ebeef5Sahrens 
138a9799022Sck 	uint64_t ds_reserved;	/* cached refreservation */
139a9799022Sck 	uint64_t ds_quota;	/* cached refquota */
140a9799022Sck 
141fa9e4066Sahrens 	/* Protected by ds_lock; keep at end of struct for better locality */
142fa9e4066Sahrens 	char ds_snapname[MAXNAMELEN];
143fa9e4066Sahrens } dsl_dataset_t;
144fa9e4066Sahrens 
145fa9e4066Sahrens #define	dsl_dataset_is_snapshot(ds)	\
146fa9e4066Sahrens 	((ds)->ds_phys->ds_num_children != 0)
147fa9e4066Sahrens 
148a9799022Sck #define	DS_UNIQUE_IS_ACCURATE(ds)	\
149a9799022Sck 	(((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
150a9799022Sck 
151*745cd3c5Smaybee int dsl_dataset_hold(const char *name, void *tag, dsl_dataset_t **dsp);
152*745cd3c5Smaybee int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj,
153*745cd3c5Smaybee     void *tag, dsl_dataset_t **);
154*745cd3c5Smaybee int dsl_dataset_own(const char *name, int flags, void *owner,
155fa9e4066Sahrens     dsl_dataset_t **dsp);
156*745cd3c5Smaybee int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj,
157*745cd3c5Smaybee     int flags, void *owner, dsl_dataset_t **);
158fa9e4066Sahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name);
159*745cd3c5Smaybee void dsl_dataset_rele(dsl_dataset_t *ds, void *tag);
160*745cd3c5Smaybee void dsl_dataset_disown(dsl_dataset_t *ds, void *owner);
161*745cd3c5Smaybee boolean_t dsl_dataset_tryown(dsl_dataset_t *ds, boolean_t inconsistentok,
162*745cd3c5Smaybee     void *owner);
163*745cd3c5Smaybee void dsl_dataset_make_exclusive(dsl_dataset_t *ds, void *owner);
1643cb34c60Sahrens uint64_t dsl_dataset_create_sync_impl(dsl_dir_t *dd, dsl_dataset_t *origin,
165ab04eb8eStimh     uint64_t flags, dmu_tx_t *tx);
166*745cd3c5Smaybee uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname,
167*745cd3c5Smaybee     dsl_dataset_t *origin, uint64_t flags, cred_t *, dmu_tx_t *);
1683cb34c60Sahrens int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag);
1691d452cf5Sahrens int dsl_snapshots_destroy(char *fsname, char *snapname);
1703cb34c60Sahrens dsl_checkfunc_t dsl_dataset_destroy_check;
1713cb34c60Sahrens dsl_syncfunc_t dsl_dataset_destroy_sync;
1721d452cf5Sahrens dsl_checkfunc_t dsl_dataset_snapshot_check;
1731d452cf5Sahrens dsl_syncfunc_t dsl_dataset_snapshot_sync;
1743cb34c60Sahrens int dsl_dataset_rollback(dsl_dataset_t *ds, dmu_objset_type_t ost);
175cdf5b4caSmmusante int dsl_dataset_rename(char *name, const char *newname, boolean_t recursive);
17699653d4eSeschrock int dsl_dataset_promote(const char *name);
1773cb34c60Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head,
1783cb34c60Sahrens     boolean_t force);
179fa9e4066Sahrens 
180fa9e4066Sahrens void *dsl_dataset_set_user_ptr(dsl_dataset_t *ds,
181fa9e4066Sahrens     void *p, dsl_dataset_evict_func_t func);
182fa9e4066Sahrens void *dsl_dataset_get_user_ptr(dsl_dataset_t *ds);
183fa9e4066Sahrens 
184c717a561Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds);
185fa9e4066Sahrens void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
186fa9e4066Sahrens 
187fa9e4066Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
188fa9e4066Sahrens 
189f18faf3fSek boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds);
190f18faf3fSek 
191c717a561Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx);
192fa9e4066Sahrens 
193fa9e4066Sahrens void dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
194c717a561Smaybee void dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, zio_t *pio,
195c717a561Smaybee     dmu_tx_t *tx);
196ea8dc4b6Seschrock int dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth);
197ea8dc4b6Seschrock uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds);
198fa9e4066Sahrens 
199fa9e4066Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
200a2eea2e1Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv);
201a2eea2e1Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat);
202a2eea2e1Sahrens void dsl_dataset_space(dsl_dataset_t *ds,
203a2eea2e1Sahrens     uint64_t *refdbytesp, uint64_t *availbytesp,
204a2eea2e1Sahrens     uint64_t *usedobjsp, uint64_t *availobjsp);
205a2eea2e1Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds);
206fa9e4066Sahrens 
207fa9e4066Sahrens void dsl_dataset_create_root(struct dsl_pool *dp, uint64_t *ddobjp,
208fa9e4066Sahrens     dmu_tx_t *tx);
209fa9e4066Sahrens 
210b1b8ab34Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf);
211b1b8ab34Slling 
212a9799022Sck int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota,
2139082849eSck     uint64_t asize, uint64_t inflight, uint64_t *used,
2149082849eSck     uint64_t *ref_rsrv);
215a9799022Sck int dsl_dataset_set_quota(const char *dsname, uint64_t quota);
216a9799022Sck void dsl_dataset_set_quota_sync(void *arg1, void *arg2, cred_t *cr,
217a9799022Sck     dmu_tx_t *tx);
218a9799022Sck int dsl_dataset_set_reservation(const char *dsname, uint64_t reservation);
219ab04eb8eStimh void dsl_dataset_set_flags(dsl_dataset_t *ds, uint64_t flags);
220a9799022Sck 
221fa9e4066Sahrens #ifdef ZFS_DEBUG
222fa9e4066Sahrens #define	dprintf_ds(ds, fmt, ...) do { \
223fa9e4066Sahrens 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
224fa9e4066Sahrens 	char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \
225fa9e4066Sahrens 	dsl_dataset_name(ds, __ds_name); \
226fa9e4066Sahrens 	dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
227fa9e4066Sahrens 	kmem_free(__ds_name, MAXNAMELEN); \
228fa9e4066Sahrens 	} \
229fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
230fa9e4066Sahrens #else
231fa9e4066Sahrens #define	dprintf_ds(dd, fmt, ...)
232fa9e4066Sahrens #endif
233fa9e4066Sahrens 
234fa9e4066Sahrens #ifdef	__cplusplus
235fa9e4066Sahrens }
236fa9e4066Sahrens #endif
237fa9e4066Sahrens 
238fa9e4066Sahrens #endif /* _SYS_DSL_DATASET_H */
239