17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56e1d2b42Samaguire  * Common Development and Distribution License (the "License").
66e1d2b42Samaguire  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
226e1d2b42Samaguire  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_LOWLEVEL_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_LOWLEVEL_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "libscf_impl.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <door.h>
327c478bd9Sstevel@tonic-gate #include <libuutil.h>
337c478bd9Sstevel@tonic-gate #include <limits.h>
347c478bd9Sstevel@tonic-gate #include <pthread.h>
357c478bd9Sstevel@tonic-gate #include <stddef.h>
367c478bd9Sstevel@tonic-gate 
37*29267a9dSAndy Fiddaman #include <sys/zone.h>
38*29267a9dSAndy Fiddaman 
397c478bd9Sstevel@tonic-gate #include "repcache_protocol.h"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef struct scf_datael {
467c478bd9Sstevel@tonic-gate 	scf_handle_t	*rd_handle;
477c478bd9Sstevel@tonic-gate 	uint32_t	rd_entity;
487c478bd9Sstevel@tonic-gate 	uint32_t	rd_type;
497c478bd9Sstevel@tonic-gate 	uint32_t	rd_reset;
507c478bd9Sstevel@tonic-gate 	uu_list_node_t	rd_node;
517c478bd9Sstevel@tonic-gate } scf_datael_t;
527c478bd9Sstevel@tonic-gate #define	DATAEL_VALID		0x0001
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Handle structure.
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * Access to handles is serialized -- access to and modification of a handle
587c478bd9Sstevel@tonic-gate  * and all of its children is protected by rh_lock.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * Different handles don't interfere with each other.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate struct scf_handle {
637c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rh_lock;
647c478bd9Sstevel@tonic-gate 	pthread_cond_t	rh_cv;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	uint32_t	rh_nextiter;
677c478bd9Sstevel@tonic-gate 	uint32_t	rh_nextentity;
687c478bd9Sstevel@tonic-gate 	uint32_t	rh_nextchangeid;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	int		rh_doorfd;
717c478bd9Sstevel@tonic-gate 	int		rh_doorfd_old;	/* fd to close once rh_fd_users == 0 */
727c478bd9Sstevel@tonic-gate 	door_id_t	rh_doorid;
737c478bd9Sstevel@tonic-gate 	pid_t		rh_doorpid;	/* pid at bind time */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	uid_t		rh_uid;
767c478bd9Sstevel@tonic-gate 	uint32_t	rh_debug;
777c478bd9Sstevel@tonic-gate 	uint32_t	rh_flags;	/* HANDLE_*, below */
787c478bd9Sstevel@tonic-gate 	uint32_t	rh_fd_users;	/* non-locked users of rh_doorfd */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	uu_list_t	*rh_dataels;
817c478bd9Sstevel@tonic-gate 	uu_list_t	*rh_iters;
827c478bd9Sstevel@tonic-gate 	long		rh_entries;
837c478bd9Sstevel@tonic-gate 	long		rh_values;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	long		rh_extrefs;	/* user-created subhandle count */
867c478bd9Sstevel@tonic-gate 	long		rh_intrefs;	/* handle-internal subhandle count */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	char		rh_doorpath[PATH_MAX + 1];
89*29267a9dSAndy Fiddaman 	zoneid_t	rh_zoneid;	/* expected zone ID for door server */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	pthread_t	rh_holder;		/* thread using subhandles */
927c478bd9Sstevel@tonic-gate 	uint32_t	rh_hold_flags;		/* which are in use */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	scf_iter_t		*rh_iter;
957c478bd9Sstevel@tonic-gate 	scf_scope_t		*rh_scope;
967c478bd9Sstevel@tonic-gate 	scf_service_t		*rh_service;
977c478bd9Sstevel@tonic-gate 	scf_instance_t		*rh_instance;
987c478bd9Sstevel@tonic-gate 	scf_snapshot_t		*rh_snapshot;
997c478bd9Sstevel@tonic-gate 	scf_snaplevel_t		*rh_snaplvl;
1007c478bd9Sstevel@tonic-gate 	scf_propertygroup_t	*rh_pg;
1017c478bd9Sstevel@tonic-gate 	scf_property_t		*rh_property;
1027c478bd9Sstevel@tonic-gate 	scf_value_t		*rh_value;
1037c478bd9Sstevel@tonic-gate };
1048918dff3Sjwadams #define	HANDLE_DEAD		0x0001
1058918dff3Sjwadams #define	HANDLE_UNREFED		0x0002
1068918dff3Sjwadams #define	HANDLE_WRAPPED_ENTITY	0x0004
1078918dff3Sjwadams #define	HANDLE_WRAPPED_ITER	0x0008
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define	RH_HOLD_ITER		0x0001
1107c478bd9Sstevel@tonic-gate #define	RH_HOLD_SCOPE		0x0002
1117c478bd9Sstevel@tonic-gate #define	RH_HOLD_SERVICE		0x0004
1127c478bd9Sstevel@tonic-gate #define	RH_HOLD_INSTANCE	0x0008
1137c478bd9Sstevel@tonic-gate #define	RH_HOLD_SNAPSHOT	0x0010
1147c478bd9Sstevel@tonic-gate #define	RH_HOLD_SNAPLVL		0x0020
1157c478bd9Sstevel@tonic-gate #define	RH_HOLD_PG		0x0040
1167c478bd9Sstevel@tonic-gate #define	RH_HOLD_PROPERTY	0x0080
1177c478bd9Sstevel@tonic-gate #define	RH_HOLD_VALUE		0x0100
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	RH_HOLD_ALL		0x01ff
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate struct scf_scope {
1227c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1237c478bd9Sstevel@tonic-gate };
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate struct scf_service {
1267c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1277c478bd9Sstevel@tonic-gate };
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate struct scf_instance {
1307c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1317c478bd9Sstevel@tonic-gate };
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate struct scf_snapshot {
1347c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1357c478bd9Sstevel@tonic-gate };
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * note: be careful of adding more state here -- snaplevel_next() relies on
1397c478bd9Sstevel@tonic-gate  * the fact that the entityid is the only library-level state.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate struct scf_snaplevel {
1427c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1437c478bd9Sstevel@tonic-gate };
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate struct scf_propertygroup {
1467c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1477c478bd9Sstevel@tonic-gate };
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate struct scf_property {
1507c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1517c478bd9Sstevel@tonic-gate };
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate struct scf_value {
1547c478bd9Sstevel@tonic-gate 	scf_handle_t		*value_handle;
1557c478bd9Sstevel@tonic-gate 	scf_value_t		*value_next;
1567c478bd9Sstevel@tonic-gate 	scf_transaction_entry_t	*value_tx;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t value_type;
1597c478bd9Sstevel@tonic-gate 	size_t			value_size;	/* only for opaque values */
1607c478bd9Sstevel@tonic-gate 	char			value_value[REP_PROTOCOL_VALUE_LEN];
1617c478bd9Sstevel@tonic-gate };
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate enum scf_entry_state {
1647c478bd9Sstevel@tonic-gate 	ENTRY_STATE_INVALID,
1657c478bd9Sstevel@tonic-gate 	ENTRY_STATE_IN_TX_ACTION
1667c478bd9Sstevel@tonic-gate };
1677c478bd9Sstevel@tonic-gate struct scf_transaction_entry {
1687c478bd9Sstevel@tonic-gate 	const char	*entry_property;
1697c478bd9Sstevel@tonic-gate 	scf_handle_t	*entry_handle;
1707c478bd9Sstevel@tonic-gate 	scf_transaction_t *entry_tx;
1717c478bd9Sstevel@tonic-gate 	enum scf_entry_state entry_state;
1727c478bd9Sstevel@tonic-gate 	uu_list_node_t	entry_link;		/* for property name list */
1737c478bd9Sstevel@tonic-gate 
1746e1d2b42Samaguire 	scf_value_t	*entry_head;
1756e1d2b42Samaguire 	scf_value_t	*entry_tail;		/* for linked values */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	enum rep_protocol_transaction_action	entry_action;
1787c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t		entry_type;
1797c478bd9Sstevel@tonic-gate 	char		entry_namebuf[REP_PROTOCOL_NAME_LEN];
1807c478bd9Sstevel@tonic-gate };
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate enum scf_tx_state {
1837c478bd9Sstevel@tonic-gate 	TRAN_STATE_NEW,
1847c478bd9Sstevel@tonic-gate 	TRAN_STATE_SETUP,
1857c478bd9Sstevel@tonic-gate 	TRAN_STATE_COMMITTED
1867c478bd9Sstevel@tonic-gate };
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate struct scf_transaction {
1897c478bd9Sstevel@tonic-gate 	enum scf_tx_state	tran_state;
1907c478bd9Sstevel@tonic-gate 	scf_propertygroup_t	tran_pg;
1917c478bd9Sstevel@tonic-gate 	int			tran_invalid;
1927c478bd9Sstevel@tonic-gate 	uu_list_t		*tran_props;
1937c478bd9Sstevel@tonic-gate };
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate struct scf_iter {
1967c478bd9Sstevel@tonic-gate 	scf_handle_t	*iter_handle;
1977c478bd9Sstevel@tonic-gate 	int		iter_type;
1987c478bd9Sstevel@tonic-gate 	uint32_t	iter_id;
1997c478bd9Sstevel@tonic-gate 	uint32_t	iter_sequence;
2007c478bd9Sstevel@tonic-gate 	uu_list_node_t	iter_node;
2017c478bd9Sstevel@tonic-gate };
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate #endif
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #endif	/* _LOWLEVEL_IMPL_H */
208