xref: /titanic_53/usr/src/cmd/svc/configd/configd.h (revision 5b7f77ad52bf657ba49d64d16f527e958d0fb820)
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*5b7f77adStw21770  * Common Development and Distribution License (the "License").
6*5b7f77adStw21770  * 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*5b7f77adStw21770  * 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	_CONFIGD_H
277c478bd9Sstevel@tonic-gate #define	_CONFIGD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
31*5b7f77adStw21770 #include <bsm/adt.h>
327c478bd9Sstevel@tonic-gate #include <door.h>
337c478bd9Sstevel@tonic-gate #include <pthread.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <libscf.h>
387c478bd9Sstevel@tonic-gate #include <repcache_protocol.h>
397c478bd9Sstevel@tonic-gate #include <libuutil.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <configd_exit.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Lock order:
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  *	client lock
517c478bd9Sstevel@tonic-gate  *		iter locks, in ID order
527c478bd9Sstevel@tonic-gate  *		entity locks, in ID order
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  *		(any iter/entity locks)
557c478bd9Sstevel@tonic-gate  *			backend locks (NORMAL, then NONPERSIST)
567c478bd9Sstevel@tonic-gate  *				rc_node lock
577c478bd9Sstevel@tonic-gate  *					children's rc_node lock
587c478bd9Sstevel@tonic-gate  *				cache bucket lock
597c478bd9Sstevel@tonic-gate  *					rc_node lock[*]
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  *	* only one node may be grabbed while holding a bucket lock
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  *	leaf locks:  (no other locks may be aquired while holding one)
647c478bd9Sstevel@tonic-gate  *		rc_pg_notify_lock
65*5b7f77adStw21770  *		rc_annotate_lock
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Returns the minimum size for a structure of type 't' such
707c478bd9Sstevel@tonic-gate  * that it is safe to access field 'f'.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	offsetofend(t, f)	(offsetof(t, f) + sizeof (((t *)0)->f))
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * We want MUTEX_HELD, but we also want pthreads.  So we're stuck with this.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate struct _lwp_mutex_t;
787c478bd9Sstevel@tonic-gate extern int _mutex_held(struct _lwp_mutex_t *);
797c478bd9Sstevel@tonic-gate #define	MUTEX_HELD(m)		_mutex_held((struct _lwp_mutex_t *)(m))
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Maximum levels of composition.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #define	COMPOSITION_DEPTH	2
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * The default locations of the repository dbs
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate #define	REPOSITORY_DB	"/etc/svc/repository.db"
907c478bd9Sstevel@tonic-gate #define	NONPERSIST_DB	"/etc/svc/volatile/svc_nonpersist.db"
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #define	CONFIGD_CORE	"core.%f.%t.%p"
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #ifndef NDEBUG
957c478bd9Sstevel@tonic-gate #define	bad_error(f, e)							\
967c478bd9Sstevel@tonic-gate 	uu_warn("%s:%d: %s() returned bad error %d.  Aborting.\n",	\
977c478bd9Sstevel@tonic-gate 	    __FILE__, __LINE__, f, e);					\
987c478bd9Sstevel@tonic-gate 	abort()
997c478bd9Sstevel@tonic-gate #else
1007c478bd9Sstevel@tonic-gate #define	bad_error(f, e)		abort()
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate typedef enum backend_type {
1047c478bd9Sstevel@tonic-gate 	BACKEND_TYPE_NORMAL		= 0,
1057c478bd9Sstevel@tonic-gate 	BACKEND_TYPE_NONPERSIST,
1067c478bd9Sstevel@tonic-gate 	BACKEND_TYPE_TOTAL			/* backend use only */
1077c478bd9Sstevel@tonic-gate } backend_type_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * pre-declare rc_* types
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate typedef struct rc_node rc_node_t;
1137c478bd9Sstevel@tonic-gate typedef struct rc_snapshot rc_snapshot_t;
1147c478bd9Sstevel@tonic-gate typedef struct rc_snaplevel rc_snaplevel_t;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * notification layer -- protected by rc_pg_notify_lock
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate typedef struct rc_notify_info rc_notify_info_t;
1207c478bd9Sstevel@tonic-gate typedef struct rc_notify_delete rc_notify_delete_t;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_MAX_NAMES	4	/* enough for now */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate typedef struct rc_notify {
1257c478bd9Sstevel@tonic-gate 	uu_list_node_t	rcn_list_node;
1267c478bd9Sstevel@tonic-gate 	rc_node_t	*rcn_node;
1277c478bd9Sstevel@tonic-gate 	rc_notify_info_t *rcn_info;
1287c478bd9Sstevel@tonic-gate 	rc_notify_delete_t *rcn_delete;
1297c478bd9Sstevel@tonic-gate } rc_notify_t;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate struct rc_notify_delete {
1327c478bd9Sstevel@tonic-gate 	rc_notify_t rnd_notify;
1337c478bd9Sstevel@tonic-gate 	char rnd_fmri[REP_PROTOCOL_FMRI_LEN];
1347c478bd9Sstevel@tonic-gate };
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate struct rc_notify_info {
1377c478bd9Sstevel@tonic-gate 	uu_list_node_t	rni_list_node;
1387c478bd9Sstevel@tonic-gate 	rc_notify_t	rni_notify;
1397c478bd9Sstevel@tonic-gate 	const char	*rni_namelist[RC_NOTIFY_MAX_NAMES];
1407c478bd9Sstevel@tonic-gate 	const char	*rni_typelist[RC_NOTIFY_MAX_NAMES];
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	int		rni_flags;
1437c478bd9Sstevel@tonic-gate 	int		rni_waiters;
1447c478bd9Sstevel@tonic-gate 	pthread_cond_t	rni_cv;
1457c478bd9Sstevel@tonic-gate };
1467c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_ACTIVE	0x00000001
1477c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_DRAIN		0x00000002
1487c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_EMPTYING	0x00000004
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate typedef struct rc_node_pg_notify {
1517c478bd9Sstevel@tonic-gate 	uu_list_node_t	rnpn_node;
1527c478bd9Sstevel@tonic-gate 	int		rnpn_fd;
1537c478bd9Sstevel@tonic-gate 	rc_node_t	*rnpn_pg;
1547c478bd9Sstevel@tonic-gate } rc_node_pg_notify_t;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * cache layer
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate  * The 'key' for the main object hash.  main_id is the main object
1627c478bd9Sstevel@tonic-gate  * identifier.  The rl_ids array contains:
1637c478bd9Sstevel@tonic-gate  *
1647c478bd9Sstevel@tonic-gate  *	TYPE		RL_IDS
1657c478bd9Sstevel@tonic-gate  *	scope		unused
1667c478bd9Sstevel@tonic-gate  *	service		unused
1677c478bd9Sstevel@tonic-gate  *	instance	{service_id}
1687c478bd9Sstevel@tonic-gate  *	snapshot	{service_id, instance_id}
1697c478bd9Sstevel@tonic-gate  *	snaplevel	{service_id, instance_id, name_id, snapshot_id}
1707c478bd9Sstevel@tonic-gate  *	propertygroup	{service_id, (instance_id or 0), (name_id or 0),
1717c478bd9Sstevel@tonic-gate  *			    (snapshot_id or 0), (l_id or 0)}
1727c478bd9Sstevel@tonic-gate  *	property	{service_id, (instance_id or 0), (name_id or 0),
1737c478bd9Sstevel@tonic-gate  *			    (snapshot_id or 0), (l_id or 0), pg_id, gen_id}
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate #define	ID_SERVICE	0
1767c478bd9Sstevel@tonic-gate #define	ID_INSTANCE	1
1777c478bd9Sstevel@tonic-gate #define	ID_NAME		2
1787c478bd9Sstevel@tonic-gate #define	ID_SNAPSHOT	3
1797c478bd9Sstevel@tonic-gate #define	ID_LEVEL	4
1807c478bd9Sstevel@tonic-gate #define	ID_PG		5
1817c478bd9Sstevel@tonic-gate #define	ID_GEN		6
1827c478bd9Sstevel@tonic-gate #define	MAX_IDS	7
1837c478bd9Sstevel@tonic-gate typedef struct rc_node_lookup {
1847c478bd9Sstevel@tonic-gate 	uint16_t	rl_type;		/* REP_PROTOCOL_ENTITY_* */
1857c478bd9Sstevel@tonic-gate 	uint16_t	rl_backend;		/* BACKEND_TYPE_* */
1867c478bd9Sstevel@tonic-gate 	uint32_t	rl_main_id;		/* primary identifier */
1877c478bd9Sstevel@tonic-gate 	uint32_t	rl_ids[MAX_IDS];	/* context */
1887c478bd9Sstevel@tonic-gate } rc_node_lookup_t;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate struct rc_node {
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * read-only data
1937c478bd9Sstevel@tonic-gate 	 */
1947c478bd9Sstevel@tonic-gate 	rc_node_lookup_t rn_id;			/* must be first */
1957c478bd9Sstevel@tonic-gate 	uint32_t	rn_hash;
1967c478bd9Sstevel@tonic-gate 	const char	*rn_name;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	/*
1997c478bd9Sstevel@tonic-gate 	 * type-specific state
2007c478bd9Sstevel@tonic-gate 	 * (if space becomes an issue, these can become a union)
2017c478bd9Sstevel@tonic-gate 	 */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	/*
2047c478bd9Sstevel@tonic-gate 	 * Used by instances, snapshots, and "composed property groups" only.
2057c478bd9Sstevel@tonic-gate 	 * These are the entities whose properties should appear composed when
2067c478bd9Sstevel@tonic-gate 	 * this entity is traversed by a composed iterator.  0 is the top-most
2077c478bd9Sstevel@tonic-gate 	 * entity, down to COMPOSITION_DEPTH - 1.
2087c478bd9Sstevel@tonic-gate 	 */
2097c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_cchain[COMPOSITION_DEPTH];
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	/*
2127c478bd9Sstevel@tonic-gate 	 * used by property groups only
2137c478bd9Sstevel@tonic-gate 	 */
2147c478bd9Sstevel@tonic-gate 	const char	*rn_type;
2157c478bd9Sstevel@tonic-gate 	uint32_t	rn_pgflags;
2167c478bd9Sstevel@tonic-gate 	uint32_t	rn_gen_id;
2177c478bd9Sstevel@tonic-gate 	uu_list_t	*rn_pg_notify_list;	/* prot by rc_pg_notify_lock */
2187c478bd9Sstevel@tonic-gate 	rc_notify_t	rn_notify;		/* prot by rc_pg_notify_lock */
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * used by properties only
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t rn_valtype;
2247c478bd9Sstevel@tonic-gate 	const char	*rn_values;		/* protected by rn_lock */
2257c478bd9Sstevel@tonic-gate 	size_t		rn_values_count;	/* protected by rn_lock */
2267c478bd9Sstevel@tonic-gate 	size_t		rn_values_size;		/* protected by rn_lock */
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	 * used by snapshots only
2307c478bd9Sstevel@tonic-gate 	 */
2317c478bd9Sstevel@tonic-gate 	uint32_t	rn_snapshot_id;
2327c478bd9Sstevel@tonic-gate 	rc_snapshot_t	*rn_snapshot;		/* protected by rn_lock */
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	/*
2357c478bd9Sstevel@tonic-gate 	 * used by snaplevels only
2367c478bd9Sstevel@tonic-gate 	 */
2377c478bd9Sstevel@tonic-gate 	rc_snaplevel_t	*rn_snaplevel;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	/*
2407c478bd9Sstevel@tonic-gate 	 * mutable state
2417c478bd9Sstevel@tonic-gate 	 */
2427c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rn_lock;
2437c478bd9Sstevel@tonic-gate 	pthread_cond_t	rn_cv;
2447c478bd9Sstevel@tonic-gate 	uint32_t	rn_flags;
2457c478bd9Sstevel@tonic-gate 	uint32_t	rn_refs;		/* reference count */
2467c478bd9Sstevel@tonic-gate 	uint32_t	rn_other_refs;		/* atomic refcount */
2477c478bd9Sstevel@tonic-gate 	uint32_t	rn_other_refs_held;	/* for 1->0 transitions */
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	uu_list_t	*rn_children;
2507c478bd9Sstevel@tonic-gate 	uu_list_node_t	rn_sibling_node;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_parent;		/* set if on child list */
2537c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_former;		/* next former node */
2547c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_parent_ref;		/* reference count target */
255*5b7f77adStw21770 	const char	*rn_fmri;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	/*
2587c478bd9Sstevel@tonic-gate 	 * external state (protected by hash chain lock)
2597c478bd9Sstevel@tonic-gate 	 */
2607c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_hash_next;
2617c478bd9Sstevel@tonic-gate };
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate  * flag ordering:
2657c478bd9Sstevel@tonic-gate  *	RC_DYING
2667c478bd9Sstevel@tonic-gate  *		RC_NODE_CHILDREN_CHANGING
2677c478bd9Sstevel@tonic-gate  *		RC_NODE_CREATING_CHILD
2687c478bd9Sstevel@tonic-gate  *		RC_NODE_USING_PARENT
2697c478bd9Sstevel@tonic-gate  *			RC_NODE_IN_TX
2707c478bd9Sstevel@tonic-gate  *
2717c478bd9Sstevel@tonic-gate  * RC_NODE_USING_PARENT is special, because it lets you proceed up the tree,
2727c478bd9Sstevel@tonic-gate  * in the reverse of the usual locking order.  Because of this, there are
2737c478bd9Sstevel@tonic-gate  * limitations on what you can do while holding it.  While holding
2747c478bd9Sstevel@tonic-gate  * RC_NODE_USING_PARENT, you may:
2757c478bd9Sstevel@tonic-gate  *	bump or release your parent's reference count
2767c478bd9Sstevel@tonic-gate  *	access fields in your parent
2777c478bd9Sstevel@tonic-gate  *	hold RC_NODE_USING_PARENT in the parent, proceeding recursively.
2787c478bd9Sstevel@tonic-gate  *
2797c478bd9Sstevel@tonic-gate  * If you are only holding *one* node's RC_NODE_USING_PARENT, and:
2807c478bd9Sstevel@tonic-gate  *	you are *not* proceeding recursively, you can hold your
2817c478bd9Sstevel@tonic-gate  *	    immediate parent's RC_NODE_CHILDREN_CHANGING flag.
2827c478bd9Sstevel@tonic-gate  *	you hold your parent's RC_NODE_CHILDREN_CHANGING flag, you can add
2837c478bd9Sstevel@tonic-gate  *	    RC_NODE_IN_TX to your flags.
2847c478bd9Sstevel@tonic-gate  *	you want to grab a flag in your parent, you must lock your parent,
2857c478bd9Sstevel@tonic-gate  *	    lock yourself, drop RC_NODE_USING_PARENT, unlock yourself,
2867c478bd9Sstevel@tonic-gate  *	    then proceed to manipulate the parent.
2877c478bd9Sstevel@tonic-gate  */
2887c478bd9Sstevel@tonic-gate #define	RC_NODE_CHILDREN_CHANGING	0x00000001 /* child list in flux */
2897c478bd9Sstevel@tonic-gate #define	RC_NODE_HAS_CHILDREN		0x00000002 /* child list is accurate */
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate #define	RC_NODE_IN_PARENT		0x00000004 /* I'm in my parent's list */
2927c478bd9Sstevel@tonic-gate #define	RC_NODE_USING_PARENT		0x00000008 /* parent ptr in use */
2937c478bd9Sstevel@tonic-gate #define	RC_NODE_CREATING_CHILD		0x00000010 /* a create is in progress */
2947c478bd9Sstevel@tonic-gate #define	RC_NODE_IN_TX			0x00000020 /* a tx is in progess */
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate #define	RC_NODE_OLD			0x00000400 /* out-of-date object */
2977c478bd9Sstevel@tonic-gate #define	RC_NODE_ON_FORMER		0x00000800 /* on an rn_former list */
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate #define	RC_NODE_PARENT_REF		0x00001000 /* parent_ref in use */
3007c478bd9Sstevel@tonic-gate #define	RC_NODE_UNREFED			0x00002000 /* unref processing active */
3017c478bd9Sstevel@tonic-gate #define	RC_NODE_DYING			0x00004000 /* node is being deleted */
3027c478bd9Sstevel@tonic-gate #define	RC_NODE_DEAD			0x00008000 /* node has been deleted */
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate #define	RC_NODE_DYING_FLAGS						\
3057c478bd9Sstevel@tonic-gate 	(RC_NODE_CHILDREN_CHANGING | RC_NODE_IN_TX | RC_NODE_DYING |	\
3067c478bd9Sstevel@tonic-gate 	    RC_NODE_CREATING_CHILD)
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate #define	RC_NODE_WAITING_FLAGS						\
3097c478bd9Sstevel@tonic-gate 	(RC_NODE_DYING_FLAGS | RC_NODE_USING_PARENT)
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 
312*5b7f77adStw21770 typedef enum rc_auth_state {
313*5b7f77adStw21770 	RC_AUTH_UNKNOWN = 0,		/* No checks done yet. */
314*5b7f77adStw21770 	RC_AUTH_FAILED,			/* Authorization checked & failed. */
315*5b7f77adStw21770 	RC_AUTH_PASSED			/* Authorization succeeded. */
316*5b7f77adStw21770 } rc_auth_state_t;
317*5b7f77adStw21770 
318*5b7f77adStw21770 /*
319*5b7f77adStw21770  * Some authorization checks are performed in rc_node_setup_tx() in
320*5b7f77adStw21770  * response to the REP_PROTOCOL_PROPERTYGRP_TX_START message.  Other checks
321*5b7f77adStw21770  * must wait until the actual transaction operations are received in the
322*5b7f77adStw21770  * REP_PROTOCOL_PROPERTYGRP_TX_COMMIT message.  This second set of checks
323*5b7f77adStw21770  * is performed in rc_tx_commit().  rnp_auth_string and rnp_authorized in
324*5b7f77adStw21770  * the following structure are used to hold the results of the
325*5b7f77adStw21770  * authorization checking done in rc_node_setup_tx() for later use by
326*5b7f77adStw21770  * rc_tx_commit().
327*5b7f77adStw21770  *
328*5b7f77adStw21770  * In client.c transactions are represented by rc_node_ptr structures which
329*5b7f77adStw21770  * point to a property group rc_node_t.  Thus, this is an appropriate place
330*5b7f77adStw21770  * to hold authorization state.
331*5b7f77adStw21770  */
3327c478bd9Sstevel@tonic-gate typedef struct rc_node_ptr {
3337c478bd9Sstevel@tonic-gate 	rc_node_t	*rnp_node;
334*5b7f77adStw21770 	const char	*rnp_auth_string;	/* authorization string */
335*5b7f77adStw21770 	rc_auth_state_t	rnp_authorized;		/* transaction pre-auth rslt. */
3367c478bd9Sstevel@tonic-gate 	char		rnp_deleted;		/* object was deleted */
3377c478bd9Sstevel@tonic-gate } rc_node_ptr_t;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate #define	NODE_PTR_NOT_HELD(npp) \
3407c478bd9Sstevel@tonic-gate 	    ((npp)->rnp_node == NULL || !MUTEX_HELD(&(npp)->rnp_node->rn_lock))
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate typedef int rc_iter_filter_func(rc_node_t *, void *);
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate typedef struct rc_node_iter {
3457c478bd9Sstevel@tonic-gate 	rc_node_t	*rni_parent;
3467c478bd9Sstevel@tonic-gate 	int		rni_clevel;	/* index into rni_parent->rn_cchain[] */
3477c478bd9Sstevel@tonic-gate 	rc_node_t	*rni_iter_node;
3487c478bd9Sstevel@tonic-gate 	uu_list_walk_t	*rni_iter;
3497c478bd9Sstevel@tonic-gate 	uint32_t	rni_type;
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	/*
3527c478bd9Sstevel@tonic-gate 	 * for normal walks
3537c478bd9Sstevel@tonic-gate 	 */
3547c478bd9Sstevel@tonic-gate 	rc_iter_filter_func *rni_filter;
3557c478bd9Sstevel@tonic-gate 	void		*rni_filter_arg;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	/*
3587c478bd9Sstevel@tonic-gate 	 * for value walks
3597c478bd9Sstevel@tonic-gate 	 */
3607c478bd9Sstevel@tonic-gate 	uint32_t	rni_offset;		/* next value offset */
3617c478bd9Sstevel@tonic-gate 	uint32_t	rni_last_offset;	/* previous value offset */
3627c478bd9Sstevel@tonic-gate } rc_node_iter_t;
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate typedef struct rc_node_tx {
3657c478bd9Sstevel@tonic-gate 	rc_node_ptr_t	rnt_ptr;
3667c478bd9Sstevel@tonic-gate 	int		rnt_authorized;		/* No need to check anymore. */
3677c478bd9Sstevel@tonic-gate } rc_node_tx_t;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate typedef struct cache_bucket {
3717c478bd9Sstevel@tonic-gate 	pthread_mutex_t	cb_lock;
3727c478bd9Sstevel@tonic-gate 	rc_node_t	*cb_head;
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	char		cb_pad[64 - sizeof (pthread_mutex_t) -
3757c478bd9Sstevel@tonic-gate 			    2 * sizeof (rc_node_t *)];
3767c478bd9Sstevel@tonic-gate } cache_bucket_t;
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate /*
379*5b7f77adStw21770  * tx_commit_data_tx is an opaque structure which is defined in object.c.
380*5b7f77adStw21770  * It contains the data of the transaction that is to be committed.
381*5b7f77adStw21770  * Accessor functions in object.c allow other modules to retrieve
382*5b7f77adStw21770  * information.
383*5b7f77adStw21770  */
384*5b7f77adStw21770 typedef struct tx_commit_data tx_commit_data_t;
385*5b7f77adStw21770 
386*5b7f77adStw21770 /*
3877c478bd9Sstevel@tonic-gate  * Snapshots
3887c478bd9Sstevel@tonic-gate  */
3897c478bd9Sstevel@tonic-gate struct rc_snapshot {
3907c478bd9Sstevel@tonic-gate 	uint32_t	rs_snap_id;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rs_lock;
3937c478bd9Sstevel@tonic-gate 	pthread_cond_t	rs_cv;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	uint32_t	rs_flags;
3967c478bd9Sstevel@tonic-gate 	uint32_t	rs_refcnt;	/* references from rc_nodes */
3977c478bd9Sstevel@tonic-gate 	uint32_t	rs_childref;	/* references to children */
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	rc_snaplevel_t	*rs_levels;	/* list of levels */
4007c478bd9Sstevel@tonic-gate 	rc_snapshot_t	*rs_hash_next;
4017c478bd9Sstevel@tonic-gate };
4027c478bd9Sstevel@tonic-gate #define	RC_SNAPSHOT_FILLING	0x00000001	/* rs_levels changing */
4037c478bd9Sstevel@tonic-gate #define	RC_SNAPSHOT_READY	0x00000002
4047c478bd9Sstevel@tonic-gate #define	RC_SNAPSHOT_DEAD	0x00000004	/* no resources */
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate typedef struct rc_snaplevel_pgs {
4077c478bd9Sstevel@tonic-gate 	uint32_t	rsp_pg_id;
4087c478bd9Sstevel@tonic-gate 	uint32_t	rsp_gen_id;
4097c478bd9Sstevel@tonic-gate } rc_snaplevel_pgs_t;
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate struct rc_snaplevel {
4127c478bd9Sstevel@tonic-gate 	rc_snapshot_t	*rsl_parent;
4137c478bd9Sstevel@tonic-gate 	uint32_t	rsl_level_num;
4147c478bd9Sstevel@tonic-gate 	uint32_t	rsl_level_id;
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	uint32_t	rsl_service_id;
4177c478bd9Sstevel@tonic-gate 	uint32_t	rsl_instance_id;
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	const char	*rsl_scope;
4207c478bd9Sstevel@tonic-gate 	const char	*rsl_service;
4217c478bd9Sstevel@tonic-gate 	const char	*rsl_instance;
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	rc_snaplevel_t	*rsl_next;
4247c478bd9Sstevel@tonic-gate };
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate /*
4277c478bd9Sstevel@tonic-gate  * Client layer -- the IDs fields must be first, in order for the search
4287c478bd9Sstevel@tonic-gate  * routines to work correctly.
4297c478bd9Sstevel@tonic-gate  */
4307c478bd9Sstevel@tonic-gate enum repcache_txstate {
4317c478bd9Sstevel@tonic-gate 	REPCACHE_TX_INIT,
4327c478bd9Sstevel@tonic-gate 	REPCACHE_TX_SETUP,
4337c478bd9Sstevel@tonic-gate 	REPCACHE_TX_COMMITTED
4347c478bd9Sstevel@tonic-gate };
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate typedef struct repcache_entity {
4377c478bd9Sstevel@tonic-gate 	uint32_t	re_id;
4388918dff3Sjwadams 	uu_avl_node_t	re_link;
4397c478bd9Sstevel@tonic-gate 	uint32_t	re_changeid;
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	pthread_mutex_t	re_lock;
4427c478bd9Sstevel@tonic-gate 	uint32_t	re_type;
4437c478bd9Sstevel@tonic-gate 	rc_node_ptr_t	re_node;
4447c478bd9Sstevel@tonic-gate 	enum repcache_txstate re_txstate;	/* property groups only */
4457c478bd9Sstevel@tonic-gate } repcache_entity_t;
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate typedef struct repcache_iter {
4487c478bd9Sstevel@tonic-gate 	uint32_t	ri_id;
4498918dff3Sjwadams 	uu_avl_node_t	ri_link;
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	uint32_t	ri_type;	/* result type */
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	pthread_mutex_t	ri_lock;
4547c478bd9Sstevel@tonic-gate 	uint32_t	ri_sequence;
4557c478bd9Sstevel@tonic-gate 	rc_node_iter_t	*ri_iter;
4567c478bd9Sstevel@tonic-gate } repcache_iter_t;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate typedef struct repcache_client {
4597c478bd9Sstevel@tonic-gate 	/*
4607c478bd9Sstevel@tonic-gate 	 * constants
4617c478bd9Sstevel@tonic-gate 	 */
4627c478bd9Sstevel@tonic-gate 	uint32_t	rc_id;		/* must be first */
4637c478bd9Sstevel@tonic-gate 	int		rc_all_auths;	/* bypass auth checks */
4647c478bd9Sstevel@tonic-gate 	uint32_t	rc_debug;	/* debug flags */
4657c478bd9Sstevel@tonic-gate 	pid_t		rc_pid;		/* pid of opening process */
4667c478bd9Sstevel@tonic-gate 	door_id_t	rc_doorid;	/* a globally unique identifier */
4677c478bd9Sstevel@tonic-gate 	int		rc_doorfd;	/* our door's FD */
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	/*
470*5b7f77adStw21770 	 * Constants used for security auditing
471*5b7f77adStw21770 	 *
472*5b7f77adStw21770 	 * rc_adt_session points to the audit session data that is used for
473*5b7f77adStw21770 	 * the life of the client.  rc_adt_sessionid is the session ID that
474*5b7f77adStw21770 	 * is initially assigned when the audit session is started.  See
475*5b7f77adStw21770 	 * start_audit_session() in client.c.  This session id is used for
476*5b7f77adStw21770 	 * audit events except when we are processing a set of annotated
477*5b7f77adStw21770 	 * events.  Annotated events use a separate session id so that they
478*5b7f77adStw21770 	 * can be grouped.  See set_annotation() in client.c.
479*5b7f77adStw21770 	 */
480*5b7f77adStw21770 	adt_session_data_t *rc_adt_session;	/* Session data. */
481*5b7f77adStw21770 	au_asid_t	rc_adt_sessionid;	/* Main session ID for */
482*5b7f77adStw21770 						/* auditing */
483*5b7f77adStw21770 
484*5b7f77adStw21770 	/*
4857c478bd9Sstevel@tonic-gate 	 * client list linkage, protected by hash chain lock
4867c478bd9Sstevel@tonic-gate 	 */
4877c478bd9Sstevel@tonic-gate 	uu_list_node_t	rc_link;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	/*
4907c478bd9Sstevel@tonic-gate 	 * notification information, protected by rc_node layer
4917c478bd9Sstevel@tonic-gate 	 */
4927c478bd9Sstevel@tonic-gate 	rc_node_pg_notify_t	rc_pg_notify;
4937c478bd9Sstevel@tonic-gate 	rc_notify_info_t	rc_notify_info;
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 	/*
4967c478bd9Sstevel@tonic-gate 	 * client_wait output, only usable by rc_notify_thr
4977c478bd9Sstevel@tonic-gate 	 */
4987c478bd9Sstevel@tonic-gate 	rc_node_ptr_t	rc_notify_ptr;
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 	/*
5018918dff3Sjwadams 	 * register sets, protected by rc_lock
5027c478bd9Sstevel@tonic-gate 	 */
5038918dff3Sjwadams 	uu_avl_t	*rc_entities;
5048918dff3Sjwadams 	uu_avl_t	*rc_iters;
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 	/*
5077c478bd9Sstevel@tonic-gate 	 * Variables, protected by rc_lock
5087c478bd9Sstevel@tonic-gate 	 */
5097c478bd9Sstevel@tonic-gate 	int		rc_refcnt;	/* in-progress door calls */
510*5b7f77adStw21770 	int		rc_flags;	/* see RC_CLIENT_* symbols below */
5117c478bd9Sstevel@tonic-gate 	uint32_t	rc_changeid;	/* used to make backups idempotent */
5127c478bd9Sstevel@tonic-gate 	pthread_t	rc_insert_thr;	/* single thread trying to insert */
5137c478bd9Sstevel@tonic-gate 	pthread_t	rc_notify_thr;	/* single thread waiting for notify */
5147c478bd9Sstevel@tonic-gate 	pthread_cond_t	rc_cv;
5157c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rc_lock;
516*5b7f77adStw21770 
517*5b7f77adStw21770 	/*
518*5b7f77adStw21770 	 * Per-client audit information.  These fields must be protected by
519*5b7f77adStw21770 	 * rc_annotate_lock separately from rc_lock because they may need
520*5b7f77adStw21770 	 * to be accessed from rc_node.c with an entity or iterator lock
521*5b7f77adStw21770 	 * held, and those must be taken after rc_lock.
522*5b7f77adStw21770 	 */
523*5b7f77adStw21770 	int		rc_annotate;	/* generate annotation event if set */
524*5b7f77adStw21770 	const char	*rc_operation;	/* operation for audit annotation */
525*5b7f77adStw21770 	const char	*rc_file;	/* file name for audit annotation */
526*5b7f77adStw21770 	pthread_mutex_t	rc_annotate_lock;
5277c478bd9Sstevel@tonic-gate } repcache_client_t;
528*5b7f77adStw21770 
529*5b7f77adStw21770 /* Bit definitions for rc_flags. */
5307c478bd9Sstevel@tonic-gate #define	RC_CLIENT_DEAD			0x00000001
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate typedef struct client_bucket {
5337c478bd9Sstevel@tonic-gate 	pthread_mutex_t	cb_lock;
5347c478bd9Sstevel@tonic-gate 	uu_list_t	*cb_list;
5357c478bd9Sstevel@tonic-gate 	char ch_pad[64 - sizeof (pthread_mutex_t) - sizeof (uu_list_t *)];
5367c478bd9Sstevel@tonic-gate } client_bucket_t;
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate enum rc_ptr_type {
5397c478bd9Sstevel@tonic-gate 	RC_PTR_TYPE_ENTITY = 1,
5407c478bd9Sstevel@tonic-gate 	RC_PTR_TYPE_ITER
5417c478bd9Sstevel@tonic-gate };
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate typedef struct request_log_ptr {
5447c478bd9Sstevel@tonic-gate 	enum rc_ptr_type	rlp_type;
5457c478bd9Sstevel@tonic-gate 	uint32_t		rlp_id;
5467c478bd9Sstevel@tonic-gate 	void			*rlp_ptr; /* repcache_{entity,iter}_t */
5477c478bd9Sstevel@tonic-gate 	void			*rlp_data;	/* rc_node, for ENTITY only */
5487c478bd9Sstevel@tonic-gate } request_log_ptr_t;
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate #define	MAX_PTRS	3
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate /*
5537c478bd9Sstevel@tonic-gate  * rl_start through rl_client cannot move without changing start_log()
5547c478bd9Sstevel@tonic-gate  */
5557c478bd9Sstevel@tonic-gate typedef struct request_log_entry {
5567c478bd9Sstevel@tonic-gate 	hrtime_t		rl_start;
5577c478bd9Sstevel@tonic-gate 	hrtime_t		rl_end;
5587c478bd9Sstevel@tonic-gate 	pthread_t		rl_tid;
5597c478bd9Sstevel@tonic-gate 	uint32_t		rl_clientid;
5607c478bd9Sstevel@tonic-gate 	repcache_client_t	*rl_client;
5617c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rl_request;
5627c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rl_response;
5637c478bd9Sstevel@tonic-gate 	int			rl_num_ptrs;
5647c478bd9Sstevel@tonic-gate 	request_log_ptr_t	rl_ptrs[MAX_PTRS];
5657c478bd9Sstevel@tonic-gate } request_log_entry_t;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate /*
5687c478bd9Sstevel@tonic-gate  * thread information
5697c478bd9Sstevel@tonic-gate  */
5707c478bd9Sstevel@tonic-gate typedef enum thread_state {
5717c478bd9Sstevel@tonic-gate 	TI_CREATED,
5727c478bd9Sstevel@tonic-gate 	TI_DOOR_RETURN,
5737c478bd9Sstevel@tonic-gate 	TI_SIGNAL_WAIT,
5747c478bd9Sstevel@tonic-gate 	TI_MAIN_DOOR_CALL,
5757c478bd9Sstevel@tonic-gate 	TI_CLIENT_CALL
5767c478bd9Sstevel@tonic-gate } thread_state_t;
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate typedef struct thread_info {
5797c478bd9Sstevel@tonic-gate 	pthread_t	ti_thread;
5807c478bd9Sstevel@tonic-gate 	uu_list_node_t	ti_node;		/* for list of all thread */
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	/*
5837c478bd9Sstevel@tonic-gate 	 * per-thread globals
5847c478bd9Sstevel@tonic-gate 	 */
5857c478bd9Sstevel@tonic-gate 	ucred_t		*ti_ucred;		/* for credential lookups */
5867c478bd9Sstevel@tonic-gate 	int		ti_ucred_read;		/* ucred holds current creds */
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 	/*
5897c478bd9Sstevel@tonic-gate 	 * per-thread state information, for debuggers
5907c478bd9Sstevel@tonic-gate 	 */
5917c478bd9Sstevel@tonic-gate 	hrtime_t	ti_lastchange;
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	thread_state_t	ti_state;
5947c478bd9Sstevel@tonic-gate 	thread_state_t	ti_prev_state;
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	repcache_client_t *ti_active_client;
5977c478bd9Sstevel@tonic-gate 	request_log_entry_t	ti_log;
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 	struct rep_protocol_request *ti_client_request;
6007c478bd9Sstevel@tonic-gate 	repository_door_request_t *ti_main_door_request;
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate } thread_info_t;
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate  * Backend layer
6067c478bd9Sstevel@tonic-gate  */
6077c478bd9Sstevel@tonic-gate typedef struct backend_query backend_query_t;
6087c478bd9Sstevel@tonic-gate typedef struct backend_tx backend_tx_t;
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /*
6117c478bd9Sstevel@tonic-gate  * configd.c
6127c478bd9Sstevel@tonic-gate  */
6137c478bd9Sstevel@tonic-gate int create_connection(ucred_t *cred, repository_door_request_t *rp,
6147c478bd9Sstevel@tonic-gate     size_t rp_size, int *out_fd);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate thread_info_t *thread_self(void);
6177c478bd9Sstevel@tonic-gate void thread_newstate(thread_info_t *, thread_state_t);
6187c478bd9Sstevel@tonic-gate ucred_t *get_ucred(void);
6197c478bd9Sstevel@tonic-gate int ucred_is_privileged(ucred_t *);
6207c478bd9Sstevel@tonic-gate 
621*5b7f77adStw21770 adt_session_data_t *get_audit_session(void);
622*5b7f77adStw21770 
6237c478bd9Sstevel@tonic-gate void configd_critical(const char *, ...);
6247c478bd9Sstevel@tonic-gate void configd_vcritical(const char *, va_list);
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate extern int is_main_repository;
6277c478bd9Sstevel@tonic-gate extern int max_repository_backups;
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate /*
6307c478bd9Sstevel@tonic-gate  * maindoor.c
6317c478bd9Sstevel@tonic-gate  */
6327c478bd9Sstevel@tonic-gate int setup_main_door(const char *);
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate /*
6357c478bd9Sstevel@tonic-gate  * client.c
6367c478bd9Sstevel@tonic-gate  */
637*5b7f77adStw21770 int client_annotation_needed(char *, size_t, char *, size_t);
638*5b7f77adStw21770 void client_annotation_finished(void);
6397c478bd9Sstevel@tonic-gate int create_client(pid_t, uint32_t, int, int *);
6407c478bd9Sstevel@tonic-gate int client_init(void);
6417c478bd9Sstevel@tonic-gate int client_is_privileged(void);
6427c478bd9Sstevel@tonic-gate void log_enter(request_log_entry_t *);
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate /*
6457c478bd9Sstevel@tonic-gate  * rc_node.c, backend/cache interfaces (rc_node_t)
6467c478bd9Sstevel@tonic-gate  */
6477c478bd9Sstevel@tonic-gate int rc_node_init();
6487c478bd9Sstevel@tonic-gate int rc_check_type_name(uint32_t, const char *);
6497c478bd9Sstevel@tonic-gate 
650*5b7f77adStw21770 void rc_node_ptr_free_mem(rc_node_ptr_t *);
6517c478bd9Sstevel@tonic-gate void rc_node_rele(rc_node_t *);
6527c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup(rc_node_t *, rc_node_lookup_t *,
6537c478bd9Sstevel@tonic-gate     const char *, rc_node_t *);
6547c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_pg(rc_node_t *, rc_node_lookup_t *, const char *,
6557c478bd9Sstevel@tonic-gate     const char *, uint32_t, uint32_t, rc_node_t *);
6567c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_snapshot(rc_node_t *, rc_node_lookup_t *, const char *,
6577c478bd9Sstevel@tonic-gate     uint32_t, rc_node_t *);
6587c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_snaplevel(rc_node_t *, rc_node_lookup_t *,
6597c478bd9Sstevel@tonic-gate     rc_snaplevel_t *, rc_node_t *);
6607c478bd9Sstevel@tonic-gate int rc_node_create_property(rc_node_t *, rc_node_lookup_t *,
6617c478bd9Sstevel@tonic-gate     const char *, rep_protocol_value_type_t, const char *, size_t, size_t);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate rc_node_t *rc_node_alloc(void);
6647c478bd9Sstevel@tonic-gate void rc_node_destroy(rc_node_t *);
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate /*
6677c478bd9Sstevel@tonic-gate  * rc_node.c, client interface (rc_node_ptr_t, rc_node_iter_t)
6687c478bd9Sstevel@tonic-gate  */
6697c478bd9Sstevel@tonic-gate void rc_node_ptr_init(rc_node_ptr_t *);
6707c478bd9Sstevel@tonic-gate int rc_local_scope(uint32_t, rc_node_ptr_t *);
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate void rc_node_clear(rc_node_ptr_t *, int);
6737c478bd9Sstevel@tonic-gate void rc_node_ptr_assign(rc_node_ptr_t *, const rc_node_ptr_t *);
6747c478bd9Sstevel@tonic-gate int rc_node_name(rc_node_ptr_t *, char *, size_t, uint32_t, size_t *);
6757c478bd9Sstevel@tonic-gate int rc_node_fmri(rc_node_ptr_t *, char *, size_t, size_t *);
6767c478bd9Sstevel@tonic-gate int rc_node_parent_type(rc_node_ptr_t *, uint32_t *);
6777c478bd9Sstevel@tonic-gate int rc_node_get_child(rc_node_ptr_t *, const char *, uint32_t, rc_node_ptr_t *);
6787c478bd9Sstevel@tonic-gate int rc_node_get_parent(rc_node_ptr_t *, uint32_t, rc_node_ptr_t *);
6797c478bd9Sstevel@tonic-gate int rc_node_get_property_type(rc_node_ptr_t *, rep_protocol_value_type_t *);
6807c478bd9Sstevel@tonic-gate int rc_node_get_property_value(rc_node_ptr_t *,
6817c478bd9Sstevel@tonic-gate     struct rep_protocol_value_response *, size_t *);
6827c478bd9Sstevel@tonic-gate int rc_node_create_child(rc_node_ptr_t *, uint32_t, const char *,
6837c478bd9Sstevel@tonic-gate     rc_node_ptr_t *);
6847c478bd9Sstevel@tonic-gate int rc_node_create_child_pg(rc_node_ptr_t *, uint32_t, const char *,
6857c478bd9Sstevel@tonic-gate     const char *, uint32_t, rc_node_ptr_t *);
6867c478bd9Sstevel@tonic-gate int rc_node_update(rc_node_ptr_t *);
6877c478bd9Sstevel@tonic-gate int rc_node_delete(rc_node_ptr_t *);
6887c478bd9Sstevel@tonic-gate int rc_node_next_snaplevel(rc_node_ptr_t *, rc_node_ptr_t *);
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate int rc_node_setup_iter(rc_node_ptr_t *, rc_node_iter_t **, uint32_t,
6917c478bd9Sstevel@tonic-gate     size_t, const char *);
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate int rc_iter_next(rc_node_iter_t *, rc_node_ptr_t *, uint32_t);
6947c478bd9Sstevel@tonic-gate int rc_iter_next_value(rc_node_iter_t *, struct rep_protocol_value_response *,
6957c478bd9Sstevel@tonic-gate     size_t *, int);
6967c478bd9Sstevel@tonic-gate void rc_iter_destroy(rc_node_iter_t **);
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate int rc_node_setup_tx(rc_node_ptr_t *, rc_node_ptr_t *);
6997c478bd9Sstevel@tonic-gate int rc_tx_commit(rc_node_ptr_t *, const void *, size_t);
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate void rc_pg_notify_init(rc_node_pg_notify_t *);
7027c478bd9Sstevel@tonic-gate int rc_pg_notify_setup(rc_node_pg_notify_t *, rc_node_ptr_t *, int);
7037c478bd9Sstevel@tonic-gate void rc_pg_notify_fini(rc_node_pg_notify_t *);
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate void rc_notify_info_init(rc_notify_info_t *);
7067c478bd9Sstevel@tonic-gate int rc_notify_info_add_name(rc_notify_info_t *, const char *);
7077c478bd9Sstevel@tonic-gate int rc_notify_info_add_type(rc_notify_info_t *, const char *);
7087c478bd9Sstevel@tonic-gate int rc_notify_info_wait(rc_notify_info_t *, rc_node_ptr_t *, char *, size_t);
7097c478bd9Sstevel@tonic-gate void rc_notify_info_fini(rc_notify_info_t *);
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate int rc_snapshot_take_new(rc_node_ptr_t *, const char *,
7127c478bd9Sstevel@tonic-gate     const char *, const char *, rc_node_ptr_t *);
7137c478bd9Sstevel@tonic-gate int rc_snapshot_take_attach(rc_node_ptr_t *, rc_node_ptr_t *);
7147c478bd9Sstevel@tonic-gate int rc_snapshot_attach(rc_node_ptr_t *, rc_node_ptr_t *);
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate /*
7177c478bd9Sstevel@tonic-gate  * file_object.c
7187c478bd9Sstevel@tonic-gate  */
7197c478bd9Sstevel@tonic-gate int object_fill_children(rc_node_t *);
7207c478bd9Sstevel@tonic-gate int object_create(rc_node_t *, uint32_t, const char *, rc_node_t **);
7217c478bd9Sstevel@tonic-gate int object_create_pg(rc_node_t *, uint32_t, const char *, const char *,
7227c478bd9Sstevel@tonic-gate     uint32_t, rc_node_t **);
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate int object_delete(rc_node_t *);
7257c478bd9Sstevel@tonic-gate void object_free_values(const char *, uint32_t, size_t, size_t);
7267c478bd9Sstevel@tonic-gate 
7278918dff3Sjwadams int object_fill_snapshot(rc_snapshot_t *);
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate int object_snapshot_take_new(rc_node_t *, const char *, const char *,
7307c478bd9Sstevel@tonic-gate     const char *, rc_node_t **);
7317c478bd9Sstevel@tonic-gate int object_snapshot_attach(rc_node_lookup_t *, uint32_t *, int);
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate /*
7347c478bd9Sstevel@tonic-gate  * object.c
7357c478bd9Sstevel@tonic-gate  */
736*5b7f77adStw21770 int object_tx_commit(rc_node_lookup_t *, tx_commit_data_t *, uint32_t *);
737*5b7f77adStw21770 
738*5b7f77adStw21770 /* Functions to access transaction commands. */
739*5b7f77adStw21770 int tx_cmd_action(tx_commit_data_t *, size_t,
740*5b7f77adStw21770     enum rep_protocol_transaction_action *);
741*5b7f77adStw21770 size_t tx_cmd_count(tx_commit_data_t *);
742*5b7f77adStw21770 int tx_cmd_nvalues(tx_commit_data_t *, size_t, uint32_t *);
743*5b7f77adStw21770 int tx_cmd_prop(tx_commit_data_t *, size_t, const char **);
744*5b7f77adStw21770 int tx_cmd_prop_type(tx_commit_data_t *, size_t, uint32_t *);
745*5b7f77adStw21770 int tx_cmd_value(tx_commit_data_t *, size_t, uint32_t, const char **);
746*5b7f77adStw21770 void tx_commit_data_free(tx_commit_data_t *);
747*5b7f77adStw21770 int tx_commit_data_new(const void *, size_t, tx_commit_data_t **);
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate /*
7507c478bd9Sstevel@tonic-gate  * snapshot.c
7517c478bd9Sstevel@tonic-gate  */
7527c478bd9Sstevel@tonic-gate int rc_snapshot_get(uint32_t, rc_snapshot_t **);
7537c478bd9Sstevel@tonic-gate void rc_snapshot_rele(rc_snapshot_t *);
7547c478bd9Sstevel@tonic-gate void rc_snaplevel_hold(rc_snaplevel_t *);
7557c478bd9Sstevel@tonic-gate void rc_snaplevel_rele(rc_snaplevel_t *);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate /*
7587c478bd9Sstevel@tonic-gate  * backend.c
7597c478bd9Sstevel@tonic-gate  */
7607c478bd9Sstevel@tonic-gate int backend_init(const char *, const char *, int);
7617c478bd9Sstevel@tonic-gate void backend_fini(void);
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate rep_protocol_responseid_t backend_create_backup(const char *);
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate /*
7667c478bd9Sstevel@tonic-gate  * call on any database inconsistency -- cleans up state as best it can,
7677c478bd9Sstevel@tonic-gate  * and exits with a "Database Bad" error code.
7687c478bd9Sstevel@tonic-gate  */
7690b5c9250Shg115875 void backend_panic(const char *, ...) __NORETURN;
7707c478bd9Sstevel@tonic-gate #pragma rarely_called(backend_panic)
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate backend_query_t *backend_query_alloc(void);
7737c478bd9Sstevel@tonic-gate void backend_query_append(backend_query_t *, const char *);
7747c478bd9Sstevel@tonic-gate void backend_query_add(backend_query_t *, const char *, ...);
7757c478bd9Sstevel@tonic-gate void backend_query_free(backend_query_t *);
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate typedef int backend_run_callback_f(void *data, int columns, char **vals,
7787c478bd9Sstevel@tonic-gate     char **names);
7797c478bd9Sstevel@tonic-gate #define	BACKEND_CALLBACK_CONTINUE	0
7807c478bd9Sstevel@tonic-gate #define	BACKEND_CALLBACK_ABORT		1
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate backend_run_callback_f backend_fail_if_seen;	/* aborts TX if called */
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate int backend_run(backend_type_t, backend_query_t *,
7857c478bd9Sstevel@tonic-gate     backend_run_callback_f *, void *);
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate int backend_tx_begin(backend_type_t, backend_tx_t **);
7887c478bd9Sstevel@tonic-gate int backend_tx_begin_ro(backend_type_t, backend_tx_t **);
7897c478bd9Sstevel@tonic-gate void backend_tx_end_ro(backend_tx_t *);
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate enum id_space {
7927c478bd9Sstevel@tonic-gate 	BACKEND_ID_SERVICE_INSTANCE,
7937c478bd9Sstevel@tonic-gate 	BACKEND_ID_PROPERTYGRP,
7947c478bd9Sstevel@tonic-gate 	BACKEND_ID_GENERATION,
7957c478bd9Sstevel@tonic-gate 	BACKEND_ID_PROPERTY,
7967c478bd9Sstevel@tonic-gate 	BACKEND_ID_VALUE,
7977c478bd9Sstevel@tonic-gate 	BACKEND_ID_SNAPNAME,
7987c478bd9Sstevel@tonic-gate 	BACKEND_ID_SNAPSHOT,
7997c478bd9Sstevel@tonic-gate 	BACKEND_ID_SNAPLEVEL,
8007c478bd9Sstevel@tonic-gate 	BACKEND_ID_INVALID	/* always illegal */
8017c478bd9Sstevel@tonic-gate };
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate uint32_t backend_new_id(backend_tx_t *, enum id_space);
8047c478bd9Sstevel@tonic-gate int backend_tx_run_update(backend_tx_t *, const char *, ...);
8057c478bd9Sstevel@tonic-gate int backend_tx_run_update_changed(backend_tx_t *, const char *, ...);
8067c478bd9Sstevel@tonic-gate int backend_tx_run_single_int(backend_tx_t *tx, backend_query_t *q,
8077c478bd9Sstevel@tonic-gate     uint32_t *buf);
8087c478bd9Sstevel@tonic-gate int backend_tx_run(backend_tx_t *, backend_query_t *,
8097c478bd9Sstevel@tonic-gate     backend_run_callback_f *, void *);
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate int backend_tx_commit(backend_tx_t *);
8127c478bd9Sstevel@tonic-gate void backend_tx_rollback(backend_tx_t *);
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8157c478bd9Sstevel@tonic-gate }
8167c478bd9Sstevel@tonic-gate #endif
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate #endif	/* _CONFIGD_H */
819