xref: /illumos-gate/usr/src/lib/libscf/common/lowlevel_impl.h (revision 29267a9d01e87d9c5d871a7bb863719d89a51281)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_LOWLEVEL_IMPL_H
27 #define	_LOWLEVEL_IMPL_H
28 
29 #include "libscf_impl.h"
30 
31 #include <door.h>
32 #include <libuutil.h>
33 #include <limits.h>
34 #include <pthread.h>
35 #include <stddef.h>
36 
37 #include <sys/zone.h>
38 
39 #include "repcache_protocol.h"
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 typedef struct scf_datael {
46 	scf_handle_t	*rd_handle;
47 	uint32_t	rd_entity;
48 	uint32_t	rd_type;
49 	uint32_t	rd_reset;
50 	uu_list_node_t	rd_node;
51 } scf_datael_t;
52 #define	DATAEL_VALID		0x0001
53 
54 /*
55  * Handle structure.
56  *
57  * Access to handles is serialized -- access to and modification of a handle
58  * and all of its children is protected by rh_lock.
59  *
60  * Different handles don't interfere with each other.
61  */
62 struct scf_handle {
63 	pthread_mutex_t	rh_lock;
64 	pthread_cond_t	rh_cv;
65 
66 	uint32_t	rh_nextiter;
67 	uint32_t	rh_nextentity;
68 	uint32_t	rh_nextchangeid;
69 
70 	int		rh_doorfd;
71 	int		rh_doorfd_old;	/* fd to close once rh_fd_users == 0 */
72 	door_id_t	rh_doorid;
73 	pid_t		rh_doorpid;	/* pid at bind time */
74 
75 	uid_t		rh_uid;
76 	uint32_t	rh_debug;
77 	uint32_t	rh_flags;	/* HANDLE_*, below */
78 	uint32_t	rh_fd_users;	/* non-locked users of rh_doorfd */
79 
80 	uu_list_t	*rh_dataels;
81 	uu_list_t	*rh_iters;
82 	long		rh_entries;
83 	long		rh_values;
84 
85 	long		rh_extrefs;	/* user-created subhandle count */
86 	long		rh_intrefs;	/* handle-internal subhandle count */
87 
88 	char		rh_doorpath[PATH_MAX + 1];
89 	zoneid_t	rh_zoneid;	/* expected zone ID for door server */
90 
91 	pthread_t	rh_holder;		/* thread using subhandles */
92 	uint32_t	rh_hold_flags;		/* which are in use */
93 
94 	scf_iter_t		*rh_iter;
95 	scf_scope_t		*rh_scope;
96 	scf_service_t		*rh_service;
97 	scf_instance_t		*rh_instance;
98 	scf_snapshot_t		*rh_snapshot;
99 	scf_snaplevel_t		*rh_snaplvl;
100 	scf_propertygroup_t	*rh_pg;
101 	scf_property_t		*rh_property;
102 	scf_value_t		*rh_value;
103 };
104 #define	HANDLE_DEAD		0x0001
105 #define	HANDLE_UNREFED		0x0002
106 #define	HANDLE_WRAPPED_ENTITY	0x0004
107 #define	HANDLE_WRAPPED_ITER	0x0008
108 
109 #define	RH_HOLD_ITER		0x0001
110 #define	RH_HOLD_SCOPE		0x0002
111 #define	RH_HOLD_SERVICE		0x0004
112 #define	RH_HOLD_INSTANCE	0x0008
113 #define	RH_HOLD_SNAPSHOT	0x0010
114 #define	RH_HOLD_SNAPLVL		0x0020
115 #define	RH_HOLD_PG		0x0040
116 #define	RH_HOLD_PROPERTY	0x0080
117 #define	RH_HOLD_VALUE		0x0100
118 
119 #define	RH_HOLD_ALL		0x01ff
120 
121 struct scf_scope {
122 	scf_datael_t	rd_d;
123 };
124 
125 struct scf_service {
126 	scf_datael_t	rd_d;
127 };
128 
129 struct scf_instance {
130 	scf_datael_t	rd_d;
131 };
132 
133 struct scf_snapshot {
134 	scf_datael_t	rd_d;
135 };
136 
137 /*
138  * note: be careful of adding more state here -- snaplevel_next() relies on
139  * the fact that the entityid is the only library-level state.
140  */
141 struct scf_snaplevel {
142 	scf_datael_t	rd_d;
143 };
144 
145 struct scf_propertygroup {
146 	scf_datael_t	rd_d;
147 };
148 
149 struct scf_property {
150 	scf_datael_t	rd_d;
151 };
152 
153 struct scf_value {
154 	scf_handle_t		*value_handle;
155 	scf_value_t		*value_next;
156 	scf_transaction_entry_t	*value_tx;
157 
158 	rep_protocol_value_type_t value_type;
159 	size_t			value_size;	/* only for opaque values */
160 	char			value_value[REP_PROTOCOL_VALUE_LEN];
161 };
162 
163 enum scf_entry_state {
164 	ENTRY_STATE_INVALID,
165 	ENTRY_STATE_IN_TX_ACTION
166 };
167 struct scf_transaction_entry {
168 	const char	*entry_property;
169 	scf_handle_t	*entry_handle;
170 	scf_transaction_t *entry_tx;
171 	enum scf_entry_state entry_state;
172 	uu_list_node_t	entry_link;		/* for property name list */
173 
174 	scf_value_t	*entry_head;
175 	scf_value_t	*entry_tail;		/* for linked values */
176 
177 	enum rep_protocol_transaction_action	entry_action;
178 	rep_protocol_value_type_t		entry_type;
179 	char		entry_namebuf[REP_PROTOCOL_NAME_LEN];
180 };
181 
182 enum scf_tx_state {
183 	TRAN_STATE_NEW,
184 	TRAN_STATE_SETUP,
185 	TRAN_STATE_COMMITTED
186 };
187 
188 struct scf_transaction {
189 	enum scf_tx_state	tran_state;
190 	scf_propertygroup_t	tran_pg;
191 	int			tran_invalid;
192 	uu_list_t		*tran_props;
193 };
194 
195 struct scf_iter {
196 	scf_handle_t	*iter_handle;
197 	int		iter_type;
198 	uint32_t	iter_id;
199 	uint32_t	iter_sequence;
200 	uu_list_node_t	iter_node;
201 };
202 
203 #ifdef	__cplusplus
204 }
205 #endif
206 
207 #endif	/* _LOWLEVEL_IMPL_H */
208