xref: /illumos-gate/usr/src/cmd/svc/configd/configd.h (revision 3d393ee6c37fa10ac512ed6d36109ad616dc7c1a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_CONFIGD_H
27 #define	_CONFIGD_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <bsm/adt.h>
32 #include <door.h>
33 #include <pthread.h>
34 #include <string.h>
35 #include <sys/types.h>
36 
37 #include <libscf.h>
38 #include <repcache_protocol.h>
39 #include <libuutil.h>
40 
41 #include <configd_exit.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  * Lock order:
49  *
50  *	client lock
51  *		iter locks, in ID order
52  *		entity locks, in ID order
53  *
54  *		(any iter/entity locks)
55  *			backend locks (NORMAL, then NONPERSIST)
56  *				rc_node lock
57  *					children's rc_node lock
58  *				cache bucket lock
59  *					rc_node lock[*]
60  *
61  *	* only one node may be grabbed while holding a bucket lock
62  *
63  *	leaf locks:  (no other locks may be aquired while holding one)
64  *		rc_pg_notify_lock
65  *		rc_annotate_lock
66  */
67 
68 /*
69  * Returns the minimum size for a structure of type 't' such
70  * that it is safe to access field 'f'.
71  */
72 #define	offsetofend(t, f)	(offsetof(t, f) + sizeof (((t *)0)->f))
73 
74 /*
75  * We want MUTEX_HELD, but we also want pthreads.  So we're stuck with this.
76  */
77 struct _lwp_mutex_t;
78 extern int _mutex_held(struct _lwp_mutex_t *);
79 #define	MUTEX_HELD(m)		_mutex_held((struct _lwp_mutex_t *)(m))
80 
81 /*
82  * Maximum levels of composition.
83  */
84 #define	COMPOSITION_DEPTH	2
85 
86 #define	CONFIGD_CORE	"core.%f.%t.%p"
87 
88 #ifndef NDEBUG
89 #define	bad_error(f, e)							\
90 	uu_warn("%s:%d: %s() returned bad error %d.  Aborting.\n",	\
91 	    __FILE__, __LINE__, f, e);					\
92 	abort()
93 #else
94 #define	bad_error(f, e)		abort()
95 #endif
96 
97 typedef enum backend_type {
98 	BACKEND_TYPE_NORMAL		= 0,
99 	BACKEND_TYPE_NONPERSIST,
100 	BACKEND_TYPE_TOTAL			/* backend use only */
101 } backend_type_t;
102 
103 /*
104  * pre-declare rc_* types
105  */
106 typedef struct rc_node rc_node_t;
107 typedef struct rc_snapshot rc_snapshot_t;
108 typedef struct rc_snaplevel rc_snaplevel_t;
109 
110 /*
111  * notification layer -- protected by rc_pg_notify_lock
112  */
113 typedef struct rc_notify_info rc_notify_info_t;
114 typedef struct rc_notify_delete rc_notify_delete_t;
115 
116 #define	RC_NOTIFY_MAX_NAMES	4	/* enough for now */
117 
118 typedef struct rc_notify {
119 	uu_list_node_t	rcn_list_node;
120 	rc_node_t	*rcn_node;
121 	rc_notify_info_t *rcn_info;
122 	rc_notify_delete_t *rcn_delete;
123 } rc_notify_t;
124 
125 struct rc_notify_delete {
126 	rc_notify_t rnd_notify;
127 	char rnd_fmri[REP_PROTOCOL_FMRI_LEN];
128 };
129 
130 struct rc_notify_info {
131 	uu_list_node_t	rni_list_node;
132 	rc_notify_t	rni_notify;
133 	const char	*rni_namelist[RC_NOTIFY_MAX_NAMES];
134 	const char	*rni_typelist[RC_NOTIFY_MAX_NAMES];
135 
136 	int		rni_flags;
137 	int		rni_waiters;
138 	pthread_cond_t	rni_cv;
139 };
140 #define	RC_NOTIFY_ACTIVE	0x00000001
141 #define	RC_NOTIFY_DRAIN		0x00000002
142 #define	RC_NOTIFY_EMPTYING	0x00000004
143 
144 typedef struct rc_node_pg_notify {
145 	uu_list_node_t	rnpn_node;
146 	int		rnpn_fd;
147 	rc_node_t	*rnpn_pg;
148 } rc_node_pg_notify_t;
149 
150 /*
151  * cache layer
152  */
153 
154 /*
155  * The 'key' for the main object hash.  main_id is the main object
156  * identifier.  The rl_ids array contains:
157  *
158  *	TYPE		RL_IDS
159  *	scope		unused
160  *	service		unused
161  *	instance	{service_id}
162  *	snapshot	{service_id, instance_id}
163  *	snaplevel	{service_id, instance_id, name_id, snapshot_id}
164  *	propertygroup	{service_id, (instance_id or 0), (name_id or 0),
165  *			    (snapshot_id or 0), (l_id or 0)}
166  *	property	{service_id, (instance_id or 0), (name_id or 0),
167  *			    (snapshot_id or 0), (l_id or 0), pg_id, gen_id}
168  */
169 #define	ID_SERVICE	0
170 #define	ID_INSTANCE	1
171 #define	ID_NAME		2
172 #define	ID_SNAPSHOT	3
173 #define	ID_LEVEL	4
174 #define	ID_PG		5
175 #define	ID_GEN		6
176 #define	MAX_IDS	7
177 typedef struct rc_node_lookup {
178 	uint16_t	rl_type;		/* REP_PROTOCOL_ENTITY_* */
179 	uint16_t	rl_backend;		/* BACKEND_TYPE_* */
180 	uint32_t	rl_main_id;		/* primary identifier */
181 	uint32_t	rl_ids[MAX_IDS];	/* context */
182 } rc_node_lookup_t;
183 
184 struct rc_node {
185 	/*
186 	 * read-only data
187 	 */
188 	rc_node_lookup_t rn_id;			/* must be first */
189 	uint32_t	rn_hash;
190 	const char	*rn_name;
191 
192 	/*
193 	 * type-specific state
194 	 * (if space becomes an issue, these can become a union)
195 	 */
196 
197 	/*
198 	 * Used by instances, snapshots, and "composed property groups" only.
199 	 * These are the entities whose properties should appear composed when
200 	 * this entity is traversed by a composed iterator.  0 is the top-most
201 	 * entity, down to COMPOSITION_DEPTH - 1.
202 	 */
203 	rc_node_t	*rn_cchain[COMPOSITION_DEPTH];
204 
205 	/*
206 	 * used by property groups only
207 	 */
208 	const char	*rn_type;
209 	uint32_t	rn_pgflags;
210 	uint32_t	rn_gen_id;
211 	uu_list_t	*rn_pg_notify_list;	/* prot by rc_pg_notify_lock */
212 	rc_notify_t	rn_notify;		/* prot by rc_pg_notify_lock */
213 
214 	/*
215 	 * used by properties only
216 	 */
217 	rep_protocol_value_type_t rn_valtype;
218 	const char	*rn_values;		/* protected by rn_lock */
219 	size_t		rn_values_count;	/* protected by rn_lock */
220 	size_t		rn_values_size;		/* protected by rn_lock */
221 
222 	/*
223 	 * used by snapshots only
224 	 */
225 	uint32_t	rn_snapshot_id;
226 	rc_snapshot_t	*rn_snapshot;		/* protected by rn_lock */
227 
228 	/*
229 	 * used by snaplevels only
230 	 */
231 	rc_snaplevel_t	*rn_snaplevel;
232 
233 	/*
234 	 * mutable state
235 	 */
236 	pthread_mutex_t	rn_lock;
237 	pthread_cond_t	rn_cv;
238 	uint32_t	rn_flags;
239 	uint32_t	rn_refs;		/* client reference count */
240 	uint32_t	rn_erefs;		/* ephemeral ref count */
241 	uint32_t	rn_other_refs;		/* atomic refcount */
242 	uint32_t	rn_other_refs_held;	/* for 1->0 transitions */
243 
244 	uu_list_t	*rn_children;
245 	uu_list_node_t	rn_sibling_node;
246 
247 	rc_node_t	*rn_parent;		/* set if on child list */
248 	rc_node_t	*rn_former;		/* next former node */
249 	rc_node_t	*rn_parent_ref;		/* reference count target */
250 	const char	*rn_fmri;
251 
252 	/*
253 	 * external state (protected by hash chain lock)
254 	 */
255 	rc_node_t	*rn_hash_next;
256 };
257 
258 /*
259  * flag ordering:
260  *	RC_DYING
261  *		RC_NODE_CHILDREN_CHANGING
262  *		RC_NODE_CREATING_CHILD
263  *		RC_NODE_USING_PARENT
264  *			RC_NODE_IN_TX
265  *
266  * RC_NODE_USING_PARENT is special, because it lets you proceed up the tree,
267  * in the reverse of the usual locking order.  Because of this, there are
268  * limitations on what you can do while holding it.  While holding
269  * RC_NODE_USING_PARENT, you may:
270  *	bump or release your parent's reference count
271  *	access fields in your parent
272  *	hold RC_NODE_USING_PARENT in the parent, proceeding recursively.
273  *
274  * If you are only holding *one* node's RC_NODE_USING_PARENT, and:
275  *	you are *not* proceeding recursively, you can hold your
276  *	    immediate parent's RC_NODE_CHILDREN_CHANGING flag.
277  *	you hold your parent's RC_NODE_CHILDREN_CHANGING flag, you can add
278  *	    RC_NODE_IN_TX to your flags.
279  *	you want to grab a flag in your parent, you must lock your parent,
280  *	    lock yourself, drop RC_NODE_USING_PARENT, unlock yourself,
281  *	    then proceed to manipulate the parent.
282  */
283 #define	RC_NODE_CHILDREN_CHANGING	0x00000001 /* child list in flux */
284 #define	RC_NODE_HAS_CHILDREN		0x00000002 /* child list is accurate */
285 
286 #define	RC_NODE_IN_PARENT		0x00000004 /* I'm in my parent's list */
287 #define	RC_NODE_USING_PARENT		0x00000008 /* parent ptr in use */
288 #define	RC_NODE_CREATING_CHILD		0x00000010 /* a create is in progress */
289 #define	RC_NODE_IN_TX			0x00000020 /* a tx is in progess */
290 
291 #define	RC_NODE_OLD			0x00000400 /* out-of-date object */
292 #define	RC_NODE_ON_FORMER		0x00000800 /* on an rn_former list */
293 
294 #define	RC_NODE_PARENT_REF		0x00001000 /* parent_ref in use */
295 #define	RC_NODE_UNREFED			0x00002000 /* unref processing active */
296 #define	RC_NODE_DYING			0x00004000 /* node is being deleted */
297 #define	RC_NODE_DEAD			0x00008000 /* node has been deleted */
298 
299 /*
300  * RC_NODE_DEAD means that the node no longer represents data in the
301  * backend, and we should return _DELETED errors to clients who try to use
302  * it.  Very much like a zombie process.
303  *
304  * RC_NODE_OLD also means that the node no longer represents data in the
305  * backend, but it's ok for clients to access it because we've loaded all of
306  * the children.  (This only happens for transactional objects such as
307  * property groups and snapshots, where we guarantee a stable view once
308  * a reference is obtained.)  When all client references are destroyed,
309  * however, the node should be destroyed.
310  *
311  * Though RC_NODE_DEAD is set by the rc_node_delete() code, it is also set
312  * by rc_node_no_client_refs() for RC_NODE_OLD nodes not long before
313  * they're destroyed.
314  */
315 
316 #define	RC_NODE_DYING_FLAGS						\
317 	(RC_NODE_CHILDREN_CHANGING | RC_NODE_IN_TX | RC_NODE_DYING |	\
318 	    RC_NODE_CREATING_CHILD)
319 
320 #define	RC_NODE_WAITING_FLAGS						\
321 	(RC_NODE_DYING_FLAGS | RC_NODE_USING_PARENT)
322 
323 
324 #define	NODE_LOCK(n)	(void) pthread_mutex_lock(&(n)->rn_lock)
325 #define	NODE_UNLOCK(n)	(void) pthread_mutex_unlock(&(n)->rn_lock)
326 
327 
328 typedef enum rc_auth_state {
329 	RC_AUTH_UNKNOWN = 0,		/* No checks done yet. */
330 	RC_AUTH_FAILED,			/* Authorization checked & failed. */
331 	RC_AUTH_PASSED			/* Authorization succeeded. */
332 } rc_auth_state_t;
333 
334 /*
335  * Some authorization checks are performed in rc_node_setup_tx() in
336  * response to the REP_PROTOCOL_PROPERTYGRP_TX_START message.  Other checks
337  * must wait until the actual transaction operations are received in the
338  * REP_PROTOCOL_PROPERTYGRP_TX_COMMIT message.  This second set of checks
339  * is performed in rc_tx_commit().  rnp_auth_string and rnp_authorized in
340  * the following structure are used to hold the results of the
341  * authorization checking done in rc_node_setup_tx() for later use by
342  * rc_tx_commit().
343  *
344  * In client.c transactions are represented by rc_node_ptr structures which
345  * point to a property group rc_node_t.  Thus, this is an appropriate place
346  * to hold authorization state.
347  */
348 typedef struct rc_node_ptr {
349 	rc_node_t	*rnp_node;
350 	const char	*rnp_auth_string;	/* authorization string */
351 	rc_auth_state_t	rnp_authorized;		/* transaction pre-auth rslt. */
352 	char		rnp_deleted;		/* object was deleted */
353 } rc_node_ptr_t;
354 
355 #define	NODE_PTR_NOT_HELD(npp) \
356 	    ((npp)->rnp_node == NULL || !MUTEX_HELD(&(npp)->rnp_node->rn_lock))
357 
358 typedef int rc_iter_filter_func(rc_node_t *, void *);
359 
360 typedef struct rc_node_iter {
361 	rc_node_t	*rni_parent;
362 	int		rni_clevel;	/* index into rni_parent->rn_cchain[] */
363 	rc_node_t	*rni_iter_node;
364 	uu_list_walk_t	*rni_iter;
365 	uint32_t	rni_type;
366 
367 	/*
368 	 * for normal walks
369 	 */
370 	rc_iter_filter_func *rni_filter;
371 	void		*rni_filter_arg;
372 
373 	/*
374 	 * for value walks
375 	 */
376 	uint32_t	rni_offset;		/* next value offset */
377 	uint32_t	rni_last_offset;	/* previous value offset */
378 } rc_node_iter_t;
379 
380 typedef struct rc_node_tx {
381 	rc_node_ptr_t	rnt_ptr;
382 	int		rnt_authorized;		/* No need to check anymore. */
383 } rc_node_tx_t;
384 
385 
386 typedef struct cache_bucket {
387 	pthread_mutex_t	cb_lock;
388 	rc_node_t	*cb_head;
389 
390 	char		cb_pad[64 - sizeof (pthread_mutex_t) -
391 			    2 * sizeof (rc_node_t *)];
392 } cache_bucket_t;
393 
394 /*
395  * tx_commit_data_tx is an opaque structure which is defined in object.c.
396  * It contains the data of the transaction that is to be committed.
397  * Accessor functions in object.c allow other modules to retrieve
398  * information.
399  */
400 typedef struct tx_commit_data tx_commit_data_t;
401 
402 /*
403  * Snapshots
404  */
405 struct rc_snapshot {
406 	uint32_t	rs_snap_id;
407 
408 	pthread_mutex_t	rs_lock;
409 	pthread_cond_t	rs_cv;
410 
411 	uint32_t	rs_flags;
412 	uint32_t	rs_refcnt;	/* references from rc_nodes */
413 	uint32_t	rs_childref;	/* references to children */
414 
415 	rc_snaplevel_t	*rs_levels;	/* list of levels */
416 	rc_snapshot_t	*rs_hash_next;
417 };
418 #define	RC_SNAPSHOT_FILLING	0x00000001	/* rs_levels changing */
419 #define	RC_SNAPSHOT_READY	0x00000002
420 #define	RC_SNAPSHOT_DEAD	0x00000004	/* no resources */
421 
422 typedef struct rc_snaplevel_pgs {
423 	uint32_t	rsp_pg_id;
424 	uint32_t	rsp_gen_id;
425 } rc_snaplevel_pgs_t;
426 
427 struct rc_snaplevel {
428 	rc_snapshot_t	*rsl_parent;
429 	uint32_t	rsl_level_num;
430 	uint32_t	rsl_level_id;
431 
432 	uint32_t	rsl_service_id;
433 	uint32_t	rsl_instance_id;
434 
435 	const char	*rsl_scope;
436 	const char	*rsl_service;
437 	const char	*rsl_instance;
438 
439 	rc_snaplevel_t	*rsl_next;
440 };
441 
442 /*
443  * Client layer -- the IDs fields must be first, in order for the search
444  * routines to work correctly.
445  */
446 enum repcache_txstate {
447 	REPCACHE_TX_INIT,
448 	REPCACHE_TX_SETUP,
449 	REPCACHE_TX_COMMITTED
450 };
451 
452 typedef struct repcache_entity {
453 	uint32_t	re_id;
454 	uu_avl_node_t	re_link;
455 	uint32_t	re_changeid;
456 
457 	pthread_mutex_t	re_lock;
458 	uint32_t	re_type;
459 	rc_node_ptr_t	re_node;
460 	enum repcache_txstate re_txstate;	/* property groups only */
461 } repcache_entity_t;
462 
463 typedef struct repcache_iter {
464 	uint32_t	ri_id;
465 	uu_avl_node_t	ri_link;
466 
467 	uint32_t	ri_type;	/* result type */
468 
469 	pthread_mutex_t	ri_lock;
470 	uint32_t	ri_sequence;
471 	rc_node_iter_t	*ri_iter;
472 } repcache_iter_t;
473 
474 typedef struct repcache_client {
475 	/*
476 	 * constants
477 	 */
478 	uint32_t	rc_id;		/* must be first */
479 	int		rc_all_auths;	/* bypass auth checks */
480 	uint32_t	rc_debug;	/* debug flags */
481 	pid_t		rc_pid;		/* pid of opening process */
482 	door_id_t	rc_doorid;	/* a globally unique identifier */
483 	int		rc_doorfd;	/* our door's FD */
484 
485 	/*
486 	 * Constants used for security auditing
487 	 *
488 	 * rc_adt_session points to the audit session data that is used for
489 	 * the life of the client.  rc_adt_sessionid is the session ID that
490 	 * is initially assigned when the audit session is started.  See
491 	 * start_audit_session() in client.c.  This session id is used for
492 	 * audit events except when we are processing a set of annotated
493 	 * events.  Annotated events use a separate session id so that they
494 	 * can be grouped.  See set_annotation() in client.c.
495 	 */
496 	adt_session_data_t *rc_adt_session;	/* Session data. */
497 	au_asid_t	rc_adt_sessionid;	/* Main session ID for */
498 						/* auditing */
499 
500 	/*
501 	 * client list linkage, protected by hash chain lock
502 	 */
503 	uu_list_node_t	rc_link;
504 
505 	/*
506 	 * notification information, protected by rc_node layer
507 	 */
508 	rc_node_pg_notify_t	rc_pg_notify;
509 	rc_notify_info_t	rc_notify_info;
510 
511 	/*
512 	 * client_wait output, only usable by rc_notify_thr
513 	 */
514 	rc_node_ptr_t	rc_notify_ptr;
515 
516 	/*
517 	 * register sets, protected by rc_lock
518 	 */
519 	uu_avl_t	*rc_entities;
520 	uu_avl_t	*rc_iters;
521 
522 	/*
523 	 * Variables, protected by rc_lock
524 	 */
525 	int		rc_refcnt;	/* in-progress door calls */
526 	int		rc_flags;	/* see RC_CLIENT_* symbols below */
527 	uint32_t	rc_changeid;	/* used to make backups idempotent */
528 	pthread_t	rc_insert_thr;	/* single thread trying to insert */
529 	pthread_t	rc_notify_thr;	/* single thread waiting for notify */
530 	pthread_cond_t	rc_cv;
531 	pthread_mutex_t	rc_lock;
532 
533 	/*
534 	 * Per-client audit information.  These fields must be protected by
535 	 * rc_annotate_lock separately from rc_lock because they may need
536 	 * to be accessed from rc_node.c with an entity or iterator lock
537 	 * held, and those must be taken after rc_lock.
538 	 */
539 	int		rc_annotate;	/* generate annotation event if set */
540 	const char	*rc_operation;	/* operation for audit annotation */
541 	const char	*rc_file;	/* file name for audit annotation */
542 	pthread_mutex_t	rc_annotate_lock;
543 } repcache_client_t;
544 
545 /* Bit definitions for rc_flags. */
546 #define	RC_CLIENT_DEAD			0x00000001
547 
548 typedef struct client_bucket {
549 	pthread_mutex_t	cb_lock;
550 	uu_list_t	*cb_list;
551 	char ch_pad[64 - sizeof (pthread_mutex_t) - sizeof (uu_list_t *)];
552 } client_bucket_t;
553 
554 enum rc_ptr_type {
555 	RC_PTR_TYPE_ENTITY = 1,
556 	RC_PTR_TYPE_ITER
557 };
558 
559 typedef struct request_log_ptr {
560 	enum rc_ptr_type	rlp_type;
561 	uint32_t		rlp_id;
562 	void			*rlp_ptr; /* repcache_{entity,iter}_t */
563 	void			*rlp_data;	/* rc_node, for ENTITY only */
564 } request_log_ptr_t;
565 
566 #define	MAX_PTRS	3
567 
568 /*
569  * rl_start through rl_client cannot move without changing start_log()
570  */
571 typedef struct request_log_entry {
572 	hrtime_t		rl_start;
573 	hrtime_t		rl_end;
574 	pthread_t		rl_tid;
575 	uint32_t		rl_clientid;
576 	repcache_client_t	*rl_client;
577 	enum rep_protocol_requestid rl_request;
578 	rep_protocol_responseid_t rl_response;
579 	int			rl_num_ptrs;
580 	request_log_ptr_t	rl_ptrs[MAX_PTRS];
581 } request_log_entry_t;
582 
583 /*
584  * thread information
585  */
586 typedef enum thread_state {
587 	TI_CREATED,
588 	TI_DOOR_RETURN,
589 	TI_SIGNAL_WAIT,
590 	TI_MAIN_DOOR_CALL,
591 	TI_CLIENT_CALL
592 } thread_state_t;
593 
594 typedef struct thread_info {
595 	pthread_t	ti_thread;
596 	uu_list_node_t	ti_node;		/* for list of all thread */
597 
598 	/*
599 	 * per-thread globals
600 	 */
601 	ucred_t		*ti_ucred;		/* for credential lookups */
602 	int		ti_ucred_read;		/* ucred holds current creds */
603 
604 	/*
605 	 * per-thread state information, for debuggers
606 	 */
607 	hrtime_t	ti_lastchange;
608 
609 	thread_state_t	ti_state;
610 	thread_state_t	ti_prev_state;
611 
612 	repcache_client_t *ti_active_client;
613 	request_log_entry_t	ti_log;
614 
615 	struct rep_protocol_request *ti_client_request;
616 	repository_door_request_t *ti_main_door_request;
617 
618 } thread_info_t;
619 
620 /*
621  * Backend layer
622  */
623 typedef struct backend_query backend_query_t;
624 typedef struct backend_tx backend_tx_t;
625 
626 /*
627  * configd.c
628  */
629 int create_connection(ucred_t *cred, repository_door_request_t *rp,
630     size_t rp_size, int *out_fd);
631 
632 thread_info_t *thread_self(void);
633 void thread_newstate(thread_info_t *, thread_state_t);
634 ucred_t *get_ucred(void);
635 int ucred_is_privileged(ucred_t *);
636 
637 adt_session_data_t *get_audit_session(void);
638 
639 void configd_critical(const char *, ...);
640 void configd_vcritical(const char *, va_list);
641 void configd_info(const char *, ...);
642 
643 extern int is_main_repository;
644 extern int max_repository_backups;
645 
646 /*
647  * maindoor.c
648  */
649 int setup_main_door(const char *);
650 
651 /*
652  * client.c
653  */
654 int client_annotation_needed(char *, size_t, char *, size_t);
655 void client_annotation_finished(void);
656 int create_client(pid_t, uint32_t, int, int *);
657 int client_init(void);
658 int client_is_privileged(void);
659 void log_enter(request_log_entry_t *);
660 
661 /*
662  * rc_node.c, backend/cache interfaces (rc_node_t)
663  */
664 int rc_node_init();
665 int rc_check_type_name(uint32_t, const char *);
666 
667 void rc_node_ptr_free_mem(rc_node_ptr_t *);
668 void rc_node_rele(rc_node_t *);
669 rc_node_t *rc_node_setup(rc_node_t *, rc_node_lookup_t *,
670     const char *, rc_node_t *);
671 rc_node_t *rc_node_setup_pg(rc_node_t *, rc_node_lookup_t *, const char *,
672     const char *, uint32_t, uint32_t, rc_node_t *);
673 rc_node_t *rc_node_setup_snapshot(rc_node_t *, rc_node_lookup_t *, const char *,
674     uint32_t, rc_node_t *);
675 rc_node_t *rc_node_setup_snaplevel(rc_node_t *, rc_node_lookup_t *,
676     rc_snaplevel_t *, rc_node_t *);
677 int rc_node_create_property(rc_node_t *, rc_node_lookup_t *,
678     const char *, rep_protocol_value_type_t, const char *, size_t, size_t);
679 
680 rc_node_t *rc_node_alloc(void);
681 void rc_node_destroy(rc_node_t *);
682 
683 /*
684  * rc_node.c, client interface (rc_node_ptr_t, rc_node_iter_t)
685  */
686 void rc_node_ptr_init(rc_node_ptr_t *);
687 int rc_local_scope(uint32_t, rc_node_ptr_t *);
688 
689 void rc_node_clear(rc_node_ptr_t *, int);
690 void rc_node_ptr_assign(rc_node_ptr_t *, const rc_node_ptr_t *);
691 int rc_node_name(rc_node_ptr_t *, char *, size_t, uint32_t, size_t *);
692 int rc_node_fmri(rc_node_ptr_t *, char *, size_t, size_t *);
693 int rc_node_parent_type(rc_node_ptr_t *, uint32_t *);
694 int rc_node_get_child(rc_node_ptr_t *, const char *, uint32_t, rc_node_ptr_t *);
695 int rc_node_get_parent(rc_node_ptr_t *, uint32_t, rc_node_ptr_t *);
696 int rc_node_get_property_type(rc_node_ptr_t *, rep_protocol_value_type_t *);
697 int rc_node_get_property_value(rc_node_ptr_t *,
698     struct rep_protocol_value_response *, size_t *);
699 int rc_node_create_child(rc_node_ptr_t *, uint32_t, const char *,
700     rc_node_ptr_t *);
701 int rc_node_create_child_pg(rc_node_ptr_t *, uint32_t, const char *,
702     const char *, uint32_t, rc_node_ptr_t *);
703 int rc_node_update(rc_node_ptr_t *);
704 int rc_node_delete(rc_node_ptr_t *);
705 int rc_node_next_snaplevel(rc_node_ptr_t *, rc_node_ptr_t *);
706 
707 int rc_node_setup_iter(rc_node_ptr_t *, rc_node_iter_t **, uint32_t,
708     size_t, const char *);
709 
710 int rc_iter_next(rc_node_iter_t *, rc_node_ptr_t *, uint32_t);
711 int rc_iter_next_value(rc_node_iter_t *, struct rep_protocol_value_response *,
712     size_t *, int);
713 void rc_iter_destroy(rc_node_iter_t **);
714 
715 int rc_node_setup_tx(rc_node_ptr_t *, rc_node_ptr_t *);
716 int rc_tx_commit(rc_node_ptr_t *, const void *, size_t);
717 
718 void rc_pg_notify_init(rc_node_pg_notify_t *);
719 int rc_pg_notify_setup(rc_node_pg_notify_t *, rc_node_ptr_t *, int);
720 void rc_pg_notify_fini(rc_node_pg_notify_t *);
721 
722 void rc_notify_info_init(rc_notify_info_t *);
723 int rc_notify_info_add_name(rc_notify_info_t *, const char *);
724 int rc_notify_info_add_type(rc_notify_info_t *, const char *);
725 int rc_notify_info_wait(rc_notify_info_t *, rc_node_ptr_t *, char *, size_t);
726 void rc_notify_info_fini(rc_notify_info_t *);
727 
728 int rc_snapshot_take_new(rc_node_ptr_t *, const char *,
729     const char *, const char *, rc_node_ptr_t *);
730 int rc_snapshot_take_attach(rc_node_ptr_t *, rc_node_ptr_t *);
731 int rc_snapshot_attach(rc_node_ptr_t *, rc_node_ptr_t *);
732 
733 /*
734  * file_object.c
735  */
736 int object_fill_children(rc_node_t *);
737 int object_create(rc_node_t *, uint32_t, const char *, rc_node_t **);
738 int object_create_pg(rc_node_t *, uint32_t, const char *, const char *,
739     uint32_t, rc_node_t **);
740 
741 int object_delete(rc_node_t *);
742 void object_free_values(const char *, uint32_t, size_t, size_t);
743 
744 int object_fill_snapshot(rc_snapshot_t *);
745 
746 int object_snapshot_take_new(rc_node_t *, const char *, const char *,
747     const char *, rc_node_t **);
748 int object_snapshot_attach(rc_node_lookup_t *, uint32_t *, int);
749 
750 /*
751  * object.c
752  */
753 int object_tx_commit(rc_node_lookup_t *, tx_commit_data_t *, uint32_t *);
754 
755 /* Functions to access transaction commands. */
756 int tx_cmd_action(tx_commit_data_t *, size_t,
757     enum rep_protocol_transaction_action *);
758 size_t tx_cmd_count(tx_commit_data_t *);
759 int tx_cmd_nvalues(tx_commit_data_t *, size_t, uint32_t *);
760 int tx_cmd_prop(tx_commit_data_t *, size_t, const char **);
761 int tx_cmd_prop_type(tx_commit_data_t *, size_t, uint32_t *);
762 int tx_cmd_value(tx_commit_data_t *, size_t, uint32_t, const char **);
763 void tx_commit_data_free(tx_commit_data_t *);
764 int tx_commit_data_new(const void *, size_t, tx_commit_data_t **);
765 
766 /*
767  * snapshot.c
768  */
769 int rc_snapshot_get(uint32_t, rc_snapshot_t **);
770 void rc_snapshot_rele(rc_snapshot_t *);
771 void rc_snaplevel_hold(rc_snaplevel_t *);
772 void rc_snaplevel_rele(rc_snaplevel_t *);
773 
774 /*
775  * backend.c
776  */
777 int backend_init(const char *, const char *, int);
778 boolean_t backend_is_upgraded(backend_tx_t *);
779 void backend_fini(void);
780 
781 rep_protocol_responseid_t backend_create_backup(const char *);
782 rep_protocol_responseid_t backend_switch(int);
783 
784 /*
785  * call on any database inconsistency -- cleans up state as best it can,
786  * and exits with a "Database Bad" error code.
787  */
788 void backend_panic(const char *, ...) __NORETURN;
789 #pragma rarely_called(backend_panic)
790 
791 backend_query_t *backend_query_alloc(void);
792 void backend_query_append(backend_query_t *, const char *);
793 void backend_query_add(backend_query_t *, const char *, ...);
794 void backend_query_free(backend_query_t *);
795 
796 typedef int backend_run_callback_f(void *data, int columns, char **vals,
797     char **names);
798 #define	BACKEND_CALLBACK_CONTINUE	0
799 #define	BACKEND_CALLBACK_ABORT		1
800 
801 backend_run_callback_f backend_fail_if_seen;	/* aborts TX if called */
802 
803 int backend_run(backend_type_t, backend_query_t *,
804     backend_run_callback_f *, void *);
805 
806 int backend_tx_begin(backend_type_t, backend_tx_t **);
807 int backend_tx_begin_ro(backend_type_t, backend_tx_t **);
808 void backend_tx_end_ro(backend_tx_t *);
809 
810 enum id_space {
811 	BACKEND_ID_SERVICE_INSTANCE,
812 	BACKEND_ID_PROPERTYGRP,
813 	BACKEND_ID_GENERATION,
814 	BACKEND_ID_PROPERTY,
815 	BACKEND_ID_VALUE,
816 	BACKEND_ID_SNAPNAME,
817 	BACKEND_ID_SNAPSHOT,
818 	BACKEND_ID_SNAPLEVEL,
819 	BACKEND_ID_INVALID	/* always illegal */
820 };
821 
822 uint32_t backend_new_id(backend_tx_t *, enum id_space);
823 int backend_tx_run_update(backend_tx_t *, const char *, ...);
824 int backend_tx_run_update_changed(backend_tx_t *, const char *, ...);
825 int backend_tx_run_single_int(backend_tx_t *tx, backend_query_t *q,
826     uint32_t *buf);
827 int backend_tx_run(backend_tx_t *, backend_query_t *,
828     backend_run_callback_f *, void *);
829 
830 int backend_tx_commit(backend_tx_t *);
831 void backend_tx_rollback(backend_tx_t *);
832 
833 #ifdef	__cplusplus
834 }
835 #endif
836 
837 #endif	/* _CONFIGD_H */
838