1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23248571Smm * Copyright (c) 2012 by Delphix. All rights reserved.
24168404Spjd */
25168404Spjd
26168404Spjd#ifndef	_SYS_DSL_PROP_H
27168404Spjd#define	_SYS_DSL_PROP_H
28168404Spjd
29168404Spjd#include <sys/dmu.h>
30168404Spjd#include <sys/dsl_pool.h>
31168404Spjd#include <sys/zfs_context.h>
32209962Smm#include <sys/dsl_synctask.h>
33168404Spjd
34168404Spjd#ifdef	__cplusplus
35168404Spjdextern "C" {
36168404Spjd#endif
37168404Spjd
38168404Spjdstruct dsl_dataset;
39185029Spjdstruct dsl_dir;
40168404Spjd
41168404Spjd/* The callback func may not call into the DMU or DSL! */
42168404Spjdtypedef void (dsl_prop_changed_cb_t)(void *arg, uint64_t newval);
43168404Spjd
44288204Sdelphijtypedef struct dsl_prop_record {
45288204Sdelphij	list_node_t pr_node; /* link on dd_props */
46288204Sdelphij	const char *pr_propname;
47288204Sdelphij	list_t pr_cbs;
48288204Sdelphij} dsl_prop_record_t;
49288204Sdelphij
50168404Spjdtypedef struct dsl_prop_cb_record {
51288204Sdelphij	list_node_t cbr_pr_node; /* link on pr_cbs */
52288204Sdelphij	list_node_t cbr_ds_node; /* link on ds_prop_cbs */
53288204Sdelphij	dsl_prop_record_t *cbr_pr;
54168404Spjd	struct dsl_dataset *cbr_ds;
55168404Spjd	dsl_prop_changed_cb_t *cbr_func;
56168404Spjd	void *cbr_arg;
57168404Spjd} dsl_prop_cb_record_t;
58168404Spjd
59219089Spjdtypedef struct dsl_props_arg {
60219089Spjd	nvlist_t *pa_props;
61219089Spjd	zprop_source_t pa_source;
62219089Spjd} dsl_props_arg_t;
63219089Spjd
64288204Sdelphijvoid dsl_prop_init(dsl_dir_t *dd);
65288204Sdelphijvoid dsl_prop_fini(dsl_dir_t *dd);
66168404Spjdint dsl_prop_register(struct dsl_dataset *ds, const char *propname,
67168404Spjd    dsl_prop_changed_cb_t *callback, void *cbarg);
68288204Sdelphijvoid dsl_prop_unregister_all(struct dsl_dataset *ds, void *cbarg);
69248571Smmvoid dsl_prop_notify_all(struct dsl_dir *dd);
70248571Smmboolean_t dsl_prop_hascb(struct dsl_dataset *ds);
71168404Spjd
72168404Spjdint dsl_prop_get(const char *ddname, const char *propname,
73168404Spjd    int intsz, int numints, void *buf, char *setpoint);
74168404Spjdint dsl_prop_get_integer(const char *ddname, const char *propname,
75168404Spjd    uint64_t *valuep, char *setpoint);
76219089Spjdint dsl_prop_get_all(objset_t *os, nvlist_t **nvp);
77248571Smmint dsl_prop_get_received(const char *dsname, nvlist_t **nvp);
78185029Spjdint dsl_prop_get_ds(struct dsl_dataset *ds, const char *propname,
79185029Spjd    int intsz, int numints, void *buf, char *setpoint);
80248571Smmint dsl_prop_get_int_ds(struct dsl_dataset *ds, const char *propname,
81248571Smm    uint64_t *valuep);
82185029Spjdint dsl_prop_get_dd(struct dsl_dir *dd, const char *propname,
83219089Spjd    int intsz, int numints, void *buf, char *setpoint,
84219089Spjd    boolean_t snapshot);
85168404Spjd
86248571Smmvoid dsl_props_set_sync_impl(struct dsl_dataset *ds, zprop_source_t source,
87248571Smm    nvlist_t *props, dmu_tx_t *tx);
88248571Smmvoid dsl_prop_set_sync_impl(struct dsl_dataset *ds, const char *propname,
89248571Smm    zprop_source_t source, int intsz, int numints, const void *value,
90248571Smm    dmu_tx_t *tx);
91219089Spjdint dsl_props_set(const char *dsname, zprop_source_t source, nvlist_t *nvl);
92248571Smmint dsl_prop_set_int(const char *dsname, const char *propname,
93248571Smm    zprop_source_t source, uint64_t value);
94248571Smmint dsl_prop_set_string(const char *dsname, const char *propname,
95248571Smm    zprop_source_t source, const char *value);
96248571Smmint dsl_prop_inherit(const char *dsname, const char *propname,
97248571Smm    zprop_source_t source);
98168404Spjd
99248571Smmint dsl_prop_predict(dsl_dir_t *dd, const char *propname,
100248571Smm    zprop_source_t source, uint64_t value, uint64_t *newvalp);
101219089Spjd
102219089Spjd/* flag first receive on or after SPA_VERSION_RECVD_PROPS */
103248571Smmboolean_t dsl_prop_get_hasrecvd(const char *dsname);
104248571Smmint dsl_prop_set_hasrecvd(const char *dsname);
105248571Smmvoid dsl_prop_unset_hasrecvd(const char *dsname);
106219089Spjd
107168404Spjdvoid dsl_prop_nvlist_add_uint64(nvlist_t *nv, zfs_prop_t prop, uint64_t value);
108168404Spjdvoid dsl_prop_nvlist_add_string(nvlist_t *nv,
109168404Spjd    zfs_prop_t prop, const char *value);
110168404Spjd
111168404Spjd#ifdef	__cplusplus
112168404Spjd}
113168404Spjd#endif
114168404Spjd
115168404Spjd#endif	/* _SYS_DSL_PROP_H */
116