xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dataset.h (revision a9799022bd90b13722204e80112efaa5bf573099)
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 /*
22c717a561Smaybee  * Copyright 2007 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)
5099653d4eSeschrock /*
5199653d4eSeschrock  * NB: nopromote can not yet be set, but we want support for it in this
5299653d4eSeschrock  * on-disk version, so that we don't need to upgrade for it later.  It
5399653d4eSeschrock  * will be needed when we implement 'zfs split' (where the split off
5499653d4eSeschrock  * clone should not be promoted).
5599653d4eSeschrock  */
5699653d4eSeschrock #define	DS_FLAG_NOPROMOTE	(1ULL<<1)
5799653d4eSeschrock 
58*a9799022Sck /*
59*a9799022Sck  * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly
60*a9799022Sck  * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE,
61*a9799022Sck  * refquota/refreservations).
62*a9799022Sck  */
63*a9799022Sck #define	DS_FLAG_UNIQUE_ACCURATE	(1ULL<<2)
64*a9799022Sck 
65fa9e4066Sahrens typedef struct dsl_dataset_phys {
66fa9e4066Sahrens 	uint64_t ds_dir_obj;
67fa9e4066Sahrens 	uint64_t ds_prev_snap_obj;
68fa9e4066Sahrens 	uint64_t ds_prev_snap_txg;
69fa9e4066Sahrens 	uint64_t ds_next_snap_obj;
70fa9e4066Sahrens 	uint64_t ds_snapnames_zapobj;	/* zap obj of snaps; ==0 for snaps */
71fa9e4066Sahrens 	uint64_t ds_num_children;	/* clone/snap children; ==0 for head */
72fa9e4066Sahrens 	uint64_t ds_creation_time;	/* seconds since 1970 */
73fa9e4066Sahrens 	uint64_t ds_creation_txg;
74fa9e4066Sahrens 	uint64_t ds_deadlist_obj;
75fa9e4066Sahrens 	uint64_t ds_used_bytes;
76fa9e4066Sahrens 	uint64_t ds_compressed_bytes;
77fa9e4066Sahrens 	uint64_t ds_uncompressed_bytes;
7863360950Smp 	uint64_t ds_unique_bytes;	/* only relevant to snapshots */
79fa9e4066Sahrens 	/*
80fa9e4066Sahrens 	 * The ds_fsid_guid is a 56-bit ID that can change to avoid
81fa9e4066Sahrens 	 * collisions.  The ds_guid is a 64-bit ID that will never
82fa9e4066Sahrens 	 * change, so there is a small probability that it will collide.
83fa9e4066Sahrens 	 */
84fa9e4066Sahrens 	uint64_t ds_fsid_guid;
85fa9e4066Sahrens 	uint64_t ds_guid;
8699653d4eSeschrock 	uint64_t ds_flags;
87fa9e4066Sahrens 	blkptr_t ds_bp;
8899653d4eSeschrock 	uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
89fa9e4066Sahrens } dsl_dataset_phys_t;
90fa9e4066Sahrens 
91fa9e4066Sahrens typedef struct dsl_dataset {
92fa9e4066Sahrens 	/* Immutable: */
93fa9e4066Sahrens 	struct dsl_dir *ds_dir;
94fa9e4066Sahrens 	dsl_dataset_phys_t *ds_phys;
95fa9e4066Sahrens 	dmu_buf_t *ds_dbuf;
96fa9e4066Sahrens 	uint64_t ds_object;
9791ebeef5Sahrens 	uint64_t ds_fsid_guid;
98fa9e4066Sahrens 
99fa9e4066Sahrens 	/* only used in syncing context: */
100fa9e4066Sahrens 	struct dsl_dataset *ds_prev; /* only valid for non-snapshots */
101fa9e4066Sahrens 
102fa9e4066Sahrens 	/* has internal locking: */
103fa9e4066Sahrens 	bplist_t ds_deadlist;
104fa9e4066Sahrens 
105fa9e4066Sahrens 	/* protected by lock on pool's dp_dirty_datasets list */
106fa9e4066Sahrens 	txg_node_t ds_dirty_link;
107fa9e4066Sahrens 	list_node_t ds_synced_link;
108fa9e4066Sahrens 
109fa9e4066Sahrens 	/*
110fa9e4066Sahrens 	 * ds_phys->ds_<accounting> is also protected by ds_lock.
111fa9e4066Sahrens 	 * Protected by ds_lock:
112fa9e4066Sahrens 	 */
113fa9e4066Sahrens 	kmutex_t ds_lock;
114fa9e4066Sahrens 	void *ds_user_ptr;
115fa9e4066Sahrens 	dsl_dataset_evict_func_t *ds_user_evict_func;
116fa9e4066Sahrens 	uint64_t ds_open_refcount;
117fa9e4066Sahrens 
1181d452cf5Sahrens 	/* no locking; only for making guesses */
1191d452cf5Sahrens 	uint64_t ds_trysnap_txg;
1201d452cf5Sahrens 
12191ebeef5Sahrens 	/* for objset_open() */
12291ebeef5Sahrens 	kmutex_t ds_opening_lock;
12391ebeef5Sahrens 
124*a9799022Sck 	uint64_t ds_reserved;	/* cached refreservation */
125*a9799022Sck 	uint64_t ds_quota;	/* cached refquota */
126*a9799022Sck 
127fa9e4066Sahrens 	/* Protected by ds_lock; keep at end of struct for better locality */
128fa9e4066Sahrens 	char ds_snapname[MAXNAMELEN];
129fa9e4066Sahrens } dsl_dataset_t;
130fa9e4066Sahrens 
131fa9e4066Sahrens #define	dsl_dataset_is_snapshot(ds)	\
132fa9e4066Sahrens 	((ds)->ds_phys->ds_num_children != 0)
133fa9e4066Sahrens 
134*a9799022Sck #define	DS_UNIQUE_IS_ACCURATE(ds)	\
135*a9799022Sck 	(((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
136*a9799022Sck 
137fa9e4066Sahrens int dsl_dataset_open_spa(spa_t *spa, const char *name, int mode,
138fa9e4066Sahrens     void *tag, dsl_dataset_t **dsp);
139fa9e4066Sahrens int dsl_dataset_open(const char *name, int mode, void *tag,
140fa9e4066Sahrens     dsl_dataset_t **dsp);
141ea8dc4b6Seschrock int dsl_dataset_open_obj(struct dsl_pool *dp, uint64_t dsobj,
142ea8dc4b6Seschrock     const char *tail, int mode, void *tag, dsl_dataset_t **);
143fa9e4066Sahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name);
144fa9e4066Sahrens void dsl_dataset_close(dsl_dataset_t *ds, int mode, void *tag);
1453cb34c60Sahrens void dsl_dataset_downgrade(dsl_dataset_t *ds, int oldmode, int newmode);
1463cb34c60Sahrens boolean_t dsl_dataset_tryupgrade(dsl_dataset_t *ds, int oldmode, int newmode);
1473cb34c60Sahrens uint64_t dsl_dataset_create_sync_impl(dsl_dir_t *dd, dsl_dataset_t *origin,
1483cb34c60Sahrens     dmu_tx_t *tx);
1491d452cf5Sahrens uint64_t dsl_dataset_create_sync(dsl_dir_t *pds,
1503cb34c60Sahrens     const char *lastname, dsl_dataset_t *origin, cred_t *, dmu_tx_t *);
1513cb34c60Sahrens int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag);
1521d452cf5Sahrens int dsl_snapshots_destroy(char *fsname, char *snapname);
1533cb34c60Sahrens dsl_checkfunc_t dsl_dataset_destroy_check;
1543cb34c60Sahrens dsl_syncfunc_t dsl_dataset_destroy_sync;
1551d452cf5Sahrens dsl_checkfunc_t dsl_dataset_snapshot_check;
1561d452cf5Sahrens dsl_syncfunc_t dsl_dataset_snapshot_sync;
1573cb34c60Sahrens int dsl_dataset_rollback(dsl_dataset_t *ds, dmu_objset_type_t ost);
158cdf5b4caSmmusante int dsl_dataset_rename(char *name, const char *newname, boolean_t recursive);
15999653d4eSeschrock int dsl_dataset_promote(const char *name);
1603cb34c60Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head,
1613cb34c60Sahrens     boolean_t force);
162fa9e4066Sahrens 
163fa9e4066Sahrens void *dsl_dataset_set_user_ptr(dsl_dataset_t *ds,
164fa9e4066Sahrens     void *p, dsl_dataset_evict_func_t func);
165fa9e4066Sahrens void *dsl_dataset_get_user_ptr(dsl_dataset_t *ds);
166fa9e4066Sahrens 
167c717a561Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds);
168fa9e4066Sahrens void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
169fa9e4066Sahrens 
170fa9e4066Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
171fa9e4066Sahrens 
172f18faf3fSek boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds);
173f18faf3fSek 
174c717a561Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx);
175fa9e4066Sahrens 
176fa9e4066Sahrens void dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
177c717a561Smaybee void dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, zio_t *pio,
178c717a561Smaybee     dmu_tx_t *tx);
179ea8dc4b6Seschrock int dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth);
180ea8dc4b6Seschrock uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds);
181fa9e4066Sahrens 
182fa9e4066Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
183a2eea2e1Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv);
184a2eea2e1Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat);
185a2eea2e1Sahrens void dsl_dataset_space(dsl_dataset_t *ds,
186a2eea2e1Sahrens     uint64_t *refdbytesp, uint64_t *availbytesp,
187a2eea2e1Sahrens     uint64_t *usedobjsp, uint64_t *availobjsp);
188a2eea2e1Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds);
189fa9e4066Sahrens 
190fa9e4066Sahrens void dsl_dataset_create_root(struct dsl_pool *dp, uint64_t *ddobjp,
191fa9e4066Sahrens     dmu_tx_t *tx);
192fa9e4066Sahrens 
193b1b8ab34Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf);
194b1b8ab34Slling 
195*a9799022Sck int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota,
196*a9799022Sck     uint64_t asize, uint64_t inflight, uint64_t *used);
197*a9799022Sck int dsl_dataset_set_quota(const char *dsname, uint64_t quota);
198*a9799022Sck void dsl_dataset_set_quota_sync(void *arg1, void *arg2, cred_t *cr,
199*a9799022Sck     dmu_tx_t *tx);
200*a9799022Sck int dsl_dataset_set_reservation(const char *dsname, uint64_t reservation);
201*a9799022Sck 
202fa9e4066Sahrens #ifdef ZFS_DEBUG
203fa9e4066Sahrens #define	dprintf_ds(ds, fmt, ...) do { \
204fa9e4066Sahrens 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
205fa9e4066Sahrens 	char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \
206fa9e4066Sahrens 	dsl_dataset_name(ds, __ds_name); \
207fa9e4066Sahrens 	dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
208fa9e4066Sahrens 	kmem_free(__ds_name, MAXNAMELEN); \
209fa9e4066Sahrens 	} \
210fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
211fa9e4066Sahrens #else
212fa9e4066Sahrens #define	dprintf_ds(dd, fmt, ...)
213fa9e4066Sahrens #endif
214fa9e4066Sahrens 
215fa9e4066Sahrens #ifdef	__cplusplus
216fa9e4066Sahrens }
217fa9e4066Sahrens #endif
218fa9e4066Sahrens 
219fa9e4066Sahrens #endif /* _SYS_DSL_DATASET_H */
220