xref: /freebsd/sys/contrib/openzfs/include/sys/dsl_prop.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2012 by Delphix. All rights reserved.
25  * Copyright 2019 Joyent, Inc.
26  */
27 
28 #ifndef	_SYS_DSL_PROP_H
29 #define	_SYS_DSL_PROP_H
30 
31 #include <sys/dmu.h>
32 #include <sys/dsl_pool.h>
33 #include <sys/zfs_context.h>
34 #include <sys/dsl_synctask.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 struct dsl_dataset;
41 struct dsl_dir;
42 
43 /* The callback func may not call into the DMU or DSL! */
44 typedef void (dsl_prop_changed_cb_t)(void *arg, uint64_t newval);
45 
46 typedef struct dsl_prop_record {
47 	list_node_t pr_node; /* link on dd_props */
48 	const char *pr_propname;
49 	list_t pr_cbs;
50 } dsl_prop_record_t;
51 
52 typedef struct dsl_prop_cb_record {
53 	list_node_t cbr_pr_node; /* link on pr_cbs */
54 	list_node_t cbr_ds_node; /* link on ds_prop_cbs */
55 	dsl_prop_record_t *cbr_pr;
56 	struct dsl_dataset *cbr_ds;
57 	dsl_prop_changed_cb_t *cbr_func;
58 	void *cbr_arg;
59 } dsl_prop_cb_record_t;
60 
61 typedef struct dsl_props_arg {
62 	nvlist_t *pa_props;
63 	zprop_source_t pa_source;
64 } dsl_props_arg_t;
65 
66 typedef struct dsl_props_set_arg {
67 	const char *dpsa_dsname;
68 	zprop_source_t dpsa_source;
69 	nvlist_t *dpsa_props;
70 } dsl_props_set_arg_t;
71 
72 void dsl_prop_init(dsl_dir_t *dd);
73 void dsl_prop_fini(dsl_dir_t *dd);
74 int dsl_prop_register(struct dsl_dataset *ds, const char *propname,
75     dsl_prop_changed_cb_t *callback, void *cbarg);
76 int dsl_prop_unregister(struct dsl_dataset *ds, const char *propname,
77     dsl_prop_changed_cb_t *callback, void *cbarg);
78 void dsl_prop_unregister_all(struct dsl_dataset *ds, void *cbarg);
79 void dsl_prop_notify_all(struct dsl_dir *dd);
80 boolean_t dsl_prop_hascb(struct dsl_dataset *ds);
81 
82 int dsl_prop_get(const char *ddname, const char *propname,
83     int intsz, int numints, void *buf, char *setpoint);
84 int dsl_prop_get_integer(const char *ddname, const char *propname,
85     uint64_t *valuep, char *setpoint);
86 int dsl_prop_get_all(objset_t *os, nvlist_t **nvp);
87 int dsl_prop_get_received(const char *dsname, nvlist_t **nvp);
88 int dsl_prop_get_ds(struct dsl_dataset *ds, const char *propname,
89     int intsz, int numints, void *buf, char *setpoint);
90 int dsl_prop_get_int_ds(struct dsl_dataset *ds, const char *propname,
91     uint64_t *valuep);
92 int dsl_prop_get_dd(struct dsl_dir *dd, const char *propname,
93     int intsz, int numints, void *buf, char *setpoint,
94     boolean_t snapshot);
95 
96 int dsl_props_set_check(void *arg, dmu_tx_t *tx);
97 void dsl_props_set_sync(void *arg, dmu_tx_t *tx);
98 void dsl_props_set_sync_impl(struct dsl_dataset *ds, zprop_source_t source,
99     nvlist_t *props, dmu_tx_t *tx);
100 void dsl_prop_set_sync_impl(struct dsl_dataset *ds, const char *propname,
101     zprop_source_t source, int intsz, int numints, const void *value,
102     dmu_tx_t *tx);
103 int dsl_props_set(const char *dsname, zprop_source_t source, nvlist_t *nvl);
104 int dsl_prop_set_int(const char *dsname, const char *propname,
105     zprop_source_t source, uint64_t value);
106 int dsl_prop_set_string(const char *dsname, const char *propname,
107     zprop_source_t source, const char *value);
108 int dsl_prop_inherit(const char *dsname, const char *propname,
109     zprop_source_t source);
110 
111 int dsl_prop_predict(dsl_dir_t *dd, const char *propname,
112     zprop_source_t source, uint64_t value, uint64_t *newvalp);
113 
114 /* flag first receive on or after SPA_VERSION_RECVD_PROPS */
115 boolean_t dsl_prop_get_hasrecvd(const char *dsname);
116 int dsl_prop_set_hasrecvd(const char *dsname);
117 void dsl_prop_unset_hasrecvd(const char *dsname);
118 
119 void dsl_prop_nvlist_add_uint64(nvlist_t *nv, zfs_prop_t prop, uint64_t value);
120 void dsl_prop_nvlist_add_string(nvlist_t *nv,
121     zfs_prop_t prop, const char *value);
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _SYS_DSL_PROP_H */
128