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
5*6e1d2b42Samaguire  * Common Development and Distribution License (the "License").
6*6e1d2b42Samaguire  * 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 /*
22*6e1d2b42Samaguire  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include "libscf_impl.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <door.h>
347c478bd9Sstevel@tonic-gate #include <libuutil.h>
357c478bd9Sstevel@tonic-gate #include <limits.h>
367c478bd9Sstevel@tonic-gate #include <pthread.h>
377c478bd9Sstevel@tonic-gate #include <stddef.h>
387c478bd9Sstevel@tonic-gate 
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];
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	pthread_t	rh_holder;		/* thread using subhandles */
917c478bd9Sstevel@tonic-gate 	uint32_t	rh_hold_flags;		/* which are in use */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	scf_iter_t		*rh_iter;
947c478bd9Sstevel@tonic-gate 	scf_scope_t		*rh_scope;
957c478bd9Sstevel@tonic-gate 	scf_service_t		*rh_service;
967c478bd9Sstevel@tonic-gate 	scf_instance_t		*rh_instance;
977c478bd9Sstevel@tonic-gate 	scf_snapshot_t		*rh_snapshot;
987c478bd9Sstevel@tonic-gate 	scf_snaplevel_t		*rh_snaplvl;
997c478bd9Sstevel@tonic-gate 	scf_propertygroup_t	*rh_pg;
1007c478bd9Sstevel@tonic-gate 	scf_property_t		*rh_property;
1017c478bd9Sstevel@tonic-gate 	scf_value_t		*rh_value;
1027c478bd9Sstevel@tonic-gate };
1038918dff3Sjwadams #define	HANDLE_DEAD		0x0001
1048918dff3Sjwadams #define	HANDLE_UNREFED		0x0002
1058918dff3Sjwadams #define	HANDLE_WRAPPED_ENTITY	0x0004
1068918dff3Sjwadams #define	HANDLE_WRAPPED_ITER	0x0008
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	RH_HOLD_ITER		0x0001
1097c478bd9Sstevel@tonic-gate #define	RH_HOLD_SCOPE		0x0002
1107c478bd9Sstevel@tonic-gate #define	RH_HOLD_SERVICE		0x0004
1117c478bd9Sstevel@tonic-gate #define	RH_HOLD_INSTANCE	0x0008
1127c478bd9Sstevel@tonic-gate #define	RH_HOLD_SNAPSHOT	0x0010
1137c478bd9Sstevel@tonic-gate #define	RH_HOLD_SNAPLVL		0x0020
1147c478bd9Sstevel@tonic-gate #define	RH_HOLD_PG		0x0040
1157c478bd9Sstevel@tonic-gate #define	RH_HOLD_PROPERTY	0x0080
1167c478bd9Sstevel@tonic-gate #define	RH_HOLD_VALUE		0x0100
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	RH_HOLD_ALL		0x01ff
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate struct scf_scope {
1217c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1227c478bd9Sstevel@tonic-gate };
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate struct scf_service {
1257c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1267c478bd9Sstevel@tonic-gate };
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate struct scf_instance {
1297c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1307c478bd9Sstevel@tonic-gate };
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate struct scf_snapshot {
1337c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1347c478bd9Sstevel@tonic-gate };
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * note: be careful of adding more state here -- snaplevel_next() relies on
1387c478bd9Sstevel@tonic-gate  * the fact that the entityid is the only library-level state.
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate struct scf_snaplevel {
1417c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1427c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate struct scf_propertygroup {
1457c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1467c478bd9Sstevel@tonic-gate };
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate struct scf_property {
1497c478bd9Sstevel@tonic-gate 	scf_datael_t	rd_d;
1507c478bd9Sstevel@tonic-gate };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate struct scf_value {
1537c478bd9Sstevel@tonic-gate 	scf_handle_t		*value_handle;
1547c478bd9Sstevel@tonic-gate 	scf_value_t		*value_next;
1557c478bd9Sstevel@tonic-gate 	scf_transaction_entry_t	*value_tx;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t value_type;
1587c478bd9Sstevel@tonic-gate 	size_t			value_size;	/* only for opaque values */
1597c478bd9Sstevel@tonic-gate 	char			value_value[REP_PROTOCOL_VALUE_LEN];
1607c478bd9Sstevel@tonic-gate };
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate enum scf_entry_state {
1637c478bd9Sstevel@tonic-gate 	ENTRY_STATE_INVALID,
1647c478bd9Sstevel@tonic-gate 	ENTRY_STATE_IN_TX_ACTION
1657c478bd9Sstevel@tonic-gate };
1667c478bd9Sstevel@tonic-gate struct scf_transaction_entry {
1677c478bd9Sstevel@tonic-gate 	const char	*entry_property;
1687c478bd9Sstevel@tonic-gate 	scf_handle_t	*entry_handle;
1697c478bd9Sstevel@tonic-gate 	scf_transaction_t *entry_tx;
1707c478bd9Sstevel@tonic-gate 	enum scf_entry_state entry_state;
1717c478bd9Sstevel@tonic-gate 	uu_list_node_t	entry_link;		/* for property name list */
1727c478bd9Sstevel@tonic-gate 
173*6e1d2b42Samaguire 	scf_value_t	*entry_head;
174*6e1d2b42Samaguire 	scf_value_t	*entry_tail;		/* for linked values */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	enum rep_protocol_transaction_action	entry_action;
1777c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t		entry_type;
1787c478bd9Sstevel@tonic-gate 	char		entry_namebuf[REP_PROTOCOL_NAME_LEN];
1797c478bd9Sstevel@tonic-gate };
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate enum scf_tx_state {
1827c478bd9Sstevel@tonic-gate 	TRAN_STATE_NEW,
1837c478bd9Sstevel@tonic-gate 	TRAN_STATE_SETUP,
1847c478bd9Sstevel@tonic-gate 	TRAN_STATE_COMMITTED
1857c478bd9Sstevel@tonic-gate };
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate struct scf_transaction {
1887c478bd9Sstevel@tonic-gate 	enum scf_tx_state	tran_state;
1897c478bd9Sstevel@tonic-gate 	scf_propertygroup_t	tran_pg;
1907c478bd9Sstevel@tonic-gate 	int			tran_invalid;
1917c478bd9Sstevel@tonic-gate 	uu_list_t		*tran_props;
1927c478bd9Sstevel@tonic-gate };
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate struct scf_iter {
1957c478bd9Sstevel@tonic-gate 	scf_handle_t	*iter_handle;
1967c478bd9Sstevel@tonic-gate 	int		iter_type;
1977c478bd9Sstevel@tonic-gate 	uint32_t	iter_id;
1987c478bd9Sstevel@tonic-gate 	uint32_t	iter_sequence;
1997c478bd9Sstevel@tonic-gate 	uu_list_node_t	iter_node;
2007c478bd9Sstevel@tonic-gate };
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate #endif
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #endif	/* _LOWLEVEL_IMPL_H */
207