xref: /onnv-gate/usr/src/cmd/svc/configd/configd.h (revision 7128:66d3ca036e07)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55777Stw21770  * Common Development and Distribution License (the "License").
65777Stw21770  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
225777Stw21770  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_CONFIGD_H
270Sstevel@tonic-gate #define	_CONFIGD_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
315777Stw21770 #include <bsm/adt.h>
320Sstevel@tonic-gate #include <door.h>
330Sstevel@tonic-gate #include <pthread.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include <libscf.h>
380Sstevel@tonic-gate #include <repcache_protocol.h>
390Sstevel@tonic-gate #include <libuutil.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include <configd_exit.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #ifdef	__cplusplus
440Sstevel@tonic-gate extern "C" {
450Sstevel@tonic-gate #endif
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate  * Lock order:
490Sstevel@tonic-gate  *
500Sstevel@tonic-gate  *	client lock
510Sstevel@tonic-gate  *		iter locks, in ID order
520Sstevel@tonic-gate  *		entity locks, in ID order
530Sstevel@tonic-gate  *
540Sstevel@tonic-gate  *		(any iter/entity locks)
550Sstevel@tonic-gate  *			backend locks (NORMAL, then NONPERSIST)
560Sstevel@tonic-gate  *				rc_node lock
570Sstevel@tonic-gate  *					children's rc_node lock
580Sstevel@tonic-gate  *				cache bucket lock
590Sstevel@tonic-gate  *					rc_node lock[*]
600Sstevel@tonic-gate  *
610Sstevel@tonic-gate  *	* only one node may be grabbed while holding a bucket lock
620Sstevel@tonic-gate  *
630Sstevel@tonic-gate  *	leaf locks:  (no other locks may be aquired while holding one)
640Sstevel@tonic-gate  *		rc_pg_notify_lock
655777Stw21770  *		rc_annotate_lock
660Sstevel@tonic-gate  */
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Returns the minimum size for a structure of type 't' such
700Sstevel@tonic-gate  * that it is safe to access field 'f'.
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate #define	offsetofend(t, f)	(offsetof(t, f) + sizeof (((t *)0)->f))
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * We want MUTEX_HELD, but we also want pthreads.  So we're stuck with this.
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate struct _lwp_mutex_t;
780Sstevel@tonic-gate extern int _mutex_held(struct _lwp_mutex_t *);
790Sstevel@tonic-gate #define	MUTEX_HELD(m)		_mutex_held((struct _lwp_mutex_t *)(m))
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate  * Maximum levels of composition.
830Sstevel@tonic-gate  */
840Sstevel@tonic-gate #define	COMPOSITION_DEPTH	2
850Sstevel@tonic-gate 
860Sstevel@tonic-gate #define	CONFIGD_CORE	"core.%f.%t.%p"
870Sstevel@tonic-gate 
880Sstevel@tonic-gate #ifndef NDEBUG
890Sstevel@tonic-gate #define	bad_error(f, e)							\
900Sstevel@tonic-gate 	uu_warn("%s:%d: %s() returned bad error %d.  Aborting.\n",	\
910Sstevel@tonic-gate 	    __FILE__, __LINE__, f, e);					\
920Sstevel@tonic-gate 	abort()
930Sstevel@tonic-gate #else
940Sstevel@tonic-gate #define	bad_error(f, e)		abort()
950Sstevel@tonic-gate #endif
960Sstevel@tonic-gate 
970Sstevel@tonic-gate typedef enum backend_type {
980Sstevel@tonic-gate 	BACKEND_TYPE_NORMAL		= 0,
990Sstevel@tonic-gate 	BACKEND_TYPE_NONPERSIST,
1000Sstevel@tonic-gate 	BACKEND_TYPE_TOTAL			/* backend use only */
1010Sstevel@tonic-gate } backend_type_t;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * pre-declare rc_* types
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate typedef struct rc_node rc_node_t;
1070Sstevel@tonic-gate typedef struct rc_snapshot rc_snapshot_t;
1080Sstevel@tonic-gate typedef struct rc_snaplevel rc_snaplevel_t;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate  * notification layer -- protected by rc_pg_notify_lock
1120Sstevel@tonic-gate  */
1130Sstevel@tonic-gate typedef struct rc_notify_info rc_notify_info_t;
1140Sstevel@tonic-gate typedef struct rc_notify_delete rc_notify_delete_t;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate #define	RC_NOTIFY_MAX_NAMES	4	/* enough for now */
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate typedef struct rc_notify {
1190Sstevel@tonic-gate 	uu_list_node_t	rcn_list_node;
1200Sstevel@tonic-gate 	rc_node_t	*rcn_node;
1210Sstevel@tonic-gate 	rc_notify_info_t *rcn_info;
1220Sstevel@tonic-gate 	rc_notify_delete_t *rcn_delete;
1230Sstevel@tonic-gate } rc_notify_t;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate struct rc_notify_delete {
1260Sstevel@tonic-gate 	rc_notify_t rnd_notify;
1270Sstevel@tonic-gate 	char rnd_fmri[REP_PROTOCOL_FMRI_LEN];
1280Sstevel@tonic-gate };
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate struct rc_notify_info {
1310Sstevel@tonic-gate 	uu_list_node_t	rni_list_node;
1320Sstevel@tonic-gate 	rc_notify_t	rni_notify;
1330Sstevel@tonic-gate 	const char	*rni_namelist[RC_NOTIFY_MAX_NAMES];
1340Sstevel@tonic-gate 	const char	*rni_typelist[RC_NOTIFY_MAX_NAMES];
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	int		rni_flags;
1370Sstevel@tonic-gate 	int		rni_waiters;
1380Sstevel@tonic-gate 	pthread_cond_t	rni_cv;
1390Sstevel@tonic-gate };
1400Sstevel@tonic-gate #define	RC_NOTIFY_ACTIVE	0x00000001
1410Sstevel@tonic-gate #define	RC_NOTIFY_DRAIN		0x00000002
1420Sstevel@tonic-gate #define	RC_NOTIFY_EMPTYING	0x00000004
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate typedef struct rc_node_pg_notify {
1450Sstevel@tonic-gate 	uu_list_node_t	rnpn_node;
1460Sstevel@tonic-gate 	int		rnpn_fd;
1470Sstevel@tonic-gate 	rc_node_t	*rnpn_pg;
1480Sstevel@tonic-gate } rc_node_pg_notify_t;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * cache layer
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate  * The 'key' for the main object hash.  main_id is the main object
1560Sstevel@tonic-gate  * identifier.  The rl_ids array contains:
1570Sstevel@tonic-gate  *
1580Sstevel@tonic-gate  *	TYPE		RL_IDS
1590Sstevel@tonic-gate  *	scope		unused
1600Sstevel@tonic-gate  *	service		unused
1610Sstevel@tonic-gate  *	instance	{service_id}
1620Sstevel@tonic-gate  *	snapshot	{service_id, instance_id}
1630Sstevel@tonic-gate  *	snaplevel	{service_id, instance_id, name_id, snapshot_id}
1640Sstevel@tonic-gate  *	propertygroup	{service_id, (instance_id or 0), (name_id or 0),
1650Sstevel@tonic-gate  *			    (snapshot_id or 0), (l_id or 0)}
1660Sstevel@tonic-gate  *	property	{service_id, (instance_id or 0), (name_id or 0),
1670Sstevel@tonic-gate  *			    (snapshot_id or 0), (l_id or 0), pg_id, gen_id}
1680Sstevel@tonic-gate  */
1690Sstevel@tonic-gate #define	ID_SERVICE	0
1700Sstevel@tonic-gate #define	ID_INSTANCE	1
1710Sstevel@tonic-gate #define	ID_NAME		2
1720Sstevel@tonic-gate #define	ID_SNAPSHOT	3
1730Sstevel@tonic-gate #define	ID_LEVEL	4
1740Sstevel@tonic-gate #define	ID_PG		5
1750Sstevel@tonic-gate #define	ID_GEN		6
1760Sstevel@tonic-gate #define	MAX_IDS	7
1770Sstevel@tonic-gate typedef struct rc_node_lookup {
1780Sstevel@tonic-gate 	uint16_t	rl_type;		/* REP_PROTOCOL_ENTITY_* */
1790Sstevel@tonic-gate 	uint16_t	rl_backend;		/* BACKEND_TYPE_* */
1800Sstevel@tonic-gate 	uint32_t	rl_main_id;		/* primary identifier */
1810Sstevel@tonic-gate 	uint32_t	rl_ids[MAX_IDS];	/* context */
1820Sstevel@tonic-gate } rc_node_lookup_t;
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate struct rc_node {
1850Sstevel@tonic-gate 	/*
1860Sstevel@tonic-gate 	 * read-only data
1870Sstevel@tonic-gate 	 */
1880Sstevel@tonic-gate 	rc_node_lookup_t rn_id;			/* must be first */
1890Sstevel@tonic-gate 	uint32_t	rn_hash;
1900Sstevel@tonic-gate 	const char	*rn_name;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	/*
1930Sstevel@tonic-gate 	 * type-specific state
1940Sstevel@tonic-gate 	 * (if space becomes an issue, these can become a union)
1950Sstevel@tonic-gate 	 */
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	/*
1980Sstevel@tonic-gate 	 * Used by instances, snapshots, and "composed property groups" only.
1990Sstevel@tonic-gate 	 * These are the entities whose properties should appear composed when
2000Sstevel@tonic-gate 	 * this entity is traversed by a composed iterator.  0 is the top-most
2010Sstevel@tonic-gate 	 * entity, down to COMPOSITION_DEPTH - 1.
2020Sstevel@tonic-gate 	 */
2030Sstevel@tonic-gate 	rc_node_t	*rn_cchain[COMPOSITION_DEPTH];
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	/*
2060Sstevel@tonic-gate 	 * used by property groups only
2070Sstevel@tonic-gate 	 */
2080Sstevel@tonic-gate 	const char	*rn_type;
2090Sstevel@tonic-gate 	uint32_t	rn_pgflags;
2100Sstevel@tonic-gate 	uint32_t	rn_gen_id;
2110Sstevel@tonic-gate 	uu_list_t	*rn_pg_notify_list;	/* prot by rc_pg_notify_lock */
2120Sstevel@tonic-gate 	rc_notify_t	rn_notify;		/* prot by rc_pg_notify_lock */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	/*
2150Sstevel@tonic-gate 	 * used by properties only
2160Sstevel@tonic-gate 	 */
2170Sstevel@tonic-gate 	rep_protocol_value_type_t rn_valtype;
2180Sstevel@tonic-gate 	const char	*rn_values;		/* protected by rn_lock */
2190Sstevel@tonic-gate 	size_t		rn_values_count;	/* protected by rn_lock */
2200Sstevel@tonic-gate 	size_t		rn_values_size;		/* protected by rn_lock */
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	/*
2230Sstevel@tonic-gate 	 * used by snapshots only
2240Sstevel@tonic-gate 	 */
2250Sstevel@tonic-gate 	uint32_t	rn_snapshot_id;
2260Sstevel@tonic-gate 	rc_snapshot_t	*rn_snapshot;		/* protected by rn_lock */
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	/*
2290Sstevel@tonic-gate 	 * used by snaplevels only
2300Sstevel@tonic-gate 	 */
2310Sstevel@tonic-gate 	rc_snaplevel_t	*rn_snaplevel;
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	/*
2340Sstevel@tonic-gate 	 * mutable state
2350Sstevel@tonic-gate 	 */
2360Sstevel@tonic-gate 	pthread_mutex_t	rn_lock;
2370Sstevel@tonic-gate 	pthread_cond_t	rn_cv;
2380Sstevel@tonic-gate 	uint32_t	rn_flags;
2390Sstevel@tonic-gate 	uint32_t	rn_refs;		/* reference count */
2400Sstevel@tonic-gate 	uint32_t	rn_other_refs;		/* atomic refcount */
2410Sstevel@tonic-gate 	uint32_t	rn_other_refs_held;	/* for 1->0 transitions */
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	uu_list_t	*rn_children;
2440Sstevel@tonic-gate 	uu_list_node_t	rn_sibling_node;
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	rc_node_t	*rn_parent;		/* set if on child list */
2470Sstevel@tonic-gate 	rc_node_t	*rn_former;		/* next former node */
2480Sstevel@tonic-gate 	rc_node_t	*rn_parent_ref;		/* reference count target */
2495777Stw21770 	const char	*rn_fmri;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * external state (protected by hash chain lock)
2530Sstevel@tonic-gate 	 */
2540Sstevel@tonic-gate 	rc_node_t	*rn_hash_next;
2550Sstevel@tonic-gate };
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate  * flag ordering:
2590Sstevel@tonic-gate  *	RC_DYING
2600Sstevel@tonic-gate  *		RC_NODE_CHILDREN_CHANGING
2610Sstevel@tonic-gate  *		RC_NODE_CREATING_CHILD
2620Sstevel@tonic-gate  *		RC_NODE_USING_PARENT
2630Sstevel@tonic-gate  *			RC_NODE_IN_TX
2640Sstevel@tonic-gate  *
2650Sstevel@tonic-gate  * RC_NODE_USING_PARENT is special, because it lets you proceed up the tree,
2660Sstevel@tonic-gate  * in the reverse of the usual locking order.  Because of this, there are
2670Sstevel@tonic-gate  * limitations on what you can do while holding it.  While holding
2680Sstevel@tonic-gate  * RC_NODE_USING_PARENT, you may:
2690Sstevel@tonic-gate  *	bump or release your parent's reference count
2700Sstevel@tonic-gate  *	access fields in your parent
2710Sstevel@tonic-gate  *	hold RC_NODE_USING_PARENT in the parent, proceeding recursively.
2720Sstevel@tonic-gate  *
2730Sstevel@tonic-gate  * If you are only holding *one* node's RC_NODE_USING_PARENT, and:
2740Sstevel@tonic-gate  *	you are *not* proceeding recursively, you can hold your
2750Sstevel@tonic-gate  *	    immediate parent's RC_NODE_CHILDREN_CHANGING flag.
2760Sstevel@tonic-gate  *	you hold your parent's RC_NODE_CHILDREN_CHANGING flag, you can add
2770Sstevel@tonic-gate  *	    RC_NODE_IN_TX to your flags.
2780Sstevel@tonic-gate  *	you want to grab a flag in your parent, you must lock your parent,
2790Sstevel@tonic-gate  *	    lock yourself, drop RC_NODE_USING_PARENT, unlock yourself,
2800Sstevel@tonic-gate  *	    then proceed to manipulate the parent.
2810Sstevel@tonic-gate  */
2820Sstevel@tonic-gate #define	RC_NODE_CHILDREN_CHANGING	0x00000001 /* child list in flux */
2830Sstevel@tonic-gate #define	RC_NODE_HAS_CHILDREN		0x00000002 /* child list is accurate */
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate #define	RC_NODE_IN_PARENT		0x00000004 /* I'm in my parent's list */
2860Sstevel@tonic-gate #define	RC_NODE_USING_PARENT		0x00000008 /* parent ptr in use */
2870Sstevel@tonic-gate #define	RC_NODE_CREATING_CHILD		0x00000010 /* a create is in progress */
2880Sstevel@tonic-gate #define	RC_NODE_IN_TX			0x00000020 /* a tx is in progess */
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate #define	RC_NODE_OLD			0x00000400 /* out-of-date object */
2910Sstevel@tonic-gate #define	RC_NODE_ON_FORMER		0x00000800 /* on an rn_former list */
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate #define	RC_NODE_PARENT_REF		0x00001000 /* parent_ref in use */
2940Sstevel@tonic-gate #define	RC_NODE_UNREFED			0x00002000 /* unref processing active */
2950Sstevel@tonic-gate #define	RC_NODE_DYING			0x00004000 /* node is being deleted */
2960Sstevel@tonic-gate #define	RC_NODE_DEAD			0x00008000 /* node has been deleted */
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate #define	RC_NODE_DYING_FLAGS						\
2990Sstevel@tonic-gate 	(RC_NODE_CHILDREN_CHANGING | RC_NODE_IN_TX | RC_NODE_DYING |	\
3000Sstevel@tonic-gate 	    RC_NODE_CREATING_CHILD)
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate #define	RC_NODE_WAITING_FLAGS						\
3030Sstevel@tonic-gate 	(RC_NODE_DYING_FLAGS | RC_NODE_USING_PARENT)
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 
3065777Stw21770 typedef enum rc_auth_state {
3075777Stw21770 	RC_AUTH_UNKNOWN = 0,		/* No checks done yet. */
3085777Stw21770 	RC_AUTH_FAILED,			/* Authorization checked & failed. */
3095777Stw21770 	RC_AUTH_PASSED			/* Authorization succeeded. */
3105777Stw21770 } rc_auth_state_t;
3115777Stw21770 
3125777Stw21770 /*
3135777Stw21770  * Some authorization checks are performed in rc_node_setup_tx() in
3145777Stw21770  * response to the REP_PROTOCOL_PROPERTYGRP_TX_START message.  Other checks
3155777Stw21770  * must wait until the actual transaction operations are received in the
3165777Stw21770  * REP_PROTOCOL_PROPERTYGRP_TX_COMMIT message.  This second set of checks
3175777Stw21770  * is performed in rc_tx_commit().  rnp_auth_string and rnp_authorized in
3185777Stw21770  * the following structure are used to hold the results of the
3195777Stw21770  * authorization checking done in rc_node_setup_tx() for later use by
3205777Stw21770  * rc_tx_commit().
3215777Stw21770  *
3225777Stw21770  * In client.c transactions are represented by rc_node_ptr structures which
3235777Stw21770  * point to a property group rc_node_t.  Thus, this is an appropriate place
3245777Stw21770  * to hold authorization state.
3255777Stw21770  */
3260Sstevel@tonic-gate typedef struct rc_node_ptr {
3270Sstevel@tonic-gate 	rc_node_t	*rnp_node;
3285777Stw21770 	const char	*rnp_auth_string;	/* authorization string */
3295777Stw21770 	rc_auth_state_t	rnp_authorized;		/* transaction pre-auth rslt. */
3300Sstevel@tonic-gate 	char		rnp_deleted;		/* object was deleted */
3310Sstevel@tonic-gate } rc_node_ptr_t;
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate #define	NODE_PTR_NOT_HELD(npp) \
3340Sstevel@tonic-gate 	    ((npp)->rnp_node == NULL || !MUTEX_HELD(&(npp)->rnp_node->rn_lock))
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate typedef int rc_iter_filter_func(rc_node_t *, void *);
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate typedef struct rc_node_iter {
3390Sstevel@tonic-gate 	rc_node_t	*rni_parent;
3400Sstevel@tonic-gate 	int		rni_clevel;	/* index into rni_parent->rn_cchain[] */
3410Sstevel@tonic-gate 	rc_node_t	*rni_iter_node;
3420Sstevel@tonic-gate 	uu_list_walk_t	*rni_iter;
3430Sstevel@tonic-gate 	uint32_t	rni_type;
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 	/*
3460Sstevel@tonic-gate 	 * for normal walks
3470Sstevel@tonic-gate 	 */
3480Sstevel@tonic-gate 	rc_iter_filter_func *rni_filter;
3490Sstevel@tonic-gate 	void		*rni_filter_arg;
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	/*
3520Sstevel@tonic-gate 	 * for value walks
3530Sstevel@tonic-gate 	 */
3540Sstevel@tonic-gate 	uint32_t	rni_offset;		/* next value offset */
3550Sstevel@tonic-gate 	uint32_t	rni_last_offset;	/* previous value offset */
3560Sstevel@tonic-gate } rc_node_iter_t;
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate typedef struct rc_node_tx {
3590Sstevel@tonic-gate 	rc_node_ptr_t	rnt_ptr;
3600Sstevel@tonic-gate 	int		rnt_authorized;		/* No need to check anymore. */
3610Sstevel@tonic-gate } rc_node_tx_t;
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate typedef struct cache_bucket {
3650Sstevel@tonic-gate 	pthread_mutex_t	cb_lock;
3660Sstevel@tonic-gate 	rc_node_t	*cb_head;
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	char		cb_pad[64 - sizeof (pthread_mutex_t) -
3690Sstevel@tonic-gate 			    2 * sizeof (rc_node_t *)];
3700Sstevel@tonic-gate } cache_bucket_t;
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate /*
3735777Stw21770  * tx_commit_data_tx is an opaque structure which is defined in object.c.
3745777Stw21770  * It contains the data of the transaction that is to be committed.
3755777Stw21770  * Accessor functions in object.c allow other modules to retrieve
3765777Stw21770  * information.
3775777Stw21770  */
3785777Stw21770 typedef struct tx_commit_data tx_commit_data_t;
3795777Stw21770 
3805777Stw21770 /*
3810Sstevel@tonic-gate  * Snapshots
3820Sstevel@tonic-gate  */
3830Sstevel@tonic-gate struct rc_snapshot {
3840Sstevel@tonic-gate 	uint32_t	rs_snap_id;
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	pthread_mutex_t	rs_lock;
3870Sstevel@tonic-gate 	pthread_cond_t	rs_cv;
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 	uint32_t	rs_flags;
3900Sstevel@tonic-gate 	uint32_t	rs_refcnt;	/* references from rc_nodes */
3910Sstevel@tonic-gate 	uint32_t	rs_childref;	/* references to children */
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	rc_snaplevel_t	*rs_levels;	/* list of levels */
3940Sstevel@tonic-gate 	rc_snapshot_t	*rs_hash_next;
3950Sstevel@tonic-gate };
3960Sstevel@tonic-gate #define	RC_SNAPSHOT_FILLING	0x00000001	/* rs_levels changing */
3970Sstevel@tonic-gate #define	RC_SNAPSHOT_READY	0x00000002
3980Sstevel@tonic-gate #define	RC_SNAPSHOT_DEAD	0x00000004	/* no resources */
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate typedef struct rc_snaplevel_pgs {
4010Sstevel@tonic-gate 	uint32_t	rsp_pg_id;
4020Sstevel@tonic-gate 	uint32_t	rsp_gen_id;
4030Sstevel@tonic-gate } rc_snaplevel_pgs_t;
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate struct rc_snaplevel {
4060Sstevel@tonic-gate 	rc_snapshot_t	*rsl_parent;
4070Sstevel@tonic-gate 	uint32_t	rsl_level_num;
4080Sstevel@tonic-gate 	uint32_t	rsl_level_id;
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate 	uint32_t	rsl_service_id;
4110Sstevel@tonic-gate 	uint32_t	rsl_instance_id;
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate 	const char	*rsl_scope;
4140Sstevel@tonic-gate 	const char	*rsl_service;
4150Sstevel@tonic-gate 	const char	*rsl_instance;
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 	rc_snaplevel_t	*rsl_next;
4180Sstevel@tonic-gate };
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate /*
4210Sstevel@tonic-gate  * Client layer -- the IDs fields must be first, in order for the search
4220Sstevel@tonic-gate  * routines to work correctly.
4230Sstevel@tonic-gate  */
4240Sstevel@tonic-gate enum repcache_txstate {
4250Sstevel@tonic-gate 	REPCACHE_TX_INIT,
4260Sstevel@tonic-gate 	REPCACHE_TX_SETUP,
4270Sstevel@tonic-gate 	REPCACHE_TX_COMMITTED
4280Sstevel@tonic-gate };
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate typedef struct repcache_entity {
4310Sstevel@tonic-gate 	uint32_t	re_id;
432407Sjwadams 	uu_avl_node_t	re_link;
4330Sstevel@tonic-gate 	uint32_t	re_changeid;
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate 	pthread_mutex_t	re_lock;
4360Sstevel@tonic-gate 	uint32_t	re_type;
4370Sstevel@tonic-gate 	rc_node_ptr_t	re_node;
4380Sstevel@tonic-gate 	enum repcache_txstate re_txstate;	/* property groups only */
4390Sstevel@tonic-gate } repcache_entity_t;
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate typedef struct repcache_iter {
4420Sstevel@tonic-gate 	uint32_t	ri_id;
443407Sjwadams 	uu_avl_node_t	ri_link;
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	uint32_t	ri_type;	/* result type */
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate 	pthread_mutex_t	ri_lock;
4480Sstevel@tonic-gate 	uint32_t	ri_sequence;
4490Sstevel@tonic-gate 	rc_node_iter_t	*ri_iter;
4500Sstevel@tonic-gate } repcache_iter_t;
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate typedef struct repcache_client {
4530Sstevel@tonic-gate 	/*
4540Sstevel@tonic-gate 	 * constants
4550Sstevel@tonic-gate 	 */
4560Sstevel@tonic-gate 	uint32_t	rc_id;		/* must be first */
4570Sstevel@tonic-gate 	int		rc_all_auths;	/* bypass auth checks */
4580Sstevel@tonic-gate 	uint32_t	rc_debug;	/* debug flags */
4590Sstevel@tonic-gate 	pid_t		rc_pid;		/* pid of opening process */
4600Sstevel@tonic-gate 	door_id_t	rc_doorid;	/* a globally unique identifier */
4610Sstevel@tonic-gate 	int		rc_doorfd;	/* our door's FD */
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate 	/*
4645777Stw21770 	 * Constants used for security auditing
4655777Stw21770 	 *
4665777Stw21770 	 * rc_adt_session points to the audit session data that is used for
4675777Stw21770 	 * the life of the client.  rc_adt_sessionid is the session ID that
4685777Stw21770 	 * is initially assigned when the audit session is started.  See
4695777Stw21770 	 * start_audit_session() in client.c.  This session id is used for
4705777Stw21770 	 * audit events except when we are processing a set of annotated
4715777Stw21770 	 * events.  Annotated events use a separate session id so that they
4725777Stw21770 	 * can be grouped.  See set_annotation() in client.c.
4735777Stw21770 	 */
4745777Stw21770 	adt_session_data_t *rc_adt_session;	/* Session data. */
4755777Stw21770 	au_asid_t	rc_adt_sessionid;	/* Main session ID for */
4765777Stw21770 						/* auditing */
4775777Stw21770 
4785777Stw21770 	/*
4790Sstevel@tonic-gate 	 * client list linkage, protected by hash chain lock
4800Sstevel@tonic-gate 	 */
4810Sstevel@tonic-gate 	uu_list_node_t	rc_link;
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 	/*
4840Sstevel@tonic-gate 	 * notification information, protected by rc_node layer
4850Sstevel@tonic-gate 	 */
4860Sstevel@tonic-gate 	rc_node_pg_notify_t	rc_pg_notify;
4870Sstevel@tonic-gate 	rc_notify_info_t	rc_notify_info;
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 	/*
4900Sstevel@tonic-gate 	 * client_wait output, only usable by rc_notify_thr
4910Sstevel@tonic-gate 	 */
4920Sstevel@tonic-gate 	rc_node_ptr_t	rc_notify_ptr;
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate 	/*
495407Sjwadams 	 * register sets, protected by rc_lock
4960Sstevel@tonic-gate 	 */
497407Sjwadams 	uu_avl_t	*rc_entities;
498407Sjwadams 	uu_avl_t	*rc_iters;
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate 	/*
5010Sstevel@tonic-gate 	 * Variables, protected by rc_lock
5020Sstevel@tonic-gate 	 */
5030Sstevel@tonic-gate 	int		rc_refcnt;	/* in-progress door calls */
5045777Stw21770 	int		rc_flags;	/* see RC_CLIENT_* symbols below */
5050Sstevel@tonic-gate 	uint32_t	rc_changeid;	/* used to make backups idempotent */
5060Sstevel@tonic-gate 	pthread_t	rc_insert_thr;	/* single thread trying to insert */
5070Sstevel@tonic-gate 	pthread_t	rc_notify_thr;	/* single thread waiting for notify */
5080Sstevel@tonic-gate 	pthread_cond_t	rc_cv;
5090Sstevel@tonic-gate 	pthread_mutex_t	rc_lock;
5105777Stw21770 
5115777Stw21770 	/*
5125777Stw21770 	 * Per-client audit information.  These fields must be protected by
5135777Stw21770 	 * rc_annotate_lock separately from rc_lock because they may need
5145777Stw21770 	 * to be accessed from rc_node.c with an entity or iterator lock
5155777Stw21770 	 * held, and those must be taken after rc_lock.
5165777Stw21770 	 */
5175777Stw21770 	int		rc_annotate;	/* generate annotation event if set */
5185777Stw21770 	const char	*rc_operation;	/* operation for audit annotation */
5195777Stw21770 	const char	*rc_file;	/* file name for audit annotation */
5205777Stw21770 	pthread_mutex_t	rc_annotate_lock;
5210Sstevel@tonic-gate } repcache_client_t;
5225777Stw21770 
5235777Stw21770 /* Bit definitions for rc_flags. */
5240Sstevel@tonic-gate #define	RC_CLIENT_DEAD			0x00000001
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate typedef struct client_bucket {
5270Sstevel@tonic-gate 	pthread_mutex_t	cb_lock;
5280Sstevel@tonic-gate 	uu_list_t	*cb_list;
5290Sstevel@tonic-gate 	char ch_pad[64 - sizeof (pthread_mutex_t) - sizeof (uu_list_t *)];
5300Sstevel@tonic-gate } client_bucket_t;
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate enum rc_ptr_type {
5330Sstevel@tonic-gate 	RC_PTR_TYPE_ENTITY = 1,
5340Sstevel@tonic-gate 	RC_PTR_TYPE_ITER
5350Sstevel@tonic-gate };
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate typedef struct request_log_ptr {
5380Sstevel@tonic-gate 	enum rc_ptr_type	rlp_type;
5390Sstevel@tonic-gate 	uint32_t		rlp_id;
5400Sstevel@tonic-gate 	void			*rlp_ptr; /* repcache_{entity,iter}_t */
5410Sstevel@tonic-gate 	void			*rlp_data;	/* rc_node, for ENTITY only */
5420Sstevel@tonic-gate } request_log_ptr_t;
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate #define	MAX_PTRS	3
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate /*
5470Sstevel@tonic-gate  * rl_start through rl_client cannot move without changing start_log()
5480Sstevel@tonic-gate  */
5490Sstevel@tonic-gate typedef struct request_log_entry {
5500Sstevel@tonic-gate 	hrtime_t		rl_start;
5510Sstevel@tonic-gate 	hrtime_t		rl_end;
5520Sstevel@tonic-gate 	pthread_t		rl_tid;
5530Sstevel@tonic-gate 	uint32_t		rl_clientid;
5540Sstevel@tonic-gate 	repcache_client_t	*rl_client;
5550Sstevel@tonic-gate 	enum rep_protocol_requestid rl_request;
5560Sstevel@tonic-gate 	rep_protocol_responseid_t rl_response;
5570Sstevel@tonic-gate 	int			rl_num_ptrs;
5580Sstevel@tonic-gate 	request_log_ptr_t	rl_ptrs[MAX_PTRS];
5590Sstevel@tonic-gate } request_log_entry_t;
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate /*
5620Sstevel@tonic-gate  * thread information
5630Sstevel@tonic-gate  */
5640Sstevel@tonic-gate typedef enum thread_state {
5650Sstevel@tonic-gate 	TI_CREATED,
5660Sstevel@tonic-gate 	TI_DOOR_RETURN,
5670Sstevel@tonic-gate 	TI_SIGNAL_WAIT,
5680Sstevel@tonic-gate 	TI_MAIN_DOOR_CALL,
5690Sstevel@tonic-gate 	TI_CLIENT_CALL
5700Sstevel@tonic-gate } thread_state_t;
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate typedef struct thread_info {
5730Sstevel@tonic-gate 	pthread_t	ti_thread;
5740Sstevel@tonic-gate 	uu_list_node_t	ti_node;		/* for list of all thread */
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate 	/*
5770Sstevel@tonic-gate 	 * per-thread globals
5780Sstevel@tonic-gate 	 */
5790Sstevel@tonic-gate 	ucred_t		*ti_ucred;		/* for credential lookups */
5800Sstevel@tonic-gate 	int		ti_ucred_read;		/* ucred holds current creds */
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate 	/*
5830Sstevel@tonic-gate 	 * per-thread state information, for debuggers
5840Sstevel@tonic-gate 	 */
5850Sstevel@tonic-gate 	hrtime_t	ti_lastchange;
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate 	thread_state_t	ti_state;
5880Sstevel@tonic-gate 	thread_state_t	ti_prev_state;
5890Sstevel@tonic-gate 
5900Sstevel@tonic-gate 	repcache_client_t *ti_active_client;
5910Sstevel@tonic-gate 	request_log_entry_t	ti_log;
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 	struct rep_protocol_request *ti_client_request;
5940Sstevel@tonic-gate 	repository_door_request_t *ti_main_door_request;
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate } thread_info_t;
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate /*
5990Sstevel@tonic-gate  * Backend layer
6000Sstevel@tonic-gate  */
6010Sstevel@tonic-gate typedef struct backend_query backend_query_t;
6020Sstevel@tonic-gate typedef struct backend_tx backend_tx_t;
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate /*
6050Sstevel@tonic-gate  * configd.c
6060Sstevel@tonic-gate  */
6070Sstevel@tonic-gate int create_connection(ucred_t *cred, repository_door_request_t *rp,
6080Sstevel@tonic-gate     size_t rp_size, int *out_fd);
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate thread_info_t *thread_self(void);
6110Sstevel@tonic-gate void thread_newstate(thread_info_t *, thread_state_t);
6120Sstevel@tonic-gate ucred_t *get_ucred(void);
6130Sstevel@tonic-gate int ucred_is_privileged(ucred_t *);
6140Sstevel@tonic-gate 
6155777Stw21770 adt_session_data_t *get_audit_session(void);
6165777Stw21770 
6170Sstevel@tonic-gate void configd_critical(const char *, ...);
6180Sstevel@tonic-gate void configd_vcritical(const char *, va_list);
619*7128Samaguire void configd_info(const char *, ...);
6200Sstevel@tonic-gate 
6210Sstevel@tonic-gate extern int is_main_repository;
6220Sstevel@tonic-gate extern int max_repository_backups;
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate /*
6250Sstevel@tonic-gate  * maindoor.c
6260Sstevel@tonic-gate  */
6270Sstevel@tonic-gate int setup_main_door(const char *);
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate /*
6300Sstevel@tonic-gate  * client.c
6310Sstevel@tonic-gate  */
6325777Stw21770 int client_annotation_needed(char *, size_t, char *, size_t);
6335777Stw21770 void client_annotation_finished(void);
6340Sstevel@tonic-gate int create_client(pid_t, uint32_t, int, int *);
6350Sstevel@tonic-gate int client_init(void);
6360Sstevel@tonic-gate int client_is_privileged(void);
6370Sstevel@tonic-gate void log_enter(request_log_entry_t *);
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate /*
6400Sstevel@tonic-gate  * rc_node.c, backend/cache interfaces (rc_node_t)
6410Sstevel@tonic-gate  */
6420Sstevel@tonic-gate int rc_node_init();
6430Sstevel@tonic-gate int rc_check_type_name(uint32_t, const char *);
6440Sstevel@tonic-gate 
6455777Stw21770 void rc_node_ptr_free_mem(rc_node_ptr_t *);
6460Sstevel@tonic-gate void rc_node_rele(rc_node_t *);
6470Sstevel@tonic-gate rc_node_t *rc_node_setup(rc_node_t *, rc_node_lookup_t *,
6480Sstevel@tonic-gate     const char *, rc_node_t *);
6490Sstevel@tonic-gate rc_node_t *rc_node_setup_pg(rc_node_t *, rc_node_lookup_t *, const char *,
6500Sstevel@tonic-gate     const char *, uint32_t, uint32_t, rc_node_t *);
6510Sstevel@tonic-gate rc_node_t *rc_node_setup_snapshot(rc_node_t *, rc_node_lookup_t *, const char *,
6520Sstevel@tonic-gate     uint32_t, rc_node_t *);
6530Sstevel@tonic-gate rc_node_t *rc_node_setup_snaplevel(rc_node_t *, rc_node_lookup_t *,
6540Sstevel@tonic-gate     rc_snaplevel_t *, rc_node_t *);
6550Sstevel@tonic-gate int rc_node_create_property(rc_node_t *, rc_node_lookup_t *,
6560Sstevel@tonic-gate     const char *, rep_protocol_value_type_t, const char *, size_t, size_t);
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate rc_node_t *rc_node_alloc(void);
6590Sstevel@tonic-gate void rc_node_destroy(rc_node_t *);
6600Sstevel@tonic-gate 
6610Sstevel@tonic-gate /*
6620Sstevel@tonic-gate  * rc_node.c, client interface (rc_node_ptr_t, rc_node_iter_t)
6630Sstevel@tonic-gate  */
6640Sstevel@tonic-gate void rc_node_ptr_init(rc_node_ptr_t *);
6650Sstevel@tonic-gate int rc_local_scope(uint32_t, rc_node_ptr_t *);
6660Sstevel@tonic-gate 
6670Sstevel@tonic-gate void rc_node_clear(rc_node_ptr_t *, int);
6680Sstevel@tonic-gate void rc_node_ptr_assign(rc_node_ptr_t *, const rc_node_ptr_t *);
6690Sstevel@tonic-gate int rc_node_name(rc_node_ptr_t *, char *, size_t, uint32_t, size_t *);
6700Sstevel@tonic-gate int rc_node_fmri(rc_node_ptr_t *, char *, size_t, size_t *);
6710Sstevel@tonic-gate int rc_node_parent_type(rc_node_ptr_t *, uint32_t *);
6720Sstevel@tonic-gate int rc_node_get_child(rc_node_ptr_t *, const char *, uint32_t, rc_node_ptr_t *);
6730Sstevel@tonic-gate int rc_node_get_parent(rc_node_ptr_t *, uint32_t, rc_node_ptr_t *);
6740Sstevel@tonic-gate int rc_node_get_property_type(rc_node_ptr_t *, rep_protocol_value_type_t *);
6750Sstevel@tonic-gate int rc_node_get_property_value(rc_node_ptr_t *,
6760Sstevel@tonic-gate     struct rep_protocol_value_response *, size_t *);
6770Sstevel@tonic-gate int rc_node_create_child(rc_node_ptr_t *, uint32_t, const char *,
6780Sstevel@tonic-gate     rc_node_ptr_t *);
6790Sstevel@tonic-gate int rc_node_create_child_pg(rc_node_ptr_t *, uint32_t, const char *,
6800Sstevel@tonic-gate     const char *, uint32_t, rc_node_ptr_t *);
6810Sstevel@tonic-gate int rc_node_update(rc_node_ptr_t *);
6820Sstevel@tonic-gate int rc_node_delete(rc_node_ptr_t *);
6830Sstevel@tonic-gate int rc_node_next_snaplevel(rc_node_ptr_t *, rc_node_ptr_t *);
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate int rc_node_setup_iter(rc_node_ptr_t *, rc_node_iter_t **, uint32_t,
6860Sstevel@tonic-gate     size_t, const char *);
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate int rc_iter_next(rc_node_iter_t *, rc_node_ptr_t *, uint32_t);
6890Sstevel@tonic-gate int rc_iter_next_value(rc_node_iter_t *, struct rep_protocol_value_response *,
6900Sstevel@tonic-gate     size_t *, int);
6910Sstevel@tonic-gate void rc_iter_destroy(rc_node_iter_t **);
6920Sstevel@tonic-gate 
6930Sstevel@tonic-gate int rc_node_setup_tx(rc_node_ptr_t *, rc_node_ptr_t *);
6940Sstevel@tonic-gate int rc_tx_commit(rc_node_ptr_t *, const void *, size_t);
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate void rc_pg_notify_init(rc_node_pg_notify_t *);
6970Sstevel@tonic-gate int rc_pg_notify_setup(rc_node_pg_notify_t *, rc_node_ptr_t *, int);
6980Sstevel@tonic-gate void rc_pg_notify_fini(rc_node_pg_notify_t *);
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate void rc_notify_info_init(rc_notify_info_t *);
7010Sstevel@tonic-gate int rc_notify_info_add_name(rc_notify_info_t *, const char *);
7020Sstevel@tonic-gate int rc_notify_info_add_type(rc_notify_info_t *, const char *);
7030Sstevel@tonic-gate int rc_notify_info_wait(rc_notify_info_t *, rc_node_ptr_t *, char *, size_t);
7040Sstevel@tonic-gate void rc_notify_info_fini(rc_notify_info_t *);
7050Sstevel@tonic-gate 
7060Sstevel@tonic-gate int rc_snapshot_take_new(rc_node_ptr_t *, const char *,
7070Sstevel@tonic-gate     const char *, const char *, rc_node_ptr_t *);
7080Sstevel@tonic-gate int rc_snapshot_take_attach(rc_node_ptr_t *, rc_node_ptr_t *);
7090Sstevel@tonic-gate int rc_snapshot_attach(rc_node_ptr_t *, rc_node_ptr_t *);
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate /*
7120Sstevel@tonic-gate  * file_object.c
7130Sstevel@tonic-gate  */
7140Sstevel@tonic-gate int object_fill_children(rc_node_t *);
7150Sstevel@tonic-gate int object_create(rc_node_t *, uint32_t, const char *, rc_node_t **);
7160Sstevel@tonic-gate int object_create_pg(rc_node_t *, uint32_t, const char *, const char *,
7170Sstevel@tonic-gate     uint32_t, rc_node_t **);
7180Sstevel@tonic-gate 
7190Sstevel@tonic-gate int object_delete(rc_node_t *);
7200Sstevel@tonic-gate void object_free_values(const char *, uint32_t, size_t, size_t);
7210Sstevel@tonic-gate 
722407Sjwadams int object_fill_snapshot(rc_snapshot_t *);
7230Sstevel@tonic-gate 
7240Sstevel@tonic-gate int object_snapshot_take_new(rc_node_t *, const char *, const char *,
7250Sstevel@tonic-gate     const char *, rc_node_t **);
7260Sstevel@tonic-gate int object_snapshot_attach(rc_node_lookup_t *, uint32_t *, int);
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate /*
7290Sstevel@tonic-gate  * object.c
7300Sstevel@tonic-gate  */
7315777Stw21770 int object_tx_commit(rc_node_lookup_t *, tx_commit_data_t *, uint32_t *);
7325777Stw21770 
7335777Stw21770 /* Functions to access transaction commands. */
7345777Stw21770 int tx_cmd_action(tx_commit_data_t *, size_t,
7355777Stw21770     enum rep_protocol_transaction_action *);
7365777Stw21770 size_t tx_cmd_count(tx_commit_data_t *);
7375777Stw21770 int tx_cmd_nvalues(tx_commit_data_t *, size_t, uint32_t *);
7385777Stw21770 int tx_cmd_prop(tx_commit_data_t *, size_t, const char **);
7395777Stw21770 int tx_cmd_prop_type(tx_commit_data_t *, size_t, uint32_t *);
7405777Stw21770 int tx_cmd_value(tx_commit_data_t *, size_t, uint32_t, const char **);
7415777Stw21770 void tx_commit_data_free(tx_commit_data_t *);
7425777Stw21770 int tx_commit_data_new(const void *, size_t, tx_commit_data_t **);
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate /*
7450Sstevel@tonic-gate  * snapshot.c
7460Sstevel@tonic-gate  */
7470Sstevel@tonic-gate int rc_snapshot_get(uint32_t, rc_snapshot_t **);
7480Sstevel@tonic-gate void rc_snapshot_rele(rc_snapshot_t *);
7490Sstevel@tonic-gate void rc_snaplevel_hold(rc_snaplevel_t *);
7500Sstevel@tonic-gate void rc_snaplevel_rele(rc_snaplevel_t *);
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate /*
7530Sstevel@tonic-gate  * backend.c
7540Sstevel@tonic-gate  */
7550Sstevel@tonic-gate int backend_init(const char *, const char *, int);
756*7128Samaguire boolean_t backend_is_upgraded(backend_tx_t *);
7570Sstevel@tonic-gate void backend_fini(void);
7580Sstevel@tonic-gate 
7590Sstevel@tonic-gate rep_protocol_responseid_t backend_create_backup(const char *);
7606035Sstevep rep_protocol_responseid_t backend_switch(int);
7610Sstevel@tonic-gate 
7620Sstevel@tonic-gate /*
7630Sstevel@tonic-gate  * call on any database inconsistency -- cleans up state as best it can,
7640Sstevel@tonic-gate  * and exits with a "Database Bad" error code.
7650Sstevel@tonic-gate  */
766471Shg115875 void backend_panic(const char *, ...) __NORETURN;
7670Sstevel@tonic-gate #pragma rarely_called(backend_panic)
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate backend_query_t *backend_query_alloc(void);
7700Sstevel@tonic-gate void backend_query_append(backend_query_t *, const char *);
7710Sstevel@tonic-gate void backend_query_add(backend_query_t *, const char *, ...);
7720Sstevel@tonic-gate void backend_query_free(backend_query_t *);
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate typedef int backend_run_callback_f(void *data, int columns, char **vals,
7750Sstevel@tonic-gate     char **names);
7760Sstevel@tonic-gate #define	BACKEND_CALLBACK_CONTINUE	0
7770Sstevel@tonic-gate #define	BACKEND_CALLBACK_ABORT		1
7780Sstevel@tonic-gate 
7790Sstevel@tonic-gate backend_run_callback_f backend_fail_if_seen;	/* aborts TX if called */
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate int backend_run(backend_type_t, backend_query_t *,
7820Sstevel@tonic-gate     backend_run_callback_f *, void *);
7830Sstevel@tonic-gate 
7840Sstevel@tonic-gate int backend_tx_begin(backend_type_t, backend_tx_t **);
7850Sstevel@tonic-gate int backend_tx_begin_ro(backend_type_t, backend_tx_t **);
7860Sstevel@tonic-gate void backend_tx_end_ro(backend_tx_t *);
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate enum id_space {
7890Sstevel@tonic-gate 	BACKEND_ID_SERVICE_INSTANCE,
7900Sstevel@tonic-gate 	BACKEND_ID_PROPERTYGRP,
7910Sstevel@tonic-gate 	BACKEND_ID_GENERATION,
7920Sstevel@tonic-gate 	BACKEND_ID_PROPERTY,
7930Sstevel@tonic-gate 	BACKEND_ID_VALUE,
7940Sstevel@tonic-gate 	BACKEND_ID_SNAPNAME,
7950Sstevel@tonic-gate 	BACKEND_ID_SNAPSHOT,
7960Sstevel@tonic-gate 	BACKEND_ID_SNAPLEVEL,
7970Sstevel@tonic-gate 	BACKEND_ID_INVALID	/* always illegal */
7980Sstevel@tonic-gate };
7990Sstevel@tonic-gate 
8000Sstevel@tonic-gate uint32_t backend_new_id(backend_tx_t *, enum id_space);
8010Sstevel@tonic-gate int backend_tx_run_update(backend_tx_t *, const char *, ...);
8020Sstevel@tonic-gate int backend_tx_run_update_changed(backend_tx_t *, const char *, ...);
8030Sstevel@tonic-gate int backend_tx_run_single_int(backend_tx_t *tx, backend_query_t *q,
8040Sstevel@tonic-gate     uint32_t *buf);
8050Sstevel@tonic-gate int backend_tx_run(backend_tx_t *, backend_query_t *,
8060Sstevel@tonic-gate     backend_run_callback_f *, void *);
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate int backend_tx_commit(backend_tx_t *);
8090Sstevel@tonic-gate void backend_tx_rollback(backend_tx_t *);
8100Sstevel@tonic-gate 
8110Sstevel@tonic-gate #ifdef	__cplusplus
8120Sstevel@tonic-gate }
8130Sstevel@tonic-gate #endif
8140Sstevel@tonic-gate 
8150Sstevel@tonic-gate #endif	/* _CONFIGD_H */
816