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 /*
223f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23000cce6bSBrad Lewis * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
24a2afb611SJerry Jelinek * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25a7a845e4SSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
26bc9014e6SJustin Gibbs * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
27c3d26abcSMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
28fa9e4066Sahrens */
29fa9e4066Sahrens
30fa9e4066Sahrens #ifndef _SYS_DSL_DATASET_H
31fa9e4066Sahrens #define _SYS_DSL_DATASET_H
32fa9e4066Sahrens
33fa9e4066Sahrens #include <sys/dmu.h>
34fa9e4066Sahrens #include <sys/spa.h>
35fa9e4066Sahrens #include <sys/txg.h>
36c717a561Smaybee #include <sys/zio.h>
37fa9e4066Sahrens #include <sys/bplist.h>
381d452cf5Sahrens #include <sys/dsl_synctask.h>
39fa9e4066Sahrens #include <sys/zfs_context.h>
40cde58dbcSMatthew Ahrens #include <sys/dsl_deadlist.h>
413b2aab18SMatthew Ahrens #include <sys/refcount.h>
42c166b69dSPaul Dagnelie #include <sys/rrwlock.h>
43eb633035STom Caputi #include <sys/dsl_crypt.h>
44ca0cc391SMatthew Ahrens #include <zfeature_common.h>
45fa9e4066Sahrens
46fa9e4066Sahrens #ifdef __cplusplus
47fa9e4066Sahrens extern "C" {
48fa9e4066Sahrens #endif
49fa9e4066Sahrens
50fa9e4066Sahrens struct dsl_dataset;
51fa9e4066Sahrens struct dsl_dir;
52fa9e4066Sahrens struct dsl_pool;
53eb633035STom Caputi struct dsl_crypto_params;
54eb633035STom Caputi struct dsl_key_mapping;
55fa9e4066Sahrens
5699653d4eSeschrock #define DS_FLAG_INCONSISTENT (1ULL<<0)
57745cd3c5Smaybee #define DS_IS_INCONSISTENT(ds) \
58c1379625SJustin T. Gibbs (dsl_dataset_phys(ds)->ds_flags & DS_FLAG_INCONSISTENT)
592acef22dSMatthew Ahrens
6099653d4eSeschrock /*
612acef22dSMatthew Ahrens * Do not allow this dataset to be promoted.
6299653d4eSeschrock */
6399653d4eSeschrock #define DS_FLAG_NOPROMOTE (1ULL<<1)
6499653d4eSeschrock
65a9799022Sck /*
66a9799022Sck * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly
67a9799022Sck * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE,
68a9799022Sck * refquota/refreservations).
69a9799022Sck */
70a9799022Sck #define DS_FLAG_UNIQUE_ACCURATE (1ULL<<2)
71a9799022Sck
72842727c2SChris Kirby /*
73842727c2SChris Kirby * DS_FLAG_DEFER_DESTROY is set after 'zfs destroy -d' has been called
74842727c2SChris Kirby * on a dataset. This allows the dataset to be destroyed using 'zfs release'.
75842727c2SChris Kirby */
76842727c2SChris Kirby #define DS_FLAG_DEFER_DESTROY (1ULL<<3)
77842727c2SChris Kirby #define DS_IS_DEFER_DESTROY(ds) \
78c1379625SJustin T. Gibbs (dsl_dataset_phys(ds)->ds_flags & DS_FLAG_DEFER_DESTROY)
79842727c2SChris Kirby
802acef22dSMatthew Ahrens /*
812acef22dSMatthew Ahrens * DS_FIELD_* are strings that are used in the "extensified" dataset zap object.
822acef22dSMatthew Ahrens * They should be of the format <reverse-dns>:<field>.
832acef22dSMatthew Ahrens */
842acef22dSMatthew Ahrens
8578f17100SMatthew Ahrens /*
8678f17100SMatthew Ahrens * This field's value is the object ID of a zap object which contains the
8778f17100SMatthew Ahrens * bookmarks of this dataset. If it is present, then this dataset is counted
8878f17100SMatthew Ahrens * in the refcount of the SPA_FEATURES_BOOKMARKS feature.
8978f17100SMatthew Ahrens */
9078f17100SMatthew Ahrens #define DS_FIELD_BOOKMARK_NAMES "com.delphix:bookmarks"
9178f17100SMatthew Ahrens
9254811da5SToomas Soome /*
9354811da5SToomas Soome * This field is present (with value=0) if this dataset may contain large
9454811da5SToomas Soome * dnodes (>512B). If it is present, then this dataset is counted in the
9554811da5SToomas Soome * refcount of the SPA_FEATURE_LARGE_DNODE feature.
9654811da5SToomas Soome */
9754811da5SToomas Soome #define DS_FIELD_LARGE_DNODE "org.zfsonlinux:large_dnode"
9854811da5SToomas Soome
999c3fd121SMatthew Ahrens /*
1009c3fd121SMatthew Ahrens * These fields are set on datasets that are in the middle of a resumable
1019c3fd121SMatthew Ahrens * receive, and allow the sender to resume the send if it is interrupted.
1029c3fd121SMatthew Ahrens */
1039c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_FROMGUID "com.delphix:resume_fromguid"
1049c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_TONAME "com.delphix:resume_toname"
1059c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_TOGUID "com.delphix:resume_toguid"
1069c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_OBJECT "com.delphix:resume_object"
1079c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_OFFSET "com.delphix:resume_offset"
1089c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_BYTES "com.delphix:resume_bytes"
1095602294fSDan Kimmel #define DS_FIELD_RESUME_LARGEBLOCK "com.delphix:resume_largeblockok"
1109c3fd121SMatthew Ahrens #define DS_FIELD_RESUME_EMBEDOK "com.delphix:resume_embedok"
1115602294fSDan Kimmel #define DS_FIELD_RESUME_COMPRESSOK "com.delphix:resume_compressok"
112eb633035STom Caputi #define DS_FIELD_RESUME_RAWOK "com.datto:resume_rawok"
1139c3fd121SMatthew Ahrens
1145cabbc6bSPrashanth Sreenivasa /*
1155cabbc6bSPrashanth Sreenivasa * This field is set to the object number of the remap deadlist if one exists.
1165cabbc6bSPrashanth Sreenivasa */
1175cabbc6bSPrashanth Sreenivasa #define DS_FIELD_REMAP_DEADLIST "com.delphix:remap_deadlist"
1185cabbc6bSPrashanth Sreenivasa
119eb633035STom Caputi /*
120eb633035STom Caputi * This field is set to the ivset guid for encrypted snapshots. This is used
121eb633035STom Caputi * for validating raw receives.
122eb633035STom Caputi */
123eb633035STom Caputi #define DS_FIELD_IVSET_GUID "com.datto:ivset_guid"
124eb633035STom Caputi
125ab04eb8eStimh /*
126ab04eb8eStimh * DS_FLAG_CI_DATASET is set if the dataset contains a file system whose
127ab04eb8eStimh * name lookups should be performed case-insensitively.
128ab04eb8eStimh */
129ab04eb8eStimh #define DS_FLAG_CI_DATASET (1ULL<<16)
130ab04eb8eStimh
1313b2aab18SMatthew Ahrens #define DS_CREATE_FLAG_NODIRTY (1ULL<<24)
1323b2aab18SMatthew Ahrens
133fa9e4066Sahrens typedef struct dsl_dataset_phys {
134088f3894Sahrens uint64_t ds_dir_obj; /* DMU_OT_DSL_DIR */
135088f3894Sahrens uint64_t ds_prev_snap_obj; /* DMU_OT_DSL_DATASET */
136fa9e4066Sahrens uint64_t ds_prev_snap_txg;
137088f3894Sahrens uint64_t ds_next_snap_obj; /* DMU_OT_DSL_DATASET */
138088f3894Sahrens uint64_t ds_snapnames_zapobj; /* DMU_OT_DSL_DS_SNAP_MAP 0 for snaps */
139fa9e4066Sahrens uint64_t ds_num_children; /* clone/snap children; ==0 for head */
140fa9e4066Sahrens uint64_t ds_creation_time; /* seconds since 1970 */
141fa9e4066Sahrens uint64_t ds_creation_txg;
142cde58dbcSMatthew Ahrens uint64_t ds_deadlist_obj; /* DMU_OT_DEADLIST */
143ad135b5dSChristopher Siden /*
144ad135b5dSChristopher Siden * ds_referenced_bytes, ds_compressed_bytes, and ds_uncompressed_bytes
145ad135b5dSChristopher Siden * include all blocks referenced by this dataset, including those
146ad135b5dSChristopher Siden * shared with any other datasets.
147ad135b5dSChristopher Siden */
148ad135b5dSChristopher Siden uint64_t ds_referenced_bytes;
149fa9e4066Sahrens uint64_t ds_compressed_bytes;
150fa9e4066Sahrens uint64_t ds_uncompressed_bytes;
15163360950Smp uint64_t ds_unique_bytes; /* only relevant to snapshots */
152fa9e4066Sahrens /*
153fa9e4066Sahrens * The ds_fsid_guid is a 56-bit ID that can change to avoid
154fa9e4066Sahrens * collisions. The ds_guid is a 64-bit ID that will never
155fa9e4066Sahrens * change, so there is a small probability that it will collide.
156fa9e4066Sahrens */
157fa9e4066Sahrens uint64_t ds_fsid_guid;
158fa9e4066Sahrens uint64_t ds_guid;
159088f3894Sahrens uint64_t ds_flags; /* DS_FLAG_* */
160fa9e4066Sahrens blkptr_t ds_bp;
161bb0ade09Sahrens uint64_t ds_next_clones_obj; /* DMU_OT_DSL_CLONES */
162bb0ade09Sahrens uint64_t ds_props_obj; /* DMU_OT_DSL_PROPS for snaps */
163842727c2SChris Kirby uint64_t ds_userrefs_obj; /* DMU_OT_USERREFS */
164842727c2SChris Kirby uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */
165fa9e4066Sahrens } dsl_dataset_phys_t;
166fa9e4066Sahrens
167fa9e4066Sahrens typedef struct dsl_dataset {
168bc9014e6SJustin Gibbs dmu_buf_user_t ds_dbu;
169c166b69dSPaul Dagnelie rrwlock_t ds_bp_rwlock; /* Protects ds_phys->ds_bp */
170bc9014e6SJustin Gibbs
171fa9e4066Sahrens /* Immutable: */
172fa9e4066Sahrens struct dsl_dir *ds_dir;
173fa9e4066Sahrens dmu_buf_t *ds_dbuf;
174fa9e4066Sahrens uint64_t ds_object;
17591ebeef5Sahrens uint64_t ds_fsid_guid;
176bc9014e6SJustin Gibbs boolean_t ds_is_snapshot;
177eb633035STom Caputi struct dsl_key_mapping *ds_key_mapping;
178fa9e4066Sahrens
17974e7dc98SMatthew Ahrens /* only used in syncing context, only valid for non-snapshots: */
18074e7dc98SMatthew Ahrens struct dsl_dataset *ds_prev;
18178f17100SMatthew Ahrens uint64_t ds_bookmarks; /* DMU_OTN_ZAP_METADATA */
182fa9e4066Sahrens
183fa9e4066Sahrens /* has internal locking: */
184cde58dbcSMatthew Ahrens dsl_deadlist_t ds_deadlist;
185cde58dbcSMatthew Ahrens bplist_t ds_pending_deadlist;
186fa9e4066Sahrens
1875cabbc6bSPrashanth Sreenivasa /*
1885cabbc6bSPrashanth Sreenivasa * The remap deadlist contains blocks (DVA's, really) that are
1895cabbc6bSPrashanth Sreenivasa * referenced by the previous snapshot and point to indirect vdevs,
1905cabbc6bSPrashanth Sreenivasa * but in this dataset they have been remapped to point to concrete
1915cabbc6bSPrashanth Sreenivasa * (or at least, less-indirect) vdevs. In other words, the
1925cabbc6bSPrashanth Sreenivasa * physical DVA is referenced by the previous snapshot but not by
1935cabbc6bSPrashanth Sreenivasa * this dataset. Logically, the DVA continues to be referenced,
1945cabbc6bSPrashanth Sreenivasa * but we are using a different (less indirect) physical DVA.
1955cabbc6bSPrashanth Sreenivasa * This deadlist is used to determine when physical DVAs that
1965cabbc6bSPrashanth Sreenivasa * point to indirect vdevs are no longer referenced anywhere,
1975cabbc6bSPrashanth Sreenivasa * and thus should be marked obsolete.
1985cabbc6bSPrashanth Sreenivasa *
1995cabbc6bSPrashanth Sreenivasa * This is only used if SPA_FEATURE_OBSOLETE_COUNTS is enabled.
2005cabbc6bSPrashanth Sreenivasa */
2015cabbc6bSPrashanth Sreenivasa dsl_deadlist_t ds_remap_deadlist;
2025cabbc6bSPrashanth Sreenivasa /* protects creation of the ds_remap_deadlist */
2035cabbc6bSPrashanth Sreenivasa kmutex_t ds_remap_deadlist_lock;
2045cabbc6bSPrashanth Sreenivasa
205fa9e4066Sahrens /* protected by lock on pool's dp_dirty_datasets list */
206fa9e4066Sahrens txg_node_t ds_dirty_link;
207fa9e4066Sahrens list_node_t ds_synced_link;
208fa9e4066Sahrens
209fa9e4066Sahrens /*
210fa9e4066Sahrens * ds_phys->ds_<accounting> is also protected by ds_lock.
211fa9e4066Sahrens * Protected by ds_lock:
212fa9e4066Sahrens */
213fa9e4066Sahrens kmutex_t ds_lock;
214503ad85cSMatthew Ahrens objset_t *ds_objset;
215842727c2SChris Kirby uint64_t ds_userrefs;
2163b2aab18SMatthew Ahrens void *ds_owner;
217745cd3c5Smaybee
218745cd3c5Smaybee /*
2193b2aab18SMatthew Ahrens * Long holds prevent the ds from being destroyed; they allow the
2203b2aab18SMatthew Ahrens * ds to remain held even after dropping the dp_config_rwlock.
2213b2aab18SMatthew Ahrens * Owning counts as a long hold. See the comments above
2223b2aab18SMatthew Ahrens * dsl_pool_hold() for details.
223745cd3c5Smaybee */
224e914ace2STim Schumacher zfs_refcount_t ds_longholds;
225fa9e4066Sahrens
2261d452cf5Sahrens /* no locking; only for making guesses */
2271d452cf5Sahrens uint64_t ds_trysnap_txg;
2281d452cf5Sahrens
22991ebeef5Sahrens /* for objset_open() */
23091ebeef5Sahrens kmutex_t ds_opening_lock;
23191ebeef5Sahrens
232a9799022Sck uint64_t ds_reserved; /* cached refreservation */
233a9799022Sck uint64_t ds_quota; /* cached refquota */
234a9799022Sck
2354e3c9f44SBill Pijewski kmutex_t ds_sendstream_lock;
2364e3c9f44SBill Pijewski list_t ds_sendstreams;
2374e3c9f44SBill Pijewski
2389c3fd121SMatthew Ahrens /*
2399c3fd121SMatthew Ahrens * When in the middle of a resumable receive, tracks how much
2409c3fd121SMatthew Ahrens * progress we have made.
2419c3fd121SMatthew Ahrens */
2429c3fd121SMatthew Ahrens uint64_t ds_resume_object[TXG_SIZE];
2439c3fd121SMatthew Ahrens uint64_t ds_resume_offset[TXG_SIZE];
2449c3fd121SMatthew Ahrens uint64_t ds_resume_bytes[TXG_SIZE];
2459c3fd121SMatthew Ahrens
24603bad06fSJustin Gibbs /* Protected by our dsl_dir's dd_lock */
24703bad06fSJustin Gibbs list_t ds_prop_cbs;
24803bad06fSJustin Gibbs
249ca0cc391SMatthew Ahrens /*
250ca0cc391SMatthew Ahrens * For ZFEATURE_FLAG_PER_DATASET features, set if this dataset
251ca0cc391SMatthew Ahrens * uses this feature.
252ca0cc391SMatthew Ahrens */
253ca0cc391SMatthew Ahrens uint8_t ds_feature_inuse[SPA_FEATURES];
254ca0cc391SMatthew Ahrens
255ca0cc391SMatthew Ahrens /*
256ca0cc391SMatthew Ahrens * Set if we need to activate the feature on this dataset this txg
257ca0cc391SMatthew Ahrens * (used only in syncing context).
258ca0cc391SMatthew Ahrens */
259ca0cc391SMatthew Ahrens uint8_t ds_feature_activation_needed[SPA_FEATURES];
260ca0cc391SMatthew Ahrens
261fa9e4066Sahrens /* Protected by ds_lock; keep at end of struct for better locality */
2629adfa60dSMatthew Ahrens char ds_snapname[ZFS_MAX_DATASET_NAME_LEN];
263fa9e4066Sahrens } dsl_dataset_t;
264fa9e4066Sahrens
265c1379625SJustin T. Gibbs inline dsl_dataset_phys_t *
dsl_dataset_phys(dsl_dataset_t * ds)266c1379625SJustin T. Gibbs dsl_dataset_phys(dsl_dataset_t *ds)
267c1379625SJustin T. Gibbs {
268c1379625SJustin T. Gibbs return (ds->ds_dbuf->db_data);
269c1379625SJustin T. Gibbs }
270c1379625SJustin T. Gibbs
271dfc11533SChris Williamson typedef struct dsl_dataset_promote_arg {
272dfc11533SChris Williamson const char *ddpa_clonename;
273dfc11533SChris Williamson dsl_dataset_t *ddpa_clone;
274dfc11533SChris Williamson list_t shared_snaps, origin_snaps, clone_snaps;
275dfc11533SChris Williamson dsl_dataset_t *origin_origin; /* origin of the origin */
276dfc11533SChris Williamson uint64_t used, comp, uncomp, unique, cloneusedsnap, originusedsnap;
277dfc11533SChris Williamson nvlist_t *err_ds;
278dfc11533SChris Williamson cred_t *cr;
279dfc11533SChris Williamson } dsl_dataset_promote_arg_t;
280dfc11533SChris Williamson
281000cce6bSBrad Lewis typedef struct dsl_dataset_rollback_arg {
282000cce6bSBrad Lewis const char *ddra_fsname;
283000cce6bSBrad Lewis const char *ddra_tosnap;
284000cce6bSBrad Lewis void *ddra_owner;
285000cce6bSBrad Lewis nvlist_t *ddra_result;
286000cce6bSBrad Lewis } dsl_dataset_rollback_arg_t;
287000cce6bSBrad Lewis
2882840dce1SChris Williamson typedef struct dsl_dataset_snapshot_arg {
2892840dce1SChris Williamson nvlist_t *ddsa_snaps;
2902840dce1SChris Williamson nvlist_t *ddsa_props;
2912840dce1SChris Williamson nvlist_t *ddsa_errors;
2922840dce1SChris Williamson cred_t *ddsa_cr;
2932840dce1SChris Williamson } dsl_dataset_snapshot_arg_t;
2942840dce1SChris Williamson
29599d5e173STim Haley /*
29699d5e173STim Haley * The max length of a temporary tag prefix is the number of hex digits
29799d5e173STim Haley * required to express UINT64_MAX plus one for the hyphen.
29899d5e173STim Haley */
29999d5e173STim Haley #define MAX_TAG_PREFIX_LEN 17
30099d5e173STim Haley
301643da460SMax Grossman #define dsl_dataset_is_snapshot(ds) \
302643da460SMax Grossman (dsl_dataset_phys(ds)->ds_num_children != 0)
303643da460SMax Grossman
304a9799022Sck #define DS_UNIQUE_IS_ACCURATE(ds) \
305c1379625SJustin T. Gibbs ((dsl_dataset_phys(ds)->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
306a9799022Sck
307eb633035STom Caputi /* flags for holding the dataset */
308eb633035STom Caputi typedef enum ds_hold_flags {
309*ef96fc31SToomas Soome DS_HOLD_FLAG_NONE = 0 << 0,
310eb633035STom Caputi DS_HOLD_FLAG_DECRYPT = 1 << 0 /* needs access to encrypted data */
311eb633035STom Caputi } ds_hold_flags_t;
312eb633035STom Caputi
3133b2aab18SMatthew Ahrens int dsl_dataset_hold(struct dsl_pool *dp, const char *name, void *tag,
3143b2aab18SMatthew Ahrens dsl_dataset_t **dsp);
315eb633035STom Caputi int dsl_dataset_hold_flags(struct dsl_pool *dp, const char *name,
316eb633035STom Caputi ds_hold_flags_t flags, void *tag, dsl_dataset_t **dsp);
317e57a022bSJustin T. Gibbs boolean_t dsl_dataset_try_add_ref(struct dsl_pool *dp, dsl_dataset_t *ds,
318e57a022bSJustin T. Gibbs void *tag);
319eb633035STom Caputi int dsl_dataset_create_key_mapping(dsl_dataset_t *ds);
3203b2aab18SMatthew Ahrens int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, void *tag,
3213b2aab18SMatthew Ahrens dsl_dataset_t **);
322eb633035STom Caputi int dsl_dataset_hold_obj_flags(struct dsl_pool *dp, uint64_t dsobj,
323eb633035STom Caputi ds_hold_flags_t flags, void *tag, dsl_dataset_t **);
324eb633035STom Caputi void dsl_dataset_remove_key_mapping(dsl_dataset_t *ds);
3253b2aab18SMatthew Ahrens void dsl_dataset_rele(dsl_dataset_t *ds, void *tag);
326eb633035STom Caputi void dsl_dataset_rele_flags(dsl_dataset_t *ds, ds_hold_flags_t flags,
327eb633035STom Caputi void *tag);
3283b2aab18SMatthew Ahrens int dsl_dataset_own(struct dsl_pool *dp, const char *name,
329eb633035STom Caputi ds_hold_flags_t flags, void *tag, dsl_dataset_t **dsp);
330745cd3c5Smaybee int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj,
331eb633035STom Caputi ds_hold_flags_t flags, void *tag, dsl_dataset_t **dsp);
332eb633035STom Caputi void dsl_dataset_disown(dsl_dataset_t *ds, ds_hold_flags_t flags, void *tag);
3333b2aab18SMatthew Ahrens void dsl_dataset_name(dsl_dataset_t *ds, char *name);
3343b2aab18SMatthew Ahrens boolean_t dsl_dataset_tryown(dsl_dataset_t *ds, void *tag);
3359adfa60dSMatthew Ahrens int dsl_dataset_namelen(dsl_dataset_t *ds);
3369c3fd121SMatthew Ahrens boolean_t dsl_dataset_has_owner(dsl_dataset_t *ds);
337745cd3c5Smaybee uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname,
338eb633035STom Caputi dsl_dataset_t *origin, uint64_t flags, cred_t *,
339eb633035STom Caputi struct dsl_crypto_params *, dmu_tx_t *);
340088f3894Sahrens uint64_t dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin,
341eb633035STom Caputi struct dsl_crypto_params *dcp, uint64_t flags, dmu_tx_t *tx);
3422840dce1SChris Williamson void dsl_dataset_snapshot_sync(void *arg, dmu_tx_t *tx);
3432840dce1SChris Williamson int dsl_dataset_snapshot_check(void *arg, dmu_tx_t *tx);
3443b2aab18SMatthew Ahrens int dsl_dataset_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t *errors);
345dfc11533SChris Williamson void dsl_dataset_promote_sync(void *arg, dmu_tx_t *tx);
346dfc11533SChris Williamson int dsl_dataset_promote_check(void *arg, dmu_tx_t *tx);
347681d9761SEric Taylor int dsl_dataset_promote(const char *name, char *conflsnap);
3483cb34c60Sahrens int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head,
3493cb34c60Sahrens boolean_t force);
3503b2aab18SMatthew Ahrens int dsl_dataset_rename_snapshot(const char *fsname,
3513b2aab18SMatthew Ahrens const char *oldsnapname, const char *newsnapname, boolean_t recursive);
3523b2aab18SMatthew Ahrens int dsl_dataset_snapshot_tmp(const char *fsname, const char *snapname,
3533b2aab18SMatthew Ahrens minor_t cleanup_minor, const char *htag);
354fa9e4066Sahrens
355c717a561Smaybee blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds);
356fa9e4066Sahrens
357fa9e4066Sahrens spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
358fa9e4066Sahrens
35934f2f8cfSMatthew Ahrens boolean_t dsl_dataset_modified_since_snap(dsl_dataset_t *ds,
36034f2f8cfSMatthew Ahrens dsl_dataset_t *snap);
361f18faf3fSek
362c717a561Smaybee void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx);
363bfaed0b9SAndriy Gapon void dsl_dataset_sync_done(dsl_dataset_t *os, dmu_tx_t *tx);
364fa9e4066Sahrens
365b24ab676SJeff Bonwick void dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp,
366c717a561Smaybee dmu_tx_t *tx);
367b24ab676SJeff Bonwick int dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp,
368b24ab676SJeff Bonwick dmu_tx_t *tx, boolean_t async);
3695cabbc6bSPrashanth Sreenivasa void dsl_dataset_block_remapped(dsl_dataset_t *ds, uint64_t vdev,
3705cabbc6bSPrashanth Sreenivasa uint64_t offset, uint64_t size, uint64_t birth, dmu_tx_t *tx);
371fa9e4066Sahrens
372fa9e4066Sahrens void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
373dfc11533SChris Williamson
374dfc11533SChris Williamson int get_clones_stat_impl(dsl_dataset_t *ds, nvlist_t *val);
375dfc11533SChris Williamson char *get_receive_resume_stats_impl(dsl_dataset_t *ds);
376dfc11533SChris Williamson char *get_child_receive_stats(dsl_dataset_t *ds);
377dfc11533SChris Williamson uint64_t dsl_get_refratio(dsl_dataset_t *ds);
378dfc11533SChris Williamson uint64_t dsl_get_logicalreferenced(dsl_dataset_t *ds);
379dfc11533SChris Williamson uint64_t dsl_get_compressratio(dsl_dataset_t *ds);
380dfc11533SChris Williamson uint64_t dsl_get_used(dsl_dataset_t *ds);
381dfc11533SChris Williamson uint64_t dsl_get_creation(dsl_dataset_t *ds);
382dfc11533SChris Williamson uint64_t dsl_get_creationtxg(dsl_dataset_t *ds);
383dfc11533SChris Williamson uint64_t dsl_get_refquota(dsl_dataset_t *ds);
384dfc11533SChris Williamson uint64_t dsl_get_refreservation(dsl_dataset_t *ds);
385dfc11533SChris Williamson uint64_t dsl_get_guid(dsl_dataset_t *ds);
386dfc11533SChris Williamson uint64_t dsl_get_unique(dsl_dataset_t *ds);
387dfc11533SChris Williamson uint64_t dsl_get_objsetid(dsl_dataset_t *ds);
388dfc11533SChris Williamson uint64_t dsl_get_userrefs(dsl_dataset_t *ds);
389dfc11533SChris Williamson uint64_t dsl_get_defer_destroy(dsl_dataset_t *ds);
390dfc11533SChris Williamson uint64_t dsl_get_referenced(dsl_dataset_t *ds);
391dfc11533SChris Williamson uint64_t dsl_get_numclones(dsl_dataset_t *ds);
392dfc11533SChris Williamson uint64_t dsl_get_inconsistent(dsl_dataset_t *ds);
393dfc11533SChris Williamson uint64_t dsl_get_available(dsl_dataset_t *ds);
394dfc11533SChris Williamson int dsl_get_written(dsl_dataset_t *ds, uint64_t *written);
395dfc11533SChris Williamson int dsl_get_prev_snap(dsl_dataset_t *ds, char *snap);
396dfc11533SChris Williamson int dsl_get_mountpoint(dsl_dataset_t *ds, const char *dsname, char *value,
397dfc11533SChris Williamson char *source);
398dfc11533SChris Williamson
399dfc11533SChris Williamson void get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv);
400dfc11533SChris Williamson
401a2eea2e1Sahrens void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv);
402dfc11533SChris Williamson
403a2eea2e1Sahrens void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat);
404a2eea2e1Sahrens void dsl_dataset_space(dsl_dataset_t *ds,
405a2eea2e1Sahrens uint64_t *refdbytesp, uint64_t *availbytesp,
406a2eea2e1Sahrens uint64_t *usedobjsp, uint64_t *availobjsp);
407a2eea2e1Sahrens uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds);
40819b94df9SMatthew Ahrens int dsl_dataset_space_written(dsl_dataset_t *oldsnap, dsl_dataset_t *new,
40919b94df9SMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
41019b94df9SMatthew Ahrens int dsl_dataset_space_wouldfree(dsl_dataset_t *firstsnap, dsl_dataset_t *last,
41119b94df9SMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
4122e2c1355SMatthew Ahrens boolean_t dsl_dataset_is_dirty(dsl_dataset_t *ds);
413fa9e4066Sahrens
414b1b8ab34Slling int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf);
415b1b8ab34Slling
416a9799022Sck int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota,
4179082849eSck uint64_t asize, uint64_t inflight, uint64_t *used,
4189082849eSck uint64_t *ref_rsrv);
4193b2aab18SMatthew Ahrens int dsl_dataset_set_refquota(const char *dsname, zprop_source_t source,
42092241e0bSTom Erickson uint64_t quota);
4213b2aab18SMatthew Ahrens int dsl_dataset_set_refreservation(const char *dsname, zprop_source_t source,
42292241e0bSTom Erickson uint64_t reservation);
423a9799022Sck
42478f17100SMatthew Ahrens boolean_t dsl_dataset_is_before(dsl_dataset_t *later, dsl_dataset_t *earlier,
42578f17100SMatthew Ahrens uint64_t earlier_txg);
4263b2aab18SMatthew Ahrens void dsl_dataset_long_hold(dsl_dataset_t *ds, void *tag);
4273b2aab18SMatthew Ahrens void dsl_dataset_long_rele(dsl_dataset_t *ds, void *tag);
4283b2aab18SMatthew Ahrens boolean_t dsl_dataset_long_held(dsl_dataset_t *ds);
4293b2aab18SMatthew Ahrens
4303b2aab18SMatthew Ahrens int dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
43191948b51SKeith M Wesolowski dsl_dataset_t *origin_head, boolean_t force, void *owner, dmu_tx_t *tx);
4323b2aab18SMatthew Ahrens void dsl_dataset_clone_swap_sync_impl(dsl_dataset_t *clone,
4333b2aab18SMatthew Ahrens dsl_dataset_t *origin_head, dmu_tx_t *tx);
4343b2aab18SMatthew Ahrens int dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
435a2afb611SJerry Jelinek dmu_tx_t *tx, boolean_t recv, uint64_t cnt, cred_t *cr);
4363b2aab18SMatthew Ahrens void dsl_dataset_snapshot_sync_impl(dsl_dataset_t *ds, const char *snapname,
4373b2aab18SMatthew Ahrens dmu_tx_t *tx);
4383b2aab18SMatthew Ahrens
4393b2aab18SMatthew Ahrens void dsl_dataset_remove_from_next_clones(dsl_dataset_t *ds, uint64_t obj,
4403b2aab18SMatthew Ahrens dmu_tx_t *tx);
4413b2aab18SMatthew Ahrens void dsl_dataset_recalc_head_uniq(dsl_dataset_t *ds);
4423b2aab18SMatthew Ahrens int dsl_dataset_get_snapname(dsl_dataset_t *ds);
4433b2aab18SMatthew Ahrens int dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name,
4443b2aab18SMatthew Ahrens uint64_t *value);
445a2afb611SJerry Jelinek int dsl_dataset_snap_remove(dsl_dataset_t *ds, const char *name, dmu_tx_t *tx,
446a2afb611SJerry Jelinek boolean_t adj_cnt);
4473b2aab18SMatthew Ahrens void dsl_dataset_set_refreservation_sync_impl(dsl_dataset_t *ds,
4483b2aab18SMatthew Ahrens zprop_source_t source, uint64_t value, dmu_tx_t *tx);
44978f17100SMatthew Ahrens void dsl_dataset_zapify(dsl_dataset_t *ds, dmu_tx_t *tx);
4509c3fd121SMatthew Ahrens boolean_t dsl_dataset_is_zapified(dsl_dataset_t *ds);
4519c3fd121SMatthew Ahrens boolean_t dsl_dataset_has_resume_receive_state(dsl_dataset_t *ds);
452000cce6bSBrad Lewis
453000cce6bSBrad Lewis int dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx);
454000cce6bSBrad Lewis void dsl_dataset_rollback_sync(void *arg, dmu_tx_t *tx);
45577b17137SAndriy Gapon int dsl_dataset_rollback(const char *fsname, const char *tosnap, void *owner,
45677b17137SAndriy Gapon nvlist_t *result);
457503ad85cSMatthew Ahrens
4585cabbc6bSPrashanth Sreenivasa uint64_t dsl_dataset_get_remap_deadlist_object(dsl_dataset_t *ds);
4595cabbc6bSPrashanth Sreenivasa void dsl_dataset_create_remap_deadlist(dsl_dataset_t *ds, dmu_tx_t *tx);
4605cabbc6bSPrashanth Sreenivasa boolean_t dsl_dataset_remap_deadlist_exists(dsl_dataset_t *ds);
4615cabbc6bSPrashanth Sreenivasa void dsl_dataset_destroy_remap_deadlist(dsl_dataset_t *ds, dmu_tx_t *tx);
4625cabbc6bSPrashanth Sreenivasa
463eb633035STom Caputi void dsl_dataset_activate_feature(uint64_t dsobj,
464eb633035STom Caputi spa_feature_t f, dmu_tx_t *tx);
465ca0cc391SMatthew Ahrens void dsl_dataset_deactivate_feature(uint64_t dsobj,
466ca0cc391SMatthew Ahrens spa_feature_t f, dmu_tx_t *tx);
467ca0cc391SMatthew Ahrens
468fa9e4066Sahrens #ifdef ZFS_DEBUG
469fa9e4066Sahrens #define dprintf_ds(ds, fmt, ...) do { \
470fa9e4066Sahrens if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
4719adfa60dSMatthew Ahrens char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
472fa9e4066Sahrens dsl_dataset_name(ds, __ds_name); \
473fa9e4066Sahrens dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
4749adfa60dSMatthew Ahrens kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
475fa9e4066Sahrens } \
476fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
477fa9e4066Sahrens #else
478fa9e4066Sahrens #define dprintf_ds(dd, fmt, ...)
479fa9e4066Sahrens #endif
480fa9e4066Sahrens
481fa9e4066Sahrens #ifdef __cplusplus
482fa9e4066Sahrens }
483fa9e4066Sahrens #endif
484fa9e4066Sahrens
485fa9e4066Sahrens #endif /* _SYS_DSL_DATASET_H */
486