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