1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21fa9e406ahrens/*
223f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23000cce6Brad Lewis * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
24a2afb61Jerry Jelinek * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25a7a845eSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
26bc9014eJustin Gibbs * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
27c3d26abMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
28fa9e406ahrens */
29fa9e406ahrens
30fa9e406ahrens#ifndef	_SYS_DSL_DATASET_H
31fa9e406ahrens#define	_SYS_DSL_DATASET_H
32fa9e406ahrens
33fa9e406ahrens#include <sys/dmu.h>
34fa9e406ahrens#include <sys/spa.h>
35fa9e406ahrens#include <sys/txg.h>
36c717a56maybee#include <sys/zio.h>
37fa9e406ahrens#include <sys/bplist.h>
381d452cfahrens#include <sys/dsl_synctask.h>
39fa9e406ahrens#include <sys/zfs_context.h>
40cde58dbMatthew Ahrens#include <sys/dsl_deadlist.h>
413b2aab1Matthew Ahrens#include <sys/refcount.h>
42c166b69Paul Dagnelie#include <sys/rrwlock.h>
43eb63303Tom Caputi#include <sys/dsl_crypt.h>
44ca0cc39Matthew Ahrens#include <zfeature_common.h>
45fa9e406ahrens
46fa9e406ahrens#ifdef	__cplusplus
47fa9e406ahrensextern "C" {
48fa9e406ahrens#endif
49fa9e406ahrens
50fa9e406ahrensstruct dsl_dataset;
51fa9e406ahrensstruct dsl_dir;
52fa9e406ahrensstruct dsl_pool;
53eb63303Tom Caputistruct dsl_crypto_params;
54eb63303Tom Caputistruct dsl_key_mapping;
55fa9e406ahrens
5699653d4eschrock#define	DS_FLAG_INCONSISTENT	(1ULL<<0)
57745cd3cmaybee#define	DS_IS_INCONSISTENT(ds)	\
58c137962Justin T. Gibbs	(dsl_dataset_phys(ds)->ds_flags & DS_FLAG_INCONSISTENT)
592acef22Matthew Ahrens
6099653d4eschrock/*
612acef22Matthew Ahrens * Do not allow this dataset to be promoted.
6299653d4eschrock */
6399653d4eschrock#define	DS_FLAG_NOPROMOTE	(1ULL<<1)
6499653d4eschrock
65a979902ck/*
66a979902ck * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly
67a979902ck * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE,
68a979902ck * refquota/refreservations).
69a979902ck */
70a979902ck#define	DS_FLAG_UNIQUE_ACCURATE	(1ULL<<2)
71a979902ck
72ab04eb8timh/*
73842727cChris Kirby * DS_FLAG_DEFER_DESTROY is set after 'zfs destroy -d' has been called
74842727cChris Kirby * on a dataset. This allows the dataset to be destroyed using 'zfs release'.
75842727cChris Kirby */
76842727cChris Kirby#define	DS_FLAG_DEFER_DESTROY	(1ULL<<3)
77842727cChris Kirby#define	DS_IS_DEFER_DESTROY(ds)	\
78c137962Justin T. Gibbs	(dsl_dataset_phys(ds)->ds_flags & DS_FLAG_DEFER_DESTROY)
79842727cChris Kirby
80842727cChris Kirby/*
812acef22Matthew Ahrens * DS_FIELD_* are strings that are used in the "extensified" dataset zap object.
822acef22Matthew Ahrens * They should be of the format <reverse-dns>:<field>.
832acef22Matthew Ahrens */
842acef22Matthew Ahrens
852acef22Matthew Ahrens/*
8678f1710Matthew Ahrens * This field's value is the object ID of a zap object which contains the
8778f1710Matthew Ahrens * bookmarks of this dataset.  If it is present, then this dataset is counted
8878f1710Matthew Ahrens * in the refcount of the SPA_FEATURES_BOOKMARKS feature.
8978f1710Matthew Ahrens */
9078f1710Matthew Ahrens#define	DS_FIELD_BOOKMARK_NAMES "com.delphix:bookmarks"
9178f1710Matthew Ahrens
9278f1710Matthew Ahrens/*
9354811daToomas Soome * This field is present (with value=0) if this dataset may contain large
9454811daToomas Soome * dnodes (>512B).  If it is present, then this dataset is counted in the
9554811daToomas Soome * refcount of the SPA_FEATURE_LARGE_DNODE feature.
9654811daToomas Soome */
9754811daToomas Soome#define	DS_FIELD_LARGE_DNODE "org.zfsonlinux:large_dnode"
9854811daToomas Soome
9954811daToomas Soome/*
1009c3fd12Matthew Ahrens * These fields are set on datasets that are in the middle of a resumable
1019c3fd12Matthew Ahrens * receive, and allow the sender to resume the send if it is interrupted.
1029c3fd12Matthew Ahrens */
1039c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_FROMGUID "com.delphix:resume_fromguid"
1049c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_TONAME "com.delphix:resume_toname"
1059c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_TOGUID "com.delphix:resume_toguid"
1069c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_OBJECT "com.delphix:resume_object"
1079c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_OFFSET "com.delphix:resume_offset"
1089c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_BYTES "com.delphix:resume_bytes"
1095602294Dan Kimmel#define	DS_FIELD_RESUME_LARGEBLOCK "com.delphix:resume_largeblockok"
1109c3fd12Matthew Ahrens#define	DS_FIELD_RESUME_EMBEDOK "com.delphix:resume_embedok"
1115602294Dan Kimmel#define	DS_FIELD_RESUME_COMPRESSOK "com.delphix:resume_compressok"
112eb63303Tom Caputi#define	DS_FIELD_RESUME_RAWOK "com.datto:resume_rawok"
1139c3fd12Matthew Ahrens
1149c3fd12Matthew Ahrens/*
1155cabbc6Prashanth Sreenivasa * This field is set to the object number of the remap deadlist if one exists.
1165cabbc6Prashanth Sreenivasa */
1175cabbc6Prashanth Sreenivasa#define	DS_FIELD_REMAP_DEADLIST	"com.delphix:remap_deadlist"
1185cabbc6Prashanth Sreenivasa
1195cabbc6Prashanth Sreenivasa/*
120eb63303Tom Caputi * This field is set to the ivset guid for encrypted snapshots. This is used
121eb63303Tom Caputi * for validating raw receives.
122eb63303Tom Caputi */
123eb63303Tom Caputi#define	DS_FIELD_IVSET_GUID	"com.datto:ivset_guid"
124eb63303Tom Caputi
125eb63303Tom Caputi/*
126ab04eb8timh * DS_FLAG_CI_DATASET is set if the dataset contains a file system whose
127ab04eb8timh * name lookups should be performed case-insensitively.
128ab04eb8timh */
129ab04eb8timh#define	DS_FLAG_CI_DATASET	(1ULL<<16)
130ab04eb8timh
1313b2aab1Matthew Ahrens#define	DS_CREATE_FLAG_NODIRTY	(1ULL<<24)
1323b2aab1Matthew Ahrens
133fa9e406ahrenstypedef struct dsl_dataset_phys {
134088f389ahrens	uint64_t ds_dir_obj;		/* DMU_OT_DSL_DIR */
135088f389ahrens	uint64_t ds_prev_snap_obj;	/* DMU_OT_DSL_DATASET */
136fa9e406ahrens	uint64_t ds_prev_snap_txg;
137088f389ahrens	uint64_t ds_next_snap_obj;	/* DMU_OT_DSL_DATASET */
138088f389ahrens	uint64_t ds_snapnames_zapobj;	/* DMU_OT_DSL_DS_SNAP_MAP 0 for snaps */
139fa9e406ahrens	uint64_t ds_num_children;	/* clone/snap children; ==0 for head */
140fa9e406ahrens	uint64_t ds_creation_time;	/* seconds since 1970 */
141fa9e406ahrens	uint64_t ds_creation_txg;
142cde58dbMatthew Ahrens	uint64_t ds_deadlist_obj;	/* DMU_OT_DEADLIST */
143ad135b5Christopher Siden	/*
144ad135b5Christopher Siden	 * ds_referenced_bytes, ds_compressed_bytes, and ds_uncompressed_bytes
145ad135b5Christopher Siden	 * include all blocks referenced by this dataset, including those
146ad135b5Christopher Siden	 * shared with any other datasets.
147ad135b5Christopher Siden	 */
148ad135b5Christopher Siden	uint64_t ds_referenced_bytes;
149fa9e406ahrens	uint64_t ds_compressed_bytes;
150fa9e406ahrens	uint64_t ds_uncompressed_bytes;
1516336095mp	uint64_t ds_unique_bytes;	/* only relevant to snapshots */
152fa9e406ahrens	/*
153fa9e406ahrens	 * The ds_fsid_guid is a 56-bit ID that can change to avoid
154fa9e406ahrens	 * collisions.  The ds_guid is a 64-bit ID that will never
155fa9e406ahrens	 * change, so there is a small probability that it will collide.
156fa9e406ahrens	 */
157fa9e406ahrens	uint64_t ds_fsid_guid;
158fa9e406ahrens	uint64_t ds_guid;
159088f389ahrens	uint64_t ds_flags;		/* DS_FLAG_* */
160fa9e406ahrens	blkptr_t ds_bp;
161bb0ade0ahrens	uint64_t ds_next_clones_obj;	/* DMU_OT_DSL_CLONES */
162bb0ade0ahrens	uint64_t ds_props_obj;		/* DMU_OT_DSL_PROPS for snaps */
163842727cChris Kirby	uint64_t ds_userrefs_obj;	/* DMU_OT_USERREFS */
164842727cChris Kirby	uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */
165fa9e406ahrens} dsl_dataset_phys_t;
166fa9e406ahrens
167fa9e406ahrenstypedef struct dsl_dataset {
168bc9014eJustin Gibbs	dmu_buf_user_t ds_dbu;
169c166b69Paul Dagnelie	rrwlock_t ds_bp_rwlock; /* Protects ds_phys->ds_bp */
170bc9014eJustin Gibbs
171fa9e406ahrens	/* Immutable: */
172fa9e406ahrens	struct dsl_dir *ds_dir;
173fa9e406ahrens	dmu_buf_t *ds_dbuf;
174fa9e406ahrens	uint64_t ds_object;
17591ebeefahrens	uint64_t ds_fsid_guid;
176bc9014eJustin Gibbs	boolean_t ds_is_snapshot;
177eb63303Tom Caputi	struct dsl_key_mapping *ds_key_mapping;
178fa9e406ahrens
17974e7dc9Matthew Ahrens	/* only used in syncing context, only valid for non-snapshots: */
18074e7dc9Matthew Ahrens	struct dsl_dataset *ds_prev;
18178f1710Matthew Ahrens	uint64_t ds_bookmarks;  /* DMU_OTN_ZAP_METADATA */
182fa9e406ahrens
183fa9e406ahrens	/* has internal locking: */
184cde58dbMatthew Ahrens	dsl_deadlist_t ds_deadlist;
185cde58dbMatthew Ahrens	bplist_t ds_pending_deadlist;
186fa9e406ahrens
1875cabbc6Prashanth Sreenivasa	/*
1885cabbc6Prashanth Sreenivasa	 * The remap deadlist contains blocks (DVA's, really) that are
1895cabbc6Prashanth Sreenivasa	 * referenced by the previous snapshot and point to indirect vdevs,
1905cabbc6Prashanth Sreenivasa	 * but in this dataset they have been remapped to point to concrete
1915cabbc6Prashanth Sreenivasa	 * (or at least, less-indirect) vdevs.  In other words, the
1925cabbc6Prashanth Sreenivasa	 * physical DVA is referenced by the previous snapshot but not by
1935cabbc6Prashanth Sreenivasa	 * this dataset.  Logically, the DVA continues to be referenced,
1945cabbc6Prashanth Sreenivasa	 * but we are using a different (less indirect) physical DVA.
1955cabbc6Prashanth Sreenivasa	 * This deadlist is used to determine when physical DVAs that
1965cabbc6Prashanth Sreenivasa	 * point to indirect vdevs are no longer referenced anywhere,
1975cabbc6Prashanth Sreenivasa	 * and thus should be marked obsolete.
1985cabbc6Prashanth Sreenivasa	 *
1995cabbc6Prashanth Sreenivasa	 * This is only used if SPA_FEATURE_OBSOLETE_COUNTS is enabled.
2005cabbc6Prashanth Sreenivasa	 */
2015cabbc6Prashanth Sreenivasa	dsl_deadlist_t ds_remap_deadlist;
2025cabbc6Prashanth Sreenivasa	/* protects creation of the ds_remap_deadlist */
2035cabbc6Prashanth Sreenivasa	kmutex_t ds_remap_deadlist_lock;
2045cabbc6Prashanth Sreenivasa
205fa9e406ahrens	/* protected by lock on pool's dp_dirty_datasets list */
206fa9e406ahrens	txg_node_t ds_dirty_link;
207fa9e406ahrens	list_node_t ds_synced_link;
208fa9e406ahrens
209fa9e406ahrens	/*
210fa9e406ahrens	 * ds_phys->ds_<accounting> is also protected by ds_lock.
211fa9e406ahrens	 * Protected by ds_lock:
212fa9e406ahrens	 */
213fa9e406ahrens	kmutex_t ds_lock;
214503ad85Matthew Ahrens	objset_t *ds_objset;
215842727cChris Kirby	uint64_t ds_userrefs;
2163b2aab1Matthew Ahrens	void *ds_owner;
217745cd3cmaybee
218745cd3cmaybee	/*
2193b2aab1Matthew Ahrens	 * Long holds prevent the ds from being destroyed; they allow the
2203b2aab1Matthew Ahrens	 * ds to remain held even after dropping the dp_config_rwlock.
2213b2aab1Matthew Ahrens	 * Owning counts as a long hold.  See the comments above
2223b2aab1Matthew Ahrens	 * dsl_pool_hold() for details.
223745cd3cmaybee	 */
224e914aceTim Schumacher	zfs_refcount_t ds_longholds;
225fa9e406ahrens
2261d452cfahrens	/* no locking; only for making guesses */
2271d452cfahrens	uint64_t ds_trysnap_txg;
2281d452cfahrens
22991ebeefahrens	/* for objset_open() */
23091ebeefahrens	kmutex_t ds_opening_lock;
23191ebeefahrens
232a979902ck	uint64_t ds_reserved;	/* cached refreservation */
233a979902ck	uint64_t ds_quota;	/* cached refquota */
234a979902ck
2354e3c9f4Bill Pijewski	kmutex_t ds_sendstream_lock;
2364e3c9f4Bill Pijewski	list_t ds_sendstreams;
2374e3c9f4Bill Pijewski
2389c3fd12Matthew Ahrens	/*
2399c3fd12Matthew Ahrens	 * When in the middle of a resumable receive, tracks how much
2409c3fd12Matthew Ahrens	 * progress we have made.
2419c3fd12Matthew Ahrens	 */
2429c3fd12Matthew Ahrens	uint64_t ds_resume_object[TXG_SIZE];
2439c3fd12Matthew Ahrens	uint64_t ds_resume_offset[TXG_SIZE];
2449c3fd12Matthew Ahrens	uint64_t ds_resume_bytes[TXG_SIZE];
2459c3fd12Matthew Ahrens
24603bad06Justin Gibbs	/* Protected by our dsl_dir's dd_lock */
24703bad06Justin Gibbs	list_t ds_prop_cbs;
24803bad06Justin Gibbs
249ca0cc39Matthew Ahrens	/*
250ca0cc39Matthew Ahrens	 * For ZFEATURE_FLAG_PER_DATASET features, set if this dataset
251ca0cc39Matthew Ahrens	 * uses this feature.
252ca0cc39Matthew Ahrens	 */
253ca0cc39Matthew Ahrens	uint8_t ds_feature_inuse[SPA_FEATURES];
254ca0cc39Matthew Ahrens
255ca0cc39Matthew Ahrens	/*
256ca0cc39Matthew Ahrens	 * Set if we need to activate the feature on this dataset this txg
257ca0cc39Matthew Ahrens	 * (used only in syncing context).
258ca0cc39Matthew Ahrens	 */
259ca0cc39Matthew Ahrens	uint8_t ds_feature_activation_needed[SPA_FEATURES];
260ca0cc39Matthew Ahrens
261fa9e406ahrens	/* Protected by ds_lock; keep at end of struct for better locality */
2629adfa60Matthew Ahrens	char ds_snapname[ZFS_MAX_DATASET_NAME_LEN];
263fa9e406ahrens} dsl_dataset_t;
264fa9e406ahrens
265c137962Justin T. Gibbsinline dsl_dataset_phys_t *
266c137962Justin T. Gibbsdsl_dataset_phys(dsl_dataset_t *ds)
267c137962Justin T. Gibbs{
268c137962Justin T. Gibbs	return (ds->ds_dbuf->db_data);
269c137962Justin T. Gibbs}
270c137962Justin T. Gibbs
271dfc1153Chris Williamsontypedef struct dsl_dataset_promote_arg {
272dfc1153Chris Williamson	const char *ddpa_clonename;
273dfc1153Chris Williamson	dsl_dataset_t *ddpa_clone;
274dfc1153Chris Williamson	list_t shared_snaps, origin_snaps, clone_snaps;
275dfc1153Chris Williamson	dsl_dataset_t *origin_origin; /* origin of the origin */
276dfc1153Chris Williamson	uint64_t used, comp, uncomp, unique, cloneusedsnap, originusedsnap;
277dfc1153Chris Williamson	nvlist_t *err_ds;
278dfc1153Chris Williamson	cred_t *cr;
279dfc1153Chris Williamson} dsl_dataset_promote_arg_t;
280dfc1153Chris Williamson
281000cce6Brad Lewistypedef struct dsl_dataset_rollback_arg {
282000cce6Brad Lewis	const char *ddra_fsname;
283000cce6Brad Lewis	const char *ddra_tosnap;
284000cce6Brad Lewis	void *ddra_owner;
285000cce6Brad Lewis	nvlist_t *ddra_result;
286000cce6Brad Lewis} dsl_dataset_rollback_arg_t;
287000cce6Brad Lewis
2882840dceChris Williamsontypedef struct dsl_dataset_snapshot_arg {
2892840dceChris Williamson	nvlist_t *ddsa_snaps;
2902840dceChris Williamson	nvlist_t *ddsa_props;
2912840dceChris Williamson	nvlist_t *ddsa_errors;
2922840dceChris Williamson	cred_t *ddsa_cr;
2932840dceChris Williamson} dsl_dataset_snapshot_arg_t;
2942840dceChris Williamson
29599d5e17Tim Haley/*
29699d5e17Tim Haley * The max length of a temporary tag prefix is the number of hex digits
29799d5e17Tim Haley * required to express UINT64_MAX plus one for the hyphen.
29899d5e17Tim Haley */
29999d5e17Tim Haley#define	MAX_TAG_PREFIX_LEN	17
30099d5e17Tim Haley
301643da46Max Grossman#define	dsl_dataset_is_snapshot(ds) \
302643da46Max Grossman	(dsl_dataset_phys(ds)->ds_num_children != 0)
303643da46Max Grossman
304a979902ck#define	DS_UNIQUE_IS_ACCURATE(ds)	\
305c137962Justin T. Gibbs	((dsl_dataset_phys(ds)->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
306a979902ck
307eb63303Tom Caputi/* flags for holding the dataset */
308eb63303Tom Caputitypedef enum ds_hold_flags {
309eb63303Tom Caputi	DS_HOLD_FLAG_DECRYPT    = 1 << 0 /* needs access to encrypted data */
310eb63303Tom Caputi} ds_hold_flags_t;
311eb63303Tom Caputi
3123b2aab1Matthew Ahrensint dsl_dataset_hold(struct dsl_pool *dp, const char *name, void *tag,
3133b2aab1Matthew Ahrens    dsl_dataset_t **dsp);
314eb63303Tom Caputiint dsl_dataset_hold_flags(struct dsl_pool *dp, const char *name,
315eb63303Tom Caputi    ds_hold_flags_t flags, void *tag, dsl_dataset_t **dsp);
316e57a022Justin T. Gibbsboolean_t dsl_dataset_try_add_ref(struct dsl_pool *dp, dsl_dataset_t *ds,
317e57a022Justin T. Gibbs    void *tag);
318eb63303Tom Caputiint dsl_dataset_create_key_mapping(dsl_dataset_t *ds);
3193b2aab1Matthew Ahrensint dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, void *tag,
3203b2aab1Matthew Ahrens    dsl_dataset_t **);
321eb63303Tom Caputiint dsl_dataset_hold_obj_flags(struct dsl_pool *dp, uint64_t dsobj,
322eb63303Tom Caputi	ds_hold_flags_t flags, void *tag, dsl_dataset_t **);
323eb63303Tom Caputivoid dsl_dataset_remove_key_mapping(dsl_dataset_t *ds);
3243b2aab1Matthew Ahrensvoid dsl_dataset_rele(dsl_dataset_t *ds, void *tag);
325eb63303Tom Caputivoid dsl_dataset_rele_flags(dsl_dataset_t *ds, ds_hold_flags_t flags,
326eb63303Tom Caputi    void *tag);
3273b2aab1Matthew Ahrensint dsl_dataset_own(struct dsl_pool *dp, const char *name,
328eb63303Tom Caputi    ds_hold_flags_t flags, void *tag, dsl_dataset_t **dsp);
329745cd3cmaybeeint dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj,
330eb63303Tom Caputi    ds_hold_flags_t flags, void *tag, dsl_dataset_t **dsp);
331eb63303Tom Caputivoid dsl_dataset_disown(dsl_dataset_t *ds, ds_hold_flags_t flags, void *tag);
3323b2aab1Matthew Ahrensvoid dsl_dataset_name(dsl_dataset_t *ds, char *name);
3333b2aab1Matthew Ahrensboolean_t dsl_dataset_tryown(dsl_dataset_t *ds, void *tag);
3349adfa60Matthew Ahrensint dsl_dataset_namelen(dsl_dataset_t *ds);
3359c3fd12Matthew Ahrensboolean_t dsl_dataset_has_owner(dsl_dataset_t *ds);
336745cd3cmaybeeuint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname,
337eb63303Tom Caputi    dsl_dataset_t *origin, uint64_t flags, cred_t *,
338eb63303Tom Caputi    struct dsl_crypto_params *, dmu_tx_t *);
339088f389ahrensuint64_t dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin,
340eb63303Tom Caputi    struct dsl_crypto_params *dcp, uint64_t flags, dmu_tx_t *tx);
3412840dceChris Williamsonvoid dsl_dataset_snapshot_sync(void *arg, dmu_tx_t *tx);
3422840dceChris Williamsonint dsl_dataset_snapshot_check(void *arg, dmu_tx_t *tx);
3433b2aab1Matthew Ahrensint dsl_dataset_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t *errors);
344dfc1153Chris Williamsonvoid dsl_dataset_promote_sync(void *arg, dmu_tx_t *tx);
345dfc1153Chris Williamsonint dsl_dataset_promote_check(void *arg, dmu_tx_t *tx);
346681d976Eric Taylorint dsl_dataset_promote(const char *name, char *conflsnap);
3473cb34c6ahrensint dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head,
3483cb34c6ahrens    boolean_t force);
3493b2aab1Matthew Ahrensint dsl_dataset_rename_snapshot(const char *fsname,
3503b2aab1Matthew Ahrens    const char *oldsnapname, const char *newsnapname, boolean_t recursive);
3513b2aab1Matthew Ahrensint dsl_dataset_snapshot_tmp(const char *fsname, const char *snapname,
3523b2aab1Matthew Ahrens    minor_t cleanup_minor, const char *htag);
353fa9e406ahrens
354c717a56maybeeblkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds);
355fa9e406ahrens
356fa9e406ahrensspa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
357fa9e406ahrens
35834f2f8cMatthew Ahrensboolean_t dsl_dataset_modified_since_snap(dsl_dataset_t *ds,
35934f2f8cMatthew Ahrens    dsl_dataset_t *snap);
360f18faf3ek
361c717a56maybeevoid dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx);
362bfaed0bAndriy Gaponvoid dsl_dataset_sync_done(dsl_dataset_t *os, dmu_tx_t *tx);
363fa9e406ahrens
364b24ab67Jeff Bonwickvoid dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp,
365c717a56maybee    dmu_tx_t *tx);
366b24ab67Jeff Bonwickint dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp,
367b24ab67Jeff Bonwick    dmu_tx_t *tx, boolean_t async);
3685cabbc6Prashanth Sreenivasavoid dsl_dataset_block_remapped(dsl_dataset_t *ds, uint64_t vdev,
3695cabbc6Prashanth Sreenivasa    uint64_t offset, uint64_t size, uint64_t birth, dmu_tx_t *tx);
370fa9e406ahrens
371fa9e406ahrensvoid dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
372dfc1153Chris Williamson
373dfc1153Chris Williamsonint get_clones_stat_impl(dsl_dataset_t *ds, nvlist_t *val);
374dfc1153Chris Williamsonchar *get_receive_resume_stats_impl(dsl_dataset_t *ds);
375dfc1153Chris Williamsonchar *get_child_receive_stats(dsl_dataset_t *ds);
376dfc1153Chris Williamsonuint64_t dsl_get_refratio(dsl_dataset_t *ds);
377dfc1153Chris Williamsonuint64_t dsl_get_logicalreferenced(dsl_dataset_t *ds);
378dfc1153Chris Williamsonuint64_t dsl_get_compressratio(dsl_dataset_t *ds);
379dfc1153Chris Williamsonuint64_t dsl_get_used(dsl_dataset_t *ds);
380dfc1153Chris Williamsonuint64_t dsl_get_creation(dsl_dataset_t *ds);
381dfc1153Chris Williamsonuint64_t dsl_get_creationtxg(dsl_dataset_t *ds);
382dfc1153Chris Williamsonuint64_t dsl_get_refquota(dsl_dataset_t *ds);
383dfc1153Chris Williamsonuint64_t dsl_get_refreservation(dsl_dataset_t *ds);
384dfc1153Chris Williamsonuint64_t dsl_get_guid(dsl_dataset_t *ds);
385dfc1153Chris Williamsonuint64_t dsl_get_unique(dsl_dataset_t *ds);
386dfc1153Chris Williamsonuint64_t dsl_get_objsetid(dsl_dataset_t *ds);
387dfc1153Chris Williamsonuint64_t dsl_get_userrefs(dsl_dataset_t *ds);
388dfc1153Chris Williamsonuint64_t dsl_get_defer_destroy(dsl_dataset_t *ds);
389dfc1153Chris Williamsonuint64_t dsl_get_referenced(dsl_dataset_t *ds);
390dfc1153Chris Williamsonuint64_t dsl_get_numclones(dsl_dataset_t *ds);
391dfc1153Chris Williamsonuint64_t dsl_get_inconsistent(dsl_dataset_t *ds);
392dfc1153Chris Williamsonuint64_t dsl_get_available(dsl_dataset_t *ds);
393dfc1153Chris Williamsonint dsl_get_written(dsl_dataset_t *ds, uint64_t *written);
394dfc1153Chris Williamsonint dsl_get_prev_snap(dsl_dataset_t *ds, char *snap);
395dfc1153Chris Williamsonint dsl_get_mountpoint(dsl_dataset_t *ds, const char *dsname, char *value,
396dfc1153Chris Williamson    char *source);
397dfc1153Chris Williamson
398dfc1153Chris Williamsonvoid get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv);
399dfc1153Chris Williamson
400a2eea2eahrensvoid dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv);
401dfc1153Chris Williamson
402a2eea2eahrensvoid dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat);
403a2eea2eahrensvoid dsl_dataset_space(dsl_dataset_t *ds,
404a2eea2eahrens    uint64_t *refdbytesp, uint64_t *availbytesp,
405a2eea2eahrens    uint64_t *usedobjsp, uint64_t *availobjsp);
406a2eea2eahrensuint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds);
40719b94dfMatthew Ahrensint dsl_dataset_space_written(dsl_dataset_t *oldsnap, dsl_dataset_t *new,
40819b94dfMatthew Ahrens    uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
40919b94dfMatthew Ahrensint dsl_dataset_space_wouldfree(dsl_dataset_t *firstsnap, dsl_dataset_t *last,
41019b94dfMatthew Ahrens    uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
4112e2c135Matthew Ahrensboolean_t dsl_dataset_is_dirty(dsl_dataset_t *ds);
412fa9e406ahrens
413b1b8ab3llingint dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf);
414b1b8ab3lling
415a979902ckint dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota,
4169082849ck    uint64_t asize, uint64_t inflight, uint64_t *used,
4179082849ck    uint64_t *ref_rsrv);
4183b2aab1Matthew Ahrensint dsl_dataset_set_refquota(const char *dsname, zprop_source_t source,
41992241e0Tom Erickson    uint64_t quota);
4203b2aab1Matthew Ahrensint dsl_dataset_set_refreservation(const char *dsname, zprop_source_t source,
42192241e0Tom Erickson    uint64_t reservation);
422a979902ck
42378f1710Matthew Ahrensboolean_t dsl_dataset_is_before(dsl_dataset_t *later, dsl_dataset_t *earlier,
42478f1710Matthew Ahrens    uint64_t earlier_txg);
4253b2aab1Matthew Ahrensvoid dsl_dataset_long_hold(dsl_dataset_t *ds, void *tag);
4263b2aab1Matthew Ahrensvoid dsl_dataset_long_rele(dsl_dataset_t *ds, void *tag);
4273b2aab1Matthew Ahrensboolean_t dsl_dataset_long_held(dsl_dataset_t *ds);
4283b2aab1Matthew Ahrens
4293b2aab1Matthew Ahrensint dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
43091948b5Keith M Wesolowski    dsl_dataset_t *origin_head, boolean_t force, void *owner, dmu_tx_t *tx);
4313b2aab1Matthew Ahrensvoid dsl_dataset_clone_swap_sync_impl(dsl_dataset_t *clone,
4323b2aab1Matthew Ahrens    dsl_dataset_t *origin_head, dmu_tx_t *tx);
4333b2aab1Matthew Ahrensint dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
434a2afb61Jerry Jelinek    dmu_tx_t *tx, boolean_t recv, uint64_t cnt, cred_t *cr);
4353b2aab1Matthew Ahrensvoid dsl_dataset_snapshot_sync_impl(dsl_dataset_t *ds, const char *snapname,
4363b2aab1Matthew Ahrens    dmu_tx_t *tx);
4373b2aab1Matthew Ahrens
4383b2aab1Matthew Ahrensvoid dsl_dataset_remove_from_next_clones(dsl_dataset_t *ds, uint64_t obj,
4393b2aab1Matthew Ahrens    dmu_tx_t *tx);
4403b2aab1Matthew Ahrensvoid dsl_dataset_recalc_head_uniq(dsl_dataset_t *ds);
4413b2aab1Matthew Ahrensint dsl_dataset_get_snapname(dsl_dataset_t *ds);
4423b2aab1Matthew Ahrensint dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name,
4433b2aab1Matthew Ahrens    uint64_t *value);
444a2afb61Jerry Jelinekint dsl_dataset_snap_remove(dsl_dataset_t *ds, const char *name, dmu_tx_t *tx,
445a2afb61Jerry Jelinek    boolean_t adj_cnt);
4463b2aab1Matthew Ahrensvoid dsl_dataset_set_refreservation_sync_impl(dsl_dataset_t *ds,
4473b2aab1Matthew Ahrens    zprop_source_t source, uint64_t value, dmu_tx_t *tx);
44878f1710Matthew Ahrensvoid dsl_dataset_zapify(dsl_dataset_t *ds, dmu_tx_t *tx);
4499c3fd12Matthew Ahrensboolean_t dsl_dataset_is_zapified(dsl_dataset_t *ds);
4509c3fd12Matthew Ahrensboolean_t dsl_dataset_has_resume_receive_state(dsl_dataset_t *ds);
451000cce6Brad Lewis
452000cce6Brad Lewisint dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx);
453000cce6Brad Lewisvoid dsl_dataset_rollback_sync(void *arg, dmu_tx_t *tx);
45477b1713Andriy Gaponint dsl_dataset_rollback(const char *fsname, const char *tosnap, void *owner,
45577b1713Andriy Gapon    nvlist_t *result);
456503ad85Matthew Ahrens
4575cabbc6Prashanth Sreenivasauint64_t dsl_dataset_get_remap_deadlist_object(dsl_dataset_t *ds);
4585cabbc6Prashanth Sreenivasavoid dsl_dataset_create_remap_deadlist(dsl_dataset_t *ds, dmu_tx_t *tx);
4595cabbc6Prashanth Sreenivasaboolean_t dsl_dataset_remap_deadlist_exists(dsl_dataset_t *ds);
4605cabbc6Prashanth Sreenivasavoid dsl_dataset_destroy_remap_deadlist(dsl_dataset_t *ds, dmu_tx_t *tx);
4615cabbc6Prashanth Sreenivasa
462eb63303Tom Caputivoid dsl_dataset_activate_feature(uint64_t dsobj,
463eb63303Tom Caputi    spa_feature_t f, dmu_tx_t *tx);
464ca0cc39Matthew Ahrensvoid dsl_dataset_deactivate_feature(uint64_t dsobj,
465ca0cc39Matthew Ahrens    spa_feature_t f, dmu_tx_t *tx);
466ca0cc39Matthew Ahrens
467fa9e406ahrens#ifdef ZFS_DEBUG
468fa9e406ahrens#define	dprintf_ds(ds, fmt, ...) do { \
469fa9e406ahrens	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
4709adfa60Matthew Ahrens	char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
471fa9e406ahrens	dsl_dataset_name(ds, __ds_name); \
472fa9e406ahrens	dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
4739adfa60Matthew Ahrens	kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
474fa9e406ahrens	} \
475fa9e406ahrens_NOTE(CONSTCOND) } while (0)
476fa9e406ahrens#else
477fa9e406ahrens#define	dprintf_ds(dd, fmt, ...)
478fa9e406ahrens#endif
479fa9e406ahrens
480fa9e406ahrens#ifdef	__cplusplus
481fa9e406ahrens}
482fa9e406ahrens#endif
483fa9e406ahrens
484fa9e406ahrens#endif /* _SYS_DSL_DATASET_H */
485