xref: /titanic_52/usr/src/lib/libscf/common/lowlevel_impl.h (revision 554ff184129088135ad2643c1c9832174a17be88)
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 2004 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 
107 #define	RH_HOLD_ITER		0x0001
108 #define	RH_HOLD_SCOPE		0x0002
109 #define	RH_HOLD_SERVICE		0x0004
110 #define	RH_HOLD_INSTANCE	0x0008
111 #define	RH_HOLD_SNAPSHOT	0x0010
112 #define	RH_HOLD_SNAPLVL		0x0020
113 #define	RH_HOLD_PG		0x0040
114 #define	RH_HOLD_PROPERTY	0x0080
115 #define	RH_HOLD_VALUE		0x0100
116 
117 #define	RH_HOLD_ALL		0x01ff
118 
119 struct scf_scope {
120 	scf_datael_t	rd_d;
121 };
122 
123 struct scf_service {
124 	scf_datael_t	rd_d;
125 };
126 
127 struct scf_instance {
128 	scf_datael_t	rd_d;
129 };
130 
131 struct scf_snapshot {
132 	scf_datael_t	rd_d;
133 };
134 
135 /*
136  * note: be careful of adding more state here -- snaplevel_next() relies on
137  * the fact that the entityid is the only library-level state.
138  */
139 struct scf_snaplevel {
140 	scf_datael_t	rd_d;
141 };
142 
143 struct scf_propertygroup {
144 	scf_datael_t	rd_d;
145 };
146 
147 struct scf_property {
148 	scf_datael_t	rd_d;
149 };
150 
151 struct scf_value {
152 	scf_handle_t		*value_handle;
153 	scf_value_t		*value_next;
154 	scf_transaction_entry_t	*value_tx;
155 
156 	rep_protocol_value_type_t value_type;
157 	size_t			value_size;	/* only for opaque values */
158 	char			value_value[REP_PROTOCOL_VALUE_LEN];
159 };
160 
161 enum scf_entry_state {
162 	ENTRY_STATE_INVALID,
163 	ENTRY_STATE_IN_TX_ACTION
164 };
165 struct scf_transaction_entry {
166 	const char	*entry_property;
167 	scf_handle_t	*entry_handle;
168 	scf_transaction_t *entry_tx;
169 	enum scf_entry_state entry_state;
170 	uu_list_node_t	entry_link;		/* for property name list */
171 
172 	scf_value_t	*entry_head;		/* for linked values */
173 
174 	enum rep_protocol_transaction_action	entry_action;
175 	rep_protocol_value_type_t		entry_type;
176 	char		entry_namebuf[REP_PROTOCOL_NAME_LEN];
177 };
178 
179 enum scf_tx_state {
180 	TRAN_STATE_NEW,
181 	TRAN_STATE_SETUP,
182 	TRAN_STATE_COMMITTED
183 };
184 
185 struct scf_transaction {
186 	enum scf_tx_state	tran_state;
187 	scf_propertygroup_t	tran_pg;
188 	int			tran_invalid;
189 	uu_list_t		*tran_props;
190 };
191 
192 struct scf_iter {
193 	scf_handle_t	*iter_handle;
194 	int		iter_type;
195 	uint32_t	iter_id;
196 	uint32_t	iter_sequence;
197 	uu_list_node_t	iter_node;
198 };
199 
200 #ifdef	__cplusplus
201 }
202 #endif
203 
204 #endif	/* _LOWLEVEL_IMPL_H */
205