xref: /illumos-gate/usr/src/lib/libpicltree/ptree_impl.h (revision 13b136d3061155363c62c9f6568d25b8b27da8f6)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
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) 1999-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_PTREE_IMPL_H
28 #define	_PTREE_IMPL_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <synch.h>
35 #include <pthread.h>
36 
37 typedef uint64_t picl_hdl_t;
38 
39 /*
40  * Hash table size of Ptree and PICL tables
41  */
42 #define	HASH_TBL_SIZE		128
43 #define	HASH_INDEX(s, x)	((int)((x) & ((s) - 1)))
44 
45 /*
46  * Invalid PICL handle
47  */
48 #define	PICL_INVALID_PICLHDL	(picl_hdl_t)0
49 
50 /*
51  * Is the object PICLized?
52  */
53 #define	IS_PICLIZED(x)		((x)->picl_hdl != 0)
54 
55 /*
56  * A handle is a 64-bit quantity with the daemon's pid value in top 32 bits
57  * and the raw handle value in the lower 32 bits.
58  */
59 #define	HASH_VAL(x)		((x) & 0xFFFFFFFF)
60 #define	GET_PID(x)		((x) >> 32)
61 #define	MAKE_HANDLE(x, y)	(((picl_hdl_t)(x) << 32) | (y))
62 
63 /*
64  * Lock type when locking a node
65  */
66 #define	RDLOCK_NODE		1
67 #define	WRLOCK_NODE		2
68 
69 /*
70  * Property access operation
71  */
72 #define	PROP_READ		1
73 #define	PROP_WRITE		2
74 
75 /*
76  * PICL object type
77  */
78 typedef	struct picl_obj		picl_obj_t;
79 
80 /*
81  * Hash table structure
82  */
83 struct hash_elem {
84 	uint32_t		hdl;
85 	union {
86 		void		*data;
87 		uint32_t	ptreeh;
88 	} u;
89 	struct hash_elem	*next;
90 };
91 typedef	struct hash_elem	hash_elem_t;
92 #define	hash_obj	u.data
93 #define	hash_hdl	u.ptreeh
94 
95 typedef struct {
96 	int		hash_size;
97 	hash_elem_t	**tbl;
98 } hash_t;
99 
100 /*
101  * Property expression list
102  */
103 typedef struct prop_list {
104 	char			*pname;
105 	char			*pval;
106 	struct prop_list	*next;
107 } prop_list_t;
108 
109 /*
110  * PICL property (scalar or a table entry)
111  */
112 struct picl_prop {
113 	ptree_propinfo_t	info;
114 	void			*pvalue;
115 	picl_obj_t		*nodep;		/* prop's node or table */
116 	picl_obj_t		*next_in_list;
117 	picl_obj_t		*next_by_row;
118 	picl_obj_t		*next_by_col;
119 };
120 typedef	struct picl_prop	picl_prop_t;
121 
122 /*
123  * PICL node
124  */
125 struct picl_node {
126 	rwlock_t	rwlock;		/* protects properties */
127 	picl_obj_t	*firstprop;
128 	char		*classname;
129 	picl_obj_t	*parent;	/* protected by ptree lock */
130 	picl_obj_t	*child;		/* protected by ptree lock */
131 	picl_obj_t	*sibling;	/* protected by ptree lock */
132 };
133 typedef struct picl_node	picl_node_t;
134 
135 /*
136  * PICL object types
137  */
138 #define	PICL_OBJ_NODE		0x1
139 #define	PICL_OBJ_PROP		0x2
140 #define	PICL_OBJ_TABLE		0x4
141 #define	PICL_OBJ_TABLEENTRY	0x8
142 
143 /*
144  * PICL object
145  */
146 struct picl_obj {
147 	uint32_t	obj_type;
148 	picl_hdl_t	ptree_hdl;		/* ptree handle */
149 	picl_hdl_t	picl_hdl;		/* client handle */
150 	union {
151 		picl_node_t	node;
152 		picl_prop_t	prop;
153 	} u;
154 };
155 
156 #define	pinfo_ver	u.prop.info.version
157 #define	prop_type	u.prop.info.piclinfo.type
158 #define	prop_size	u.prop.info.piclinfo.size
159 #define	prop_mode	u.prop.info.piclinfo.accessmode
160 #define	prop_name	u.prop.info.piclinfo.name
161 #define	prop_val	u.prop.pvalue
162 #define	next_row	u.prop.next_by_row
163 #define	next_col	u.prop.next_by_col
164 #define	next_prop	u.prop.next_in_list
165 #define	table_prop	u.prop.next_in_list
166 #define	prop_node	u.prop.nodep
167 #define	prop_table	u.prop.nodep
168 #define	read_func	u.prop.info.read
169 #define	write_func	u.prop.info.write
170 
171 #define	first_prop	u.node.firstprop
172 #define	node_lock	u.node.rwlock
173 #define	child_node	u.node.child
174 #define	sibling_node	u.node.sibling
175 #define	parent_node	u.node.parent
176 #define	node_classname	u.node.classname
177 
178 /*
179  * PICL event queue structures
180  */
181 struct eventq {
182 	const char		*ename;
183 	const void		*earg;
184 	size_t		size;
185 	void		(*completion_handler)(char *ename, void *earg,
186 			    size_t size);
187 	struct eventq	*next;
188 };
189 typedef struct eventq	eventq_t;
190 
191 /*
192  * Event handler list
193  */
194 struct eh_list {
195 	char		*ename;
196 	void		*cookie;
197 	void		(*evt_handler)(const char *ename, const void *earg,
198 			    size_t size, void *cookie);
199 	short		execflg;
200 	short		wakeupflg;
201 	pthread_cond_t	cv;
202 	struct eh_list	*next;
203 };
204 typedef struct eh_list	evt_handler_t;
205 
206 #define	SUPER_USER		0
207 
208 #define	MIN(x, y)		((x) < (y) ? (x) : (y))
209 
210 typedef struct picld_plugin_reg_list {
211 	picld_plugin_reg_t		reg;
212 	struct picld_plugin_reg_list	*next;
213 } picld_plugin_reg_list_t;
214 
215 typedef struct picld_plinfo {
216 	char			*libname;
217 	char			*pathname;
218 	void			*dlh;
219 	struct picld_plinfo	*next;
220 } picld_plugin_desc_t;
221 
222 extern	int	xptree_initialize(int);
223 extern	void	xptree_destroy(void);
224 extern	int	xptree_reinitialize(void);
225 extern	int	xptree_refresh_notify(uint32_t secs);
226 extern	int	cvt_picl2ptree(picl_hdl_t piclh, picl_hdl_t *ptreeh);
227 extern	void	cvt_ptree2picl(picl_hdl_t *vbuf);
228 extern	int	xptree_get_propinfo_by_name(picl_nodehdl_t nodeh,
229 			const char *pname, ptree_propinfo_t *pinfo);
230 extern	int	xptree_get_propval_with_cred(picl_prophdl_t proph, void *valbuf,
231 			size_t size, door_cred_t cred);
232 extern	int	xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh,
233 			const char *propname, void *valbuf, size_t sz,
234 			door_cred_t cred);
235 extern	int	xptree_update_propval_with_cred(picl_prophdl_t proph,
236 			const void *valbuf, size_t sz, door_cred_t cred);
237 extern	int	xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh,
238 			const char *propname, const void *valbuf, size_t sz,
239 			door_cred_t cred);
240 
241 /*
242  * PICL daemon verbose level flag
243  */
244 extern	int	verbose_level;
245 extern	void	dbg_print(int level, const char *fmt, ...);
246 extern	void	dbg_exec(int level, void (*fn)(void *), void *arg);
247 
248 #ifdef	__cplusplus
249 }
250 #endif
251 
252 #endif	/* _PTREE_IMPL_H */
253