xref: /titanic_44/usr/src/lib/libscf/common/lowlevel_impl.h (revision 6e1d2b428379e5270ccda99d403eb225e8699c3e)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include "libscf_impl.h"
32 
33 #include <door.h>
34 #include <libuutil.h>
35 #include <limits.h>
36 #include <pthread.h>
37 #include <stddef.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 
90 	pthread_t	rh_holder;		/* thread using subhandles */
91 	uint32_t	rh_hold_flags;		/* which are in use */
92 
93 	scf_iter_t		*rh_iter;
94 	scf_scope_t		*rh_scope;
95 	scf_service_t		*rh_service;
96 	scf_instance_t		*rh_instance;
97 	scf_snapshot_t		*rh_snapshot;
98 	scf_snaplevel_t		*rh_snaplvl;
99 	scf_propertygroup_t	*rh_pg;
100 	scf_property_t		*rh_property;
101 	scf_value_t		*rh_value;
102 };
103 #define	HANDLE_DEAD		0x0001
104 #define	HANDLE_UNREFED		0x0002
105 #define	HANDLE_WRAPPED_ENTITY	0x0004
106 #define	HANDLE_WRAPPED_ITER	0x0008
107 
108 #define	RH_HOLD_ITER		0x0001
109 #define	RH_HOLD_SCOPE		0x0002
110 #define	RH_HOLD_SERVICE		0x0004
111 #define	RH_HOLD_INSTANCE	0x0008
112 #define	RH_HOLD_SNAPSHOT	0x0010
113 #define	RH_HOLD_SNAPLVL		0x0020
114 #define	RH_HOLD_PG		0x0040
115 #define	RH_HOLD_PROPERTY	0x0080
116 #define	RH_HOLD_VALUE		0x0100
117 
118 #define	RH_HOLD_ALL		0x01ff
119 
120 struct scf_scope {
121 	scf_datael_t	rd_d;
122 };
123 
124 struct scf_service {
125 	scf_datael_t	rd_d;
126 };
127 
128 struct scf_instance {
129 	scf_datael_t	rd_d;
130 };
131 
132 struct scf_snapshot {
133 	scf_datael_t	rd_d;
134 };
135 
136 /*
137  * note: be careful of adding more state here -- snaplevel_next() relies on
138  * the fact that the entityid is the only library-level state.
139  */
140 struct scf_snaplevel {
141 	scf_datael_t	rd_d;
142 };
143 
144 struct scf_propertygroup {
145 	scf_datael_t	rd_d;
146 };
147 
148 struct scf_property {
149 	scf_datael_t	rd_d;
150 };
151 
152 struct scf_value {
153 	scf_handle_t		*value_handle;
154 	scf_value_t		*value_next;
155 	scf_transaction_entry_t	*value_tx;
156 
157 	rep_protocol_value_type_t value_type;
158 	size_t			value_size;	/* only for opaque values */
159 	char			value_value[REP_PROTOCOL_VALUE_LEN];
160 };
161 
162 enum scf_entry_state {
163 	ENTRY_STATE_INVALID,
164 	ENTRY_STATE_IN_TX_ACTION
165 };
166 struct scf_transaction_entry {
167 	const char	*entry_property;
168 	scf_handle_t	*entry_handle;
169 	scf_transaction_t *entry_tx;
170 	enum scf_entry_state entry_state;
171 	uu_list_node_t	entry_link;		/* for property name list */
172 
173 	scf_value_t	*entry_head;
174 	scf_value_t	*entry_tail;		/* for linked values */
175 
176 	enum rep_protocol_transaction_action	entry_action;
177 	rep_protocol_value_type_t		entry_type;
178 	char		entry_namebuf[REP_PROTOCOL_NAME_LEN];
179 };
180 
181 enum scf_tx_state {
182 	TRAN_STATE_NEW,
183 	TRAN_STATE_SETUP,
184 	TRAN_STATE_COMMITTED
185 };
186 
187 struct scf_transaction {
188 	enum scf_tx_state	tran_state;
189 	scf_propertygroup_t	tran_pg;
190 	int			tran_invalid;
191 	uu_list_t		*tran_props;
192 };
193 
194 struct scf_iter {
195 	scf_handle_t	*iter_handle;
196 	int		iter_type;
197 	uint32_t	iter_id;
198 	uint32_t	iter_sequence;
199 	uu_list_node_t	iter_node;
200 };
201 
202 #ifdef	__cplusplus
203 }
204 #endif
205 
206 #endif	/* _LOWLEVEL_IMPL_H */
207