xref: /illumos-gate/usr/src/cmd/svc/configd/configd.h (revision 54d02241)
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
55b7f77adStw  * Common Development and Distribution License (the "License").
65b7f77adStw  * 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  */
2153f3aea0SRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
2353f3aea0SRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*54d02241SBryan Cantrill /*
28*54d02241SBryan Cantrill  * Copyright (c) 2015, Joyent, Inc. All rights reserved.
29*54d02241SBryan Cantrill  */
30*54d02241SBryan Cantrill 
317c478bd9Sstevel@tonic-gate #ifndef	_CONFIGD_H
327c478bd9Sstevel@tonic-gate #define	_CONFIGD_H
337c478bd9Sstevel@tonic-gate 
345b7f77adStw #include <bsm/adt.h>
357c478bd9Sstevel@tonic-gate #include <door.h>
367c478bd9Sstevel@tonic-gate #include <pthread.h>
3753f3aea0SRoger A. Faulkner #include <synch.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <libscf.h>
427c478bd9Sstevel@tonic-gate #include <repcache_protocol.h>
437c478bd9Sstevel@tonic-gate #include <libuutil.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <configd_exit.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
487c478bd9Sstevel@tonic-gate extern "C" {
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Lock order:
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  *	client lock
557c478bd9Sstevel@tonic-gate  *		iter locks, in ID order
567c478bd9Sstevel@tonic-gate  *		entity locks, in ID order
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  *		(any iter/entity locks)
597c478bd9Sstevel@tonic-gate  *			backend locks (NORMAL, then NONPERSIST)
607c478bd9Sstevel@tonic-gate  *				rc_node lock
617c478bd9Sstevel@tonic-gate  *					children's rc_node lock
627c478bd9Sstevel@tonic-gate  *				cache bucket lock
637c478bd9Sstevel@tonic-gate  *					rc_node lock[*]
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  *	* only one node may be grabbed while holding a bucket lock
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  *	leaf locks:  (no other locks may be aquired while holding one)
687c478bd9Sstevel@tonic-gate  *		rc_pg_notify_lock
695b7f77adStw  *		rc_annotate_lock
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Returns the minimum size for a structure of type 't' such
747c478bd9Sstevel@tonic-gate  * that it is safe to access field 'f'.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate #define	offsetofend(t, f)	(offsetof(t, f) + sizeof (((t *)0)->f))
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
7953f3aea0SRoger A. Faulkner  * We want MUTEX_HELD, but we also want pthreads.  So we're stuck with this
8053f3aea0SRoger A. Faulkner  * for the native build, at least until the build machines can catch up
8153f3aea0SRoger A. Faulkner  * with the latest version of MUTEX_HELD() in <synch.h>.
827c478bd9Sstevel@tonic-gate  */
8353f3aea0SRoger A. Faulkner #if defined(NATIVE_BUILD)
8453f3aea0SRoger A. Faulkner #undef	MUTEX_HELD
8553f3aea0SRoger A. Faulkner #define	MUTEX_HELD(m)		_mutex_held((mutex_t *)(m))
8653f3aea0SRoger A. Faulkner #endif
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Maximum levels of composition.
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate #define	COMPOSITION_DEPTH	2
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	CONFIGD_CORE	"core.%f.%t.%p"
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	bad_error(f, e)							\
96*54d02241SBryan Cantrill 	uu_panic("%s:%d: %s() returned bad error %d.  Aborting.\n",	\
97*54d02241SBryan Cantrill 	    __FILE__, __LINE__, f, e);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate typedef enum backend_type {
1007c478bd9Sstevel@tonic-gate 	BACKEND_TYPE_NORMAL		= 0,
1017c478bd9Sstevel@tonic-gate 	BACKEND_TYPE_NONPERSIST,
1027c478bd9Sstevel@tonic-gate 	BACKEND_TYPE_TOTAL			/* backend use only */
1037c478bd9Sstevel@tonic-gate } backend_type_t;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * pre-declare rc_* types
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate typedef struct rc_node rc_node_t;
1097c478bd9Sstevel@tonic-gate typedef struct rc_snapshot rc_snapshot_t;
1107c478bd9Sstevel@tonic-gate typedef struct rc_snaplevel rc_snaplevel_t;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * notification layer -- protected by rc_pg_notify_lock
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate typedef struct rc_notify_info rc_notify_info_t;
1167c478bd9Sstevel@tonic-gate typedef struct rc_notify_delete rc_notify_delete_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_MAX_NAMES	4	/* enough for now */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate typedef struct rc_notify {
1217c478bd9Sstevel@tonic-gate 	uu_list_node_t	rcn_list_node;
1227c478bd9Sstevel@tonic-gate 	rc_node_t	*rcn_node;
1237c478bd9Sstevel@tonic-gate 	rc_notify_info_t *rcn_info;
1247c478bd9Sstevel@tonic-gate 	rc_notify_delete_t *rcn_delete;
1257c478bd9Sstevel@tonic-gate } rc_notify_t;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate struct rc_notify_delete {
1287c478bd9Sstevel@tonic-gate 	rc_notify_t rnd_notify;
1297c478bd9Sstevel@tonic-gate 	char rnd_fmri[REP_PROTOCOL_FMRI_LEN];
1307c478bd9Sstevel@tonic-gate };
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate struct rc_notify_info {
1337c478bd9Sstevel@tonic-gate 	uu_list_node_t	rni_list_node;
1347c478bd9Sstevel@tonic-gate 	rc_notify_t	rni_notify;
1357c478bd9Sstevel@tonic-gate 	const char	*rni_namelist[RC_NOTIFY_MAX_NAMES];
1367c478bd9Sstevel@tonic-gate 	const char	*rni_typelist[RC_NOTIFY_MAX_NAMES];
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	int		rni_flags;
1397c478bd9Sstevel@tonic-gate 	int		rni_waiters;
1407c478bd9Sstevel@tonic-gate 	pthread_cond_t	rni_cv;
1417c478bd9Sstevel@tonic-gate };
1427c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_ACTIVE	0x00000001
1437c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_DRAIN		0x00000002
1447c478bd9Sstevel@tonic-gate #define	RC_NOTIFY_EMPTYING	0x00000004
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate typedef struct rc_node_pg_notify {
1477c478bd9Sstevel@tonic-gate 	uu_list_node_t	rnpn_node;
1487c478bd9Sstevel@tonic-gate 	int		rnpn_fd;
1497c478bd9Sstevel@tonic-gate 	rc_node_t	*rnpn_pg;
1507c478bd9Sstevel@tonic-gate } rc_node_pg_notify_t;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * cache layer
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * The 'key' for the main object hash.  main_id is the main object
1587c478bd9Sstevel@tonic-gate  * identifier.  The rl_ids array contains:
1597c478bd9Sstevel@tonic-gate  *
1607c478bd9Sstevel@tonic-gate  *	TYPE		RL_IDS
1617c478bd9Sstevel@tonic-gate  *	scope		unused
1627c478bd9Sstevel@tonic-gate  *	service		unused
1637c478bd9Sstevel@tonic-gate  *	instance	{service_id}
1647c478bd9Sstevel@tonic-gate  *	snapshot	{service_id, instance_id}
1657c478bd9Sstevel@tonic-gate  *	snaplevel	{service_id, instance_id, name_id, snapshot_id}
1667c478bd9Sstevel@tonic-gate  *	propertygroup	{service_id, (instance_id or 0), (name_id or 0),
1677c478bd9Sstevel@tonic-gate  *			    (snapshot_id or 0), (l_id or 0)}
1687c478bd9Sstevel@tonic-gate  *	property	{service_id, (instance_id or 0), (name_id or 0),
1697c478bd9Sstevel@tonic-gate  *			    (snapshot_id or 0), (l_id or 0), pg_id, gen_id}
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate #define	ID_SERVICE	0
1727c478bd9Sstevel@tonic-gate #define	ID_INSTANCE	1
1737c478bd9Sstevel@tonic-gate #define	ID_NAME		2
1747c478bd9Sstevel@tonic-gate #define	ID_SNAPSHOT	3
1757c478bd9Sstevel@tonic-gate #define	ID_LEVEL	4
1767c478bd9Sstevel@tonic-gate #define	ID_PG		5
1777c478bd9Sstevel@tonic-gate #define	ID_GEN		6
1787c478bd9Sstevel@tonic-gate #define	MAX_IDS	7
1797c478bd9Sstevel@tonic-gate typedef struct rc_node_lookup {
1807c478bd9Sstevel@tonic-gate 	uint16_t	rl_type;		/* REP_PROTOCOL_ENTITY_* */
1817c478bd9Sstevel@tonic-gate 	uint16_t	rl_backend;		/* BACKEND_TYPE_* */
1827c478bd9Sstevel@tonic-gate 	uint32_t	rl_main_id;		/* primary identifier */
1837c478bd9Sstevel@tonic-gate 	uint32_t	rl_ids[MAX_IDS];	/* context */
1847c478bd9Sstevel@tonic-gate } rc_node_lookup_t;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate struct rc_node {
1877c478bd9Sstevel@tonic-gate 	/*
1887c478bd9Sstevel@tonic-gate 	 * read-only data
1897c478bd9Sstevel@tonic-gate 	 */
1907c478bd9Sstevel@tonic-gate 	rc_node_lookup_t rn_id;			/* must be first */
1917c478bd9Sstevel@tonic-gate 	uint32_t	rn_hash;
1927c478bd9Sstevel@tonic-gate 	const char	*rn_name;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	/*
1957c478bd9Sstevel@tonic-gate 	 * type-specific state
1967c478bd9Sstevel@tonic-gate 	 * (if space becomes an issue, these can become a union)
1977c478bd9Sstevel@tonic-gate 	 */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	/*
2007c478bd9Sstevel@tonic-gate 	 * Used by instances, snapshots, and "composed property groups" only.
2017c478bd9Sstevel@tonic-gate 	 * These are the entities whose properties should appear composed when
2027c478bd9Sstevel@tonic-gate 	 * this entity is traversed by a composed iterator.  0 is the top-most
2037c478bd9Sstevel@tonic-gate 	 * entity, down to COMPOSITION_DEPTH - 1.
2047c478bd9Sstevel@tonic-gate 	 */
2057c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_cchain[COMPOSITION_DEPTH];
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	/*
2087c478bd9Sstevel@tonic-gate 	 * used by property groups only
2097c478bd9Sstevel@tonic-gate 	 */
2107c478bd9Sstevel@tonic-gate 	const char	*rn_type;
2117c478bd9Sstevel@tonic-gate 	uint32_t	rn_pgflags;
2127c478bd9Sstevel@tonic-gate 	uint32_t	rn_gen_id;
2137c478bd9Sstevel@tonic-gate 	uu_list_t	*rn_pg_notify_list;	/* prot by rc_pg_notify_lock */
2147c478bd9Sstevel@tonic-gate 	rc_notify_t	rn_notify;		/* prot by rc_pg_notify_lock */
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	/*
2177c478bd9Sstevel@tonic-gate 	 * used by properties only
2187c478bd9Sstevel@tonic-gate 	 */
2197c478bd9Sstevel@tonic-gate 	rep_protocol_value_type_t rn_valtype;
2207c478bd9Sstevel@tonic-gate 	const char	*rn_values;		/* protected by rn_lock */
2217c478bd9Sstevel@tonic-gate 	size_t		rn_values_count;	/* protected by rn_lock */
2227c478bd9Sstevel@tonic-gate 	size_t		rn_values_size;		/* protected by rn_lock */
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	/*
2257c478bd9Sstevel@tonic-gate 	 * used by snapshots only
2267c478bd9Sstevel@tonic-gate 	 */
2277c478bd9Sstevel@tonic-gate 	uint32_t	rn_snapshot_id;
2287c478bd9Sstevel@tonic-gate 	rc_snapshot_t	*rn_snapshot;		/* protected by rn_lock */
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	/*
2317c478bd9Sstevel@tonic-gate 	 * used by snaplevels only
2327c478bd9Sstevel@tonic-gate 	 */
2337c478bd9Sstevel@tonic-gate 	rc_snaplevel_t	*rn_snaplevel;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	/*
2367c478bd9Sstevel@tonic-gate 	 * mutable state
2377c478bd9Sstevel@tonic-gate 	 */
2387c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rn_lock;
2397c478bd9Sstevel@tonic-gate 	pthread_cond_t	rn_cv;
2407c478bd9Sstevel@tonic-gate 	uint32_t	rn_flags;
2416643e1ffSbustos 	uint32_t	rn_refs;		/* client reference count */
2426643e1ffSbustos 	uint32_t	rn_erefs;		/* ephemeral ref count */
2437c478bd9Sstevel@tonic-gate 	uint32_t	rn_other_refs;		/* atomic refcount */
2447c478bd9Sstevel@tonic-gate 	uint32_t	rn_other_refs_held;	/* for 1->0 transitions */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	uu_list_t	*rn_children;
2477c478bd9Sstevel@tonic-gate 	uu_list_node_t	rn_sibling_node;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_parent;		/* set if on child list */
2507c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_former;		/* next former node */
2517c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_parent_ref;		/* reference count target */
2525b7f77adStw 	const char	*rn_fmri;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	/*
2557c478bd9Sstevel@tonic-gate 	 * external state (protected by hash chain lock)
2567c478bd9Sstevel@tonic-gate 	 */
2577c478bd9Sstevel@tonic-gate 	rc_node_t	*rn_hash_next;
2587c478bd9Sstevel@tonic-gate };
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate  * flag ordering:
2627c478bd9Sstevel@tonic-gate  *	RC_DYING
2637c478bd9Sstevel@tonic-gate  *		RC_NODE_CHILDREN_CHANGING
2647c478bd9Sstevel@tonic-gate  *		RC_NODE_CREATING_CHILD
2657c478bd9Sstevel@tonic-gate  *		RC_NODE_USING_PARENT
2667c478bd9Sstevel@tonic-gate  *			RC_NODE_IN_TX
2677c478bd9Sstevel@tonic-gate  *
2687c478bd9Sstevel@tonic-gate  * RC_NODE_USING_PARENT is special, because it lets you proceed up the tree,
2697c478bd9Sstevel@tonic-gate  * in the reverse of the usual locking order.  Because of this, there are
2707c478bd9Sstevel@tonic-gate  * limitations on what you can do while holding it.  While holding
2717c478bd9Sstevel@tonic-gate  * RC_NODE_USING_PARENT, you may:
2727c478bd9Sstevel@tonic-gate  *	bump or release your parent's reference count
2737c478bd9Sstevel@tonic-gate  *	access fields in your parent
2747c478bd9Sstevel@tonic-gate  *	hold RC_NODE_USING_PARENT in the parent, proceeding recursively.
2757c478bd9Sstevel@tonic-gate  *
2767c478bd9Sstevel@tonic-gate  * If you are only holding *one* node's RC_NODE_USING_PARENT, and:
2777c478bd9Sstevel@tonic-gate  *	you are *not* proceeding recursively, you can hold your
2787c478bd9Sstevel@tonic-gate  *	    immediate parent's RC_NODE_CHILDREN_CHANGING flag.
2797c478bd9Sstevel@tonic-gate  *	you hold your parent's RC_NODE_CHILDREN_CHANGING flag, you can add
2807c478bd9Sstevel@tonic-gate  *	    RC_NODE_IN_TX to your flags.
2817c478bd9Sstevel@tonic-gate  *	you want to grab a flag in your parent, you must lock your parent,
2827c478bd9Sstevel@tonic-gate  *	    lock yourself, drop RC_NODE_USING_PARENT, unlock yourself,
2837c478bd9Sstevel@tonic-gate  *	    then proceed to manipulate the parent.
2847c478bd9Sstevel@tonic-gate  */
2857c478bd9Sstevel@tonic-gate #define	RC_NODE_CHILDREN_CHANGING	0x00000001 /* child list in flux */
2867c478bd9Sstevel@tonic-gate #define	RC_NODE_HAS_CHILDREN		0x00000002 /* child list is accurate */
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate #define	RC_NODE_IN_PARENT		0x00000004 /* I'm in my parent's list */
2897c478bd9Sstevel@tonic-gate #define	RC_NODE_USING_PARENT		0x00000008 /* parent ptr in use */
2907c478bd9Sstevel@tonic-gate #define	RC_NODE_CREATING_CHILD		0x00000010 /* a create is in progress */
2917c478bd9Sstevel@tonic-gate #define	RC_NODE_IN_TX			0x00000020 /* a tx is in progess */
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #define	RC_NODE_OLD			0x00000400 /* out-of-date object */
2947c478bd9Sstevel@tonic-gate #define	RC_NODE_ON_FORMER		0x00000800 /* on an rn_former list */
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate #define	RC_NODE_PARENT_REF		0x00001000 /* parent_ref in use */
2977c478bd9Sstevel@tonic-gate #define	RC_NODE_UNREFED			0x00002000 /* unref processing active */
2987c478bd9Sstevel@tonic-gate #define	RC_NODE_DYING			0x00004000 /* node is being deleted */
2997c478bd9Sstevel@tonic-gate #define	RC_NODE_DEAD			0x00008000 /* node has been deleted */
3007c478bd9Sstevel@tonic-gate 
3016643e1ffSbustos /*
3026643e1ffSbustos  * RC_NODE_DEAD means that the node no longer represents data in the
3036643e1ffSbustos  * backend, and we should return _DELETED errors to clients who try to use
3046643e1ffSbustos  * it.  Very much like a zombie process.
3056643e1ffSbustos  *
3066643e1ffSbustos  * RC_NODE_OLD also means that the node no longer represents data in the
3076643e1ffSbustos  * backend, but it's ok for clients to access it because we've loaded all of
3086643e1ffSbustos  * the children.  (This only happens for transactional objects such as
3096643e1ffSbustos  * property groups and snapshots, where we guarantee a stable view once
3106643e1ffSbustos  * a reference is obtained.)  When all client references are destroyed,
3116643e1ffSbustos  * however, the node should be destroyed.
3126643e1ffSbustos  *
3136643e1ffSbustos  * Though RC_NODE_DEAD is set by the rc_node_delete() code, it is also set
3146643e1ffSbustos  * by rc_node_no_client_refs() for RC_NODE_OLD nodes not long before
3156643e1ffSbustos  * they're destroyed.
3166643e1ffSbustos  */
3176643e1ffSbustos 
3187c478bd9Sstevel@tonic-gate #define	RC_NODE_DYING_FLAGS						\
3197c478bd9Sstevel@tonic-gate 	(RC_NODE_CHILDREN_CHANGING | RC_NODE_IN_TX | RC_NODE_DYING |	\
3207c478bd9Sstevel@tonic-gate 	    RC_NODE_CREATING_CHILD)
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate #define	RC_NODE_WAITING_FLAGS						\
3237c478bd9Sstevel@tonic-gate 	(RC_NODE_DYING_FLAGS | RC_NODE_USING_PARENT)
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 
3266643e1ffSbustos #define	NODE_LOCK(n)	(void) pthread_mutex_lock(&(n)->rn_lock)
3276643e1ffSbustos #define	NODE_UNLOCK(n)	(void) pthread_mutex_unlock(&(n)->rn_lock)
3286643e1ffSbustos 
3296643e1ffSbustos 
3305b7f77adStw typedef enum rc_auth_state {
3315b7f77adStw 	RC_AUTH_UNKNOWN = 0,		/* No checks done yet. */
3325b7f77adStw 	RC_AUTH_FAILED,			/* Authorization checked & failed. */
3335b7f77adStw 	RC_AUTH_PASSED			/* Authorization succeeded. */
3345b7f77adStw } rc_auth_state_t;
3355b7f77adStw 
3365b7f77adStw /*
3375b7f77adStw  * Some authorization checks are performed in rc_node_setup_tx() in
3385b7f77adStw  * response to the REP_PROTOCOL_PROPERTYGRP_TX_START message.  Other checks
3395b7f77adStw  * must wait until the actual transaction operations are received in the
3405b7f77adStw  * REP_PROTOCOL_PROPERTYGRP_TX_COMMIT message.  This second set of checks
3415b7f77adStw  * is performed in rc_tx_commit().  rnp_auth_string and rnp_authorized in
3425b7f77adStw  * the following structure are used to hold the results of the
3435b7f77adStw  * authorization checking done in rc_node_setup_tx() for later use by
3445b7f77adStw  * rc_tx_commit().
3455b7f77adStw  *
3465b7f77adStw  * In client.c transactions are represented by rc_node_ptr structures which
3475b7f77adStw  * point to a property group rc_node_t.  Thus, this is an appropriate place
3485b7f77adStw  * to hold authorization state.
3495b7f77adStw  */
3507c478bd9Sstevel@tonic-gate typedef struct rc_node_ptr {
3517c478bd9Sstevel@tonic-gate 	rc_node_t	*rnp_node;
3525b7f77adStw 	const char	*rnp_auth_string;	/* authorization string */
3535b7f77adStw 	rc_auth_state_t	rnp_authorized;		/* transaction pre-auth rslt. */
3547c478bd9Sstevel@tonic-gate 	char		rnp_deleted;		/* object was deleted */
3557c478bd9Sstevel@tonic-gate } rc_node_ptr_t;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate #define	NODE_PTR_NOT_HELD(npp) \
3587c478bd9Sstevel@tonic-gate 	    ((npp)->rnp_node == NULL || !MUTEX_HELD(&(npp)->rnp_node->rn_lock))
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate typedef int rc_iter_filter_func(rc_node_t *, void *);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate typedef struct rc_node_iter {
3637c478bd9Sstevel@tonic-gate 	rc_node_t	*rni_parent;
3647c478bd9Sstevel@tonic-gate 	int		rni_clevel;	/* index into rni_parent->rn_cchain[] */
3657c478bd9Sstevel@tonic-gate 	rc_node_t	*rni_iter_node;
3667c478bd9Sstevel@tonic-gate 	uu_list_walk_t	*rni_iter;
3677c478bd9Sstevel@tonic-gate 	uint32_t	rni_type;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	/*
3707c478bd9Sstevel@tonic-gate 	 * for normal walks
3717c478bd9Sstevel@tonic-gate 	 */
3727c478bd9Sstevel@tonic-gate 	rc_iter_filter_func *rni_filter;
3737c478bd9Sstevel@tonic-gate 	void		*rni_filter_arg;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	/*
3767c478bd9Sstevel@tonic-gate 	 * for value walks
3777c478bd9Sstevel@tonic-gate 	 */
3787c478bd9Sstevel@tonic-gate 	uint32_t	rni_offset;		/* next value offset */
3797c478bd9Sstevel@tonic-gate 	uint32_t	rni_last_offset;	/* previous value offset */
3807c478bd9Sstevel@tonic-gate } rc_node_iter_t;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate typedef struct rc_node_tx {
3837c478bd9Sstevel@tonic-gate 	rc_node_ptr_t	rnt_ptr;
3847c478bd9Sstevel@tonic-gate 	int		rnt_authorized;		/* No need to check anymore. */
3857c478bd9Sstevel@tonic-gate } rc_node_tx_t;
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate typedef struct cache_bucket {
3897c478bd9Sstevel@tonic-gate 	pthread_mutex_t	cb_lock;
3907c478bd9Sstevel@tonic-gate 	rc_node_t	*cb_head;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	char		cb_pad[64 - sizeof (pthread_mutex_t) -
3937c478bd9Sstevel@tonic-gate 			    2 * sizeof (rc_node_t *)];
3947c478bd9Sstevel@tonic-gate } cache_bucket_t;
3957c478bd9Sstevel@tonic-gate 
3965b7f77adStw /*
3975b7f77adStw  * tx_commit_data_tx is an opaque structure which is defined in object.c.
3985b7f77adStw  * It contains the data of the transaction that is to be committed.
3995b7f77adStw  * Accessor functions in object.c allow other modules to retrieve
4005b7f77adStw  * information.
4015b7f77adStw  */
4025b7f77adStw typedef struct tx_commit_data tx_commit_data_t;
4035b7f77adStw 
4047c478bd9Sstevel@tonic-gate /*
4057c478bd9Sstevel@tonic-gate  * Snapshots
4067c478bd9Sstevel@tonic-gate  */
4077c478bd9Sstevel@tonic-gate struct rc_snapshot {
4087c478bd9Sstevel@tonic-gate 	uint32_t	rs_snap_id;
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rs_lock;
4117c478bd9Sstevel@tonic-gate 	pthread_cond_t	rs_cv;
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 	uint32_t	rs_flags;
4147c478bd9Sstevel@tonic-gate 	uint32_t	rs_refcnt;	/* references from rc_nodes */
4157c478bd9Sstevel@tonic-gate 	uint32_t	rs_childref;	/* references to children */
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 	rc_snaplevel_t	*rs_levels;	/* list of levels */
4187c478bd9Sstevel@tonic-gate 	rc_snapshot_t	*rs_hash_next;
4197c478bd9Sstevel@tonic-gate };
4207c478bd9Sstevel@tonic-gate #define	RC_SNAPSHOT_FILLING	0x00000001	/* rs_levels changing */
4217c478bd9Sstevel@tonic-gate #define	RC_SNAPSHOT_READY	0x00000002
4227c478bd9Sstevel@tonic-gate #define	RC_SNAPSHOT_DEAD	0x00000004	/* no resources */
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate typedef struct rc_snaplevel_pgs {
4257c478bd9Sstevel@tonic-gate 	uint32_t	rsp_pg_id;
4267c478bd9Sstevel@tonic-gate 	uint32_t	rsp_gen_id;
4277c478bd9Sstevel@tonic-gate } rc_snaplevel_pgs_t;
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate struct rc_snaplevel {
4307c478bd9Sstevel@tonic-gate 	rc_snapshot_t	*rsl_parent;
4317c478bd9Sstevel@tonic-gate 	uint32_t	rsl_level_num;
4327c478bd9Sstevel@tonic-gate 	uint32_t	rsl_level_id;
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	uint32_t	rsl_service_id;
4357c478bd9Sstevel@tonic-gate 	uint32_t	rsl_instance_id;
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	const char	*rsl_scope;
4387c478bd9Sstevel@tonic-gate 	const char	*rsl_service;
4397c478bd9Sstevel@tonic-gate 	const char	*rsl_instance;
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	rc_snaplevel_t	*rsl_next;
4427c478bd9Sstevel@tonic-gate };
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate /*
4457c478bd9Sstevel@tonic-gate  * Client layer -- the IDs fields must be first, in order for the search
4467c478bd9Sstevel@tonic-gate  * routines to work correctly.
4477c478bd9Sstevel@tonic-gate  */
4487c478bd9Sstevel@tonic-gate enum repcache_txstate {
4497c478bd9Sstevel@tonic-gate 	REPCACHE_TX_INIT,
4507c478bd9Sstevel@tonic-gate 	REPCACHE_TX_SETUP,
4517c478bd9Sstevel@tonic-gate 	REPCACHE_TX_COMMITTED
4527c478bd9Sstevel@tonic-gate };
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate typedef struct repcache_entity {
4557c478bd9Sstevel@tonic-gate 	uint32_t	re_id;
4568918dff3Sjwadams 	uu_avl_node_t	re_link;
4577c478bd9Sstevel@tonic-gate 	uint32_t	re_changeid;
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 	pthread_mutex_t	re_lock;
4607c478bd9Sstevel@tonic-gate 	uint32_t	re_type;
4617c478bd9Sstevel@tonic-gate 	rc_node_ptr_t	re_node;
4627c478bd9Sstevel@tonic-gate 	enum repcache_txstate re_txstate;	/* property groups only */
4637c478bd9Sstevel@tonic-gate } repcache_entity_t;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate typedef struct repcache_iter {
4667c478bd9Sstevel@tonic-gate 	uint32_t	ri_id;
4678918dff3Sjwadams 	uu_avl_node_t	ri_link;
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	uint32_t	ri_type;	/* result type */
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	pthread_mutex_t	ri_lock;
4727c478bd9Sstevel@tonic-gate 	uint32_t	ri_sequence;
4737c478bd9Sstevel@tonic-gate 	rc_node_iter_t	*ri_iter;
4747c478bd9Sstevel@tonic-gate } repcache_iter_t;
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate typedef struct repcache_client {
4777c478bd9Sstevel@tonic-gate 	/*
4787c478bd9Sstevel@tonic-gate 	 * constants
4797c478bd9Sstevel@tonic-gate 	 */
4807c478bd9Sstevel@tonic-gate 	uint32_t	rc_id;		/* must be first */
4817c478bd9Sstevel@tonic-gate 	int		rc_all_auths;	/* bypass auth checks */
4827c478bd9Sstevel@tonic-gate 	uint32_t	rc_debug;	/* debug flags */
4837c478bd9Sstevel@tonic-gate 	pid_t		rc_pid;		/* pid of opening process */
4847c478bd9Sstevel@tonic-gate 	door_id_t	rc_doorid;	/* a globally unique identifier */
4857c478bd9Sstevel@tonic-gate 	int		rc_doorfd;	/* our door's FD */
4867c478bd9Sstevel@tonic-gate 
4875b7f77adStw 	/*
4885b7f77adStw 	 * Constants used for security auditing
4895b7f77adStw 	 *
4905b7f77adStw 	 * rc_adt_session points to the audit session data that is used for
4915b7f77adStw 	 * the life of the client.  rc_adt_sessionid is the session ID that
4925b7f77adStw 	 * is initially assigned when the audit session is started.  See
4935b7f77adStw 	 * start_audit_session() in client.c.  This session id is used for
4945b7f77adStw 	 * audit events except when we are processing a set of annotated
4955b7f77adStw 	 * events.  Annotated events use a separate session id so that they
4965b7f77adStw 	 * can be grouped.  See set_annotation() in client.c.
4975b7f77adStw 	 */
4985b7f77adStw 	adt_session_data_t *rc_adt_session;	/* Session data. */
4995b7f77adStw 	au_asid_t	rc_adt_sessionid;	/* Main session ID for */
5005b7f77adStw 						/* auditing */
5015b7f77adStw 
5027c478bd9Sstevel@tonic-gate 	/*
5037c478bd9Sstevel@tonic-gate 	 * client list linkage, protected by hash chain lock
5047c478bd9Sstevel@tonic-gate 	 */
5057c478bd9Sstevel@tonic-gate 	uu_list_node_t	rc_link;
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	/*
5087c478bd9Sstevel@tonic-gate 	 * notification information, protected by rc_node layer
5097c478bd9Sstevel@tonic-gate 	 */
5107c478bd9Sstevel@tonic-gate 	rc_node_pg_notify_t	rc_pg_notify;
5117c478bd9Sstevel@tonic-gate 	rc_notify_info_t	rc_notify_info;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	/*
5147c478bd9Sstevel@tonic-gate 	 * client_wait output, only usable by rc_notify_thr
5157c478bd9Sstevel@tonic-gate 	 */
5167c478bd9Sstevel@tonic-gate 	rc_node_ptr_t	rc_notify_ptr;
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	/*
5198918dff3Sjwadams 	 * register sets, protected by rc_lock
5207c478bd9Sstevel@tonic-gate 	 */
5218918dff3Sjwadams 	uu_avl_t	*rc_entities;
5228918dff3Sjwadams 	uu_avl_t	*rc_iters;
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	/*
5257c478bd9Sstevel@tonic-gate 	 * Variables, protected by rc_lock
5267c478bd9Sstevel@tonic-gate 	 */
5277c478bd9Sstevel@tonic-gate 	int		rc_refcnt;	/* in-progress door calls */
5285b7f77adStw 	int		rc_flags;	/* see RC_CLIENT_* symbols below */
5297c478bd9Sstevel@tonic-gate 	uint32_t	rc_changeid;	/* used to make backups idempotent */
5307c478bd9Sstevel@tonic-gate 	pthread_t	rc_insert_thr;	/* single thread trying to insert */
5317c478bd9Sstevel@tonic-gate 	pthread_t	rc_notify_thr;	/* single thread waiting for notify */
5327c478bd9Sstevel@tonic-gate 	pthread_cond_t	rc_cv;
5337c478bd9Sstevel@tonic-gate 	pthread_mutex_t	rc_lock;
5345b7f77adStw 
5355b7f77adStw 	/*
5365b7f77adStw 	 * Per-client audit information.  These fields must be protected by
5375b7f77adStw 	 * rc_annotate_lock separately from rc_lock because they may need
5385b7f77adStw 	 * to be accessed from rc_node.c with an entity or iterator lock
5395b7f77adStw 	 * held, and those must be taken after rc_lock.
5405b7f77adStw 	 */
5415b7f77adStw 	int		rc_annotate;	/* generate annotation event if set */
5425b7f77adStw 	const char	*rc_operation;	/* operation for audit annotation */
5435b7f77adStw 	const char	*rc_file;	/* file name for audit annotation */
5445b7f77adStw 	pthread_mutex_t	rc_annotate_lock;
5457c478bd9Sstevel@tonic-gate } repcache_client_t;
5465b7f77adStw 
5475b7f77adStw /* Bit definitions for rc_flags. */
5487c478bd9Sstevel@tonic-gate #define	RC_CLIENT_DEAD			0x00000001
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate typedef struct client_bucket {
5517c478bd9Sstevel@tonic-gate 	pthread_mutex_t	cb_lock;
5527c478bd9Sstevel@tonic-gate 	uu_list_t	*cb_list;
5537c478bd9Sstevel@tonic-gate 	char ch_pad[64 - sizeof (pthread_mutex_t) - sizeof (uu_list_t *)];
5547c478bd9Sstevel@tonic-gate } client_bucket_t;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate enum rc_ptr_type {
5577c478bd9Sstevel@tonic-gate 	RC_PTR_TYPE_ENTITY = 1,
5587c478bd9Sstevel@tonic-gate 	RC_PTR_TYPE_ITER
5597c478bd9Sstevel@tonic-gate };
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate typedef struct request_log_ptr {
5627c478bd9Sstevel@tonic-gate 	enum rc_ptr_type	rlp_type;
5637c478bd9Sstevel@tonic-gate 	uint32_t		rlp_id;
5647c478bd9Sstevel@tonic-gate 	void			*rlp_ptr; /* repcache_{entity,iter}_t */
5657c478bd9Sstevel@tonic-gate 	void			*rlp_data;	/* rc_node, for ENTITY only */
5667c478bd9Sstevel@tonic-gate } request_log_ptr_t;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate #define	MAX_PTRS	3
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate /*
5717c478bd9Sstevel@tonic-gate  * rl_start through rl_client cannot move without changing start_log()
5727c478bd9Sstevel@tonic-gate  */
5737c478bd9Sstevel@tonic-gate typedef struct request_log_entry {
5747c478bd9Sstevel@tonic-gate 	hrtime_t		rl_start;
5757c478bd9Sstevel@tonic-gate 	hrtime_t		rl_end;
5767c478bd9Sstevel@tonic-gate 	pthread_t		rl_tid;
5777c478bd9Sstevel@tonic-gate 	uint32_t		rl_clientid;
5787c478bd9Sstevel@tonic-gate 	repcache_client_t	*rl_client;
5797c478bd9Sstevel@tonic-gate 	enum rep_protocol_requestid rl_request;
5807c478bd9Sstevel@tonic-gate 	rep_protocol_responseid_t rl_response;
5817c478bd9Sstevel@tonic-gate 	int			rl_num_ptrs;
5827c478bd9Sstevel@tonic-gate 	request_log_ptr_t	rl_ptrs[MAX_PTRS];
5837c478bd9Sstevel@tonic-gate } request_log_entry_t;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate /*
5867c478bd9Sstevel@tonic-gate  * thread information
5877c478bd9Sstevel@tonic-gate  */
5887c478bd9Sstevel@tonic-gate typedef enum thread_state {
5897c478bd9Sstevel@tonic-gate 	TI_CREATED,
5907c478bd9Sstevel@tonic-gate 	TI_DOOR_RETURN,
5917c478bd9Sstevel@tonic-gate 	TI_SIGNAL_WAIT,
5927c478bd9Sstevel@tonic-gate 	TI_MAIN_DOOR_CALL,
5937c478bd9Sstevel@tonic-gate 	TI_CLIENT_CALL
5947c478bd9Sstevel@tonic-gate } thread_state_t;
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate typedef struct thread_info {
5977c478bd9Sstevel@tonic-gate 	pthread_t	ti_thread;
5987c478bd9Sstevel@tonic-gate 	uu_list_node_t	ti_node;		/* for list of all thread */
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	/*
6017c478bd9Sstevel@tonic-gate 	 * per-thread globals
6027c478bd9Sstevel@tonic-gate 	 */
6037c478bd9Sstevel@tonic-gate 	ucred_t		*ti_ucred;		/* for credential lookups */
6047c478bd9Sstevel@tonic-gate 	int		ti_ucred_read;		/* ucred holds current creds */
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	/*
6077c478bd9Sstevel@tonic-gate 	 * per-thread state information, for debuggers
6087c478bd9Sstevel@tonic-gate 	 */
6097c478bd9Sstevel@tonic-gate 	hrtime_t	ti_lastchange;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	thread_state_t	ti_state;
6127c478bd9Sstevel@tonic-gate 	thread_state_t	ti_prev_state;
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate 	repcache_client_t *ti_active_client;
6157c478bd9Sstevel@tonic-gate 	request_log_entry_t	ti_log;
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 	struct rep_protocol_request *ti_client_request;
6187c478bd9Sstevel@tonic-gate 	repository_door_request_t *ti_main_door_request;
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate } thread_info_t;
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate /*
6237c478bd9Sstevel@tonic-gate  * Backend layer
6247c478bd9Sstevel@tonic-gate  */
6257c478bd9Sstevel@tonic-gate typedef struct backend_query backend_query_t;
6267c478bd9Sstevel@tonic-gate typedef struct backend_tx backend_tx_t;
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate /*
6297c478bd9Sstevel@tonic-gate  * configd.c
6307c478bd9Sstevel@tonic-gate  */
6317c478bd9Sstevel@tonic-gate int create_connection(ucred_t *cred, repository_door_request_t *rp,
6327c478bd9Sstevel@tonic-gate     size_t rp_size, int *out_fd);
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate thread_info_t *thread_self(void);
6357c478bd9Sstevel@tonic-gate void thread_newstate(thread_info_t *, thread_state_t);
6367c478bd9Sstevel@tonic-gate ucred_t *get_ucred(void);
6377c478bd9Sstevel@tonic-gate int ucred_is_privileged(ucred_t *);
6387c478bd9Sstevel@tonic-gate 
6395b7f77adStw adt_session_data_t *get_audit_session(void);
6405b7f77adStw 
6417c478bd9Sstevel@tonic-gate void configd_critical(const char *, ...);
6427c478bd9Sstevel@tonic-gate void configd_vcritical(const char *, va_list);
6436e1d2b42Samaguire void configd_info(const char *, ...);
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate extern int is_main_repository;
6467c478bd9Sstevel@tonic-gate extern int max_repository_backups;
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate  * maindoor.c
6507c478bd9Sstevel@tonic-gate  */
6517c478bd9Sstevel@tonic-gate int setup_main_door(const char *);
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate /*
6547c478bd9Sstevel@tonic-gate  * client.c
6557c478bd9Sstevel@tonic-gate  */
6565b7f77adStw int client_annotation_needed(char *, size_t, char *, size_t);
6575b7f77adStw void client_annotation_finished(void);
6587c478bd9Sstevel@tonic-gate int create_client(pid_t, uint32_t, int, int *);
6597c478bd9Sstevel@tonic-gate int client_init(void);
6607c478bd9Sstevel@tonic-gate int client_is_privileged(void);
6617c478bd9Sstevel@tonic-gate void log_enter(request_log_entry_t *);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate /*
6647c478bd9Sstevel@tonic-gate  * rc_node.c, backend/cache interfaces (rc_node_t)
6657c478bd9Sstevel@tonic-gate  */
6667c478bd9Sstevel@tonic-gate int rc_node_init();
6677c478bd9Sstevel@tonic-gate int rc_check_type_name(uint32_t, const char *);
6687c478bd9Sstevel@tonic-gate 
6695b7f77adStw void rc_node_ptr_free_mem(rc_node_ptr_t *);
6707c478bd9Sstevel@tonic-gate void rc_node_rele(rc_node_t *);
6717c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup(rc_node_t *, rc_node_lookup_t *,
6727c478bd9Sstevel@tonic-gate     const char *, rc_node_t *);
6737c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_pg(rc_node_t *, rc_node_lookup_t *, const char *,
6747c478bd9Sstevel@tonic-gate     const char *, uint32_t, uint32_t, rc_node_t *);
6757c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_snapshot(rc_node_t *, rc_node_lookup_t *, const char *,
6767c478bd9Sstevel@tonic-gate     uint32_t, rc_node_t *);
6777c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_snaplevel(rc_node_t *, rc_node_lookup_t *,
6787c478bd9Sstevel@tonic-gate     rc_snaplevel_t *, rc_node_t *);
6797c478bd9Sstevel@tonic-gate int rc_node_create_property(rc_node_t *, rc_node_lookup_t *,
6807c478bd9Sstevel@tonic-gate     const char *, rep_protocol_value_type_t, const char *, size_t, size_t);
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate rc_node_t *rc_node_alloc(void);
6837c478bd9Sstevel@tonic-gate void rc_node_destroy(rc_node_t *);
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate /*
6867c478bd9Sstevel@tonic-gate  * rc_node.c, client interface (rc_node_ptr_t, rc_node_iter_t)
6877c478bd9Sstevel@tonic-gate  */
6887c478bd9Sstevel@tonic-gate void rc_node_ptr_init(rc_node_ptr_t *);
6897c478bd9Sstevel@tonic-gate int rc_local_scope(uint32_t, rc_node_ptr_t *);
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate void rc_node_clear(rc_node_ptr_t *, int);
6927c478bd9Sstevel@tonic-gate void rc_node_ptr_assign(rc_node_ptr_t *, const rc_node_ptr_t *);
6937c478bd9Sstevel@tonic-gate int rc_node_name(rc_node_ptr_t *, char *, size_t, uint32_t, size_t *);
6947c478bd9Sstevel@tonic-gate int rc_node_fmri(rc_node_ptr_t *, char *, size_t, size_t *);
6957c478bd9Sstevel@tonic-gate int rc_node_parent_type(rc_node_ptr_t *, uint32_t *);
6967c478bd9Sstevel@tonic-gate int rc_node_get_child(rc_node_ptr_t *, const char *, uint32_t, rc_node_ptr_t *);
6977c478bd9Sstevel@tonic-gate int rc_node_get_parent(rc_node_ptr_t *, uint32_t, rc_node_ptr_t *);
6987c478bd9Sstevel@tonic-gate int rc_node_get_property_type(rc_node_ptr_t *, rep_protocol_value_type_t *);
6997c478bd9Sstevel@tonic-gate int rc_node_get_property_value(rc_node_ptr_t *,
7007c478bd9Sstevel@tonic-gate     struct rep_protocol_value_response *, size_t *);
7017c478bd9Sstevel@tonic-gate int rc_node_create_child(rc_node_ptr_t *, uint32_t, const char *,
7027c478bd9Sstevel@tonic-gate     rc_node_ptr_t *);
7037c478bd9Sstevel@tonic-gate int rc_node_create_child_pg(rc_node_ptr_t *, uint32_t, const char *,
7047c478bd9Sstevel@tonic-gate     const char *, uint32_t, rc_node_ptr_t *);
7057c478bd9Sstevel@tonic-gate int rc_node_update(rc_node_ptr_t *);
7067c478bd9Sstevel@tonic-gate int rc_node_delete(rc_node_ptr_t *);
7077c478bd9Sstevel@tonic-gate int rc_node_next_snaplevel(rc_node_ptr_t *, rc_node_ptr_t *);
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate int rc_node_setup_iter(rc_node_ptr_t *, rc_node_iter_t **, uint32_t,
7107c478bd9Sstevel@tonic-gate     size_t, const char *);
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate int rc_iter_next(rc_node_iter_t *, rc_node_ptr_t *, uint32_t);
7137c478bd9Sstevel@tonic-gate int rc_iter_next_value(rc_node_iter_t *, struct rep_protocol_value_response *,
7147c478bd9Sstevel@tonic-gate     size_t *, int);
7157c478bd9Sstevel@tonic-gate void rc_iter_destroy(rc_node_iter_t **);
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate int rc_node_setup_tx(rc_node_ptr_t *, rc_node_ptr_t *);
7187c478bd9Sstevel@tonic-gate int rc_tx_commit(rc_node_ptr_t *, const void *, size_t);
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate void rc_pg_notify_init(rc_node_pg_notify_t *);
7217c478bd9Sstevel@tonic-gate int rc_pg_notify_setup(rc_node_pg_notify_t *, rc_node_ptr_t *, int);
7227c478bd9Sstevel@tonic-gate void rc_pg_notify_fini(rc_node_pg_notify_t *);
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate void rc_notify_info_init(rc_notify_info_t *);
7257c478bd9Sstevel@tonic-gate int rc_notify_info_add_name(rc_notify_info_t *, const char *);
7267c478bd9Sstevel@tonic-gate int rc_notify_info_add_type(rc_notify_info_t *, const char *);
7277c478bd9Sstevel@tonic-gate int rc_notify_info_wait(rc_notify_info_t *, rc_node_ptr_t *, char *, size_t);
7287c478bd9Sstevel@tonic-gate void rc_notify_info_fini(rc_notify_info_t *);
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate int rc_snapshot_take_new(rc_node_ptr_t *, const char *,
7317c478bd9Sstevel@tonic-gate     const char *, const char *, rc_node_ptr_t *);
7327c478bd9Sstevel@tonic-gate int rc_snapshot_take_attach(rc_node_ptr_t *, rc_node_ptr_t *);
7337c478bd9Sstevel@tonic-gate int rc_snapshot_attach(rc_node_ptr_t *, rc_node_ptr_t *);
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate /*
7367c478bd9Sstevel@tonic-gate  * file_object.c
7377c478bd9Sstevel@tonic-gate  */
7387c478bd9Sstevel@tonic-gate int object_fill_children(rc_node_t *);
7397c478bd9Sstevel@tonic-gate int object_create(rc_node_t *, uint32_t, const char *, rc_node_t **);
7407c478bd9Sstevel@tonic-gate int object_create_pg(rc_node_t *, uint32_t, const char *, const char *,
7417c478bd9Sstevel@tonic-gate     uint32_t, rc_node_t **);
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate int object_delete(rc_node_t *);
7447c478bd9Sstevel@tonic-gate void object_free_values(const char *, uint32_t, size_t, size_t);
7457c478bd9Sstevel@tonic-gate 
7468918dff3Sjwadams int object_fill_snapshot(rc_snapshot_t *);
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate int object_snapshot_take_new(rc_node_t *, const char *, const char *,
7497c478bd9Sstevel@tonic-gate     const char *, rc_node_t **);
7507c478bd9Sstevel@tonic-gate int object_snapshot_attach(rc_node_lookup_t *, uint32_t *, int);
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate /*
7537c478bd9Sstevel@tonic-gate  * object.c
7547c478bd9Sstevel@tonic-gate  */
7555b7f77adStw int object_tx_commit(rc_node_lookup_t *, tx_commit_data_t *, uint32_t *);
7565b7f77adStw 
7575b7f77adStw /* Functions to access transaction commands. */
7585b7f77adStw int tx_cmd_action(tx_commit_data_t *, size_t,
7595b7f77adStw     enum rep_protocol_transaction_action *);
7605b7f77adStw size_t tx_cmd_count(tx_commit_data_t *);
7615b7f77adStw int tx_cmd_nvalues(tx_commit_data_t *, size_t, uint32_t *);
7625b7f77adStw int tx_cmd_prop(tx_commit_data_t *, size_t, const char **);
7635b7f77adStw int tx_cmd_prop_type(tx_commit_data_t *, size_t, uint32_t *);
7645b7f77adStw int tx_cmd_value(tx_commit_data_t *, size_t, uint32_t, const char **);
7655b7f77adStw void tx_commit_data_free(tx_commit_data_t *);
7665b7f77adStw int tx_commit_data_new(const void *, size_t, tx_commit_data_t **);
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate /*
7697c478bd9Sstevel@tonic-gate  * snapshot.c
7707c478bd9Sstevel@tonic-gate  */
7717c478bd9Sstevel@tonic-gate int rc_snapshot_get(uint32_t, rc_snapshot_t **);
7727c478bd9Sstevel@tonic-gate void rc_snapshot_rele(rc_snapshot_t *);
7737c478bd9Sstevel@tonic-gate void rc_snaplevel_hold(rc_snaplevel_t *);
7747c478bd9Sstevel@tonic-gate void rc_snaplevel_rele(rc_snaplevel_t *);
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate /*
7777c478bd9Sstevel@tonic-gate  * backend.c
7787c478bd9Sstevel@tonic-gate  */
7797c478bd9Sstevel@tonic-gate int backend_init(const char *, const char *, int);
7806e1d2b42Samaguire boolean_t backend_is_upgraded(backend_tx_t *);
7817c478bd9Sstevel@tonic-gate void backend_fini(void);
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate rep_protocol_responseid_t backend_create_backup(const char *);
784c0889d7aSstevep rep_protocol_responseid_t backend_switch(int);
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate /*
7877c478bd9Sstevel@tonic-gate  * call on any database inconsistency -- cleans up state as best it can,
7887c478bd9Sstevel@tonic-gate  * and exits with a "Database Bad" error code.
7897c478bd9Sstevel@tonic-gate  */
7900b5c9250Shg void backend_panic(const char *, ...) __NORETURN;
7917c478bd9Sstevel@tonic-gate #pragma rarely_called(backend_panic)
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate backend_query_t *backend_query_alloc(void);
7947c478bd9Sstevel@tonic-gate void backend_query_append(backend_query_t *, const char *);
7957c478bd9Sstevel@tonic-gate void backend_query_add(backend_query_t *, const char *, ...);
7967c478bd9Sstevel@tonic-gate void backend_query_free(backend_query_t *);
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate typedef int backend_run_callback_f(void *data, int columns, char **vals,
7997c478bd9Sstevel@tonic-gate     char **names);
8007c478bd9Sstevel@tonic-gate #define	BACKEND_CALLBACK_CONTINUE	0
8017c478bd9Sstevel@tonic-gate #define	BACKEND_CALLBACK_ABORT		1
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate backend_run_callback_f backend_fail_if_seen;	/* aborts TX if called */
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate int backend_run(backend_type_t, backend_query_t *,
8067c478bd9Sstevel@tonic-gate     backend_run_callback_f *, void *);
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate int backend_tx_begin(backend_type_t, backend_tx_t **);
8097c478bd9Sstevel@tonic-gate int backend_tx_begin_ro(backend_type_t, backend_tx_t **);
8107c478bd9Sstevel@tonic-gate void backend_tx_end_ro(backend_tx_t *);
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate enum id_space {
8137c478bd9Sstevel@tonic-gate 	BACKEND_ID_SERVICE_INSTANCE,
8147c478bd9Sstevel@tonic-gate 	BACKEND_ID_PROPERTYGRP,
8157c478bd9Sstevel@tonic-gate 	BACKEND_ID_GENERATION,
8167c478bd9Sstevel@tonic-gate 	BACKEND_ID_PROPERTY,
8177c478bd9Sstevel@tonic-gate 	BACKEND_ID_VALUE,
8187c478bd9Sstevel@tonic-gate 	BACKEND_ID_SNAPNAME,
8197c478bd9Sstevel@tonic-gate 	BACKEND_ID_SNAPSHOT,
8207c478bd9Sstevel@tonic-gate 	BACKEND_ID_SNAPLEVEL,
8217c478bd9Sstevel@tonic-gate 	BACKEND_ID_INVALID	/* always illegal */
8227c478bd9Sstevel@tonic-gate };
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate uint32_t backend_new_id(backend_tx_t *, enum id_space);
8257c478bd9Sstevel@tonic-gate int backend_tx_run_update(backend_tx_t *, const char *, ...);
8267c478bd9Sstevel@tonic-gate int backend_tx_run_update_changed(backend_tx_t *, const char *, ...);
8277c478bd9Sstevel@tonic-gate int backend_tx_run_single_int(backend_tx_t *tx, backend_query_t *q,
8287c478bd9Sstevel@tonic-gate     uint32_t *buf);
8297c478bd9Sstevel@tonic-gate int backend_tx_run(backend_tx_t *, backend_query_t *,
8307c478bd9Sstevel@tonic-gate     backend_run_callback_f *, void *);
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate int backend_tx_commit(backend_tx_t *);
8337c478bd9Sstevel@tonic-gate void backend_tx_rollback(backend_tx_t *);
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8367c478bd9Sstevel@tonic-gate }
8377c478bd9Sstevel@tonic-gate #endif
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate #endif	/* _CONFIGD_H */
840