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 */ 21*11466SRoger.Faulkner@Sun.COM 220Sstevel@tonic-gate /* 23*11466SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _CONFIGD_H 280Sstevel@tonic-gate #define _CONFIGD_H 290Sstevel@tonic-gate 305777Stw21770 #include <bsm/adt.h> 310Sstevel@tonic-gate #include <door.h> 320Sstevel@tonic-gate #include <pthread.h> 33*11466SRoger.Faulkner@Sun.COM #include <synch.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 /* 75*11466SRoger.Faulkner@Sun.COM * We want MUTEX_HELD, but we also want pthreads. So we're stuck with this 76*11466SRoger.Faulkner@Sun.COM * for the native build, at least until the build machines can catch up 77*11466SRoger.Faulkner@Sun.COM * with the latest version of MUTEX_HELD() in <synch.h>. 780Sstevel@tonic-gate */ 79*11466SRoger.Faulkner@Sun.COM #if defined(NATIVE_BUILD) 80*11466SRoger.Faulkner@Sun.COM #undef MUTEX_HELD 81*11466SRoger.Faulkner@Sun.COM #define MUTEX_HELD(m) _mutex_held((mutex_t *)(m)) 82*11466SRoger.Faulkner@Sun.COM #endif 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Maximum levels of composition. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate #define COMPOSITION_DEPTH 2 880Sstevel@tonic-gate 890Sstevel@tonic-gate #define CONFIGD_CORE "core.%f.%t.%p" 900Sstevel@tonic-gate 910Sstevel@tonic-gate #ifndef NDEBUG 920Sstevel@tonic-gate #define bad_error(f, e) \ 930Sstevel@tonic-gate uu_warn("%s:%d: %s() returned bad error %d. Aborting.\n", \ 940Sstevel@tonic-gate __FILE__, __LINE__, f, e); \ 950Sstevel@tonic-gate abort() 960Sstevel@tonic-gate #else 970Sstevel@tonic-gate #define bad_error(f, e) abort() 980Sstevel@tonic-gate #endif 990Sstevel@tonic-gate 1000Sstevel@tonic-gate typedef enum backend_type { 1010Sstevel@tonic-gate BACKEND_TYPE_NORMAL = 0, 1020Sstevel@tonic-gate BACKEND_TYPE_NONPERSIST, 1030Sstevel@tonic-gate BACKEND_TYPE_TOTAL /* backend use only */ 1040Sstevel@tonic-gate } backend_type_t; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * pre-declare rc_* types 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate typedef struct rc_node rc_node_t; 1100Sstevel@tonic-gate typedef struct rc_snapshot rc_snapshot_t; 1110Sstevel@tonic-gate typedef struct rc_snaplevel rc_snaplevel_t; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* 1140Sstevel@tonic-gate * notification layer -- protected by rc_pg_notify_lock 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate typedef struct rc_notify_info rc_notify_info_t; 1170Sstevel@tonic-gate typedef struct rc_notify_delete rc_notify_delete_t; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define RC_NOTIFY_MAX_NAMES 4 /* enough for now */ 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate typedef struct rc_notify { 1220Sstevel@tonic-gate uu_list_node_t rcn_list_node; 1230Sstevel@tonic-gate rc_node_t *rcn_node; 1240Sstevel@tonic-gate rc_notify_info_t *rcn_info; 1250Sstevel@tonic-gate rc_notify_delete_t *rcn_delete; 1260Sstevel@tonic-gate } rc_notify_t; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate struct rc_notify_delete { 1290Sstevel@tonic-gate rc_notify_t rnd_notify; 1300Sstevel@tonic-gate char rnd_fmri[REP_PROTOCOL_FMRI_LEN]; 1310Sstevel@tonic-gate }; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate struct rc_notify_info { 1340Sstevel@tonic-gate uu_list_node_t rni_list_node; 1350Sstevel@tonic-gate rc_notify_t rni_notify; 1360Sstevel@tonic-gate const char *rni_namelist[RC_NOTIFY_MAX_NAMES]; 1370Sstevel@tonic-gate const char *rni_typelist[RC_NOTIFY_MAX_NAMES]; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate int rni_flags; 1400Sstevel@tonic-gate int rni_waiters; 1410Sstevel@tonic-gate pthread_cond_t rni_cv; 1420Sstevel@tonic-gate }; 1430Sstevel@tonic-gate #define RC_NOTIFY_ACTIVE 0x00000001 1440Sstevel@tonic-gate #define RC_NOTIFY_DRAIN 0x00000002 1450Sstevel@tonic-gate #define RC_NOTIFY_EMPTYING 0x00000004 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate typedef struct rc_node_pg_notify { 1480Sstevel@tonic-gate uu_list_node_t rnpn_node; 1490Sstevel@tonic-gate int rnpn_fd; 1500Sstevel@tonic-gate rc_node_t *rnpn_pg; 1510Sstevel@tonic-gate } rc_node_pg_notify_t; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * cache layer 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * The 'key' for the main object hash. main_id is the main object 1590Sstevel@tonic-gate * identifier. The rl_ids array contains: 1600Sstevel@tonic-gate * 1610Sstevel@tonic-gate * TYPE RL_IDS 1620Sstevel@tonic-gate * scope unused 1630Sstevel@tonic-gate * service unused 1640Sstevel@tonic-gate * instance {service_id} 1650Sstevel@tonic-gate * snapshot {service_id, instance_id} 1660Sstevel@tonic-gate * snaplevel {service_id, instance_id, name_id, snapshot_id} 1670Sstevel@tonic-gate * propertygroup {service_id, (instance_id or 0), (name_id or 0), 1680Sstevel@tonic-gate * (snapshot_id or 0), (l_id or 0)} 1690Sstevel@tonic-gate * property {service_id, (instance_id or 0), (name_id or 0), 1700Sstevel@tonic-gate * (snapshot_id or 0), (l_id or 0), pg_id, gen_id} 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate #define ID_SERVICE 0 1730Sstevel@tonic-gate #define ID_INSTANCE 1 1740Sstevel@tonic-gate #define ID_NAME 2 1750Sstevel@tonic-gate #define ID_SNAPSHOT 3 1760Sstevel@tonic-gate #define ID_LEVEL 4 1770Sstevel@tonic-gate #define ID_PG 5 1780Sstevel@tonic-gate #define ID_GEN 6 1790Sstevel@tonic-gate #define MAX_IDS 7 1800Sstevel@tonic-gate typedef struct rc_node_lookup { 1810Sstevel@tonic-gate uint16_t rl_type; /* REP_PROTOCOL_ENTITY_* */ 1820Sstevel@tonic-gate uint16_t rl_backend; /* BACKEND_TYPE_* */ 1830Sstevel@tonic-gate uint32_t rl_main_id; /* primary identifier */ 1840Sstevel@tonic-gate uint32_t rl_ids[MAX_IDS]; /* context */ 1850Sstevel@tonic-gate } rc_node_lookup_t; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate struct rc_node { 1880Sstevel@tonic-gate /* 1890Sstevel@tonic-gate * read-only data 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate rc_node_lookup_t rn_id; /* must be first */ 1920Sstevel@tonic-gate uint32_t rn_hash; 1930Sstevel@tonic-gate const char *rn_name; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* 1960Sstevel@tonic-gate * type-specific state 1970Sstevel@tonic-gate * (if space becomes an issue, these can become a union) 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * Used by instances, snapshots, and "composed property groups" only. 2020Sstevel@tonic-gate * These are the entities whose properties should appear composed when 2030Sstevel@tonic-gate * this entity is traversed by a composed iterator. 0 is the top-most 2040Sstevel@tonic-gate * entity, down to COMPOSITION_DEPTH - 1. 2050Sstevel@tonic-gate */ 2060Sstevel@tonic-gate rc_node_t *rn_cchain[COMPOSITION_DEPTH]; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * used by property groups only 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate const char *rn_type; 2120Sstevel@tonic-gate uint32_t rn_pgflags; 2130Sstevel@tonic-gate uint32_t rn_gen_id; 2140Sstevel@tonic-gate uu_list_t *rn_pg_notify_list; /* prot by rc_pg_notify_lock */ 2150Sstevel@tonic-gate rc_notify_t rn_notify; /* prot by rc_pg_notify_lock */ 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate /* 2180Sstevel@tonic-gate * used by properties only 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate rep_protocol_value_type_t rn_valtype; 2210Sstevel@tonic-gate const char *rn_values; /* protected by rn_lock */ 2220Sstevel@tonic-gate size_t rn_values_count; /* protected by rn_lock */ 2230Sstevel@tonic-gate size_t rn_values_size; /* protected by rn_lock */ 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* 2260Sstevel@tonic-gate * used by snapshots only 2270Sstevel@tonic-gate */ 2280Sstevel@tonic-gate uint32_t rn_snapshot_id; 2290Sstevel@tonic-gate rc_snapshot_t *rn_snapshot; /* protected by rn_lock */ 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate /* 2320Sstevel@tonic-gate * used by snaplevels only 2330Sstevel@tonic-gate */ 2340Sstevel@tonic-gate rc_snaplevel_t *rn_snaplevel; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate /* 2370Sstevel@tonic-gate * mutable state 2380Sstevel@tonic-gate */ 2390Sstevel@tonic-gate pthread_mutex_t rn_lock; 2400Sstevel@tonic-gate pthread_cond_t rn_cv; 2410Sstevel@tonic-gate uint32_t rn_flags; 2427266Sbustos uint32_t rn_refs; /* client reference count */ 2437266Sbustos uint32_t rn_erefs; /* ephemeral ref count */ 2440Sstevel@tonic-gate uint32_t rn_other_refs; /* atomic refcount */ 2450Sstevel@tonic-gate uint32_t rn_other_refs_held; /* for 1->0 transitions */ 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate uu_list_t *rn_children; 2480Sstevel@tonic-gate uu_list_node_t rn_sibling_node; 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate rc_node_t *rn_parent; /* set if on child list */ 2510Sstevel@tonic-gate rc_node_t *rn_former; /* next former node */ 2520Sstevel@tonic-gate rc_node_t *rn_parent_ref; /* reference count target */ 2535777Stw21770 const char *rn_fmri; 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate /* 2560Sstevel@tonic-gate * external state (protected by hash chain lock) 2570Sstevel@tonic-gate */ 2580Sstevel@tonic-gate rc_node_t *rn_hash_next; 2590Sstevel@tonic-gate }; 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /* 2620Sstevel@tonic-gate * flag ordering: 2630Sstevel@tonic-gate * RC_DYING 2640Sstevel@tonic-gate * RC_NODE_CHILDREN_CHANGING 2650Sstevel@tonic-gate * RC_NODE_CREATING_CHILD 2660Sstevel@tonic-gate * RC_NODE_USING_PARENT 2670Sstevel@tonic-gate * RC_NODE_IN_TX 2680Sstevel@tonic-gate * 2690Sstevel@tonic-gate * RC_NODE_USING_PARENT is special, because it lets you proceed up the tree, 2700Sstevel@tonic-gate * in the reverse of the usual locking order. Because of this, there are 2710Sstevel@tonic-gate * limitations on what you can do while holding it. While holding 2720Sstevel@tonic-gate * RC_NODE_USING_PARENT, you may: 2730Sstevel@tonic-gate * bump or release your parent's reference count 2740Sstevel@tonic-gate * access fields in your parent 2750Sstevel@tonic-gate * hold RC_NODE_USING_PARENT in the parent, proceeding recursively. 2760Sstevel@tonic-gate * 2770Sstevel@tonic-gate * If you are only holding *one* node's RC_NODE_USING_PARENT, and: 2780Sstevel@tonic-gate * you are *not* proceeding recursively, you can hold your 2790Sstevel@tonic-gate * immediate parent's RC_NODE_CHILDREN_CHANGING flag. 2800Sstevel@tonic-gate * you hold your parent's RC_NODE_CHILDREN_CHANGING flag, you can add 2810Sstevel@tonic-gate * RC_NODE_IN_TX to your flags. 2820Sstevel@tonic-gate * you want to grab a flag in your parent, you must lock your parent, 2830Sstevel@tonic-gate * lock yourself, drop RC_NODE_USING_PARENT, unlock yourself, 2840Sstevel@tonic-gate * then proceed to manipulate the parent. 2850Sstevel@tonic-gate */ 2860Sstevel@tonic-gate #define RC_NODE_CHILDREN_CHANGING 0x00000001 /* child list in flux */ 2870Sstevel@tonic-gate #define RC_NODE_HAS_CHILDREN 0x00000002 /* child list is accurate */ 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate #define RC_NODE_IN_PARENT 0x00000004 /* I'm in my parent's list */ 2900Sstevel@tonic-gate #define RC_NODE_USING_PARENT 0x00000008 /* parent ptr in use */ 2910Sstevel@tonic-gate #define RC_NODE_CREATING_CHILD 0x00000010 /* a create is in progress */ 2920Sstevel@tonic-gate #define RC_NODE_IN_TX 0x00000020 /* a tx is in progess */ 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate #define RC_NODE_OLD 0x00000400 /* out-of-date object */ 2950Sstevel@tonic-gate #define RC_NODE_ON_FORMER 0x00000800 /* on an rn_former list */ 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate #define RC_NODE_PARENT_REF 0x00001000 /* parent_ref in use */ 2980Sstevel@tonic-gate #define RC_NODE_UNREFED 0x00002000 /* unref processing active */ 2990Sstevel@tonic-gate #define RC_NODE_DYING 0x00004000 /* node is being deleted */ 3000Sstevel@tonic-gate #define RC_NODE_DEAD 0x00008000 /* node has been deleted */ 3010Sstevel@tonic-gate 3027266Sbustos /* 3037266Sbustos * RC_NODE_DEAD means that the node no longer represents data in the 3047266Sbustos * backend, and we should return _DELETED errors to clients who try to use 3057266Sbustos * it. Very much like a zombie process. 3067266Sbustos * 3077266Sbustos * RC_NODE_OLD also means that the node no longer represents data in the 3087266Sbustos * backend, but it's ok for clients to access it because we've loaded all of 3097266Sbustos * the children. (This only happens for transactional objects such as 3107266Sbustos * property groups and snapshots, where we guarantee a stable view once 3117266Sbustos * a reference is obtained.) When all client references are destroyed, 3127266Sbustos * however, the node should be destroyed. 3137266Sbustos * 3147266Sbustos * Though RC_NODE_DEAD is set by the rc_node_delete() code, it is also set 3157266Sbustos * by rc_node_no_client_refs() for RC_NODE_OLD nodes not long before 3167266Sbustos * they're destroyed. 3177266Sbustos */ 3187266Sbustos 3190Sstevel@tonic-gate #define RC_NODE_DYING_FLAGS \ 3200Sstevel@tonic-gate (RC_NODE_CHILDREN_CHANGING | RC_NODE_IN_TX | RC_NODE_DYING | \ 3210Sstevel@tonic-gate RC_NODE_CREATING_CHILD) 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate #define RC_NODE_WAITING_FLAGS \ 3240Sstevel@tonic-gate (RC_NODE_DYING_FLAGS | RC_NODE_USING_PARENT) 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate 3277266Sbustos #define NODE_LOCK(n) (void) pthread_mutex_lock(&(n)->rn_lock) 3287266Sbustos #define NODE_UNLOCK(n) (void) pthread_mutex_unlock(&(n)->rn_lock) 3297266Sbustos 3307266Sbustos 3315777Stw21770 typedef enum rc_auth_state { 3325777Stw21770 RC_AUTH_UNKNOWN = 0, /* No checks done yet. */ 3335777Stw21770 RC_AUTH_FAILED, /* Authorization checked & failed. */ 3345777Stw21770 RC_AUTH_PASSED /* Authorization succeeded. */ 3355777Stw21770 } rc_auth_state_t; 3365777Stw21770 3375777Stw21770 /* 3385777Stw21770 * Some authorization checks are performed in rc_node_setup_tx() in 3395777Stw21770 * response to the REP_PROTOCOL_PROPERTYGRP_TX_START message. Other checks 3405777Stw21770 * must wait until the actual transaction operations are received in the 3415777Stw21770 * REP_PROTOCOL_PROPERTYGRP_TX_COMMIT message. This second set of checks 3425777Stw21770 * is performed in rc_tx_commit(). rnp_auth_string and rnp_authorized in 3435777Stw21770 * the following structure are used to hold the results of the 3445777Stw21770 * authorization checking done in rc_node_setup_tx() for later use by 3455777Stw21770 * rc_tx_commit(). 3465777Stw21770 * 3475777Stw21770 * In client.c transactions are represented by rc_node_ptr structures which 3485777Stw21770 * point to a property group rc_node_t. Thus, this is an appropriate place 3495777Stw21770 * to hold authorization state. 3505777Stw21770 */ 3510Sstevel@tonic-gate typedef struct rc_node_ptr { 3520Sstevel@tonic-gate rc_node_t *rnp_node; 3535777Stw21770 const char *rnp_auth_string; /* authorization string */ 3545777Stw21770 rc_auth_state_t rnp_authorized; /* transaction pre-auth rslt. */ 3550Sstevel@tonic-gate char rnp_deleted; /* object was deleted */ 3560Sstevel@tonic-gate } rc_node_ptr_t; 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate #define NODE_PTR_NOT_HELD(npp) \ 3590Sstevel@tonic-gate ((npp)->rnp_node == NULL || !MUTEX_HELD(&(npp)->rnp_node->rn_lock)) 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate typedef int rc_iter_filter_func(rc_node_t *, void *); 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate typedef struct rc_node_iter { 3640Sstevel@tonic-gate rc_node_t *rni_parent; 3650Sstevel@tonic-gate int rni_clevel; /* index into rni_parent->rn_cchain[] */ 3660Sstevel@tonic-gate rc_node_t *rni_iter_node; 3670Sstevel@tonic-gate uu_list_walk_t *rni_iter; 3680Sstevel@tonic-gate uint32_t rni_type; 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate /* 3710Sstevel@tonic-gate * for normal walks 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate rc_iter_filter_func *rni_filter; 3740Sstevel@tonic-gate void *rni_filter_arg; 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate /* 3770Sstevel@tonic-gate * for value walks 3780Sstevel@tonic-gate */ 3790Sstevel@tonic-gate uint32_t rni_offset; /* next value offset */ 3800Sstevel@tonic-gate uint32_t rni_last_offset; /* previous value offset */ 3810Sstevel@tonic-gate } rc_node_iter_t; 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate typedef struct rc_node_tx { 3840Sstevel@tonic-gate rc_node_ptr_t rnt_ptr; 3850Sstevel@tonic-gate int rnt_authorized; /* No need to check anymore. */ 3860Sstevel@tonic-gate } rc_node_tx_t; 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate typedef struct cache_bucket { 3900Sstevel@tonic-gate pthread_mutex_t cb_lock; 3910Sstevel@tonic-gate rc_node_t *cb_head; 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate char cb_pad[64 - sizeof (pthread_mutex_t) - 3940Sstevel@tonic-gate 2 * sizeof (rc_node_t *)]; 3950Sstevel@tonic-gate } cache_bucket_t; 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate /* 3985777Stw21770 * tx_commit_data_tx is an opaque structure which is defined in object.c. 3995777Stw21770 * It contains the data of the transaction that is to be committed. 4005777Stw21770 * Accessor functions in object.c allow other modules to retrieve 4015777Stw21770 * information. 4025777Stw21770 */ 4035777Stw21770 typedef struct tx_commit_data tx_commit_data_t; 4045777Stw21770 4055777Stw21770 /* 4060Sstevel@tonic-gate * Snapshots 4070Sstevel@tonic-gate */ 4080Sstevel@tonic-gate struct rc_snapshot { 4090Sstevel@tonic-gate uint32_t rs_snap_id; 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate pthread_mutex_t rs_lock; 4120Sstevel@tonic-gate pthread_cond_t rs_cv; 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate uint32_t rs_flags; 4150Sstevel@tonic-gate uint32_t rs_refcnt; /* references from rc_nodes */ 4160Sstevel@tonic-gate uint32_t rs_childref; /* references to children */ 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate rc_snaplevel_t *rs_levels; /* list of levels */ 4190Sstevel@tonic-gate rc_snapshot_t *rs_hash_next; 4200Sstevel@tonic-gate }; 4210Sstevel@tonic-gate #define RC_SNAPSHOT_FILLING 0x00000001 /* rs_levels changing */ 4220Sstevel@tonic-gate #define RC_SNAPSHOT_READY 0x00000002 4230Sstevel@tonic-gate #define RC_SNAPSHOT_DEAD 0x00000004 /* no resources */ 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate typedef struct rc_snaplevel_pgs { 4260Sstevel@tonic-gate uint32_t rsp_pg_id; 4270Sstevel@tonic-gate uint32_t rsp_gen_id; 4280Sstevel@tonic-gate } rc_snaplevel_pgs_t; 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate struct rc_snaplevel { 4310Sstevel@tonic-gate rc_snapshot_t *rsl_parent; 4320Sstevel@tonic-gate uint32_t rsl_level_num; 4330Sstevel@tonic-gate uint32_t rsl_level_id; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate uint32_t rsl_service_id; 4360Sstevel@tonic-gate uint32_t rsl_instance_id; 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate const char *rsl_scope; 4390Sstevel@tonic-gate const char *rsl_service; 4400Sstevel@tonic-gate const char *rsl_instance; 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate rc_snaplevel_t *rsl_next; 4430Sstevel@tonic-gate }; 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate /* 4460Sstevel@tonic-gate * Client layer -- the IDs fields must be first, in order for the search 4470Sstevel@tonic-gate * routines to work correctly. 4480Sstevel@tonic-gate */ 4490Sstevel@tonic-gate enum repcache_txstate { 4500Sstevel@tonic-gate REPCACHE_TX_INIT, 4510Sstevel@tonic-gate REPCACHE_TX_SETUP, 4520Sstevel@tonic-gate REPCACHE_TX_COMMITTED 4530Sstevel@tonic-gate }; 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate typedef struct repcache_entity { 4560Sstevel@tonic-gate uint32_t re_id; 457407Sjwadams uu_avl_node_t re_link; 4580Sstevel@tonic-gate uint32_t re_changeid; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate pthread_mutex_t re_lock; 4610Sstevel@tonic-gate uint32_t re_type; 4620Sstevel@tonic-gate rc_node_ptr_t re_node; 4630Sstevel@tonic-gate enum repcache_txstate re_txstate; /* property groups only */ 4640Sstevel@tonic-gate } repcache_entity_t; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate typedef struct repcache_iter { 4670Sstevel@tonic-gate uint32_t ri_id; 468407Sjwadams uu_avl_node_t ri_link; 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate uint32_t ri_type; /* result type */ 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate pthread_mutex_t ri_lock; 4730Sstevel@tonic-gate uint32_t ri_sequence; 4740Sstevel@tonic-gate rc_node_iter_t *ri_iter; 4750Sstevel@tonic-gate } repcache_iter_t; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate typedef struct repcache_client { 4780Sstevel@tonic-gate /* 4790Sstevel@tonic-gate * constants 4800Sstevel@tonic-gate */ 4810Sstevel@tonic-gate uint32_t rc_id; /* must be first */ 4820Sstevel@tonic-gate int rc_all_auths; /* bypass auth checks */ 4830Sstevel@tonic-gate uint32_t rc_debug; /* debug flags */ 4840Sstevel@tonic-gate pid_t rc_pid; /* pid of opening process */ 4850Sstevel@tonic-gate door_id_t rc_doorid; /* a globally unique identifier */ 4860Sstevel@tonic-gate int rc_doorfd; /* our door's FD */ 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* 4895777Stw21770 * Constants used for security auditing 4905777Stw21770 * 4915777Stw21770 * rc_adt_session points to the audit session data that is used for 4925777Stw21770 * the life of the client. rc_adt_sessionid is the session ID that 4935777Stw21770 * is initially assigned when the audit session is started. See 4945777Stw21770 * start_audit_session() in client.c. This session id is used for 4955777Stw21770 * audit events except when we are processing a set of annotated 4965777Stw21770 * events. Annotated events use a separate session id so that they 4975777Stw21770 * can be grouped. See set_annotation() in client.c. 4985777Stw21770 */ 4995777Stw21770 adt_session_data_t *rc_adt_session; /* Session data. */ 5005777Stw21770 au_asid_t rc_adt_sessionid; /* Main session ID for */ 5015777Stw21770 /* auditing */ 5025777Stw21770 5035777Stw21770 /* 5040Sstevel@tonic-gate * client list linkage, protected by hash chain lock 5050Sstevel@tonic-gate */ 5060Sstevel@tonic-gate uu_list_node_t rc_link; 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate /* 5090Sstevel@tonic-gate * notification information, protected by rc_node layer 5100Sstevel@tonic-gate */ 5110Sstevel@tonic-gate rc_node_pg_notify_t rc_pg_notify; 5120Sstevel@tonic-gate rc_notify_info_t rc_notify_info; 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * client_wait output, only usable by rc_notify_thr 5160Sstevel@tonic-gate */ 5170Sstevel@tonic-gate rc_node_ptr_t rc_notify_ptr; 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate /* 520407Sjwadams * register sets, protected by rc_lock 5210Sstevel@tonic-gate */ 522407Sjwadams uu_avl_t *rc_entities; 523407Sjwadams uu_avl_t *rc_iters; 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate /* 5260Sstevel@tonic-gate * Variables, protected by rc_lock 5270Sstevel@tonic-gate */ 5280Sstevel@tonic-gate int rc_refcnt; /* in-progress door calls */ 5295777Stw21770 int rc_flags; /* see RC_CLIENT_* symbols below */ 5300Sstevel@tonic-gate uint32_t rc_changeid; /* used to make backups idempotent */ 5310Sstevel@tonic-gate pthread_t rc_insert_thr; /* single thread trying to insert */ 5320Sstevel@tonic-gate pthread_t rc_notify_thr; /* single thread waiting for notify */ 5330Sstevel@tonic-gate pthread_cond_t rc_cv; 5340Sstevel@tonic-gate pthread_mutex_t rc_lock; 5355777Stw21770 5365777Stw21770 /* 5375777Stw21770 * Per-client audit information. These fields must be protected by 5385777Stw21770 * rc_annotate_lock separately from rc_lock because they may need 5395777Stw21770 * to be accessed from rc_node.c with an entity or iterator lock 5405777Stw21770 * held, and those must be taken after rc_lock. 5415777Stw21770 */ 5425777Stw21770 int rc_annotate; /* generate annotation event if set */ 5435777Stw21770 const char *rc_operation; /* operation for audit annotation */ 5445777Stw21770 const char *rc_file; /* file name for audit annotation */ 5455777Stw21770 pthread_mutex_t rc_annotate_lock; 5460Sstevel@tonic-gate } repcache_client_t; 5475777Stw21770 5485777Stw21770 /* Bit definitions for rc_flags. */ 5490Sstevel@tonic-gate #define RC_CLIENT_DEAD 0x00000001 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate typedef struct client_bucket { 5520Sstevel@tonic-gate pthread_mutex_t cb_lock; 5530Sstevel@tonic-gate uu_list_t *cb_list; 5540Sstevel@tonic-gate char ch_pad[64 - sizeof (pthread_mutex_t) - sizeof (uu_list_t *)]; 5550Sstevel@tonic-gate } client_bucket_t; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate enum rc_ptr_type { 5580Sstevel@tonic-gate RC_PTR_TYPE_ENTITY = 1, 5590Sstevel@tonic-gate RC_PTR_TYPE_ITER 5600Sstevel@tonic-gate }; 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate typedef struct request_log_ptr { 5630Sstevel@tonic-gate enum rc_ptr_type rlp_type; 5640Sstevel@tonic-gate uint32_t rlp_id; 5650Sstevel@tonic-gate void *rlp_ptr; /* repcache_{entity,iter}_t */ 5660Sstevel@tonic-gate void *rlp_data; /* rc_node, for ENTITY only */ 5670Sstevel@tonic-gate } request_log_ptr_t; 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate #define MAX_PTRS 3 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate /* 5720Sstevel@tonic-gate * rl_start through rl_client cannot move without changing start_log() 5730Sstevel@tonic-gate */ 5740Sstevel@tonic-gate typedef struct request_log_entry { 5750Sstevel@tonic-gate hrtime_t rl_start; 5760Sstevel@tonic-gate hrtime_t rl_end; 5770Sstevel@tonic-gate pthread_t rl_tid; 5780Sstevel@tonic-gate uint32_t rl_clientid; 5790Sstevel@tonic-gate repcache_client_t *rl_client; 5800Sstevel@tonic-gate enum rep_protocol_requestid rl_request; 5810Sstevel@tonic-gate rep_protocol_responseid_t rl_response; 5820Sstevel@tonic-gate int rl_num_ptrs; 5830Sstevel@tonic-gate request_log_ptr_t rl_ptrs[MAX_PTRS]; 5840Sstevel@tonic-gate } request_log_entry_t; 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate /* 5870Sstevel@tonic-gate * thread information 5880Sstevel@tonic-gate */ 5890Sstevel@tonic-gate typedef enum thread_state { 5900Sstevel@tonic-gate TI_CREATED, 5910Sstevel@tonic-gate TI_DOOR_RETURN, 5920Sstevel@tonic-gate TI_SIGNAL_WAIT, 5930Sstevel@tonic-gate TI_MAIN_DOOR_CALL, 5940Sstevel@tonic-gate TI_CLIENT_CALL 5950Sstevel@tonic-gate } thread_state_t; 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate typedef struct thread_info { 5980Sstevel@tonic-gate pthread_t ti_thread; 5990Sstevel@tonic-gate uu_list_node_t ti_node; /* for list of all thread */ 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* 6020Sstevel@tonic-gate * per-thread globals 6030Sstevel@tonic-gate */ 6040Sstevel@tonic-gate ucred_t *ti_ucred; /* for credential lookups */ 6050Sstevel@tonic-gate int ti_ucred_read; /* ucred holds current creds */ 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate /* 6080Sstevel@tonic-gate * per-thread state information, for debuggers 6090Sstevel@tonic-gate */ 6100Sstevel@tonic-gate hrtime_t ti_lastchange; 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate thread_state_t ti_state; 6130Sstevel@tonic-gate thread_state_t ti_prev_state; 6140Sstevel@tonic-gate 6150Sstevel@tonic-gate repcache_client_t *ti_active_client; 6160Sstevel@tonic-gate request_log_entry_t ti_log; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate struct rep_protocol_request *ti_client_request; 6190Sstevel@tonic-gate repository_door_request_t *ti_main_door_request; 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate } thread_info_t; 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate /* 6240Sstevel@tonic-gate * Backend layer 6250Sstevel@tonic-gate */ 6260Sstevel@tonic-gate typedef struct backend_query backend_query_t; 6270Sstevel@tonic-gate typedef struct backend_tx backend_tx_t; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * configd.c 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate int create_connection(ucred_t *cred, repository_door_request_t *rp, 6330Sstevel@tonic-gate size_t rp_size, int *out_fd); 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate thread_info_t *thread_self(void); 6360Sstevel@tonic-gate void thread_newstate(thread_info_t *, thread_state_t); 6370Sstevel@tonic-gate ucred_t *get_ucred(void); 6380Sstevel@tonic-gate int ucred_is_privileged(ucred_t *); 6390Sstevel@tonic-gate 6405777Stw21770 adt_session_data_t *get_audit_session(void); 6415777Stw21770 6420Sstevel@tonic-gate void configd_critical(const char *, ...); 6430Sstevel@tonic-gate void configd_vcritical(const char *, va_list); 6447128Samaguire void configd_info(const char *, ...); 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate extern int is_main_repository; 6470Sstevel@tonic-gate extern int max_repository_backups; 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* 6500Sstevel@tonic-gate * maindoor.c 6510Sstevel@tonic-gate */ 6520Sstevel@tonic-gate int setup_main_door(const char *); 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate /* 6550Sstevel@tonic-gate * client.c 6560Sstevel@tonic-gate */ 6575777Stw21770 int client_annotation_needed(char *, size_t, char *, size_t); 6585777Stw21770 void client_annotation_finished(void); 6590Sstevel@tonic-gate int create_client(pid_t, uint32_t, int, int *); 6600Sstevel@tonic-gate int client_init(void); 6610Sstevel@tonic-gate int client_is_privileged(void); 6620Sstevel@tonic-gate void log_enter(request_log_entry_t *); 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* 6650Sstevel@tonic-gate * rc_node.c, backend/cache interfaces (rc_node_t) 6660Sstevel@tonic-gate */ 6670Sstevel@tonic-gate int rc_node_init(); 6680Sstevel@tonic-gate int rc_check_type_name(uint32_t, const char *); 6690Sstevel@tonic-gate 6705777Stw21770 void rc_node_ptr_free_mem(rc_node_ptr_t *); 6710Sstevel@tonic-gate void rc_node_rele(rc_node_t *); 6720Sstevel@tonic-gate rc_node_t *rc_node_setup(rc_node_t *, rc_node_lookup_t *, 6730Sstevel@tonic-gate const char *, rc_node_t *); 6740Sstevel@tonic-gate rc_node_t *rc_node_setup_pg(rc_node_t *, rc_node_lookup_t *, const char *, 6750Sstevel@tonic-gate const char *, uint32_t, uint32_t, rc_node_t *); 6760Sstevel@tonic-gate rc_node_t *rc_node_setup_snapshot(rc_node_t *, rc_node_lookup_t *, const char *, 6770Sstevel@tonic-gate uint32_t, rc_node_t *); 6780Sstevel@tonic-gate rc_node_t *rc_node_setup_snaplevel(rc_node_t *, rc_node_lookup_t *, 6790Sstevel@tonic-gate rc_snaplevel_t *, rc_node_t *); 6800Sstevel@tonic-gate int rc_node_create_property(rc_node_t *, rc_node_lookup_t *, 6810Sstevel@tonic-gate const char *, rep_protocol_value_type_t, const char *, size_t, size_t); 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate rc_node_t *rc_node_alloc(void); 6840Sstevel@tonic-gate void rc_node_destroy(rc_node_t *); 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate /* 6870Sstevel@tonic-gate * rc_node.c, client interface (rc_node_ptr_t, rc_node_iter_t) 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate void rc_node_ptr_init(rc_node_ptr_t *); 6900Sstevel@tonic-gate int rc_local_scope(uint32_t, rc_node_ptr_t *); 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate void rc_node_clear(rc_node_ptr_t *, int); 6930Sstevel@tonic-gate void rc_node_ptr_assign(rc_node_ptr_t *, const rc_node_ptr_t *); 6940Sstevel@tonic-gate int rc_node_name(rc_node_ptr_t *, char *, size_t, uint32_t, size_t *); 6950Sstevel@tonic-gate int rc_node_fmri(rc_node_ptr_t *, char *, size_t, size_t *); 6960Sstevel@tonic-gate int rc_node_parent_type(rc_node_ptr_t *, uint32_t *); 6970Sstevel@tonic-gate int rc_node_get_child(rc_node_ptr_t *, const char *, uint32_t, rc_node_ptr_t *); 6980Sstevel@tonic-gate int rc_node_get_parent(rc_node_ptr_t *, uint32_t, rc_node_ptr_t *); 6990Sstevel@tonic-gate int rc_node_get_property_type(rc_node_ptr_t *, rep_protocol_value_type_t *); 7000Sstevel@tonic-gate int rc_node_get_property_value(rc_node_ptr_t *, 7010Sstevel@tonic-gate struct rep_protocol_value_response *, size_t *); 7020Sstevel@tonic-gate int rc_node_create_child(rc_node_ptr_t *, uint32_t, const char *, 7030Sstevel@tonic-gate rc_node_ptr_t *); 7040Sstevel@tonic-gate int rc_node_create_child_pg(rc_node_ptr_t *, uint32_t, const char *, 7050Sstevel@tonic-gate const char *, uint32_t, rc_node_ptr_t *); 7060Sstevel@tonic-gate int rc_node_update(rc_node_ptr_t *); 7070Sstevel@tonic-gate int rc_node_delete(rc_node_ptr_t *); 7080Sstevel@tonic-gate int rc_node_next_snaplevel(rc_node_ptr_t *, rc_node_ptr_t *); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate int rc_node_setup_iter(rc_node_ptr_t *, rc_node_iter_t **, uint32_t, 7110Sstevel@tonic-gate size_t, const char *); 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate int rc_iter_next(rc_node_iter_t *, rc_node_ptr_t *, uint32_t); 7140Sstevel@tonic-gate int rc_iter_next_value(rc_node_iter_t *, struct rep_protocol_value_response *, 7150Sstevel@tonic-gate size_t *, int); 7160Sstevel@tonic-gate void rc_iter_destroy(rc_node_iter_t **); 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate int rc_node_setup_tx(rc_node_ptr_t *, rc_node_ptr_t *); 7190Sstevel@tonic-gate int rc_tx_commit(rc_node_ptr_t *, const void *, size_t); 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate void rc_pg_notify_init(rc_node_pg_notify_t *); 7220Sstevel@tonic-gate int rc_pg_notify_setup(rc_node_pg_notify_t *, rc_node_ptr_t *, int); 7230Sstevel@tonic-gate void rc_pg_notify_fini(rc_node_pg_notify_t *); 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate void rc_notify_info_init(rc_notify_info_t *); 7260Sstevel@tonic-gate int rc_notify_info_add_name(rc_notify_info_t *, const char *); 7270Sstevel@tonic-gate int rc_notify_info_add_type(rc_notify_info_t *, const char *); 7280Sstevel@tonic-gate int rc_notify_info_wait(rc_notify_info_t *, rc_node_ptr_t *, char *, size_t); 7290Sstevel@tonic-gate void rc_notify_info_fini(rc_notify_info_t *); 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate int rc_snapshot_take_new(rc_node_ptr_t *, const char *, 7320Sstevel@tonic-gate const char *, const char *, rc_node_ptr_t *); 7330Sstevel@tonic-gate int rc_snapshot_take_attach(rc_node_ptr_t *, rc_node_ptr_t *); 7340Sstevel@tonic-gate int rc_snapshot_attach(rc_node_ptr_t *, rc_node_ptr_t *); 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate /* 7370Sstevel@tonic-gate * file_object.c 7380Sstevel@tonic-gate */ 7390Sstevel@tonic-gate int object_fill_children(rc_node_t *); 7400Sstevel@tonic-gate int object_create(rc_node_t *, uint32_t, const char *, rc_node_t **); 7410Sstevel@tonic-gate int object_create_pg(rc_node_t *, uint32_t, const char *, const char *, 7420Sstevel@tonic-gate uint32_t, rc_node_t **); 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate int object_delete(rc_node_t *); 7450Sstevel@tonic-gate void object_free_values(const char *, uint32_t, size_t, size_t); 7460Sstevel@tonic-gate 747407Sjwadams int object_fill_snapshot(rc_snapshot_t *); 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate int object_snapshot_take_new(rc_node_t *, const char *, const char *, 7500Sstevel@tonic-gate const char *, rc_node_t **); 7510Sstevel@tonic-gate int object_snapshot_attach(rc_node_lookup_t *, uint32_t *, int); 7520Sstevel@tonic-gate 7530Sstevel@tonic-gate /* 7540Sstevel@tonic-gate * object.c 7550Sstevel@tonic-gate */ 7565777Stw21770 int object_tx_commit(rc_node_lookup_t *, tx_commit_data_t *, uint32_t *); 7575777Stw21770 7585777Stw21770 /* Functions to access transaction commands. */ 7595777Stw21770 int tx_cmd_action(tx_commit_data_t *, size_t, 7605777Stw21770 enum rep_protocol_transaction_action *); 7615777Stw21770 size_t tx_cmd_count(tx_commit_data_t *); 7625777Stw21770 int tx_cmd_nvalues(tx_commit_data_t *, size_t, uint32_t *); 7635777Stw21770 int tx_cmd_prop(tx_commit_data_t *, size_t, const char **); 7645777Stw21770 int tx_cmd_prop_type(tx_commit_data_t *, size_t, uint32_t *); 7655777Stw21770 int tx_cmd_value(tx_commit_data_t *, size_t, uint32_t, const char **); 7665777Stw21770 void tx_commit_data_free(tx_commit_data_t *); 7675777Stw21770 int tx_commit_data_new(const void *, size_t, tx_commit_data_t **); 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate /* 7700Sstevel@tonic-gate * snapshot.c 7710Sstevel@tonic-gate */ 7720Sstevel@tonic-gate int rc_snapshot_get(uint32_t, rc_snapshot_t **); 7730Sstevel@tonic-gate void rc_snapshot_rele(rc_snapshot_t *); 7740Sstevel@tonic-gate void rc_snaplevel_hold(rc_snaplevel_t *); 7750Sstevel@tonic-gate void rc_snaplevel_rele(rc_snaplevel_t *); 7760Sstevel@tonic-gate 7770Sstevel@tonic-gate /* 7780Sstevel@tonic-gate * backend.c 7790Sstevel@tonic-gate */ 7800Sstevel@tonic-gate int backend_init(const char *, const char *, int); 7817128Samaguire boolean_t backend_is_upgraded(backend_tx_t *); 7820Sstevel@tonic-gate void backend_fini(void); 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate rep_protocol_responseid_t backend_create_backup(const char *); 7856035Sstevep rep_protocol_responseid_t backend_switch(int); 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate /* 7880Sstevel@tonic-gate * call on any database inconsistency -- cleans up state as best it can, 7890Sstevel@tonic-gate * and exits with a "Database Bad" error code. 7900Sstevel@tonic-gate */ 791471Shg115875 void backend_panic(const char *, ...) __NORETURN; 7920Sstevel@tonic-gate #pragma rarely_called(backend_panic) 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate backend_query_t *backend_query_alloc(void); 7950Sstevel@tonic-gate void backend_query_append(backend_query_t *, const char *); 7960Sstevel@tonic-gate void backend_query_add(backend_query_t *, const char *, ...); 7970Sstevel@tonic-gate void backend_query_free(backend_query_t *); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate typedef int backend_run_callback_f(void *data, int columns, char **vals, 8000Sstevel@tonic-gate char **names); 8010Sstevel@tonic-gate #define BACKEND_CALLBACK_CONTINUE 0 8020Sstevel@tonic-gate #define BACKEND_CALLBACK_ABORT 1 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate backend_run_callback_f backend_fail_if_seen; /* aborts TX if called */ 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate int backend_run(backend_type_t, backend_query_t *, 8070Sstevel@tonic-gate backend_run_callback_f *, void *); 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate int backend_tx_begin(backend_type_t, backend_tx_t **); 8100Sstevel@tonic-gate int backend_tx_begin_ro(backend_type_t, backend_tx_t **); 8110Sstevel@tonic-gate void backend_tx_end_ro(backend_tx_t *); 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate enum id_space { 8140Sstevel@tonic-gate BACKEND_ID_SERVICE_INSTANCE, 8150Sstevel@tonic-gate BACKEND_ID_PROPERTYGRP, 8160Sstevel@tonic-gate BACKEND_ID_GENERATION, 8170Sstevel@tonic-gate BACKEND_ID_PROPERTY, 8180Sstevel@tonic-gate BACKEND_ID_VALUE, 8190Sstevel@tonic-gate BACKEND_ID_SNAPNAME, 8200Sstevel@tonic-gate BACKEND_ID_SNAPSHOT, 8210Sstevel@tonic-gate BACKEND_ID_SNAPLEVEL, 8220Sstevel@tonic-gate BACKEND_ID_INVALID /* always illegal */ 8230Sstevel@tonic-gate }; 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate uint32_t backend_new_id(backend_tx_t *, enum id_space); 8260Sstevel@tonic-gate int backend_tx_run_update(backend_tx_t *, const char *, ...); 8270Sstevel@tonic-gate int backend_tx_run_update_changed(backend_tx_t *, const char *, ...); 8280Sstevel@tonic-gate int backend_tx_run_single_int(backend_tx_t *tx, backend_query_t *q, 8290Sstevel@tonic-gate uint32_t *buf); 8300Sstevel@tonic-gate int backend_tx_run(backend_tx_t *, backend_query_t *, 8310Sstevel@tonic-gate backend_run_callback_f *, void *); 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate int backend_tx_commit(backend_tx_t *); 8340Sstevel@tonic-gate void backend_tx_rollback(backend_tx_t *); 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate #ifdef __cplusplus 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate #endif 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate #endif /* _CONFIGD_H */ 841