xref: /freebsd/sys/contrib/openzfs/include/sys/dsl_bookmark.h (revision 2f10ffc003be396f3fc23cd2888023896560252b)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright (c) 2013, 2018 by Delphix. All rights reserved.
14  */
15 
16 #ifndef	_SYS_DSL_BOOKMARK_H
17 #define	_SYS_DSL_BOOKMARK_H
18 
19 #include <sys/zfs_context.h>
20 #include <sys/zfs_refcount.h>
21 #include <sys/dmu_tx.h>
22 #include <sys/dsl_dataset.h>
23 #include <sys/dsl_pool.h>
24 
25 #ifdef	__cplusplus
26 extern "C" {
27 #endif
28 
29 /*
30  * On disk zap object.
31  */
32 typedef struct zfs_bookmark_phys {
33 	uint64_t zbm_guid;		/* guid of bookmarked dataset */
34 	uint64_t zbm_creation_txg;	/* birth transaction group */
35 	uint64_t zbm_creation_time;	/* bookmark creation time */
36 
37 	/* fields used for redacted send / recv */
38 	uint64_t zbm_redaction_obj;	/* redaction list object */
39 	uint64_t zbm_flags;		/* ZBM_FLAG_* */
40 
41 	/* fields used for bookmark written size */
42 	uint64_t zbm_referenced_bytes_refd;
43 	uint64_t zbm_compressed_bytes_refd;
44 	uint64_t zbm_uncompressed_bytes_refd;
45 	uint64_t zbm_referenced_freed_before_next_snap;
46 	uint64_t zbm_compressed_freed_before_next_snap;
47 	uint64_t zbm_uncompressed_freed_before_next_snap;
48 
49 	/* fields used for raw sends */
50 	uint64_t zbm_ivset_guid;
51 } zfs_bookmark_phys_t;
52 
53 
54 #define	BOOKMARK_PHYS_SIZE_V1	(3 * sizeof (uint64_t))
55 #define	BOOKMARK_PHYS_SIZE_V2	(12 * sizeof (uint64_t))
56 
57 typedef enum zbm_flags {
58 	ZBM_FLAG_HAS_FBN = (1 << 0),
59 	ZBM_FLAG_SNAPSHOT_EXISTS = (1 << 1),
60 } zbm_flags_t;
61 
62 typedef struct redaction_list_phys {
63 	uint64_t rlp_last_object;
64 	uint64_t rlp_last_blkid;
65 	uint64_t rlp_num_entries;
66 	uint64_t rlp_num_snaps;
67 	uint64_t rlp_snaps[]; /* variable length */
68 } redaction_list_phys_t;
69 
70 typedef struct redaction_list {
71 	dmu_buf_user_t		rl_dbu;
72 	redaction_list_phys_t	*rl_phys;
73 	dmu_buf_t		*rl_bonus;
74 	dmu_buf_t		*rl_dbuf;
75 	uint64_t		rl_object;
76 	zfs_refcount_t		rl_longholds;
77 	objset_t		*rl_mos;
78 } redaction_list_t;
79 
80 /* node in ds_bookmarks */
81 typedef struct dsl_bookmark_node {
82 	char *dbn_name; /* free with strfree() */
83 	kmutex_t dbn_lock; /* protects dirty/phys in block_killed */
84 	boolean_t dbn_dirty; /* in currently syncing txg */
85 	zfs_bookmark_phys_t dbn_phys;
86 	avl_node_t dbn_node;
87 } dsl_bookmark_node_t;
88 
89 typedef struct redact_block_phys {
90 	uint64_t	rbp_object;
91 	uint64_t	rbp_blkid;
92 	/*
93 	 * The top 16 bits of this field represent the block size in sectors of
94 	 * the blocks in question; the bottom 48 bits are used to store the
95 	 * number of consecutive blocks that are in the redaction list.  They
96 	 * should be accessed using the inline functions below.
97 	 */
98 	uint64_t	rbp_size_count;
99 	uint64_t	rbp_padding;
100 } redact_block_phys_t;
101 
102 typedef int (*rl_traverse_callback_t)(redact_block_phys_t *, void *);
103 
104 
105 typedef struct dsl_bookmark_create_arg {
106 	nvlist_t *dbca_bmarks;
107 	nvlist_t *dbca_errors;
108 } dsl_bookmark_create_arg_t;
109 
110 typedef struct dsl_bookmark_create_redacted_arg {
111 	const char	*dbcra_bmark;
112 	const char	*dbcra_snap;
113 	redaction_list_t **dbcra_rl;
114 	uint64_t	dbcra_numsnaps;
115 	uint64_t	*dbcra_snaps;
116 	const void	*dbcra_tag;
117 } dsl_bookmark_create_redacted_arg_t;
118 
119 typedef struct dsl_bookmark_destroy_arg {
120 	nvlist_t *dbda_bmarks;
121 	nvlist_t *dbda_success;
122 	nvlist_t *dbda_errors;
123 } dsl_bookmark_destroy_arg_t;
124 
125 int dsl_bookmark_create(nvlist_t *, nvlist_t *);
126 int dsl_bookmark_create_nvl_validate(nvlist_t *);
127 int dsl_bookmark_create_check(void *arg, dmu_tx_t *tx);
128 void dsl_bookmark_create_sync(void *arg, dmu_tx_t *tx);
129 int dsl_bookmark_create_redacted(const char *, const char *, uint64_t,
130     uint64_t *, const void *, redaction_list_t **);
131 int dsl_get_bookmarks(const char *, nvlist_t *, nvlist_t *);
132 int dsl_get_bookmarks_impl(dsl_dataset_t *, nvlist_t *, nvlist_t *);
133 int dsl_get_bookmark_props(const char *, const char *, nvlist_t *);
134 int dsl_bookmark_destroy(nvlist_t *, nvlist_t *);
135 int dsl_bookmark_destroy_check(void *, dmu_tx_t *);
136 void dsl_bookmark_destroy_sync(void *, dmu_tx_t *);
137 int dsl_bookmark_lookup(struct dsl_pool *, const char *,
138     struct dsl_dataset *, zfs_bookmark_phys_t *);
139 int dsl_bookmark_lookup_impl(dsl_dataset_t *, const char *,
140     zfs_bookmark_phys_t *);
141 int dsl_redaction_list_hold_obj(struct dsl_pool *, uint64_t, const void *,
142     redaction_list_t **);
143 void dsl_redaction_list_rele(redaction_list_t *, const void *);
144 void dsl_redaction_list_long_hold(struct dsl_pool *, redaction_list_t *,
145     const void *);
146 void dsl_redaction_list_long_rele(redaction_list_t *, const void *);
147 boolean_t dsl_redaction_list_long_held(redaction_list_t *);
148 int dsl_bookmark_init_ds(dsl_dataset_t *);
149 void dsl_bookmark_fini_ds(dsl_dataset_t *);
150 boolean_t dsl_bookmark_ds_destroyed(dsl_dataset_t *, dmu_tx_t *);
151 void dsl_bookmark_snapshotted(dsl_dataset_t *, dmu_tx_t *);
152 void dsl_bookmark_block_killed(dsl_dataset_t *, const blkptr_t *, dmu_tx_t *);
153 void dsl_bookmark_sync_done(dsl_dataset_t *, dmu_tx_t *);
154 void dsl_bookmark_node_add(dsl_dataset_t *, dsl_bookmark_node_t *, dmu_tx_t *);
155 uint64_t dsl_bookmark_latest_txg(dsl_dataset_t *);
156 int dsl_redaction_list_traverse(redaction_list_t *, zbookmark_phys_t *,
157     rl_traverse_callback_t, void *);
158 void dsl_bookmark_next_changed(dsl_dataset_t *, dsl_dataset_t *, dmu_tx_t *);
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif /* _SYS_DSL_BOOKMARK_H */
165