xref: /titanic_41/usr/src/lib/libscf/common/lowlevel_impl.h (revision 6dfee4834394825da35b977ca71cdc965bc7b6a4)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LOWLEVEL_IMPL_H
28 #define	_LOWLEVEL_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include "libscf_impl.h"
33 
34 #include <door.h>
35 #include <libuutil.h>
36 #include <limits.h>
37 #include <pthread.h>
38 #include <stddef.h>
39 
40 #include "repcache_protocol.h"
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 typedef struct scf_datael {
47 	scf_handle_t	*rd_handle;
48 	uint32_t	rd_entity;
49 	uint32_t	rd_type;
50 	uint32_t	rd_reset;
51 	uu_list_node_t	rd_node;
52 } scf_datael_t;
53 #define	DATAEL_VALID		0x0001
54 
55 /*
56  * Handle structure.
57  *
58  * Access to handles is serialized -- access to and modification of a handle
59  * and all of its children is protected by rh_lock.
60  *
61  * Different handles don't interfere with each other.
62  */
63 struct scf_handle {
64 	pthread_mutex_t	rh_lock;
65 	pthread_cond_t	rh_cv;
66 
67 	uint32_t	rh_nextiter;
68 	uint32_t	rh_nextentity;
69 	uint32_t	rh_nextchangeid;
70 
71 	int		rh_doorfd;
72 	int		rh_doorfd_old;	/* fd to close once rh_fd_users == 0 */
73 	door_id_t	rh_doorid;
74 	pid_t		rh_doorpid;	/* pid at bind time */
75 
76 	uid_t		rh_uid;
77 	uint32_t	rh_debug;
78 	uint32_t	rh_flags;	/* HANDLE_*, below */
79 	uint32_t	rh_fd_users;	/* non-locked users of rh_doorfd */
80 
81 	uu_list_t	*rh_dataels;
82 	uu_list_t	*rh_iters;
83 	long		rh_entries;
84 	long		rh_values;
85 
86 	long		rh_extrefs;	/* user-created subhandle count */
87 	long		rh_intrefs;	/* handle-internal subhandle count */
88 
89 	char		rh_doorpath[PATH_MAX + 1];
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;		/* 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